Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
8.8 Give character classes a projectile type
'.........................
Class Game Extends App
'.........................
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")
' create a projectile type for our player
Local projectile_type:ProjectileType = New ProjectileType()
' and add it to the creation call
Self.player = New Character(box, 3, True, projectile_type)
Self.enemies = New List<Character>()
Self.last_enemy_time = Millisecs()
Self.next_enemy_interval = 3000
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)
' create a base projectile type for our enemies
Local projectile_type:ProjectileType = New ProjectileType()
Local rand_color:Float = Rnd(0, 3)
Local health = 1
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
Else
colors = [0, 0, 255]
health = 3
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")
' give enemies a projectile type
enemies.AddLast(New Character(box, health, False, projectile_type))
Self.next_enemy_interval = Rnd(0, 3) * 1000
End
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment