Last active
February 12, 2017 12:40
-
-
Save codetravis/d7eb3dae4f6ee600c4737d5feafe0c7a to your computer and use it in GitHub Desktop.
14.5 Update the Enemy generator code to set the enemy type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Game Class | |
' Modify the CreateEnemy method to set the enemies box Text different | |
' for each enemy so the type is set properly | |
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 | |
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) | |
box.SetText("ORANGE_SHARK_ENEMY") | |
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) | |
box.SetText("PURPLE_TENTACLE_ENEMY") | |
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) | |
box.SetText("GREY_MECH_ENEMY") | |
End | |
box.SetSpeedX(Rnd(10, 30) * -1) | |
box.SetColGroup(ENEMY_GROUP) | |
box.SetColWith(PLAYER_GROUP, True) | |
enemies.AddLast(New Character(box, projectile_type, points, health, box.GetText(), engine.GetCanvasWidth(), rand_y)) | |
Self.next_enemy_interval = Rnd(0, 5) * 700 | |
End |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment