add code so that enemy gains a new projectile when attacking falling enemies, and also draw the falling enemies
This commit is contained in:
@@ -58,4 +58,56 @@ struct
|
|||||||
* as it is off screen *)
|
* as it is off screen *)
|
||||||
updateList (pos - 1, vec, acc)
|
updateList (pos - 1, vec, acc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun helpGetDrawVec
|
||||||
|
(pos, fallingVec, width, height, ratio, xOffset, yOffset, acc) =
|
||||||
|
if pos = Vector.length fallingVec then
|
||||||
|
Vector.concat acc
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val {x, y, variant = _, jumped = _} = Vector.sub (fallingVec, pos)
|
||||||
|
|
||||||
|
val x = Real32.fromInt x * ratio + xOffset
|
||||||
|
val y = Real32.fromInt y * ratio + yOffset
|
||||||
|
val size = Real32.fromInt Constants.enemySize * ratio
|
||||||
|
|
||||||
|
val vec = Block.lerp (x, y, size, size, width, height, 0.3, 0.3, 0.3)
|
||||||
|
val acc = vec :: acc
|
||||||
|
in
|
||||||
|
helpGetDrawVec
|
||||||
|
(pos + 1, fallingVec, width, height, ratio, xOffset, yOffset, acc)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun getDrawVec (game: game_type, width, height) =
|
||||||
|
if Vector.length (#fallingEnemies game) = 0 then
|
||||||
|
Vector.fromList []
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val fallingEnemies = #fallingEnemies game
|
||||||
|
val wratio = width / Constants.worldWidthReal
|
||||||
|
val hratio = height / Constants.worldHeightReal
|
||||||
|
in
|
||||||
|
if wratio < hratio then
|
||||||
|
let
|
||||||
|
val scale = Constants.worldHeightReal * wratio
|
||||||
|
val yOffset =
|
||||||
|
if height > scale then (height - scale) / 2.0
|
||||||
|
else if height < scale then (scale - height) / 2.0
|
||||||
|
else 0.0
|
||||||
|
in
|
||||||
|
helpGetDrawVec
|
||||||
|
(0, fallingEnemies, width, height, wratio, 0.0, yOffset, [])
|
||||||
|
end
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val scale = Constants.worldWidthReal * hratio
|
||||||
|
val xOffset =
|
||||||
|
if width > scale then (width - scale) / 2.0
|
||||||
|
else if width < scale then (scale - width) / 2.0
|
||||||
|
else 0.0
|
||||||
|
in
|
||||||
|
helpGetDrawVec
|
||||||
|
(0, fallingEnemies, width, height, hratio, xOffset, 0.0, [])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -451,8 +451,16 @@ struct
|
|||||||
| FACING_LEFT => x - length)
|
| FACING_LEFT => x - length)
|
||||||
|
|
||||||
val state = []
|
val state = []
|
||||||
|
(* detect collisions from enemies who are hit by attack *)
|
||||||
val newDefeated = AttackEnemies.foldRegion
|
val newDefeated = AttackEnemies.foldRegion
|
||||||
(x, y, length, height, (), state, enemyTree)
|
(x, y, length, height, (), state, enemyTree)
|
||||||
|
|
||||||
|
(* detect collisions from falling enemies too *)
|
||||||
|
val fallingTree =
|
||||||
|
FallingEnemies.generateTree (#fallingEnemies game)
|
||||||
|
val newDefeated = AttackEnemies.foldRegion
|
||||||
|
(x, y, length, height, (), newDefeated, fallingTree)
|
||||||
|
|
||||||
val allDefeated =
|
val allDefeated =
|
||||||
Vector.concat [Vector.fromList newDefeated, enemies]
|
Vector.concat [Vector.fromList newDefeated, enemies]
|
||||||
in
|
in
|
||||||
|
|||||||
@@ -242,7 +242,8 @@ struct
|
|||||||
val wallVec = Wall.getDrawVec (#walls game, width, height)
|
val wallVec = Wall.getDrawVec (#walls game, width, height)
|
||||||
val platVec = Platform.getDrawVec (#platforms game, width, height)
|
val platVec = Platform.getDrawVec (#platforms game, width, height)
|
||||||
val chainVec = Player.getFieldVec (#player game, width, height)
|
val chainVec = Player.getFieldVec (#player game, width, height)
|
||||||
val wallVec = Vector.concat [wallVec, platVec, chainVec]
|
val fallingVec = FallingEnemies.getDrawVec (game, width, height)
|
||||||
|
val wallVec = Vector.concat [wallVec, platVec, chainVec, fallingVec]
|
||||||
|
|
||||||
(* temp *)
|
(* temp *)
|
||||||
val pelletVec = Player.getPelletVec (#player game, width, height)
|
val pelletVec = Player.getPelletVec (#player game, width, height)
|
||||||
|
|||||||
Reference in New Issue
Block a user