Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing centipede game(having trouble increasing length)
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Heartseed




PostPosted: Sun Jun 15, 2014 3:10 pm   Post subject: RE:Turing centipede game(having trouble increasing length)

Okay thankyou, ill try to make it then, btw do you know how I could make my end game screen less flashy and volatile ?

Code here

% Snake
% Version 6
%Im only commenting the left line of code, all the others are just repeats for different directions.


%prepare turing for graphics
setscreen ("graphics: 800;600")
View.Set ("offscreenonly")


%prepare keyboard input
var chars : array char of boolean

%music
%defines subprocess
process PlayMusic
%the command that plays the file
Music.PlayFile ("Nujabes - Aruarian Dance.mp3")
end PlayMusic

%checks if a fruit is currently present
var spawnedfruit : boolean := true

%true or false for constant snake motion
var leftflag : boolean := false
var rightflag : boolean := false
var upflag : boolean := false
var downflag : boolean := false
%fruit coordinate
var fruitX : int
var fruitY : int
%fruit random location
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)

%links snake growthX/Y
var h : int := 1
%initial snake length
var len : int := 1
%size of circles
var s : int := 8
%snake movement speed
var spd : int := 10
%fruit color
var col : int := 42
%point related stuff
%score
var score : int := 0
%how much the score increases by will vary
var point : int := 1
%the 3 highscores, if player score passes these they will replace them in the end screen
var highscore : array 1 .. 3 of int := init (9001, 80, 6)
%displays score in Font.Draw, without this there will be an synatax error
% var scoredisplay : array 1..20 of string
% scoredisplay(1) := "Your score is " + score + " congratulations, and good luck nextime"

%snake growth distancing
var gain : int := 10
%snakes body and initial length
var growthX : flexible array 1 .. len of int
var growthY : flexible array 1 .. len of int
%grows snake in length
var grow : int := upper (growthX)
%variable for zero(since a normal zero would be constant and unchanging)
var zero : int := 0
%initializes array
for i : 1 .. upper (growthX)
growthX (i) := 0
growthY (i) := 0
end for
%tracks the tail position, this helps indicate if youve made contact with the head
var taillock : flexible array 1 .. len of int
%checks if player has lost
var death : boolean := false
%map color
var mapcol : int := 0
%map
var map : int := 0
%snake/player/centipede color
var playercol : int := 0
%game fonts
var startscreenfont : int
startscreenfont := Font.New ("Arial:36")
var font : int
font := Font.New ("Arial:16")
var smalllettering : int
smalllettering := Font.New ("Arial:14")
%options menu variables
var GAMEMODE : int := 0
loop
%Startscreen
drawfillbox (0, 0, maxx, maxy, black)
Font.Draw ("Snake Game by Kevin", 75, 400, startscreenfont, white)
Font.Draw ("-The snake grows by eating fruit which also increases your score. ", 100, 250, font, white)
Font.Draw ("-If you attempt to leave the screen or bite your tail the game will end.", 100, 200, font, white)
Font.Draw ("- GOOD LUCK AND HAVE FUN !!", 100, 150, font, white)
Font.Draw ("GAMEMODES: 1 default settings, 2 mapped, 3 secret settings.", 0, 8, smalllettering, white)
View.Update
%keyboard input
Input.KeyDown (chars)
if chars ('1') then
GAMEMODE := 1
exit

elsif
chars ('2') then
GAMEMODE := 2
exit
elsif chars ('3') then
GAMEMODE := 3
exit
end if
end loop
%location of snake
var posx : int := maxx div 2
var posy : int := maxy div 2




%gamemodes
if GAMEMODE = 1
then
%for moving the snake
loop
% fork PlayMusic
%backround
drawfillbox (maxx, maxy, 0, 0, black)
%fruit
drawfilloval (fruitX, fruitY, s, s, col)
%information hud
%current score
Font.Draw("Current score:", 0, maxy - 25, font, white)
Font.Draw(intstr(score), 150, maxy - 25, font, white)
%coordinates
Font.Draw("X:",175,maxy - 25, font, white)
Font.Draw(intstr(posx),200, maxy - 25, font, white)
Font.Draw("Y:",250,maxy - 25, font, white)
Font.Draw(intstr(posy), 275, maxy - 25, font, white)
Font.Draw("Fruit:", 325, maxy - 25, font, white)
Font.Draw(intstr(fruitX), 375, maxy - 25, font, white)
Font.Draw("/", 415, maxy - 25, font, white)
Font.Draw(intstr(fruitY), 420, maxy - 25, font, white)
View.Update
% put "coordinates ", posx, " ", posy, " ", whatdotcolour (posx, posy)
%get keyboard input
Input.KeyDown (chars)

%determines direction pressed
if chars (KEY_LEFT_ARROW) and rightflag = false then
leftflag := true
rightflag := false
upflag := false
downflag := false

elsif chars (KEY_RIGHT_ARROW) and leftflag = false then
leftflag := false
rightflag := true
upflag := false
downflag := false

elsif chars (KEY_DOWN_ARROW) and upflag = false then
leftflag := false
rightflag := false
upflag := false
downflag := true

elsif chars (KEY_UP_ARROW) and downflag = false then
leftflag := false
rightflag := false
upflag := true
downflag := false

end if

if leftflag = true then
posx := posx - 2
end if

%ends game if player makes contact with itself
if whatdotcolour (posx, posy) = playercol then
death := true
%ends game if head leaves visible area
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
%when snake makes contact with fruit
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
%new random location for fruit
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
%adds points to previous score
score := score + point
%draws fruit
drawfilloval (fruitX, fruitY, s, s, col)
%zero keeps track of current size as the grow grows the snake, this is so the snake will grow the conssistently for each fruit
zero := grow
%gain is how much the snake will grow by, this just grows the snake
grow := grow + gain
%the new grow value increases thus adding growing the snake from its previous size in the flexible array
new growthX, grow
new growthY, grow
%the new array values become 0, this is so the snake can continue to grow within the flexible array
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if





if rightflag = true then
posx := posx + 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if upflag = true then
posy := posy + 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if downflag = true then
posy := posy - 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if
end if








%snake head
drawfilloval (posx, posy, s, s, playercol)
%snake body, this moves the snake
for decreasing i : upper (growthX) .. 2
growthX (i) := growthX (i - 1)
growthY (i) := growthY (i - 1)
drawfilloval (growthX (i), growthY (i), s, s, playercol)
end for
growthX (h) := posx
growthY (h) := posy
View.Update
delay (spd)

%checks if player has lost
if death = true then

Text.Color (playercol)
%displays the score
Font.Draw ("Your Score Was:", 0, 25, startscreenfont, white)
Font.Draw (intstr(score), maxx div 2, 0, startscreenfont, white)
View.Update
%changes high scores
if score > highscore (1) then %changes high scores
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, white)
highscore (3) := highscore (2)
highscore (2) := highscore (1)
highscore (1) := score
elsif score > highscore (2) then
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, white)
highscore (3) := highscore (2)
highscore (2) := score
elsif score > highscore (3) then
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, white)
highscore (3) := score
end if
%displays highscores
Font.Draw ("The top 3 scores are:", 8, 500, startscreenfont, white)
Font.Draw (intstr (highscore (1)), 500, 500, startscreenfont, white)
Font.Draw (intstr (highscore (2)), 500, 450, startscreenfont, white)
Font.Draw (intstr (highscore (3)), 500, 400, startscreenfont, white)

View.Update

end if


end loop
%checks if second gamemode was selected
elsif GAMEMODE = 2 then
%gameplay adjustments
playercol := 7
spd := 8
len := 80
gain := 16

%for moving the snake
loop
% fork PlayMusic
%backround
drawfillbox (maxx, maxy, 0, 0, white)
%fruit
drawfilloval (fruitX, fruitY, s, s, col)
%score

%get keyboard input
Input.KeyDown (chars)

%determines direction pressed
if chars (KEY_LEFT_ARROW) and rightflag = false then
leftflag := true
rightflag := false
upflag := false
downflag := false

elsif chars (KEY_RIGHT_ARROW) and leftflag = false then
leftflag := false
rightflag := true
upflag := false
downflag := false

elsif chars (KEY_DOWN_ARROW) and upflag = false then
leftflag := false
rightflag := false
upflag := false
downflag := true

elsif chars (KEY_UP_ARROW) and downflag = false then
leftflag := false
rightflag := false
upflag := true
downflag := false

end if

if leftflag = true then
posx := posx - 2
end if

%ends game if player makes contact with itself
if whatdotcolour (posx, posy) = playercol then
death := true
%ends game if head leaves visible area
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
%when snake makes contact with fruit
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
%new random location for fruit
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
%adds points to previous score
score := score + point
%draws fruit
drawfilloval (fruitX, fruitY, s, s, col)
%zero keeps track of current size as the grow grows the snake, this is so the snake will grow the conssistently for each fruit
zero := grow
%gain is how much the snake will grow by, this just grows the snake
grow := grow + gain
%the new grow value increases thus adding growing the snake from its previous size in the flexible array
new growthX, grow
new growthY, grow
%the new array values become 0, this is so the snake can continue to grow within the flexible array
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if





if rightflag = true then
posx := posx + 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if upflag = true then
posy := posy + 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if downflag = true then
posy := posy - 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if
end if








%snake head
drawfilloval (posx, posy, s, s, playercol)

%snake body, this moves the snake
for decreasing i : upper (growthX) .. 2
growthX (i) := growthX (i - 1)
growthY (i) := growthY (i - 1)
drawfilloval (growthX (i), growthY (i), s, s, playercol)
end for
growthX (h) := posx
growthY (h) := posy
View.Update
delay (spd)
cls
%checks if player has lost
if death = true then
Text.Color (playercol)
Text.ColorBack (black)



end if


end loop


end if
Sponsor
Sponsor
Sponsor
sponsor
Heartseed




PostPosted: Sun Jun 15, 2014 3:39 pm   Post subject: RE:Turing centipede game(having trouble increasing length)

For my 2d array could I do this ?

Code

var taillock : flexible array 0..maxx, 0..maxy of int
Insectoid




PostPosted: Sun Jun 15, 2014 4:28 pm   Post subject: RE:Turing centipede game(having trouble increasing length)

That will only really work if your centipede parts are 1 pixel by 1 pixel. You can do it with larger centipede parts too, but it takes a wee bit more work.
Heartseed




PostPosted: Sun Jun 15, 2014 4:33 pm   Post subject: RE:Turing centipede game(having trouble increasing length)

They are by 10, since my screen is 800;600 (default), should I go with 80 and 60 then ?
Heartseed




PostPosted: Sun Jun 15, 2014 4:39 pm   Post subject: RE:Turing centipede game(having trouble increasing length)

I dont understand how to do the the 2d array, is there an example program that has a similar application as this ?
Can someone help me with this please I dont know how to keep track of the tail.

My game thus far.

Code

% Snake
% Version 6
%Im only commenting the left line of code, all the others are just repeats for different directions.


%prepare turing for graphics
setscreen ("graphics: 800;600")
View.Set ("offscreenonly")


%prepare keyboard input
var chars : array char of boolean

%music
%defines subprocess
process PlayMusic
%the command that plays the file
Music.PlayFile ("Nujabes - Aruarian Dance.mp3")
end PlayMusic

%checks if a fruit is currently present
var spawnedfruit : boolean := true

%true or false for constant snake motion
var leftflag : boolean := false
var rightflag : boolean := false
var upflag : boolean := false
var downflag : boolean := false
%fruit coordinate
var fruitX : int
var fruitY : int
%fruit random location
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)

%links snake growthX/Y
var h : int := 1
%initial snake length
var len : int := 1
%size of circles
var s : int := 8
%snake movement speed
var spd : int := 10
%fruit color
var col : int := 42
%point related stuff
%score
var score : int := 0
%how much the score increases by will vary
var point : int := 1
%the 3 highscores, if player score passes these they will replace them in the end screen
var highscore : array 1 .. 3 of int := init (9001, 80, 6)
%displays score in Font.Draw, without this there will be an synatax error
% var scoredisplay : array 1..20 of string
% scoredisplay(1) := "Your score is " + score + " congratulations, and good luck nextime"

%snake growth distancing
var gain : int := 10
%snakes body and initial length
var growthX : flexible array 1 .. len of int
var growthY : flexible array 1 .. len of int
%grows snake in length
var grow : int := upper (growthX)
%variable for zero(since a normal zero would be constant and unchanging)
var zero : int := 0
%initializes array
for i : 1 .. upper (growthX)
growthX (i) := 0
growthY (i) := 0
end for
%since whatdotcolor is evil this 2 dimentional array grid tracks the tail position, this helps indicate if youve made contact with the head
var taillock : flexible array 0..80, 0..60 of int
%sets grid values, these values are small or else the array subscript becomes out of range
for x : 0 .. 80
for y : 0 .. 60
taillock (x, y) := 0
end for
end for
for x : 0 .. maxx
taillock (x, 0) := 1
taillock (x, 80) := 1
end for
for y : 0 .. maxy
taillock (0, y) := 1
taillock (60, y) := 1
end for


%checks if player has lost
var death : boolean := false

%snake/player/centipede color
var playercol : int := 0
%game fonts
var startscreenfont : int
startscreenfont := Font.New ("Arial:36")
var font : int
font := Font.New ("Arial:16")
var smalllettering : int
smalllettering := Font.New ("Arial:14")

%options menu variables
var GAMEMODE : int := 0
loop

%Startscreen
drawfillbox (0, 0, maxx, maxy, black)
Font.Draw ("Snake Game by Kevin", 75, 400, startscreenfont, white)
Font.Draw ("-The snake grows by eating fruit which also increases your score. ", 100, 250, font, white)
Font.Draw ("-If you attempt to leave the screen or bite your tail the game will end.", 100, 200, font, white)
Font.Draw ("- GOOD LUCK AND HAVE FUN !!", 100, 150, font, white)
Font.Draw ("GAMEMODES: 1 default settings, 2 mapped, 3 secret settings.", 0, 8, smalllettering, white)
View.Update
%keyboard input
Input.KeyDown (chars)
if chars ('1') then
GAMEMODE := 1
exit

elsif
chars ('2') then
GAMEMODE := 2
exit
elsif chars ('3') then
GAMEMODE := 3
exit
end if
end loop
%location of snake
var posx : int := maxx div 2
var posy : int := maxy div 2




%gamemodes
if GAMEMODE = 1
then
%for moving the snake
loop
% fork PlayMusic
%backround
drawfillbox (maxx, maxy, 0, 0, black)
%fruit
drawfilloval (fruitX, fruitY, s, s, col)
%information hud
%current score
Font.Draw("Current score:", 0, maxy - 25, font, white)
Font.Draw(intstr(score), 150, maxy - 25, font, white)
%coordinates
Font.Draw("X:",175,maxy - 25, font, white)
Font.Draw(intstr(posx),200, maxy - 25, font, white)
Font.Draw("Y:",250,maxy - 25, font, white)
Font.Draw(intstr(posy), 275, maxy - 25, font, white)
Font.Draw("Fruit:", 325, maxy - 25, font, white)
Font.Draw(intstr(fruitX), 375, maxy - 25, font, white)
Font.Draw("/", 415, maxy - 25, font, white)
Font.Draw(intstr(fruitY), 420, maxy - 25, font, white)
View.Update
%get keyboard input
Input.KeyDown (chars)

%determines direction pressed
if chars (KEY_LEFT_ARROW) and rightflag = false then
leftflag := true
rightflag := false
upflag := false
downflag := false

elsif chars (KEY_RIGHT_ARROW) and leftflag = false then
leftflag := false
rightflag := true
upflag := false
downflag := false

elsif chars (KEY_DOWN_ARROW) and upflag = false then
leftflag := false
rightflag := false
upflag := false
downflag := true

elsif chars (KEY_UP_ARROW) and downflag = false then
leftflag := false
rightflag := false
upflag := true
downflag := false

end if

if leftflag = true then
posx := posx - 2
end if

%chekcs if player made contact with tail

for c : 2 .. upper (growthX)
if taillock (posx - 1, posx) = taillock (growthX (c), growthY (c)) then
death := true
end if
end for
%ends game if head leaves visible area
if posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
%when snake makes contact with fruit
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
%new random location for fruit
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
%adds points to previous score
score := score + point
%draws fruit
drawfilloval (fruitX, fruitY, s, s, col)
%zero keeps track of current size as the grow grows the snake, this is so the snake will grow the conssistently for each fruit
zero := grow
%gain is how much the snake will grow by, this just grows the snake
grow := grow + gain
%the new grow value increases thus adding growing the snake from its previous size in the flexible array
new growthX, grow
new growthY, grow
%the new array values become 0, this is so the snake can continue to grow within the flexible array
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if





if rightflag = true then
posx := posx + 2
for c : 2 .. upper (growthX)
if taillock (posx - 1, posx) = taillock (growthX (c), growthY (c)) then
death := true
end if
end for
if posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if upflag = true then
posy := posy + 2
end if
for c : 2 .. upper (growthX)
if taillock (posx - 1, posx) = taillock (growthX (c), growthY (c)) then
death := true
end if
end for
if posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true


elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

if downflag = true then
posy := posy - 2
for c : 2 .. upper (growthX)
if taillock (posx - 1, posx) = taillock (growthX (c), growthY (c)) then
death := true
end if
end for
if posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if
end if








%snake head
drawfilloval (posx, posy, s, s, playercol)
%snake body, this moves the snake
for decreasing i : upper (growthX) .. 2
growthX (i) := growthX (i - 1)
growthY (i) := growthY (i - 1)
drawfilloval (growthX (i), growthY (i), s, s, playercol)
end for
growthX (h) := posx
growthY (h) := posy
View.Update
delay (spd)

%checks if player has lost
if death = true then

Text.Color (playercol)
%displays the score
Font.Draw ("Your Score Was:", 0, 25, startscreenfont, white)
Font.Draw (intstr(score), maxx div 2, 0, startscreenfont, white)
View.Update
%changes high scores
if score > highscore (1) then %changes high scores
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, white)
highscore (3) := highscore (2)
highscore (2) := highscore (1)
highscore (1) := score
elsif score > highscore (2) then
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, white)
highscore (3) := highscore (2)
highscore (2) := score
elsif score > highscore (3) then
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, white)
highscore (3) := score
end if
%displays highscores
Font.Draw ("The top 3 scores are:", 8, 500, startscreenfont, white)
Font.Draw (intstr (highscore (1)), 500, 500, startscreenfont, white)
Font.Draw (intstr (highscore (2)), 500, 450, startscreenfont, white)
Font.Draw (intstr (highscore (3)), 500, 400, startscreenfont, white)

View.Update

end if


end loop
%checks if second gamemode was selected
elsif GAMEMODE = 2 then
%gameplay adjustments
playercol := 7
spd := 5

%for moving the snake
loop
% fork PlayMusic
%backround
drawfillbox (maxx, maxy, 0, 0, white)
%fruit
drawfilloval (fruitX, fruitY, s, s, col)
%score
%information hud
%current score
Font.Draw("Current score:", 0, maxy - 25, font, black)
Font.Draw(intstr(score), 150, maxy - 25, font, black)
%coordinates
Font.Draw("X:",175,maxy - 25, font, black)
Font.Draw(intstr(posx),200, maxy - 25, font, black)
Font.Draw("Y:",250,maxy - 25, font, white)
Font.Draw(intstr(posy), 275, maxy - 25, font, black)
Font.Draw("Fruit:", 325, maxy - 25, font, black)
Font.Draw(intstr(fruitX), 375, maxy - 25, font, black)
Font.Draw("/", 415, maxy - 25, font, white)
Font.Draw(intstr(fruitY), 420, maxy - 25, font, black)
View.Update
%get keyboard input
Input.KeyDown (chars)

%determines direction pressed
if chars (KEY_LEFT_ARROW) and rightflag = false then
leftflag := true
rightflag := false
upflag := false
downflag := false

elsif chars (KEY_RIGHT_ARROW) and leftflag = false then
leftflag := false
rightflag := true
upflag := false
downflag := false

elsif chars (KEY_DOWN_ARROW) and upflag = false then
leftflag := false
rightflag := false
upflag := false
downflag := true

elsif chars (KEY_UP_ARROW) and downflag = false then
leftflag := false
rightflag := false
upflag := true
downflag := false

end if

if leftflag = true then
posx := posx - 2
end if

%ends game if player makes contact with itself
if whatdotcolour (posx, posy) = playercol then
death := true
%ends game if head leaves visible area
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
%when snake makes contact with fruit
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
%new random location for fruit
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
%adds points to previous score
score := score + point
%draws fruit
drawfilloval (fruitX, fruitY, s, s, col)
%zero keeps track of current size as the grow grows the snake, this is so the snake will grow the conssistently for each fruit
zero := grow
%gain is how much the snake will grow by, this just grows the snake
grow := grow + gain
%the new grow value increases thus adding growing the snake from its previous size in the flexible array
new growthX, grow
new growthY, grow
%the new array values become 0, this is so the snake can continue to grow within the flexible array
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if





if rightflag = true then
posx := posx + 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if upflag = true then
posy := posy + 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if

end if
if downflag = true then
posy := posy - 2
if whatdotcolour (posx, posy) = playercol then
death := true
elsif posx < 0 or posx > maxx or posy < 0 or posy > maxy then
death := true
elsif sqrt ((posx - fruitX) ** 2 + (posy - fruitY) ** 2) <= 2 * s then
randint (fruitX, 25, maxx - 25)
randint (fruitY, 25, maxy - 25)
score := score + 1
drawfilloval (fruitX, fruitY, s, s, col)
zero := grow
grow := grow + gain
new growthX, grow
new growthY, grow
for i : zero + 1 .. grow
growthX (i) := 0
growthY (i) := 0
end for
end if
end if








%snake head
drawfilloval (posx, posy, s, s, playercol)

%snake body, this moves the snake
for decreasing i : upper (growthX) .. 2
growthX (i) := growthX (i - 1)
growthY (i) := growthY (i - 1)
drawfilloval (growthX (i), growthY (i), s, s, playercol)
end for
growthX (h) := posx
growthY (h) := posy
View.Update
delay (spd)
cls
%checks if player has lost
if death = true then

Text.Color (playercol)
%displays the score
Font.Draw ("Your Score Was:", 0, 25, startscreenfont, black)
Font.Draw (intstr(score), maxx div 2, 0, startscreenfont, black)
View.Update
%changes high scores
if score > highscore (1) then %changes high scores
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, black)
highscore (3) := highscore (2)
highscore (2) := highscore (1)
highscore (1) := score
elsif score > highscore (2) then
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, black)
highscore (3) := highscore (2)
highscore (2) := score
elsif score > highscore (3) then
Font.Draw ("High Score!", maxx div 2, maxy div 2, startscreenfont, black)
highscore (3) := score
end if
%displays highscores
Font.Draw ("The top 3 scores are:", 8, 500, startscreenfont, black)
Font.Draw (intstr (highscore (1)), 500, 500, startscreenfont, black)
Font.Draw (intstr (highscore (2)), 500, 450, startscreenfont, black)
Font.Draw (intstr (highscore (3)), 500, 400, startscreenfont, black)

View.Update


end if


end loop


end if
Srlancelot39




PostPosted: Mon Jun 16, 2014 10:44 am   Post subject: RE:Turing centipede game(having trouble increasing length)

My username was originally used for an online game, and I ended up using it for other accounts like this one Razz

Remember to use code tags. Your code is near impossible to read when it is in regular text form as it is.

The end(s) of the tail will always be moved to the position of the part of the tail that is ahead of it. This can be done very easily when you use an array.
Heartseed




PostPosted: Mon Jun 16, 2014 5:12 pm   Post subject: RE:Turing centipede game(having trouble increasing length)

Code tags, all I did was put code before pasting in my code, am I supposed to do something else ?
Dreadnought




PostPosted: Mon Jun 16, 2014 7:34 pm   Post subject: Re: Turing centipede game(having trouble increasing length)

If you do this
code:
[syntax="Turing"]
...
awesome code here
...
[/syntax]


Then your code will look like this
Turing:
var awesome : string := "This code is awesome"
% Comments are awesome too!
put awesome
Sponsor
Sponsor
Sponsor
sponsor
Srlancelot39




PostPosted: Mon Jun 16, 2014 11:06 pm   Post subject: Re: Turing centipede game(having trouble increasing length)

End Game Screen:
It is flashing because you do not end the game; the playing screen and end game screen are being displayed simultaneously.

2D Array:
Yes, if you want to maintain the size of 10, then you could use 80 and 60 as your array size. As Insectoid said though, you would need to do a bit of add work to "redefine" your "pixels" (snake segments) as being 10 wide.
Part of this extra work would be making your snake move by 10 pixels at a time. You would be drawing the segments at x*10-5, and y*10-5, where x and y are values from 1 to 80 and 60 respectively. The subtraction of 5 is so that you draw the circles at the centre point of the divisions of 80 and 60, since the drawfilloval command draws the shape relative to its centre.

EDIT: Using a diameter of 10 for the snake and having 80 positions across and 60 high on an 800x600 resolution will work fine, however, the segments of your snake will be drawn end to end and not overlap like they do now to appear as a solid line. To make the above appear as a line, you would need to either use 160 and 120 as you array dimensions, or simply draw circles with diameter of 20 instead of 10 (all calculations would stay the same).
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 24 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: