Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
8.17 Update the character constructors with point values in the Game class
' Game Class
Method OnCreate()
Self.engine = New CustomEngine
default_scene = engine.GetDefaultScene()
default_layer = engine.GetDefaultLayer()
Local box:ftObject = Self.engine.CreateBox(120, 20, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2)
box.SetColor(0, 70, 70)
box.SetMaxSpeed(20.0)
box.SetMinSpeed(-20.0)
box.SetColGroup(PLAYER_GROUP)
box.SetColType(Self.engine.ctBox)
box.SetText("PLAYER")
Local projectile_type:ProjectileType = New ProjectileType()
' Make the player worth 0 points
Self.player = New Character(box, projectile_type, 0, 3, True)
Self.enemies = New List<Character>()
Self.last_enemy_time = Millisecs()
Self.next_enemy_interval = 3000
Self.projectiles = New List<Projectile>()
Seed = Millisecs()
End
'.......................
Method CreateEnemy()
Local rand_width:Float = Rnd(3, 7) * 10
Local rand_height:Float = Rnd(3, 7) * 10
Local rand_y:Float = Rnd(rand_height, Self.engine.GetCanvasHeight())
Local box:ftObject = Self.engine.CreateBox(rand_width, rand_height, Self.engine.GetCanvasWidth(), rand_y)
Local projectile_type:ProjectileType = New ProjectileType()
Local rand_color:Float = Rnd(0, 3)
Local health = 1
' make tougher enemies worth more points
Local points = 10
Local colors:Int[] = [0, 0, 0]
If (rand_color <= 1.0)
colors = [255, 0, 0]
Else If (rand_color > 1.0 And rand_color <= 2.0)
colors = [0, 255, 0]
health = 2
points = 25
Else
colors = [0, 0, 255]
health = 3
points = 45
End
box.SetColor(colors[0], colors[1], colors[2])
box.SetSpeedX(Rnd(10, 30) * -1)
box.SetColGroup(ENEMY_GROUP)
box.SetColWith(PLAYER_GROUP, True)
box.SetText("ENEMY")
' add the points in the constructor
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