diff --git a/app/main.rb b/app/main.rb index 453c24a..de04205 100644 --- a/app/main.rb +++ b/app/main.rb @@ -34,6 +34,7 @@ require 'app/scenes/main_menu.rb' require 'app/scenes/paused.rb' require 'app/scenes/settings.rb' require 'app/scenes/cube_tube.rb' +require 'app/scenes/intro.rb' require 'app/scenes/_list.rb' require 'app/util/scene.rb' diff --git a/app/scenes/_list.rb b/app/scenes/_list.rb index 15b67d2..19e6504 100644 --- a/app/scenes/_list.rb +++ b/app/scenes/_list.rb @@ -6,6 +6,7 @@ module Scene main_menu: MainMenu, settings: SettingsMenu, paused: PauseMenu, - cube_tube: CubeTubeGame + cube_tube: CubeTubeGame, + intro: Intro } end diff --git a/app/scenes/cube_tube.rb b/app/scenes/cube_tube.rb index 0650dce..710d7b2 100644 --- a/app/scenes/cube_tube.rb +++ b/app/scenes/cube_tube.rb @@ -15,7 +15,7 @@ class CubeTubeGame < GameplayScene @start_grid_x = @grid_x @start_grid_y = @grid_y @bg_x = 0 - @bg_w = 1335 + @bg_w = Sprite.for(:tunnel_loop).w @next_piece_box = [2, -9, 7, 7] @@ -62,19 +62,19 @@ class CubeTubeGame < GameplayScene 0, 0, 0 ] - @bg_x += (@level + 1) * 2 unless @gameover + @bg_x += (@level + 2) * 2 unless @gameover @bg_x %= @bg_w if @bg_x >= @bg_w - Sprite.for(:tunnel).render(@args, { x: @bg_x, y: 0, w: @bg_w, h: 720 }) - Sprite.for(:tunnel).render(@args, { x: @bg_x - @bg_w, y: 0, w: @bg_w, h: 720 }) + Sprite.for(:tunnel_loop).render(@args, { x: @bg_x, y: 0, w: @bg_w, h: 720 }) + Sprite.for(:tunnel_loop).render(@args, { x: @bg_x - @bg_w, y: 0, w: @bg_w, h: 720 }) # @grid_y = ((1280 - (@grid_h * @blocksize)) / 2) - 21 Sprite.for(:train).render(@args, { x: 0, y: @grid_x - 140.75 }) end def render_foreground - Sprite.for(:tracks).render(@args, { x: @bg_x, y: 0, w: @bg_w, h: 720 }) - Sprite.for(:tracks).render(@args, { x: @bg_x - @bg_w, y: 0, w: @bg_w, h: 720 }) + Sprite.for(:tracks).render(@args, { x: @bg_x, y: 0, w: @bg_w }) + Sprite.for(:tracks).render(@args, { x: @bg_x - @bg_w, y: 0, w: @bg_w }) Sprite.for(:train_fore).render(@args, { x: 0, y: @grid_x - 140.75 }) end @@ -132,14 +132,10 @@ class CubeTubeGame < GameplayScene screen_s = case (@args.state.tick_count % 32) - when 0..7 - :screen_s1 - when 8..15 - :screen_s2 - when 16..23 - :screen_s3 - when 24..31 - :screen_s4 + when 0..7 then :screen_s1 + when 8..15 then :screen_s2 + when 16..23 then :screen_s3 + when 24..31 then :screen_s4 end Sprite.for(screen_s).render(@args, { x: screen_x, y: screen_y + 10, w: screen_w, h: screen_h + 10 }) diff --git a/app/scenes/intro.rb b/app/scenes/intro.rb new file mode 100644 index 0000000..65751ed --- /dev/null +++ b/app/scenes/intro.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true + +# this is the lead-in to the main gameplay +class Intro < GameplayScene + def initialize(args, opts = {}) + super + + @train_duration = 200 + @train_spline = [ + [1.0, 0.25, 0, 0] + ] + @station_start_w = Sprite.for(:station_start).w + @full_station_start_w = Sprite.for(:station_start).w + Sprite.for(:tunnel_loop).w + @tracks_w = Sprite.for(:tracks).w + + @leave_duration = 600 + @leave_spline = [ + [0, 0, 0.5, 1.0] + ] + reset(args) + end + + # called every tick of the game loop + def tick(args) + @start ||= args.state.tick_count + case @state + when 0 + if (args.state.tick_count - @start) > 60 + @train_start = args.state.tick_count + @state += 1 + end + when 1 + @train_pos = 1280 * args.easing.ease_spline(@train_start, args.state.tick_count, @train_duration, @train_spline) + if @train_pos <= 0 + @state += 1 + @wait_start = args.state.tick_count + end + when 2 + if (args.state.tick_count - @wait_start) > 60 + @leave_start = args.state.tick_count + @state += 1 + end + when 3 + ease = args.easing.ease_spline(@leave_start, args.state.tick_count, @leave_duration, @leave_spline) + @station_pos = @full_station_start_w * ease + + @screen_on = true if ease > 0.75 + + if @station_pos >= @full_station_start_w + Scene.switch(args, :cube_tube, reset: true) + end + end + + Sprite.for(:station_loop).render(args, { x: @station_pos }) + Sprite.for(:station_start).render(args, { x: @station_pos - @station_start_w }) + Sprite.for(:tunnel_loop).render(args, { x: @station_pos - @full_station_start_w }) + + Sprite.for(:train).render(args, { y: 39.25, x: @train_pos }) + Sprite.for(:screen).render(args, { x: @train_pos + 1024, y: 270 }) + + if @screen_on + screen_s = + case (args.state.tick_count % 32) + when 0..7 then :screen_s1 + when 8..15 then :screen_s2 + when 16..23 then :screen_s3 + when 24..31 then :screen_s4 + end + + Sprite.for(screen_s).render(args, { x: @train_pos + 1024, y: 270 }) + end + + Sprite.for(:tracks).render(args, { x: @station_pos }) + Sprite.for(:tracks).render(args, { x: @station_pos - @tracks_w }) + Sprite.for(:tracks).render(args, { x: @station_pos - (@tracks_w * 2) }) + Sprite.for(:train_fore).render(args, { y: 39.25, x: @train_pos }) + + super + end + + # custom logic to reset this scene + def reset(args) + super + @state = 0 + @start = 0 + @train_start = 0 + @wait_start = 0 + @leave_start = 0 + @train_pos = 1280 + @station_pos = 0 + @screen_on = false + end +end \ No newline at end of file diff --git a/app/scenes/main_menu.rb b/app/scenes/main_menu.rb index 9f80ff1..5f17bab 100644 --- a/app/scenes/main_menu.rb +++ b/app/scenes/main_menu.rb @@ -7,7 +7,7 @@ class MainMenu < MenuScene menu_options = [ { key: :start, - on_select: ->(iargs) { Scene.switch(iargs, :cube_tube, reset: true) } + on_select: ->(iargs) { Scene.switch(iargs, :intro, reset: true) } }, { key: :settings, diff --git a/app/util/scene.rb b/app/util/scene.rb index fe055db..4bd278e 100644 --- a/app/util/scene.rb +++ b/app/util/scene.rb @@ -36,7 +36,7 @@ module Scene # if we asked to reset the scene, then do so. the_scene.reset(args) if reset - raise FinishTick, 'finish tick early' + # raise FinishTick, 'finish tick early' end # Change the current scene by pushing it onto the scene stack diff --git a/sprites/_list.rb b/sprites/_list.rb index b54f310..d528325 100644 --- a/sprites/_list.rb +++ b/sprites/_list.rb @@ -4,26 +4,30 @@ module Sprite # annoying to track but useful for reloading with +i+ in debug mode; would be # nice to define a different way SPRITES = { - train: SpriteInstance.new({ w: 1894, h: 473, path: 'sprites/train.png' }), - train_fore: SpriteInstance.new({ w: 1894, h: 473, path: 'sprites/train-fore.png' }), - screen: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen.png' }), - tunnel: SpriteInstance.new({ w: 267, h: 144, path: 'sprites/tunnel.png' }), - tracks: SpriteInstance.new({ w: 267, h: 144, path: 'sprites/tracks.png' }), - pause: SpriteInstance.new({ w: 16, h: 16, path: 'sprites/pause.png' }), - gray: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/gray.png' }), - black: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/black.png' }), - white: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/white.png' }), - red: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/red.png' }), - green: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/green.png' }), - blue: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/blue.png' }), - yellow: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/yellow.png' }), - indigo: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/indigo.png' }), - violet: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/violet.png' }), - orange: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/orange.png' }), - screen_s1: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s1.png' }), - screen_s2: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s2.png' }), - screen_s3: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s3.png' }), - screen_s4: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s4.png' }), - menu: SpriteInstance.new({ w: 1280, h: 720, path: 'sprites/menu.png' }), + train: SpriteInstance.new({ w: 1894, h: 473, path: 'sprites/train.png' }), + train_fore: SpriteInstance.new({ w: 1894, h: 473, path: 'sprites/train-fore.png' }), + screen: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen.png' }), + tunnel: SpriteInstance.new({ w: 267, h: 144, path: 'sprites/tunnel.png' }), + pause: SpriteInstance.new({ w: 16, h: 16, path: 'sprites/pause.png' }), + gray: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/gray.png' }), + black: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/black.png' }), + white: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/white.png' }), + red: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/red.png' }), + green: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/green.png' }), + blue: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/blue.png' }), + yellow: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/yellow.png' }), + indigo: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/indigo.png' }), + violet: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/violet.png' }), + orange: SpriteInstance.new({ w: 176, h: 148, path: 'sprites/box/orange.png' }), + screen_s1: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s1.png' }), + screen_s2: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s2.png' }), + screen_s3: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s3.png' }), + screen_s4: SpriteInstance.new({ w: 250, h: 210, path: 'sprites/screen-s4.png' }), + menu: SpriteInstance.new({ w: 1280, h: 720, path: 'sprites/menu.png' }), + tunnel_loop: SpriteInstance.new({ w: 1358, h: 720, path: 'sprites/tunnel-loop.png' }), + tracks: SpriteInstance.new({ w: 1358, h: 55, path: 'sprites/tracks.png' }), + station_loop: SpriteInstance.new({ w: 1811, h: 720, path: 'sprites/station-loop.png' }), + station_start: SpriteInstance.new({ w: 618, h: 720, path: 'sprites/station-start.png' }), + station_end: SpriteInstance.new({ w: 518, h: 720, path: 'sprites/station-end.png' }) } end diff --git a/sprites/station-end.png b/sprites/station-end.png new file mode 100644 index 0000000..f0f52e3 Binary files /dev/null and b/sprites/station-end.png differ diff --git a/sprites/station-loop.png b/sprites/station-loop.png new file mode 100644 index 0000000..215266e Binary files /dev/null and b/sprites/station-loop.png differ diff --git a/sprites/station-start.png b/sprites/station-start.png new file mode 100644 index 0000000..49a57e3 Binary files /dev/null and b/sprites/station-start.png differ diff --git a/sprites/tracks.png b/sprites/tracks.png index c9e8abf..a049208 100644 Binary files a/sprites/tracks.png and b/sprites/tracks.png differ diff --git a/sprites/tunnel-loop.png b/sprites/tunnel-loop.png new file mode 100644 index 0000000..ef20a33 Binary files /dev/null and b/sprites/tunnel-loop.png differ diff --git a/sprites/tunnel.png b/sprites/tunnel.png deleted file mode 100644 index 3c03a26..0000000 Binary files a/sprites/tunnel.png and /dev/null differ diff --git a/wip-assets/sprites/station.pdn b/wip-assets/sprites/station.pdn new file mode 100644 index 0000000..cd2b07f Binary files /dev/null and b/wip-assets/sprites/station.pdn differ diff --git a/wip-assets/sprites/station.png b/wip-assets/sprites/station.png new file mode 100644 index 0000000..d919a60 Binary files /dev/null and b/wip-assets/sprites/station.png differ diff --git a/wip-assets/sprites/subway-title.vox b/wip-assets/sprites/subway-title.vox index 22c7f30..a549407 100644 Binary files a/wip-assets/sprites/subway-title.vox and b/wip-assets/sprites/subway-title.vox differ