Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. Field last_enemy_time:Float
  2. Field next_enemy_interval:Float
  3.  
  4. ' create named collision groups
  5. Const PLAYER_GROUP:Int = 1
  6. Const ENEMY_GROUP:Int = 2
  7.  
  8. Method OnCreate()
  9. Self.engine = New ftEngine
  10.  
  11. default_scene = engine.GetDefaultScene()
  12. default_layer = engine.GetDefaultLayer()
  13.  
  14. Local box:ftObject = Self.engine.CreateBox(120, 20, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2)
  15. box.SetColor(0, 70, 70)
  16. box.SetMaxSpeed(20.0)
  17. box.SetMinSpeed(-20.0)
  18. ' Set the collision group the player character is part of
  19. ' and the collsion type
  20. box.SetColGroup(PLAYER_GROUP)
  21. box.SetColType(Self.engine.ctBox)
  22.  
  23. Self.player = New Character(box, True)
  24.  
  25. Self.enemies = New List<Character>()
  26. Self.last_enemy_time = Millisecs()
  27. Self.next_enemy_interval = 3000
  28. Seed = Millisecs()
  29. End
  30.  
  31. ' .....................
  32.  
  33. Method CreateEnemy()
  34. Local rand_width:Float = Rnd(3, 7) * 10
  35. Local rand_height:Float = Rnd(3, 7) * 10
  36. Local rand_y:Float = Rnd(rand_height, Self.engine.GetCanvasHeight())
  37.  
  38. Local box:ftObject = Self.engine.CreateBox(rand_width, rand_height, Self.engine.GetCanvasWidth(), rand_y)
  39.  
  40. Local rand_color:Float = Rnd(0, 3)
  41. Local colors:Int[] = [0, 0, 0]
  42. If (rand_color <= 1.0)
  43. colors = [255, 0, 0]
  44. Else If (rand_color > 1.0 And rand_color <= 2.0)
  45. colors = [0, 255, 0]
  46. Else
  47. colors = [0, 255, 0]
  48. End
  49.  
  50. box.SetColor(colors[0], colors[1], colors[2])
  51. box.SetSpeedX(Rnd(10, 30) * -1)
  52. ' We add the enemy box to the enemy collision group
  53. ' and make it able to collide with the player
  54. box.SetColGroup(ENEMY_GROUP)
  55. box.SetColWith(PLAYER_GROUP, True)
  56. enemies.AddLast(New Character(box))
  57.  
  58. Self.next_enemy_interval = Rnd(0, 3) * 1000
  59. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement