Snake Growing
Author |
Message |
Mr. T
![](http://www.madpaintballer.com/images/purepwnage.gif)
|
Posted: Sat Mar 19, 2005 12:44 am Post subject: Snake Growing |
|
|
Any ideas how i would go about making my snake grow?
(im using drawfilloval for my snake, not drawfillbox) |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Sat Mar 19, 2005 1:32 am Post subject: (No subject) |
|
|
flexible arrays |
|
|
|
|
![](images/spacer.gif) |
Mr. T
![](http://www.madpaintballer.com/images/purepwnage.gif)
|
Posted: Sat Mar 19, 2005 1:33 am Post subject: (No subject) |
|
|
elaborate. |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Sat Mar 19, 2005 1:38 am Post subject: (No subject) |
|
|
code: | var snake:flexible array 1..1 of %#for peice of snake
record
x,y,:int %location of the peice
end record
loop %main loop
move snake
blah blah
if eaten food then
new snake,upper(snake)+1
upper(snake).x=newpeiceplacement
upper(snake).y=newpeiceplacement
end if
blah blah
end loop | ... ya kinda like that lol, except with accual code, hopefully you get the idea i mean |
|
|
|
|
![](images/spacer.gif) |
Mr. T
![](http://www.madpaintballer.com/images/purepwnage.gif)
|
Posted: Sat Mar 19, 2005 1:40 am Post subject: (No subject) |
|
|
i dont understand what upper and .x or .y mean? |
|
|
|
|
![](images/spacer.gif) |
Bacchus
![](http://img104.exs.cx/img104/9206/ravenmoon12ns.jpg)
|
Posted: Sat Mar 19, 2005 1:47 am Post subject: (No subject) |
|
|
the upper() function is used to just get the upper bounds of the flexible array. so i was doing:
new snake,upper(snake)+1
the "new snake" part is refering to the flexible array "snake" and teling turing that im going to set a new upper bound for it which will be after the coma(,) the "upper(snake)+1" part is saying the upper bounds of "snake" (which was 1) plus 1 (so it becomes 2) so then the flexible array is then set to 1..2 instead of 1..1 the .x and .y part is a record (read the tutorial) it lets you create a typeSpec that can be used (tutorial explains better). in the crappy non-code thing i did was just saying use a flexible array and when you have to create a new peice, set the upper bound of the array one more and then set the variables accordinly. that way when you draw it you can just do:
code: | for i:1..upper(snake)
drawfilloval(snake(i).x,snake(i).y,5,5,7)
end for |
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Sat Mar 19, 2005 8:52 am Post subject: (No subject) |
|
|
Read tutorials on flexible arrays and records, Pwned. Both are pretty well necessary to making snake.
As for actually moving each segment of the snake, here's how you do it. You want to move the last segment of the snake into the position of the second last segment. Then, move the second last segment into the position of the third last segment. Continue this process until you've moved the second segment to the position of the first segment, or head. Then, move the first segment, or head, in the direction that the snake is going. This is all done very easily with records (you can assign a whole record to another record of a matching type. So, segments (3) := segments (3). Instead of segments (4).x = segments (3).x ; segments (4).y := segments (3).y. Also, it's easy to do with a decreasing for loop)
Hopefully, after you read the tutorials, then re-read this, you'l be able to do it.
Cheers |
|
|
|
|
![](images/spacer.gif) |
|
|