From: Alexis Laferrière Date: Mon, 19 Jun 2017 00:53:45 +0000 (-0400) Subject: action_nitro: update to use gamnit animations X-Git-Url: http://nitlanguage.org action_nitro: update to use gamnit animations Signed-off-by: Alexis Laferrière --- diff --git a/contrib/action_nitro/assets/textures/player.png b/contrib/action_nitro/assets/textures/player.png new file mode 100644 index 0000000..bbd402f Binary files /dev/null and b/contrib/action_nitro/assets/textures/player.png differ diff --git a/contrib/action_nitro/assets/textures/player/frame_01.png b/contrib/action_nitro/assets/textures/player/frame_01.png deleted file mode 100644 index eb6f0ac..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_01.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_02.png b/contrib/action_nitro/assets/textures/player/frame_02.png deleted file mode 100644 index e4c1311..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_02.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_03.png b/contrib/action_nitro/assets/textures/player/frame_03.png deleted file mode 100644 index 1d63a6e..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_03.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_04.png b/contrib/action_nitro/assets/textures/player/frame_04.png deleted file mode 100644 index 9c331fd..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_04.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_05.png b/contrib/action_nitro/assets/textures/player/frame_05.png deleted file mode 100644 index 8948eb1..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_05.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_06.png b/contrib/action_nitro/assets/textures/player/frame_06.png deleted file mode 100644 index 84e30d9..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_06.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_07.png b/contrib/action_nitro/assets/textures/player/frame_07.png deleted file mode 100644 index a9cd3e5..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_07.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_08.png b/contrib/action_nitro/assets/textures/player/frame_08.png deleted file mode 100644 index 2cdbbeb..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_08.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_09.png b/contrib/action_nitro/assets/textures/player/frame_09.png deleted file mode 100644 index 5f70296..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_09.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_10.png b/contrib/action_nitro/assets/textures/player/frame_10.png deleted file mode 100644 index a122246..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_10.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_11.png b/contrib/action_nitro/assets/textures/player/frame_11.png deleted file mode 100644 index 231eef8..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_11.png and /dev/null differ diff --git a/contrib/action_nitro/assets/textures/player/frame_12.png b/contrib/action_nitro/assets/textures/player/frame_12.png deleted file mode 100644 index ccf5003..0000000 Binary files a/contrib/action_nitro/assets/textures/player/frame_12.png and /dev/null differ diff --git a/contrib/action_nitro/src/action_nitro.nit b/contrib/action_nitro/src/action_nitro.nit index 5a2c3bc..f928a85 100644 --- a/contrib/action_nitro/src/action_nitro.nit +++ b/contrib/action_nitro/src/action_nitro.nit @@ -42,8 +42,8 @@ redef class App var planes_sheet = new PlanesImages # Animation for the player movement - private var player_textures: Array[Texture] = - [for f in [1..12] do new Texture("textures/player/frame_{f.pad(2)}.png")] + private var running_texture = new Texture("textures/player.png") + private var running_animation: Animation = running_texture.to_animation(10.0, 12, 0) # Boss 3D model private var iss_model = new Model("models/iss.obj") @@ -276,7 +276,6 @@ redef class App player.moving = 0.0 if pressed_keys.has("left") then player.moving -= 1.0 if pressed_keys.has("right") then player.moving += 1.0 - player.sprite.as(PlayerSprite).update end # Try to fire as long as a key is pressed @@ -404,16 +403,12 @@ redef class App if event.name == "left" then var mod = if event.is_down then -1.0 else 1.0 player.moving += mod - end - - if event.name == "right" then + player.animate_move + else if event.name == "right" then var mod = if event.is_down then 1.0 else -1.0 player.moving += mod + player.animate_move end - - if player.moving == 0.0 then - player.sprite.as(PlayerSprite).stop_running - else player.sprite.as(PlayerSprite).start_running end end end @@ -525,7 +520,7 @@ redef class Boss end redef class Enemy - redef var sprite = new Sprite(app.player_textures.rand, center) is lazy + redef var sprite = new Sprite(app.running_animation.frames.rand, center) is lazy init do sprite.scale = width/sprite.texture.width * 2.0 end @@ -535,9 +530,17 @@ redef class Parachute end redef class Player - redef var sprite = new PlayerSprite(app.player_textures[1], center, app.player_textures, 0.08) is lazy + redef var sprite = new Sprite(app.running_animation.frames.last, center) is lazy init do sprite.scale = width/sprite.texture.width * 2.0 + # Update current animation + fun animate_move + do + if moving == 0.0 then + sprite.animate_stop + else sprite.animate(app.running_animation, -1.0) + end + redef fun update(dt, world) do super @@ -632,44 +635,6 @@ redef class Int end end -# Special `Sprite` for the player character which is animated -class PlayerSprite - super Sprite - - # Animation of the running character - var running_animation: Array[Texture] - - # Seconds per frame of the animations - var time_per_frame: Float - - # Currently playing animation - private var current_animation: nullable Array[Texture] = null - - # Second at witch `current_animation` started - private var anim_ot = 0.0 - - # Start the running animation - fun start_running - do - anim_ot = app.world.t - current_animation = running_animation - end - - # Stop the running animation - fun stop_running do current_animation = null - - # Update `texture` from `current_animation` - fun update - do - var anim = current_animation - if anim != null then - var dt = app.world.t - anim_ot - var i = (dt / time_per_frame).to_i+2 - texture = anim.modulo(i) - end - end -end - # Manager to display numbers in sprite class CounterSprites