Merge pull request #349 from rafaelnsantos/AirShooter_animation

Air shooter explosion animation
This commit is contained in:
Derenash 2022-05-28 03:18:07 -03:00 committed by GitHub
commit 5ba9dc286d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 88 additions and 8 deletions

View File

@ -1,7 +1,3 @@
// npm i -g kind-lang-voxbox-maker
// klvm Name.Space.Here [Z_index] [Z_scale]
App.AirShooter.State: App.State
App.State.new(App.AirShooter.State.Local, App.AirShooter.State.Global)
@ -18,7 +14,7 @@ App.AirShooter.Effect.Time: Nat
800
App.AirShooter.Effect.CooldownModifier: U32
Nat.to_u32(2)
2#32
App.AirShooter.Effect.SpeedModifier: F64
1.5
@ -47,6 +43,7 @@ type App.AirShooter.State.Local {
shooting: Bool
started: Bool
drops: Map<App.AirShooter.Drop>
animations: Map<App.AirShooter.Animation>
)
}
@ -116,11 +113,12 @@ App.AirShooter.Local.init(): App.AirShooter.State.Local
let enemies = Map.new<App.AirShooter.Enemy>
let bullets = Map.new<App.AirShooter.Parts.Bullet>
let drops = Map.new<App.AirShooter.Drop>
let animations = Map.new<App.AirShooter.Animation>
let player = App.AirShooter.Player.new(ship, 0, "", "", 0)
let mouse_over = "game_screen"
let mouse_pos = { 128, 200 }
App.AirShooter.State.Local.new(player, enemies, mouse_over, mouse_pos, bullets, 0, max_enemies, false, false, drops)
App.AirShooter.State.Local.new(player, enemies, mouse_over, mouse_pos, bullets, 0, max_enemies, false, false, drops, animations)
// Initial state
App.AirShooter.init: App.Init<App.AirShooter.State>
@ -136,6 +134,7 @@ App.AirShooter.reset(local: App.AirShooter.State.Local): App.AirShooter.State.Lo
let local = local@max_enemies <- initial@max_enemies
let local = local@bullets <- initial@bullets
let local = local@drops <- initial@drops
let local = local@animations <- initial@animations
local
@ -150,9 +149,12 @@ App.AirShooter.draw.canvas(local: App.AirShooter.State.Local, img: VoxBox): VoxB
// draw bullets
let img = Map.for!(local@bullets)!(img, (key, bullet, img) App.AirShooter.Parts.Bullet.draw(bullet, img))
// TOOD: draw drops
// draw drops
let img = Map.for!(local@drops)!(img, (key, drop, img) App.AirShooter.Drop.draw(drop, img))
// TODO: draw animations
let img = Map.for!(local@animations)!(img, (key, animation, img) App.AirShooter.Animation.draw(animation, img))
img
@ -253,9 +255,16 @@ App.AirShooter.frame.collision(local: App.AirShooter.State.Local): IO<Maybe<App.
for keyEnemy:enemy in local@enemies with local:
if Bool.not(Shape.Circle.collision.circle(bullet@hitbox, enemy@ship@hitbox)) then local else
// todo: check enemy hp
let enemy = enemy@ship@hp <- enemy@ship@hp - 1
let local = local@bullets <- Map.delete!(key, local@bullets)
let local = local@enemies <- Map.set!(keyEnemy, enemy, local@enemies)
if enemy@ship@hp >? 0 then local else
let animation_key = App.AirShooter.new_key!(local@animations, local@seed)
let local = local@animations <- Map.set!(animation_key, App.AirShooter.Animation.new(27, App.AirShooter.Sprites.Explosion, 0, enemy@ship@position), local@animations)
let local = local@player@score <- local@player@score + 1
let local = local@enemies <- Map.delete!(keyEnemy, local@enemies)
let local = local@bullets <- Map.delete!(key, local@bullets)
local
local
else
@ -269,6 +278,8 @@ App.AirShooter.frame.collision(local: App.AirShooter.State.Local): IO<Maybe<App.
for key:enemy in local@enemies with local:
if Bool.not(Shape.Circle.collision.circle(enemy@ship@hitbox, local@player@ship@hitbox)) then local else
// if hit, delete enemy, player loses hp
let animation_key = App.AirShooter.new_key!(local@animations, local@seed)
let local = local@animations <- Map.set!(animation_key, App.AirShooter.Animation.new(27, App.AirShooter.Sprites.Explosion, 0, enemy@ship@position), local@animations)
let local = local@enemies <- Map.delete!(key, local@enemies)
let local = local@player@ship@hp <- Nat.pred(local@player@ship@hp)
local
@ -357,6 +368,21 @@ App.AirShooter.frame.effects(local: App.AirShooter.State.Local): App.AirShooter.
local
App.AirShooter.frame.animations(local: App.AirShooter.State.Local): App.AirShooter.State.Local
for key:animation in local@animations with local:
if animation@frame >=? animation@duration then local@animations <- Map.delete!(key, local@animations) else
let animation = animation@frame <- animation@frame + 1
let local = local@animations <- Map.set!(key, animation, local@animations)
local
local
// Event handler
App.AirShooter.when: App.When<App.AirShooter.State>
(event, state)
@ -408,6 +434,7 @@ App.AirShooter.when: App.When<App.AirShooter.State>
let local = App.AirShooter.frame.garbage_collector(local)
let local = App.AirShooter.frame.shoot(local)
let local = App.AirShooter.frame.drops(local)
let local = App.AirShooter.frame.animations(local)
App.AirShooter.frame.collision(local)
}
mouse_move:

View File

@ -0,0 +1,8 @@
type App.AirShooter.Animation {
new(
duration: U32
sprite: U32 -> VoxBox
frame: U32
position: App.AirShooter.Position
)
}

View File

@ -0,0 +1,8 @@
// fps = frames per sprite
App.AirShooter.Animation.Build(sprites: List<VoxBox>, fps: Nat): U32 -> VoxBox
(frame: U32)
let idx = (U32.to_nat(frame) / fps) % List.length!(sprites)
sprites[idx] <> App.AirShooter.Sprites.Explosion.Explosion_1

View File

@ -0,0 +1,8 @@
App.AirShooter.Animation.draw(animation: App.AirShooter.Animation, img: VoxBox): VoxBox
let pos = animation@position
let pos = { F64.to_u32(pos@fst), F64.to_u32(pos@snd) }
let pos = { pos@fst - 128, pos@snd - 128 }
let sprite = animation@sprite(animation@frame)
VoxBox.Draw.image(pos@fst, pos@snd, 1, sprite, img)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,15 @@
// numero de sprites = 7
// frames por sprite = 4
App.AirShooter.Sprites.Explosion(frame: U32): VoxBox
let sprites = [
App.AirShooter.Sprites.Explosion.Explosion_1,
App.AirShooter.Sprites.Explosion.Explosion_2,
App.AirShooter.Sprites.Explosion.Explosion_3,
App.AirShooter.Sprites.Explosion.Explosion_4,
App.AirShooter.Sprites.Explosion.Explosion_5,
App.AirShooter.Sprites.Explosion.Explosion_6,
App.AirShooter.Sprites.Explosion.Explosion_7
]
App.AirShooter.Animation.Build(sprites, 4)(frame)

View File

@ -0,0 +1,2 @@
App.AirShooter.Sprites.Explosion.Explosion_1: VoxBox
VoxBox.parse("7c7500f8b8007d7500f8b8007e7500f8b800797600f8b8007a7600f8b8007b7600f8b8007c7600f8b8007d7600f8b8007e7600f8b8007f7600f8b800807600f8b800817600f8b800787700f8b800797700f8d8787a7700f8d8787b7700f8d8787c7700f8d8787d7700f8d8787e7700f8d8787f7700f8d878807700f8d878817700f8b800827700f8b800837700f8b800847700f8b800777800f8b800787800f8d878797800f8d8787a7800f8d8787b7800f8d8787c7800f8d8787d7800f8d8787e7800f8d8787f7800f8d878807800f8d878817800f8b800827800f8b800837800f8d878847800f8d878857800f8b800767900f8b800777900f8d878787900f8d878797900f8d8787a7900f8d8787b7900f8d8787c7900f8b8007d7900f8b8007e7900f8b8007f7900f8d878807900f8d878817900f8d878827900f8b800837900f8d878847900f8d878857900f8d878867900f8b800757a00f8b800767a00f8d878777a00f8d878787a00f8d878797a00f8d8787a7a00f8d8787b7a00fcfcfc7c7a00fcfcfc7d7a00fcfcfc7e7a00fcfcfc7f7a00f8b800807a00f8d878817a00f8d878827a00f8b800837a00f8d878847a00f8d878857a00f8d878867a00f8d878877a00f8b800757b00f8b800767b00f8d878777b00f8d878787b00f8d878797b00f8d8787a7b00fcfcfc7b7b00fcfcfc7c7b00fcfcfc7d7b00fcfcfc7e7b00fcfcfc7f7b00f8b800807b00f8d878817b00f8d878827b00f8d878837b00f8d878847b00f8d878857b00f8d878867b00f8d878877b00f8d878887b00f8b800747c00f8b800757c00f8d878767c00f8d878777c00f8d878787c00f8d878797c00f8d8787a7c00fcfcfc7b7c00fcfcfc7c7c00fcfcfc7d7c00fcfcfc7e7c00f8d8787f7c00f8d878807c00f8d878817c00f8d878827c00f8d878837c00f8d878847c00f8d878857c00f8d878867c00f8d878877c00f8b800887c00f8b800897c00f8b800747d00f8b800757d00f8d878767d00f8d878777d00f8d878787d00f8d878797d00f8d8787a7d00f8d8787b7d00fcfcfc7c7d00fcfcfc7d7d00fcfcfc7e7d00f8b8007f7d00f8b800807d00f8d878817d00f8d878827d00f8d878837d00f8d878847d00fcfcfc857d00fcfcfc867d00f8d878877d00f8d878887d00f8d878897d00f8b800747e00f8b800757e00f8d878767e00f8d878777e00f8d878787e00f8d878797e00f8d8787a7e00f8d8787b7e00f8d8787c7e00f8d8787d7e00f8b8007e7e00f8b8007f7e00f8b800807e00f8b800817e00f8b800827e00f8b800837e00fcfcfc847e00fcfcfc857e00fcfcfc867e00f8d878877e00f8d878887e00f8d878897e00f8b8008a7e00f8b800747f00f8b800757f00f8d878767f00f8d878777f00f8d878787f00f8d878797f00fcfcfc7a7f00f8d8787b7f00f8b8007c7f00f8b8007d7f00f8b8007e7f00fcfcfc7f7f00fcfcfc807f00fcfcfc817f00fcfcfc827f00fcfcfc837f00fcfcfc847f00fcfcfc857f00fca044867f00f8d878877f00f8d878887f00f8d878897f00f8b8008a7f00f8b800758000f8b800768000f8d878778000f8d878788000f8d878798000fcfcfc7a8000fcfcfc7b8000f8d8787c8000fcfcfc7d8000fcfcfc7e8000f8d8787f8000f8d878808000fcfcfc818000fcfcfc828000fcfcfc838000fcfcfc848000fca044858000fca044868000f8d878878000f8d878888000f8d878898000f8b8008a8000f8b800768100f8b800778100f8d878788100f8d878798100fcfcfc7a8100fcfcfc7b8100fcfcfc7c8100fcfcfc7d8100fcfcfc7e8100f8d8787f8100f8d878808100fcfcfc818100fcfcfc828100fca044838100fca044848100fca044858100f8b800868100f8d878878100f8d878888100f8d878898100f8b800778200f8b800788200f8d878798200f8d8787a8200fcfcfc7b8200fcfcfc7c8200fcfcfc7d8200fcfcfc7e8200f8d8787f8200f8d878808200f8d878818200fca044828200fca044838200f8b800848200f8b800858200f8d878868200f8d878878200f8d878888200f8d878898200f8b800788300f8b800798300f8d8787a8300f8d8787b8300f8d8787c8300f8b8007d8300fcfcfc7e8300fcfcfc7f8300f8d878808300f8d878818300f8d878828300f8b800838300f8d878848300f8d878858300f8d878868300f8d878878300f8d878888300f8b800798400f8b8007a8400f8b8007b8400f8b8007c8400f8d8787d8400f8d8787e8400f8d8787f8400f8d878808400f8d878818400f8d878828400f8d878838400f8d878848400f8d878858400f8d878868400f8b800878400f8b8007a8500f8b8007b8500f8b8007c8500f8d8787d8500f8d8787e8500f8d8787f8500f8d878808500f8d878818500f8d878828500f8d878838500f8d878848500f8d878858500f8b8007a8600f8b8007b8600f8b8007c8600f8d8787d8600f8d8787e8600f8d8787f8600f8d878808600f8d878818600f8d878828600f8d878838600f8d878848600f8b8007b8700f8b8007c8700f8b8007d8700f8b8007e8700f8b8007f8700f8b800808700f8b800818700f8b800828700f8b800838700f8b8007d8800f8b8007e8800f8b8007f8800f8b800808800f8b800818800f8b800")

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
App.AirShooter.Sprites.Explosion.Explosion_7: VoxBox
VoxBox.parse("846f000000008170000000008270000000008071000000008171000000008271000000008371000000008b71000000007f72000000008072000000008172000000008272000000008b72000000007873000000008073000000008173000000008973000000008a73000000008b73000000008c73000000007674000000007774000000007874000000008874000000008974000000008a74000000008b74000000008c74000000008d74000000007475000000007575000000007675000000008875000000008975000000008a75000000008b75000000008c75000000008976000000008a76000000008b7600000000737700000000747700000000757700000000877700000000857800000000867800000000877800000000887800000000867900000000727b000000007e7b000000007f7b00000000737c000000007d7c000000007e7c000000007f7c00000000807c00000000897c00000000717d00000000727d00000000747d000000007e7d000000007f7d00000000877d00000000727e00000000757e000000007e7e000000007f7e00000000877e00000000727f00000000737f000000007c7f000000007e7f00000000877f000000007680000000008880000000008a80000000007181000000007681000000007c81000000008881000000008e81000000008f81000000007082000000007182000000007282000000008082000000008882000000008d82000000008e82000000008f82000000009082000000006f83000000007083000000007183000000007283000000007383000000007f83000000008d83000000008e83000000008f83000000006e84000000006f84000000007084000000007184000000007284000000007384000000007484000000008e84000000006f85000000007085000000007185000000007285000000008985000000006f86000000007086000000007186000000008086000000008786000000008886000000007087000000008287000000008687000000008787000000007688000000007788000000008188000000008288000000008388000000008688000000007589000000007889000000007b8900000000808900000000818900000000838900000000848900000000748a00000000758a00000000778a00000000788a00000000808a00000000888a00000000738b00000000748b00000000768b000000007a8b00000000828b00000000868b00000000878b00000000738c00000000748c00000000848c00000000748d000000007c8d00000000758e000000007b8e000000007c8e000000007d8e000000007a8f000000007b8f000000007c8f000000007d8f000000007e8f000000007990000000007a90000000007c9000000000")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 219 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 B