'WarCraft 64
'2018-08-29 00:10
'last update 01:30 2018-09-01
'Build Count 0013
'Kobolt
'
'Routine
'SetPath (Path() AS Coord, StartPos AS Coord, TargetPos AS Coord, Map())
' -Path() - the array for the path found from StartPos to TargetPos [UNITS.PATH()]
' -StartPos - the Begining Location of the unit [Unit().Movement.MapX, Unit().Movement.MapY]
' -TargetPos- where the player clicked the mouse to have unit reach [MapClick.X, MapClick.Y]
' -Map() - the map array to search for a path in [Map()]
'
'Loadlayers()
' -Load sprite and tile sheets
'
'MapDrawer (Lx%, Ly%, Sx~%%, Sy~%%, Scale%%, Sets%%, Lay%%)
' -Lx%,Ly% - screen pos to draw map
' -Sx~%%,Sy~%%- start pos to read map data
' -Scale%% - tile size to display 1x or 2x
' -Sets%% - Tile Set to use, Plains[26] or Swamp[0] (and maybe Cave)
' -Lay%% - layer to draw map on
'
'DrawSprite(Lx%, Ly%,Mx~%%, My~%%, Scale%%, D%%)
' -Draws a Units sprites
' -Lx%,Ly% - screen pos to draw sprite
' -Mx~%%,My~%%- Current start pos of the map being displayed
' -Scale%% - sprite size to display 1x or 2x
' -D%% - Destination layer to draw sprite on
pos AS Coord
' Coordinates of position on map parent
AS Coord
' Coordinates of previous position on path f
AS INTEGER ' F = G + H (total movement cost) status
AS INTEGER ' 0 for unsearched, 1 for open, 2 for closed (explored)
IDmark
AS _BYTE ' which sprite is it (1-Unit(0), 2-Peon ect...) MapX
AS _BYTE ' current Map square occupied MapY
AS _BYTE ' current Map square occupied MoveAngle
AS SINGLE 'direction sprite is moving MoveSpeed
AS SINGLE 'speed at which sprite is moving Direction
AS _BYTE ' sprite image faceing direction Frame
AS _BYTE ' which frame of animation sprite is on Is_Moving
AS _BYTE ' is the unit currently moving?
Movement
AS SpriteData
'inherited data HP
AS _UNSIGNED _BYTE ' a unit hit tolerance, includeing buildings and resources Armor
AS _BYTE ' units defence from an attack Range
AS _BYTE ' distance a unit can attack from DamLo
AS _BYTE ' minimal damage a unit can do DamHi
AS _BYTE ' Maximum damage a unit can do CostG
AS INTEGER ' Gold cost of unit to be produced CostW
AS INTEGER ' Wood Cost of unit to be produced Act
AS _BYTE ' is unit moving, mining, chopping wood, attacking, carrying wood or gold Build
AS _BYTE ' Time in seconds to build unit Based on Normal Speed X2.25 on slowest X0.45 Fastest
Structure
AS SpriteData
' not all elements used
MapX
AS _BYTE 'top left corner of the area of map the player MapY
AS _BYTE ' is currently veiwing
CONST TRUE
= -1, FALSE
= NOT TRUE
'Duh and DUH CONST Ts
= 17, Tc
= 37 'tile box size, tile count per line 'action constants
CONST Still
= 0, Moving
= 1, Mining
= 2, LumberJack
= 3, Attacking
= 4, CarryWood
= 5 CONST CarryGold
= 6, Shooting
= 7, Casting
= 8, Decomposing
= 9, Removal
= 10 'Direction constants
CONST North
= 0, NorthEast
= 1, East
= 2, SouthEast
= 3, South
= 4, SouthWest
= 5, West
= 6, NorthWest
= 7 'Unit Constants
CONST Peasant
= 1, Peon
= 2, Footman
= 3, Grunt
= 4, Archer
= 5, Spearman
= 6, Knight
= 7, Raider
= 8 CONST Cleric
= 9, Necrolyte
= 10, Conjurer
= 11, Warlock
= 12, SkeletonO
= 13, Skeleton
= 14 CONST Deamon
= 15, WaterElemt
= 16, FireElemt
= 17, Lothar
= 18 'Tile sets
CONST Plains
= 26, Swamp
= 0, Cave
= 28 'Player screens
CONST Human
= 27, Orc
= 28 'Game Tile\Sprite scaling
DIM Path
(2048) AS Coord
'' Dimension array of path coords to be filled in later DIM startpos
AS Coord
, targetpos
AS Coord
LoadLayers
READ Anima
(AnimaA%%
, AnimaB%%
)
startpos.x = 40: startpos.y = 21
targetpos.x = 24: targetpos.y = 33
SetPath Path(), startpos, targetpos, Map()
Unit(0).Movement.xloc = 320
Unit(0).Movement.yloc = 200
Unit(0).Movement.Direction = North
Unit(0).Movement.IDmark = Peasant
Unit(0).Act = Moving
Unit(0).Movement.MapX = startpos.x
Unit(0).Movement.MapY = startpos.y
Game.MapX = 30
Game.MapY = 20
'figure out spirte facing direction
'the units MapX\Y are the previous location and Path is the next location
IF Unit
(0).Movement.MapX
> Path
(i%
).x
AND Unit
(0).Movement.MapY
= Path
(i%
).y
THEN Unit
(0).Movement.Direction
= West
IF Unit
(0).Movement.MapX
< Path
(i%
).x
AND Unit
(0).Movement.MapY
= Path
(i%
).y
THEN Unit
(0).Movement.Direction
= East
IF Unit
(0).Movement.MapX
= Path
(i%
).x
AND Unit
(0).Movement.MapY
> Path
(i%
).y
THEN Unit
(0).Movement.Direction
= North
IF Unit
(0).Movement.MapX
= Path
(i%
).x
AND Unit
(0).Movement.MapY
< Path
(i%
).y
THEN Unit
(0).Movement.Direction
= South
IF Unit
(0).Movement.MapX
> Path
(i%
).x
AND Unit
(0).Movement.MapY
> Path
(i%
).y
THEN Unit
(0).Movement.Direction
= NorthWest
IF Unit
(0).Movement.MapX
> Path
(i%
).x
AND Unit
(0).Movement.MapY
< Path
(i%
).y
THEN Unit
(0).Movement.Direction
= SouthWest
IF Unit
(0).Movement.MapX
< Path
(i%
).x
AND Unit
(0).Movement.MapY
> Path
(i%
).y
THEN Unit
(0).Movement.Direction
= NorthEast
IF Unit
(0).Movement.MapX
< Path
(i%
).x
AND Unit
(0).Movement.MapY
< Path
(i%
).y
THEN Unit
(0).Movement.Direction
= SouthEast
'find units on screen location
Unit(0).Movement.xloc = (Unit(0).Movement.MapX - Game.MapX) * (16 * Scaling)
Unit(0).Movement.yloc = (Unit(0).Movement.MapY - Game.MapY) * (16 * Scaling)
MapDrawer 144, 24, Game.MapX, Game.MapY, Scaling, Plains, 62
DrawSprite 144, 24, Game.MapX, Game.MapY, Scaling, 63
'_DELAY 1
'_DELAY 1
'_DELAY 1
'MapDrawer 144, 24, Game.MapX, Game.MapY, Scaling, Plains, _DISPLAY
'DrawSprite 144, 24, Game.MapX, Game.MapY, Scaling, _DISPLAY
'update units pos
Unit(0).Movement.MapX = Path(i%).x
Unit(0).Movement.MapY = Path(i%).y
'$include:'Movementdata.bi'
'$include:'Loadlayers.bi'
'$include:'Warpath.bi'
'$include:'MapDrawer.bi'
'$include:'DrawSprite.bi'