Hey everyone,
Looking for a little help or suggestions/pointers.
I have a tile engine build with App Game Kit, it renders a 400x200 tile map (tiles are 60x60). I did some fancy foot work so that to cut down on battery drain, there's only Screen Width / 60 number of actual tiles on the screen and as you go left/right on the map, it simply updates the "View" to the textures of the offset we're looking at, I'm quite impressed with that, anyway, that's just me bragging. What I'm trying to work out, is rasterized line movement.
The way it works, is based on a tick count (when the tick = 100) if a "Troop" has a Destination X/Y tile that is greater than their current X/Y position, it moves them one step closer to the destination X/Y. The way I build it right now is simply this
/* if Troop[TroopSlot].MoveToX > tmpX
NewX = tmpX + 1
endif
if Troop[TroopSlot].MoveToX < tmpX
NewX = tmpX - 1
endif
if Troop[TroopSlot].MoveToY > tmpY
NewY = tmpY + 1
endif
if Troop[TroopSlot].MoveToY < tmpY
NewY = tmpY - 1
endif */
The problem here is that the troop moves diagonal until the x or y is the same, then they walk in a straight line to the destination tile.
What I'm looking to do is something similar to this:
Here's my entire move function, what I suspect I'd have to do is do the math for the invisible line from Start X, Start Y to End X, End Y, find out where the next tile works out to based on that line and then move the troop the proper direction. However, it's apparent I just stink at math!
function MoveTroop(TroopSlot)
TileWidth = 60
TileHeight = 60
StartX = Troop[TroopSlot].StartX
StartY = Troop[TroopSlot].StartY
CurrentX = Troop[TroopSlot].X
CurrentY = Troop[TroopSlot].Y
EndX = Troop[TroopSlot].MoveToX
EndY = Troop[TroopSlot].MoveToY
if Troop[TroopSlot].MoveToX > CurrentX
NewX = CurrentX + 1
endif
if Troop[TroopSlot].MoveToX < CurrentX
NewX = CurrentX - 1
endif
if Troop[TroopSlot].MoveToY > CurrentY
NewY = CurrentY + 1
endif
if Troop[TroopSlot].MoveToY < CurrentY
NewY = CurrentY - 1
endif
Troop[TroopSlot].X = NewX
Troop[TroopSlot].Y = NewY
endfunction
Robert Janes (Samu Games)
http://www.samugames.com/artifact