Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
13.3 Create enemies with animations and images
' change how we randomize and create the enemies
Method CreateEnemy()
Local rand_enemy:Float = Rnd(0, 3)
Local projectile_type:ProjectileType = New ProjectileType()
Local width = 48
Local height = 32
Local health = 1
Local points = 10
Local rand_y:Float = Rnd(height, Self.engine.GetCanvasHeight())
Local box:ftObject = Self.engine.CreateBox(width, height, Self.engine.GetCanvasWidth(), rand_y)
If (rand_enemy <= 2.0)
box = Self.engine.CreateAnimImage(game_sprite_atlas.GetImage("orange_shark_animation"), 0, 0,
width, height, 3, engine.GetCanvasWidth(), rand_y)
Else If (rand_enemy > 2.0 And rand_enemy <= 2.5)
height = 48
width = 48
health = 2
points = 25
rand_y = Rnd(height, Self.engine.GetCanvasHeight())
box = Self.engine.CreateAnimImage(game_sprite_atlas.GetImage("purple_tentacle_enemy_animation"), 0, 0,
width, height, 2, engine.GetCanvasWidth(), rand_y)
Else
height = 64
width = 96
health = 3
points = 45
rand_y = Rnd(height, Self.engine.GetCanvasHeight())
box = Self.engine.CreateImage(game_sprite_atlas.GetImage("grey_mech_enemy"), engine.GetCanvasWidth(), rand_y)
End
box.SetSpeedX(Rnd(10, 30) * -1)
box.SetColGroup(ENEMY_GROUP)
box.SetColWith(PLAYER_GROUP, True)
box.SetText("ENEMY")
enemies.AddLast(New Character(box, projectile_type, points, health))
Self.next_enemy_interval = Rnd(0, 3) * 1000
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment