| Immediate Help needed with snake game!!!! Please!!!! 
 
	 
	
		| Author | Message |   
		| kytes5 
 
 
 
 
 | 
			
				|  Posted: Mon May 05, 2008 8:42 pm    Post subject: Immediate Help needed with snake game!!!! Please!!!! |  |   
				| 
 |  
				| im trying to make a snake game. i have done as much as i can upto the part where when the snake eats the apple, it pops up in a new spot
 but im having trouble getting the snake to grow
 all the part of the code that is in red, is what i tryed to do to make the snake grow
 could someone please tell me what im doing wrong and tell the correct code that would work with my program?
 i would greatly appreciate it
 
 
 
 
 
 
 import GUI
 const LEFT_ARROW := chr (203)
 const RIGHT_ARROW := chr (205)
 const UP_ARROW := chr (200)
 const DOWN_ARROW := chr (208)
 
 var BLOCKER_ROW := 12
 var ss1, ss2 : int
 var Blocker_Column := 38
 var Key : string (1)
 var x2, y2 : int
 var x1, y1 : int
 var sq1, sq2, ssq1, ssq2 : int
 var diff : int
 var U, R, L, D : int := 0
 var score : int := 0
 var arrows : array char of boolean
 ss1 := 20
 ss2 := 20
 x2 := ss1
 y2 := ss2
 sq1 := ss1
 sq2 := ss2
 ssq1 := ss1
 ssq2 := ss2
 
 setscreen ("graphics")
 setscreen ("nocursor")
 colourback (green)
 randint (x1, 15, maxx - 15)
 randint (y1, 15, maxy - 15)
 procedure game
 cls
 loop
 drawbox (10, 10, maxx - 10, maxy - 10, brightgreen)
 
 
 drawfillbox (x2, y2, x2 + 10, y2 + 10, green)
 drawfillbox (ss1, ss2, ss1 + 10, ss2 + 10, black)
 
 
 
 x2 := ss1
 y2 := ss2
 delay (50)
 Input.KeyDown (arrows)
 locate (BLOCKER_ROW, Blocker_Column)
 if arrows (KEY_RIGHT_ARROW) then
 L := 0
 D := 0
 R := 1
 U := 0
 elsif arrows (KEY_LEFT_ARROW) then
 L := 1
 D := 0
 R := 0
 U := 0
 elsif arrows (KEY_DOWN_ARROW) then
 L := 0
 D := 1
 R := 0
 U := 0
 elsif arrows (KEY_UP_ARROW) then
 L := 0
 D := 0
 R := 0
 U := 1
 end if
 
 if U = 1 then
 ss2 := ss2 + 10
 elsif R = 1 then
 ss1 := ss1 + 10
 elsif D = 1 then
 ss2 := ss2 - 10
 elsif L = 1 then
 ss1 := ss1 - 10
 
 end if
 
 if ss1 >= maxx - 10 then
 exit
 elsif ss1 < 1 then
 exit
 elsif ss2 >= maxy - 10 then
 exit
 elsif ss2 < 1 then
 exit
 end if
 drawfilloval (x1, y1, 5, 5, brightred)
 if ss1 > x1 - 10 and ss1 < x1 + 10 and ss2 > y1 - 10 and ss2 < y1 + 10 then
 drawfilloval (x1, y1, 5, 5, green)
 x1 := Rand.Int (10, maxx - 15)
 y1 := Rand.Int (10, maxy - 15)
 score := score + 10
 end if
 drawfillbox (sq1, sq2, sq1 + 10, sq2 + 10, black)
 if ss1 > x1 - 10 and ss1 < x1 + 10 and ss2 > y1 - 10 and ss2 < y1 + 10 then
 drawfillbox (ssq1, ssq2, ssq1 + 10, ssq2 + 10, green)
 end if
 end loop
 
 cls
 locate (12, 35)
 put "GAME OVER"
 put "your score was ", score
 end game
 var button1 : int := GUI.CreateButton (200, 200, 200, "Play Game", game)
 
 loop
 exit when GUI.ProcessEvent
 end loop
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| Asherel 
 
  
 
 
 | 
			
				|  Posted: Tue May 06, 2008 6:20 am    Post subject: Re: Immediate Help needed with snake game!!!! Please!!!! |  |   
				| 
 |  
				| Suggestion, do NOT use GUI. It's never nice to use it. You can create your own buttons instead that work better then GUI. 
 Also, if you still need your snake to grow, take out your X2 Variable of the Snake and replace it with another variable. Lets say, ss3.
 
 With the way you have it, and they way I suggested it, you are affecting two variables if you increase it by an increment. Swapping out the ss1 + 10 for ss3 you can now effect only one variable, and have it grow the way you want.
 
 I'm guessing your collision is working right now. Can't use the other machine until later. However you will want to do this.
 
 
 	  | Turing: |  	  | 
const LEFT_ARROW := chr (203) 
const  RIGHT_ARROW := chr (205) 
const  UP_ARROW := chr (200) 
const  DOWN_ARROW := chr (208) 
var  BLOCKER_ROW := 12 
var  ss1, ss2, ss3 : int 
var  Blocker_Column := 38 
var  Key : string (1) 
var  x2, y2 : int 
var  x1, y1 : int 
var  sq1, sq2, ssq1, ssq2 : int 
var  diff : int 
var  U, R, L, D : int := 0 
var  score : int := 0 
var  arrows : array char of boolean 
ss1 := 20 
ss2 := 20 
ss3 := 30
setscreen ("graphics") 
setscreen ("nocursor") 
colourback (green) 
randint ( x1, 15 , maxx  - 15) 
randint ( y1, 15 , maxy  - 15) 
procedure  game 
cls 
loop 
drawbox (10 , 10 , maxx  - 10 , maxy  - 10 , brightgreen) 
drawfillbox ( x2, y2, x2 + 10 , y2 + 10 , green) 
drawfillbox ( ss1, ss2, ss3 ,  ss2 + 10 , black) 
delay (50) 
Input.KeyDown ( arrows) 
locate ( BLOCKER_ROW, Blocker_Column) 
if  arrows (KEY_RIGHT_ARROW) then 
L := 0 
D := 0 
R := 1 
U := 0 
elsif  arrows (KEY_LEFT_ARROW) then 
L := 1 
D := 0 
R := 0 
U := 0 
elsif  arrows (KEY_DOWN_ARROW) then 
L := 0 
D := 1 
R := 0 
U := 0 
elsif  arrows (KEY_UP_ARROW) then 
L := 0 
D := 0 
R := 0 
U := 1 
end if 
if  U = 1 then 
ss2 :=  ss2 + 10 
elsif  R = 1 then 
ss1 :=  ss1 + 10 
elsif  D = 1 then 
ss2 :=  ss2 - 10 
elsif  L = 1 then 
ss1 :=  ss1 - 10 
end if 
if  ss1 >= maxx  - 10 then 
exit 
elsif  ss1 < 1 then 
exit 
elsif  ss2 >= maxy  - 10 then 
exit 
elsif  ss2 < 1 then 
exit 
end if 
drawfilloval ( x1, y1, 5 , 5 , brightred) 
if  ss1 > x1 - 10 and  ss1 < x1 + 10 and  ss2 > y1 - 10 and  ss2 < y1 + 10 then 
drawfilloval ( x1, y1, 5 , 5 , green) 
x1 :=  Rand.Int (10 , maxx  - 15) 
y1 :=  Rand.Int (10 , maxy  - 15) 
score :=  score + 10 
end if 
    drawfillbox ( sq1, sq2, sq1 + 10 , sq2 + 10 , black) 
      if  ss1 > x1 - 10 and  ss1 < x1 + 10 and  ss2 > y1 - 10 and  ss2 < y1 + 10 then 
          ss3 += 5
     end if 
end loop 
cls 
locate (12 , 35) 
put "GAME OVER" 
put "your score was ",  score 
end  game 
 
game
 | 
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| kytes5 
 
 
 
 
 | 
			
				|  Posted: Tue May 06, 2008 7:36 am    Post subject: Re: Immediate Help needed with snake game!!!! Please!!!! |  |   
				| 
 |  
				| that doesnt work, the snake is now just a huge black line, you are getting it to grow the box, not make another box after it |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |