polish explosions

This commit is contained in:
Fabien Freling 2021-08-12 13:43:52 +02:00
parent c7fb1d5a86
commit b860968ef5

View file

@ -20,6 +20,7 @@ class Color {
static green_light { 5 }
static green { 6 }
static green_dark { 7 }
static white { 12 }
}
class Star {
@ -157,6 +158,9 @@ class Player {
}
draw() {
if (!_alive) {
return
}
TIC.spr(256, _x - _w / 2, _y - _h / 2, 0, 1, 0, 0, 2, 2)
for (b in _bullets) {
b.draw()
@ -178,22 +182,34 @@ class Player {
class Explosion {
construct new(x, y) {
System.print("explosion at %(x), %(y)")
_x = x
_y = y
_countdown = 30
_countdown = 10
_t = 0
}
expired { _countdown < 0 }
expired { _t > _countdown }
update() {
//System.print("explosion countdown %(_countdown)")
_countdown = _countdown - 1
_t = _t + 1
}
draw() {
var size = 10
TIC.circ(_x, _y, size, 2)
if (_t <= 2) {
TIC.circ(_x, _y, 10, Color.white)
} else if (_t <= 4) {
TIC.circ(_x, _y, 10, Color.red)
} else if (_t <= 6) {
TIC.circ(_x - 4, _y - 4, 4, Color.white)
TIC.circ(_x - 4, _y + 4, 4, Color.white)
TIC.circ(_x + 4, _y + 4, 4, Color.white)
TIC.circ(_x + 4, _y - 4, 4, Color.white)
} else if (_t <= 8) {
TIC.circ(_x - 4, _y - 4, 4, Color.red)
TIC.circ(_x - 4, _y + 4, 4, Color.red)
TIC.circ(_x + 4, _y + 4, 4, Color.red)
TIC.circ(_x + 4, _y - 4, 4, Color.red)
}
}
}
@ -259,14 +275,8 @@ class World {
v.update()
}
// Collect
while (_stars.count > 0 && _stars[0].expired) {
_stars.removeAt(0)
}
collect(_enemies)
collect(_vfx)
// Generation
//
// small stars
if (_t % 30 == 0) {
_stars.add(Star.new(W, R.int(0,H), 1, 1, 12))
@ -280,15 +290,24 @@ class World {
_stars.add(Star.new(W, R.int(0,H), width, speed, 13))
}
if (_player.alive) {
_t = _t + 1
}
// Map scrolling
if (_t % _world_scroll_speed == 0) {
_world_x = _world_x + 1
}
_w_offset_x = -(_t % _world_scroll_speed) / (_world_scroll_speed / 8)
if (_player.alive) {
_t = _t + 1
}
// Collect
while (_stars.count > 0 && _stars[0].expired) {
_stars.removeAt(0)
}
collect(_enemies)
collect(_vfx)
// Collisions
var i = 0
while (i < _player.bullets.count) {
@ -307,13 +326,15 @@ class World {
i = i + 1
}
}
if (!(fgCheck(_player.x - _player.bw / 2, _player.y - _player.bh / 2) &&
fgCheck(_player.x - _player.bw / 2, _player.y + _player.bh / 2) &&
fgCheck(_player.x + _player.bw / 2, _player.y + _player.bh / 2) &&
fgCheck(_player.x + _player.bw / 2, _player.y - _player.bh / 2))) {
System.print("collision with foreground")
_player.die()
_vfx.add(Explosion.new(_player.x, _player.y))
if (_player.alive) {
if (!(fgCheck(_player.x - _player.bw / 2, _player.y - _player.bh / 2) &&
fgCheck(_player.x - _player.bw / 2, _player.y + _player.bh / 2) &&
fgCheck(_player.x + _player.bw / 2, _player.y + _player.bh / 2) &&
fgCheck(_player.x + _player.bw / 2, _player.y - _player.bh / 2))) {
//System.print("collision with foreground")
_player.die()
_vfx.add(Explosion.new(_player.x, _player.y))
}
}
}
@ -350,7 +371,7 @@ class World {
if (tile == 0) {
return true
}
System.print("collision at %(x), %(y)!")
//System.print("collision at %(x), %(y)!")
return false
}