• Announcements

Archived

This topic is now archived and is closed to further replies.

centipede like movement

Recommended Posts

I have been attempting to write this script that moves like the game centipede or nibbles from back in the Qbasic days. My dilemmas is that I am attempting to move these boxes less than the dimensions of the boxes. The boxes 3 dimensional dimensions are 10 X 10 X 10. Because I¡¦m attempting to move it less than 10 pixels per increment it is creating a very difficult problem. If I did move the boxes ten units every time then I could just write an array Store the positions of the boxes and just pass them to the other every time threw the loop. I would like to not move a unit less than or equal to the dimensions of the boxes. This is what my algorithm look like. I initialize an array that stores the boxes position in reference to each other, example if the lead box is to the right then I store an ¡§r¡¨ in the first position of array, etc. Then I compare the array called old position if this array is different from current position array that stores, right, left, up etc. Then adjust the boxes positions based upon the letter in the array. Save this new position array in old position array. It doesn¡¦t work. The code is written in lingo 8.5 please help. on exitframe me --moving the box if keypressed(123) then place_box.translate (-speed,0,0) end if--left if keypressed(124) then place_box.translate (speed,0,0) end if -- right if keypressed(125) then place_box.translate (0,-speed,0) end if --down if keypressed(126) then place_box.translate (0,speed,0) end if --up -- this will move the boxes and check to see if the array --is different repeat with ii = 0 to (totalbox-1) if member(5).model("box" & (ii+1)).transform.position.y < member(5).model("box" & ii).transform.position.y and abs (member(5).model("box" & (ii+1)).transform.position.y - member(5).model("box" & ii).transform.position.y) > 11.5 then -- vec="up" update_pos (me) member(5).model("box" & (ii+1)).transform.position.y=member(5).model("box" & ii).transform.position.y-11.5 else if member(5).model("box" & (ii+1)).transform.position.y > member(5).model("box" & ii).transform.position.y and abs (member(5).model("box" & (ii+1)).transform.position.y - member(5).model("box" & ii).transform.position.y) > 11.5 then ƒÞ vec="down" ƒÞ update_pos (me) member(5).model("box" & (ii+1)).transform.position.y=member(5).model("box" & ii).transform.position.y+11.5 else if member(5).model("box" & (ii+1)).transform.position.x < member(5).model("box" & ii).transform.position.x and abs (member(5).model("box" & (ii+1)).transform.position.x - member(5).model("box" & ii).transform.position.x) > 11.5 then ƒÞ vec="right" ƒÞ update_pos (me) member(5).model("box" & (ii+1)).transform.position.x = member(5).model("box" & ii).transform.position.x - 11.5 else if member(5).model("box" & (ii+1)).transform.position.x > member(5).model("box" & ii).transform.position.x and abs (member(5).model("box" & (ii+1)).transform.position.x - member(5).model("box" & ii).transform.position.x) > 11.5 then --vec="left" update_pos (me) member(5).model("box" & (ii+1)).transform.position.x = member(5).model("box" & ii).transform.position.x + 11.5 end if end repeat end on update_pos me --this clear the array pos pos.deleteall() repeat with ii = 0 to (totalbox-1) if member(5).model("box" & (ii+1)).transform.position.y < member(5).model("box" & ii).transform.position.y and abs (member(5).model("box" & (ii+1)).transform.position.y - member(5).model("box" & ii).transform.position.y) > 10 then -- vec="u" pos.addat((ii+1),"u") else if member(5).model("box" & (ii+1)).transform.position.y > member(5).model("box" & ii).transform.position.y and abs (member(5).model("box" & (ii+1)).transform.position.y - member(5).model("box" & ii).transform.position.y) > 10 then --vec="d" pos.addat((ii+1),"d") else if member(5).model("box" & (ii+1)).transform.position.x < member(5).model("box" & ii).transform.position.x and abs (member(5).model("box" & (ii+1)).transform.position.x - member(5).model("box" & ii).transform.position.x) > 10 then --vec="r" pos.addat((ii+1),"r") else if member(5).model("box" & (ii+1)).transform.position.x > member(5).model("box" & ii).transform.position.x and abs (member(5).model("box" & (ii+1)).transform.position.x - member(5).model("box" & ii).transform.position.x) > 10 then --vec="l" pos.addat((ii+1),"l") end if end repeat --this chunk of code checks to see if the arrays are different --then moves the boxes to the correct axis if pos <> oldpos then repeat with ii = 0 to 1 --repeat with ii = 0 to (totalbox-1) if pos[(ii+1)]="d" then member(5).model("box" & (ii+1)).transform.position.x=member(5).model("box" & ii).transform.position.x else if pos[(ii+1)]="u" then member(5).model("box" & (ii+1)).transform.position.x=member(5).model("box" & ii).transform.position.x else if pos[(ii+1)]="r" then member(5).model("box" & (ii+1)).transform.position.y=member(5).model("box" & ii).transform.position.y else if pos[(ii+1)]="l" then member(5).model("box" & (ii+1)).transform.position.y=member(5).model("box" & ii).transform.position.y end if end repeat repeat with ii = 1 to totalbox oldpos[ii]=pos[ii] end repeat end if end Edited by - lindylex on December 9, 2001 3:10:18 AM

Share on other sites
i dont know lingo, but i your algo seems wrong. you should be storing an array of postions of where the tail scetions are. if you move less then 10 pixels thats ok. basically you have a loop that goes like:

// go through in reverse and
// move all blocks up to where the block in front of them was
// assume block at index 0 is the head block
for(i=num_blks-1; i>=1; i=i-1)
{
blks.x = blks[i-1].x
blks[i].y = blks[i-1].y
}

now move the front block (the head)
this will ensure all blocks travel along where the last one was
aint this much easier then what you have?

bonus, you can make the centipede go at any speed you want. just make sure it only turns on mulitples of the width of the block (otherwise it will look wrong) and then only at 90 degrees (which you probally know already).

bonus number two, no comparing to old array

Share on other sites
a person :

your solution will not work. i have tried that before. the only way that will work is if i was moving half the dimension of the boxes everytime.

eg. if the lead box was located at 0 on the x axis and the following box - 10 on the x axis when i move 1 pixel to the right the lead box new position on the x axis will be 1 and the following box 0. they will overlap right away.

if the dimension of the box are 10x10x10 you must move 5 unit each time for the array to work.

take a look http://www.mo-de.net/d/lex_centipede_15.htm

Share on other sites
quote:
I have been attempting to write this script that moves like the game centipede or nibbles from back in the Qbasic days.

uhh...the original centipede arcade was written in assembly for the 6502 processor. its ROM footprint was about 4k with around 512bytes of RAM (ed''s not exact on these numbers anymore..it was a while ago afterall..)

Share on other sites
first off (i am very to the point, dont take it personally), that flash thing was not working at all. the algorithm you were using in that was either coded completly wrong or the algo itself was bad.

on to step 2 of my hints to getting it to work right.

you may have misunderstood the algo i presented which works very well (considering its similar to the original algo). i assumed you were interpolating your movemnet. i guess i was wrong. revised method to handle this bad assumption.
  // you can use two arrays to make things easy// or one array// unlike the original centipede// you can interpolate at higher degree// also when doing things in 3d, you never move things at pixel// level, you move things at a unit level since at higher// resolutions the ratio of pixel to units change// per framefor(i=num_blks-1; i>0; i++){ draw_blk[i].x = cur_blk[i].x*percentTick+cur_blk[i-1].x*(1.0-percentTick); // do the same for all position varibles // turning should be done at 90 degrees}// do head block interpolationdraw_blk[0].x = cur_blk[i].x*(1.0-percentTick)+nextPos.x*percentTick;// per tickfor(i=num_blks-1; i>=1; i=i-1){blks[i].x = blks[i-1].x}// move head blockblks[0].x = nextPos.x;nextPos.x = // what ever you want on the grid// look up how to do frame independent movement

this method will work. you just need to implemnet it corrrectly. unfortunatly i am unsure what timing fetures you have access to. also you will have to deal with changing the theory and code you find on the topic to lingo. it may be tough, but its the only way to do what you want that will work 100% (well there are other methods, but this is the best way to gauruntee no overlap of blocks nor any other wierd anomolies). if you rell me this method dont work, then you did not implmenet it correctly.

Share on other sites
a person: ok i am a little confused about the first for do statement.

for(i=num_blks-1; i>0; i++)
{ draw_blk.x = cur_blk[i].x*percentTick+cur_blk[i-1].x*(1.0-percentTick);
// do the same for all position varibles
// turning should be done at 90 degrees
}

what does the percenTick mean? I don't know what you are referring to.

Is this referring to the frame rate? If so i do have access to it. Also yes i meant i was moving the box 1 unit/frame rate not 1 pixel/frame rate.

What is the 1.0 referring to?

If you have icq or any im message me this would be so much faster.

Edited by - lindylex on December 14, 2001 9:33:19 PM

Share on other sites
unfortunatly no, i dont use any messaging services.

percentTick is just the varible i used to hold how far along the tick we are. since we can run mulitple frames per tick. a tick is a slice of time where game stuff happens. it is a constant slice of time ALWAYS and is not affected by framerate at all.

since percentTick is ALWAYS between 0.0 and 1.0, subtracting percentTick form 1.0 gives you the inverse percentage of the tick. allowing you to interpolate between the ticks, since you will most likly get more frames then ticks. on the other hand if the framerate goes to the toliet, the game will still play at the same speed (but choppy) as if it was running on an uber machine (smooth as silk). so everyone gets to enjoy the game. your tick rate should be as fast as the lowest framerate you expect to get on the slowest machine you expect to play the game. if the tick rate is too low, then bump it up a bit (good rates are about 20-30 milliseconds.

try this page with some info explaining what i mean (it uses c code, but you should be able to get the gist of it)

• Forum Statistics

• Total Topics
627711
• Total Posts
2978753

• 21
• 14
• 12
• 39