0 registered members (),
17,416
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: npc movement - 2d game
[Re: dmBlack]
#291874
09/28/09 17:35
09/28/09 17:35
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
// ???
// move difference between player and npc positions
diffX = pX - npcX;
diffY = pY - npcY;
// move difference to direction
dirX = sign(diffX);
dirY = sign(diffY);
// add direction as distance each frame
npcX += dirX;
npcY += dirY;
// ???
|
|
|
Re: npc movement - 2d game
[Re: dmBlack]
#298447
11/15/09 04:09
11/15/09 04:09
|
Joined: Jun 2004
Posts: 2,234 Wisconsin USA
FoxHound
Expert
|
Expert
Joined: Jun 2004
Posts: 2,234
Wisconsin USA
|
function npcMove(var d) { var dir = d;
That part is redundant. Why make a new var to get the d var info?
also, since only one of those "ifs" could work you should "return" the function to help speed up processing time. I know it's very little time but every bit helps.
Are you making a side scroller game? if so you will need to wait until the player gets within the screen width to start them using any of their main functions, however you will still need to check to see how close they are. If it is not then regular code will need to be used as rendering will not be done on anything outside of the screen view.
I would have it create and destroy the panels as need, as per level. However I would think 200 would be fine.
--------------------- There is no signature here.
QUIT LOOKING FOR ONE!
|
|
|
|