end
# Current forture of the player
- var money: Int writable = 0
+ var money: Int = 0 is writable
# Number of basic bullets fired together
- var nbshoots: Int writable = 1
+ var nbshoots: Int = 1 is writable
# Time bebore the player shoot again a basic bullet (cooldown)
# Shoot if 0
var shoot_ttl = 0
# Number of missiles
- var nbmissiles: Int writable = 0
+ var nbmissiles: Int = 0 is writable
# Time bebore the player shoot again a missile (cooldown)
# Shoot if 0
if self.y < 0 then
self.y = 0
self.vy = 0
- else if self.y > 60000 then
- self.y = 60000
+ else if self.y > scene.height then
+ self.y = scene.height
self.vy = 0
end
if self.x < 0 then
self.x = 0
self.vx = 0
- else if self.x > 80000 then
- self.x = 80000
+ else if self.x > scene.width then
+ self.x = scene.width
self.vx = 0
end
else
shoot_ttl = 30
for i in [0..nbshoots[ do
- var shoot = new Shoot
+ var shoot = new Shoot(scene)
shoot.x = x
shoot.y = top
shoot.vy = -500
missile_ttl -= 1
else if nbmissiles > 0 then
missile_ttl = 500 / nbmissiles
- var shoot = new Missile
+ var shoot = new Missile(scene)
shoot.x = x
shoot.y = top
shoot.vy = -300
self.exists = false
# Reset the position for respawn
- self.x = 400 * 100
- self.y = 500 * 100
+ self.x = scene.width / 2
+ self.y = scene.height - 10000
self.vx = 0
self.vy = 0
self.respawn_ttl = 50
super Hitable
# true in on move, false if player is at rest
- var active writable = false
+ var active = false is writable
init do
self.width = 500
# Since there is no frendly fire, it is important to distinguish ownership
var enemy: Bool = false
- init do
+ # The scene of the sprite
+ # Is used with bound limits
+ var scene: PlayScene
+
+ init(scene: PlayScene)
+ do
+ self.scene = scene
self.width = 800
self.height = 800
end
super
# Out of screen ?
- if self.y < -100 * 100 or self.y > 700 * 100 or self.x < -100 * 100 or self.x > 900 * 100 then
+ if self.y < -100 * 100 or self.y > scene.height + 10000 or self.x < -100 * 100 or self.x > scene.width + 10000 then
self.exists = false
end
end
super Shoot
# The target aquired by the missile
- var target: nullable Sprite
+ var target: nullable Sprite = null
# When ttl is 0 then the angle stay fixed
# The angle is updated toward the target if ttl>0
super
# Out of screen ?
- if self.y > 700 * 100 or self.x < -100 * 100 or self.x > 900 * 100 then
+ if self.y > scene.height + 10000 or self.x < -100 * 100 or self.x > scene.width + 10000 then
# Note: no control on the top to let ennemies appear
self.exists = false
end
self.exists = false
scene.explosion(self.x, self.y, 5)
if 100.rand < 3 then
- var upmissile = new UpMissile
+ var upmissile = new UpMissile(scene)
upmissile.x = self.x
upmissile.y = self.y
upmissile.vx = 0
scene.hitables.add(new LootArea(upmissile, 2000))
else
for i in [0..self.loot[ do
- var money = new Money
+ var money = new Money(scene)
money.x = self.x
money.y = self.y
money.set_velocity(100.rand.to_f*pi/50.0, (500+self.loot).rand)
super Enemy
redef fun loot do return 3
+
+ redef init(scene)
+ do
+ self.width = 3600
+ self.height = 3600
+ end
end
-# Simple shooter of paris of basic bullets
+# Simple shooter of pairs of basic bullets
class Enemy1
super Enemy
+ redef init(scene)
+ do
+ self.width = 4400
+ self.height = 4400
+ end
+
redef fun shoot
do
# Next shoot
# two bullets shoot each time
for dx in [-11, 11] do
- var shoot = new Shoot
+ var shoot = new Shoot(scene)
shoot.enemy = true
shoot.x = self.x + dx * 100
shoot.y = self.bottom
class Enemy2
super Enemy
+ redef init(scene)
+ do
+ self.width = 6000
+ self.height = 6000
+ end
+
redef fun shoot
do
# Next shoot
shoot_ttl = 200
# The missile targets the player
- var shoot = new Missile
+ var shoot = new Missile(scene)
shoot.enemy = true
shoot.x = self.x
shoot.y = self.bottom
redef fun loot do return 10
end
-# Enem that shoot rings of basic bullets
+# Enemy that shoot rings of basic bullets
class Enemy3
super Enemy
+ redef init(scene)
+ do
+ self.width = 5800
+ self.height = 5800
+ end
+
redef fun shoot
do
# Next shoot
shoot_ttl = 50
for i in [0..10[ do
- var shoot = new Shoot
+ var shoot = new Shoot(scene)
shoot.enemy = true
shoot.x = self.x
shoot.y = self.bottom
# The angle of the turret
var angle: Float = 0.0
+ redef init(scene)
+ do
+ self.width = 4200
+ self.height = 4200
+ end
+
redef fun update
do
super
end
# Shoot with the turret angle
- var shoot = new Shoot
+ var shoot = new Shoot(scene)
shoot.enemy = true
shoot.x = self.x
shoot.y = self.y
class EnemyKamikaze
super Enemy
+ redef init(scene)
+ do
+ self.width = 3200
+ self.height = 3200
+ end
+
redef fun update
do
super
init(scene)
do
super
- self.width = 128 * 100
- self.height = 100 * 100
- self.x = 400 * 100
+ self.width = 140 * 100
+ self.height = 96 * 100
+ self.x = scene.width / 2
self.y = -100 * 100
- self.left_part = new BossPart(self, -48*100)
- self.right_part = new BossPart(self, 48*100)
+ self.left_part = new BossPart(self, -66*100)
+ self.right_part = new BossPart(self, 66*100)
end
var flick_ttl: Int = 0
else if self.vx == 0 then
self.vx = 100
self.vy = 0
- else if self.x > 700 * 100 and self.vx > 0 then
+ else if self.x > scene.width - 10000 and self.vx > 0 then
self.vx = -self.vx
- else if self.x < 100 * 100 and self.vx < 0 then
+ else if self.x < 10000 and self.vx < 0 then
self.vx = -self.vx
end
end
# Shoot the player with a basic bullet
- var shoot = new Shoot
+ var shoot = new Shoot(scene)
shoot.enemy = true
shoot.x = self.x
shoot.y = self.bottom
self.boss = boss
self.relx = relx
super(boss.scene)
- self.width = 32 * 100
- self.height = 60 * 100
+ self.width = 38 * 100
+ self.height = 48 * 100
# Alternate the shoots of the arms
if relx > 0 then
shoot_ttl = 600
# Shoot a missile that targets the player
- var shoot = new Missile
+ var shoot = new Missile(scene)
shoot.enemy = true
shoot.x = self.x
shoot.y = self.bottom
abstract class Loot
super Hitable
- init
+ var scene: PlayScene
+
+ init(scene: PlayScene)
do
+ self.scene = scene
self.width = 400
self.height = 400
end
super
# Out of screen ?
- if self.y > 700 * 100 then
+ if self.y > scene.height + 10000 then
self.exists = false
end
class Star
super Sprite
- init
+ # The scene of the sprite
+ # Is used with bound limits
+ var scene: ShotScene
+
+ init(scene: ShotScene)
do
+ self.scene = scene
# Randomely places stars on the plane
- self.x = 800.rand * 100
- self.y = 600.rand * 100
+ self.x = scene.width.rand
+ self.y = scene.height.rand
self.vy = 40.rand + 11
end
super
# Replace the star on the top
- if self.y > 600 * 100 then
+ if self.y > scene.height then
self.y = 200.rand * -100
- self.x = 800.rand * 100
+ self.x = scene.width.rand
self.vy = 40.rand + 11
end
end
super Scene
# When a scene need to be replaced, just assign the next_scene to a non null value
- var next_scene: nullable ShotScene writable = null
+ var next_scene: nullable ShotScene = null is writable
# The width of the whole scene
- var width: Int writable
+ var width: Int is writable
# The height of the whole scene
- var height: Int writable
+ var height: Int is writable
init(w,h: Int)
do
do
super
self.player = new Player(self)
- player.x = 400 * 100
- player.y = 500 * 100
+ player.x = self.width / 2
+ player.y = self.height - 10000
self.sprites.add(background)
self.sprites.add(pasive_stuff)
self.sprites.add(loots)
self.sprites.add(hitables)
for i in [0..100[ do
- background.add(new Star)
+ background.add(new Star(self))
end
hitables.add(player.going_target)
else
enemy = new Enemy4(self)
end
- enemy.x = 600.rand * 100 + 10000
+ enemy.x = (self.width - 20000).rand + 10000
enemy.vy = 200.rand + 100
if 10.rand < 3 then
enemy.vx = 200.rand - 100
do
super
for i in [0..100[ do
- sprites.add(new Star)
+ sprites.add(new Star(self))
end
end
- var play: Bool writable = false
+ var play: Bool = false is writable
var ttl: Int = 50
redef fun update