Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 55412bb99e0652a8efbc98589ad933d4bdade4b0 @authorNari committed
Showing with 2,199 additions and 0 deletions.
  1. +20 −0 MIT-LICENSE
  2. +32 −0 README
  3. +182 −0 lib/fpstimer.rb
  4. +173 −0 lib/input.rb
  5. +14 −0 lib/sdl_helper.rb
  6. +48 −0 nario.rb
  7. +130 −0 nario/factor.rb
  8. BIN nario/fonts/VeraMoBd.ttf
  9. +77 −0 nario/gamestart.rb
  10. BIN nario/image/bush2.bmp
  11. BIN nario/image/can.bmp
  12. BIN nario/image/castle.bmp
  13. BIN nario/image/chibi_nario.bmp
  14. BIN nario/image/cloud1.bmp
  15. BIN nario/image/cloud2.bmp
  16. BIN nario/image/cloud3.bmp
  17. BIN nario/image/coin.bmp
  18. BIN nario/image/dustbin.bmp
  19. BIN nario/image/flag.bmp
  20. BIN nario/image/floor_block.bmp
  21. BIN nario/image/gc_start.bmp
  22. BIN nario/image/goal.bmp
  23. BIN nario/image/item_block.bmp
  24. BIN nario/image/left_nario.bmp
  25. BIN nario/image/mountain.bmp
  26. BIN nario/image/pipe.bmp
  27. BIN nario/image/pole.bmp
  28. +1 −0 nario/image/replace_png.rb
  29. BIN nario/image/stop.bmp
  30. BIN nario/image/strong_block.bmp
  31. BIN nario/image/title.bmp
  32. BIN nario/image/title.jpg
  33. BIN nario/image/weak_block.bmp
  34. +167 −0 nario/life.rb
  35. +75 −0 nario/life/can.rb
  36. +77 −0 nario/life/carapace.rb
  37. +65 −0 nario/life/dustbin.rb
  38. +34 −0 nario/life/enemy.rb
  39. +162 −0 nario/life/nario.rb
  40. +5 −0 nario/map.rb
  41. +93 −0 nario/map/map1_1.rb
  42. +7 −0 nario/map/title.rb
  43. +90 −0 nario/material.rb
  44. +4 −0 nario/material/background.rb
  45. +7 −0 nario/material/floor.rb
  46. +11 −0 nario/material/goal.rb
  47. +40 −0 nario/material/itemblock.rb
  48. +46 −0 nario/material/itembox.rb
  49. +29 −0 nario/material/jumpcoin.rb
  50. +8 −0 nario/material/pipe.rb
  51. +31 −0 nario/material/pole.rb
  52. +7 −0 nario/material/strongblock.rb
  53. +30 −0 nario/material/weakblock.rb
  54. +214 −0 nario/scene.rb
  55. +97 −0 nario/scene/flowworld.rb
  56. +15 −0 nario/scene/title.rb
  57. +208 −0 nario/test.rb
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Narihiro Nakamura
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 README
@@ -0,0 +1,32 @@
+= nario
+
+nario(SUPER NARIO GC) is horizontal scrolling game style demo tool for Ruby's GC.
+
+== require libs
+(1) ruby 1.9.2 or later
+(2) rubysdl-2.1.1
+
+== run
+
+ $ ruby nario.rb
+
+== options
+
+Please see:
+
+ $ ruby nario.rb -h
+
+== after
+
+You say "nario, It's revolutionary work!!", right?
+
+== Thanks
+* SDL
+ * author:slouken
+ * http://www.devolution.com/~slouken/
+* ruby/sdl
+ * author:ohai
+ * http://www.kmc.gr.jp/~ohai/index.html
+* rskit
+ * author:yhara
+ * http://mono.kmc.gr.jp/~yhara/
182 lib/fpstimer.rb
@@ -0,0 +1,182 @@
+require 'sdl'
+
+class FPSTimerSample
+ FPS_COUNT = 10
+
+ attr_accessor :fps
+ attr_reader :real_fps, :total_skip
+ attr_reader :count_sleep
+ # +fps+ is the number of frames per second that you want to keep,
+ # +accurary+ is the accurary of sleep/SDL.delay in milisecond
+ def initialize(fps = 60, accurary = 10, skip_limit = 15)
+ @fps = fps
+ @accurary = accurary / 1000.0
+ @skip_limit = skip_limit
+ end
+
+ # reset timer, you should call just before starting loop
+ def reset
+ @old = get_ticks
+ @skip = 0
+ @real_fps = @fps
+ @frame_count = 0
+ @fps_old = @old
+ @count_sleep = 0
+ @total_skip = 0
+ end
+
+ # execute given block and wait
+ def wait_frame
+ now = get_ticks
+ nxt = @old + (1.0/@fps)
+ if nxt > now
+ yield
+ @skip = 0
+ wait(nxt)
+ @old = nxt
+ elsif @skip > @skip_limit
+ yield
+ @skip = 0
+ @old = get_ticks
+ else
+ @skip += 1
+ @total_skip += 1
+ @old = nxt
+ end
+
+ calc_real_fps
+ end
+
+ private
+ def wait(nxt)
+ while nxt > get_ticks + @accurary
+ sleep(@accurary - 0.005)
+ @count_sleep += 1
+ end
+
+ while nxt > get_ticks
+ # busy loop, do nothing
+ end
+ end
+
+ def get_ticks
+ SDL.getTicks / 1000.0
+ end
+
+ def calc_real_fps
+ @frame_count += 1
+ if @frame_count >= FPS_COUNT
+ @frame_count = 0
+ now = get_ticks
+ @real_fps = FPS_COUNT / (now - @fps_old)
+ @fps_old = now
+ end
+ end
+end
+
+class FPSTimerLight
+ N = 12
+ DT = 2
+ FPS_COUNT = 10
+
+ attr_reader :fps
+ attr_reader :real_fps
+ # +fps+ is the number of frames per second that you want to keep,
+ # +accurary+ is the accurary of sleep/SDL.delay in milisecond
+ def initialize(fps = 60, accurary = 10, skip_limit = 15)
+ @fps = fps
+ @accurary = accurary * N
+ @skip_limit = skip_limit
+ @one_frame = 1000*N / fps
+ @delay = accurary - 2
+ end
+
+ # reset timer, you should call just before starting loop
+ def reset
+ @old = get_ticks
+ @skip = 0
+
+ # for calculate real fps
+ @frame_count = 0
+ @fps_old = @old
+ @real_fps = @fps
+ end
+
+ def wait_frame
+ now = get_ticks
+ nxt = @old + @one_frame
+ if nxt > now
+ yield
+ @skip = 0
+ wait(nxt)
+ @old = nxt
+ elsif @skip > @skip_limit
+ yield
+ @skip = 0
+ @old = get_ticks
+ else
+ @skip += 1
+ @old = nxt
+ end
+
+ calc_real_fps
+ end
+
+ private
+ def get_ticks
+ SDL.getTicks * N
+ end
+
+ def wait(nxt)
+ while nxt > get_ticks + @accurary
+ SDL.delay(@delay)
+ end
+
+ while nxt > get_ticks
+ # busy loop, do nothing
+ end
+ end
+
+ def calc_real_fps
+ @frame_count += 1
+ if @frame_count >= FPS_COUNT
+ @frame_count = 0
+ now = get_ticks
+ @real_fps = (N*1000*FPS_COUNT)/(now - @fps_old)
+ @fps_old = now
+ end
+ end
+end
+
+if __FILE__ == $0
+ timer = FPSTimerSample.new
+ log = []
+
+ timer.reset
+ 300.times do
+ sleep 0.005 if rand(5) == 0
+ timer.wait_frame do
+ log << timer.real_fps.to_s
+ end
+ end
+
+ puts log
+ printf "skip:%d\n", timer.total_skip
+ printf "sleep:%d\n", timer.count_sleep
+
+ puts
+
+ timer = FPSTimerLight.new
+ log = []
+
+ timer.reset
+ old = SDL.getTicks
+ 300.times do
+ sleep 0.005 if rand(5) == 0
+ timer.wait_frame do
+ log << timer.real_fps
+ end
+ end
+
+ puts log
+end
173 lib/input.rb
@@ -0,0 +1,173 @@
+#
+# input.rb - version 20061223
+#
+
+class Input
+ AXIS_THRESHOLD = 500
+ REPEAT_THRESHOLD = 19
+ REPEAT_SPEED = 6
+ REPEATS = []
+ KEY_MAP = {}
+ KeyMapInfo = Struct.new(:name, :mod)
+ MOD_MAP = {
+ :ctrl => SDL::Key::MOD_CTRL,
+ :shift => SDL::Key::MOD_SHIFT,
+ :alt => SDL::Key::MOD_ALT,
+ :meta => SDL::Key::MOD_META,
+ }
+ JOYHAT_MAP = {
+ SDL::Joystick::HAT_UP => :up,
+ SDL::Joystick::HAT_RIGHT => :right,
+ SDL::Joystick::HAT_DOWN => :down,
+ SDL::Joystick::HAT_LEFT => :left
+ }
+ JOYBUTTON_MAP = {}
+
+ def self.define_key_ctrl( key,name,repeats=false); define_key(key,name,repeats,:ctrl) ; end
+ def self.define_key_shift(key,name,repeats=false); define_key(key,name,repeats,:shift) ; end
+ def self.define_key_alt( key,name,repeats=false); define_key(key,name,repeats,:alt) ; end
+ def self.define_key_meta( key,name,repeats=false); define_key(key,name,repeats,:meta) ; end
+
+ def self.define_key(key, name, repeats = false, mod=nil)
+ KEY_MAP[key] = KeyMapInfo.new(name, MOD_MAP[mod])
+ module_eval <<-EOD
+ def #{name}
+ @info[:#{name}]
+ end
+ EOD
+ if repeats
+ REPEATS << name
+ end
+ end
+
+ def self.define_pad_button(button, name)
+ JOYBUTTON_MAP[button] = name
+ module_eval <<-EOD
+ def #{name}
+ @info[:#{name}]
+ end
+ EOD
+ end
+
+ def initialize
+ #ジョイスティックの初期化
+ if SDL::Joystick.num > 0
+ @joystick = SDL::Joystick.open(0)
+ else
+ @joystick = Object.new #ダミーのジョイスティックをつくる
+ def @joystick.axis(i) ; 0 ; end
+ def @joystick.hat(i) ; nil ; end
+ def @joystick.button(i) ; false ; end
+ end
+
+ @stopped = false
+ @repeat_ct = Hash.new(0)
+ clear
+ end
+ attr_accessor :stopped
+ attr_reader :info
+
+ def clear
+ @info = {}
+ end
+
+ def poll
+ clear
+
+ #scan
+ SDL::Key.scan
+ KEY_MAP.each do |key, info|
+ if SDL::Key.press?(key)
+ if info.mod.nil? || (SDL::Key.mod_state & info.mod)
+ set_pressed(info.name)
+ end
+ end
+ end
+ JOYBUTTON_MAP.each do |button, name|
+ set_pressed(name) if @joystick.button(button)
+ end
+ set_pressed(axis2name(0, @joystick.axis(0)))
+ set_pressed(axis2name(1, @joystick.axis(1)))
+ set_pressed(JOYHAT_MAP[@joystick.hat(0)])
+
+ #event
+ while event = SDL::Event2.poll
+ case event
+ when SDL::Event2::Quit
+ set_pushed(:exit)
+ when SDL::Event2::KeyDown
+ if (info = KEY_MAP[event.sym])
+ if info.mod.nil? || (event.mod & info.mod)
+ set_pushed(info.name)
+ end
+ end
+ when SDL::Event2::JoyAxis
+ set_pushed(axis2name(event.axis, event.value))
+ when SDL::Event2::JoyHat
+ set_pushed(JOYHAT_MAP[event.value])
+ when SDL::Event2::JoyButtonDown
+ set_pushed(JOYBUTTON_MAP[event.button])
+ end
+ end
+
+ end
+
+ def axis2name(axis, value)
+ case axis
+ when 0
+ if value > AXIS_THRESHOLD
+ :right
+ elsif value < -AXIS_THRESHOLD
+ :left
+ end
+ when 1
+ if value > AXIS_THRESHOLD
+ :down
+ elsif value < -AXIS_THRESHOLD
+ :up
+ end
+ end
+ end
+
+ def set_pushed(name)
+ @info[name] = :push
+ @repeat_ct = Hash.new(0)
+ end
+
+ def set_pressed(name)
+ return if name.nil?
+
+ @info[name] = :press
+
+ if REPEATS.include? name
+ @repeat_ct[name] += 1
+ diff = @repeat_ct[name] - REPEAT_THRESHOLD
+
+ if diff == 0
+ @info[name] = :push
+ elsif diff > REPEAT_SPEED
+ @info[name] = :push
+ @repeat_ct[name] = REPEAT_THRESHOLD
+ end
+ end
+ end
+
+ def pushed?(name)
+ @info[name] == :push && (not @stopped)
+ end
+
+ def pressed?(name)
+ @info[name] && (not @stopped)
+ end
+ alias :[] :pressed?
+
+ def pushed_first
+ if (keys = @info.find{|name,type| type==:push}) && (not @stopped)
+ keys.first
+ else
+ nil
+ end
+ end
+
+end
+
14 lib/sdl_helper.rb
@@ -0,0 +1,14 @@
+class << SDL::Surface
+ alias :org_load :load
+end
+
+class SDL::Surface
+ def self.load(path)
+ org_load("#{File.join(File.dirname(__FILE__), "..")}/#{path}")
+ end
+
+ def rotate_surface(angle, color)
+ transform_surface(color, angle, 1, 1, 2)
+ end
+end
+
48 nario.rb
@@ -0,0 +1,48 @@
+# super nario gc
+
+$: << File.join(File.dirname(__FILE__), 'nario')
+
+require 'sdl'
+require_relative 'lib/fpstimer.rb'
+require_relative 'lib/input.rb'
+require_relative 'lib/sdl_helper.rb'
+require 'optparse'
+
+$GC_BURDEN_MODE = false
+$TEST_MODE = false
+$DEBUG_EVENT_WATCH_MODE = false
+$DEBUG_PLAYER_WATCH_MODE = false
+opt = OptionParser.new
+opt.version = "1.0.0"
+opt.on('-g', '--gc', "To stop the world. and gc stop grafical mode :)") {|v| $GC_BURDEN_MODE = true}
+opt.on('-t', '--test', "test mode") {|v| $TEST_MODE = true}
+opt.on('--debug-event', "debug: event watch mode") {|v| $DEBUG_EVENT_WATCH_MODE = true}
+opt.on('--debug-player', "debug: player watch mode") {|v| $DEBUG_PLAYER_WATCH_MODE = true}
+opt.parse!(ARGV)
+
+# burden to nario and gc :)
+if $GC_BURDEN_MODE
+ @@arry = []
+ 3000000.times{@@arry << Array.new}
+ @@skip = 1
+
+ def gc_start(screen)
+ case @@skip
+ when 30
+ screen.put(SDL::Surface.load("nario/image/gc_start.bmp"), 270, 270)
+ return @@skip = 0
+ when 0
+ @@skip = 1
+ return GC.start()
+ end
+ @@skip += 1
+ end
+end
+
+module Nario
+end
+
+require_relative 'nario/scene'
+require_relative 'nario/material'
+require_relative 'nario/gamestart' unless $TEST_MODE
+require_relative 'nario/test' if $TEST_MODE
130 nario/factor.rb
@@ -0,0 +1,130 @@
+module Nario
+ class Factor
+ attr_accessor :x, :y, :w, :h, :img, :foot, :head, :left, :right, :is_dead, :is_garbage, :frame, :now_scene, :movie_event
+
+ def initialize(x, y, w, h, img=nil)
+ @x = x
+ @y = y
+ @w = w
+ @h = h
+ @img = img
+ w_delete = @w/6
+ h_delete = @h/6
+ @is_garbage = false
+ @is_dead = false
+ @movie_event = nil
+ @frame = 0
+ @now_scene = nil
+ end
+
+ def action
+ send(@movie_event) if @movie_event
+ end
+
+ def collision_event(collide)
+ event = nil
+ return event unless collision_maybe? collide
+ return event_call(event, collide) if event = have_event_range(foot_range, collide.head_range)
+ return event_call(event, collide) if event = have_event_range(head_range, collide.foot_range)
+ return event_call(event, collide) if event = have_event_range(leftside_range, collide.rightside_range)
+ return event_call(event, collide) if event = have_event_range(rightside_range, collide.leftside_range)
+ end
+
+ def center
+ [(@x+@w/2), (@y+@h/2)]
+ end
+
+ def head_range
+ {:x_range => @x..(@x+@w), :y_range => @y..(@y+10), :event => ("collide_#{extract_class_name(self)}_head".to_sym)}
+ end
+
+ def leftside_range
+ {:x_range => @x..(@x+@w/6), :y_range => @y..(@y+@h), :event => ("collide_#{extract_class_name(self)}_left".to_sym)}
+ end
+
+ def rightside_range
+ {:x_range => (@x+@w-@w/6)..(@x+@w), :y_range => @y..(@y+@h), :event => ("collide_#{extract_class_name(self)}_right".to_sym)}
+ end
+
+ def foot_range
+ {:x_range => @x..(@x+@w), :y_range => (@y+@h-10)..(@y+@h), :event => ("collide_#{extract_class_name(self)}_foot".to_sym)}
+ end
+
+ def garbage?
+ @is_garbage
+ end
+
+ def dead?
+ @is_dead
+ end
+
+ def xy_move(x, y)
+ @x += x
+ @y += y
+ end
+
+ def x_move(x)
+ @x += x
+ end
+
+ def y_move(y)
+ @y += y
+ end
+
+ def countup_frame
+ @frame += 1
+ @frame = 0 if @frame > 50000
+ end
+
+ private
+ def animate(imgs, frame_time)
+ if (@frame % frame_time).zero?
+ index = imgs.last
+ index = 0 if imgs.size-1 == index
+ change_img(imgs[index])
+ index += 1
+ imgs[imgs.size-1] = index
+ end
+ end
+
+ def extract_class_name(obj)
+ obj.class.to_s.downcase[/\w+\z/]
+ end
+
+ def collision_maybe?(other)
+ (center[0] - other.center[0]).abs < ((@w/2) + (other.w/2) + 20) and (center[1] - other.center[1]).abs < ((@h/2) + (other.h/2) + 20)
+ end
+
+ def event_call(event, other)
+ is_or_dead = (@is_dead or other.is_dead)
+ puts "event! #{self.class}\##{event[:self_event]} <--> #{other.class}\##{event[:other_event]}" if $DEBUG_EVENT_WATCH_MODE
+ other.send(event[:self_event], self) if other.methods.map{|a| a.to_s}.include? event[:self_event].to_s and !is_or_dead
+ send(event[:other_event], other) if methods.map{|b| b.to_s}.include? event[:other_event].to_s and !is_or_dead
+ end
+
+ def have_event_range(self_range, other_range)
+ e = false
+ return e unless self_range and other_range
+ self_range[:x_range].each{|i| break e = true if other_range[:x_range].include? i}
+ return e unless e
+ e = false
+ self_range[:y_range].each{|i| break e = true if other_range[:y_range].include? i}
+ {:self_event => self_range[:event], :other_event => other_range[:event]} if e
+ end
+
+ def clean_bg(img)
+ img.set_color_key(SDL::SRCCOLORKEY, [255, 255, 255])
+ img
+ end
+
+ def change_img(img)
+ @img = img
+ @w = img.w
+ @h = img.h
+ end
+
+ def movie_end
+ @movie_event = nil
+ end
+ end
+end
BIN nario/fonts/VeraMoBd.ttf
Binary file not shown.
77 nario/gamestart.rb
@@ -0,0 +1,77 @@
+require_relative 'scene'
+require_relative 'material'
+require_relative 'life'
+require_relative 'map'
+
+# key config(SDL <--> nario)
+class Input
+ define_key SDL::Key::ESCAPE, :exit
+ define_key SDL::Key::Q, :exit
+ define_key SDL::Key::LEFT, :left
+ define_key SDL::Key::RIGHT, :right
+ define_key SDL::Key::UP, :up
+ define_key SDL::Key::DOWN, :down
+ define_key SDL::Key::RETURN, :ok
+ define_key SDL::Key::A, :a
+ define_key SDL::Key::B, :b
+ define_key SDL::Key::S, :start
+ define_key SDL::Key::G, :go
+end
+
+module Nario
+ # nario make map
+ def self.creation_nario_world(screen)
+ world = {}
+ world[:title] = Scene::Title.new { success :map1_1 }
+ world[:title].build_scene &Map::TITLE
+ world[:map1_1] = Scene::FlowWorld.new { success :title; miss :title }
+ world[:map1_1].build_scene &Map::MAP1_1
+ world
+ end
+
+ def self.setup_sdl
+ SDL.init(SDL::INIT_JOYSTICK)
+ SDL::TTF.init
+ SDL.set_video_mode(Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT, 16, SDL::HWSURFACE|SDL::DOUBLEBUF)
+ end
+
+ @stop = false
+ def self.stop?(input, screen)
+ if input.start
+ screen.put(SDL::Surface.load("nario/image/stop.bmp"), 270, 270)
+ screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT)
+ @stop = true
+ end
+ if input.go
+ @stop = false
+ end
+ return @stop
+ end
+
+ def self.go_nario!
+ screen = setup_sdl()
+ world = creation_nario_world(screen)
+
+ input = Input.new
+ timer = FPSTimerLight.new
+ timer.reset
+ scene = world[:title]
+
+ # main loop
+ loop {
+ input.poll
+ break if input[:exit]
+ redo if stop?(input, screen)
+
+ s_next = scene.act(input)
+ scene.render(screen)
+ scene = world[s_next].rebuild if s_next
+ timer.wait_frame {
+ gc_start(screen) if $GC_BURDEN_MODE
+ screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT)
+ }
+ }
+ end
+
+ go_nario!
+end
BIN nario/image/bush2.bmp
Binary file not shown.
BIN nario/image/can.bmp
Binary file not shown.
BIN nario/image/castle.bmp
Binary file not shown.
BIN nario/image/chibi_nario.bmp
Binary file not shown.
BIN nario/image/cloud1.bmp
Binary file not shown.
BIN nario/image/cloud2.bmp
Binary file not shown.
BIN nario/image/cloud3.bmp
Binary file not shown.
BIN nario/image/coin.bmp
Binary file not shown.
BIN nario/image/dustbin.bmp
Binary file not shown.
BIN nario/image/flag.bmp
Binary file not shown.
BIN nario/image/floor_block.bmp
Binary file not shown.
BIN nario/image/gc_start.bmp
Binary file not shown.
BIN nario/image/goal.bmp
Binary file not shown.
BIN nario/image/item_block.bmp
Binary file not shown.
BIN nario/image/left_nario.bmp
Binary file not shown.
BIN nario/image/mountain.bmp
Binary file not shown.
BIN nario/image/pipe.bmp
Binary file not shown.
BIN nario/image/pole.bmp
Binary file not shown.
1 nario/image/replace_png.rb
@@ -0,0 +1 @@
+Dir['*.PNG'].each { |f| File.rename(f,f.downcase)}
BIN nario/image/stop.bmp
Binary file not shown.
BIN nario/image/strong_block.bmp
Binary file not shown.
BIN nario/image/title.bmp
Binary file not shown.
BIN nario/image/title.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN nario/image/weak_block.bmp
Binary file not shown.
167 nario/life.rb
@@ -0,0 +1,167 @@
+require_relative 'factor'
+
+module Nario::Life
+ class Life < Nario::Factor
+ attr_accessor :frame, :direction
+
+ def initialize(x, y, img)
+ super(x, y, img.w, img.h, img)
+ @slip_right_img = nil
+ @slip_left_img = nil
+ @jump_right_img = nil
+ @jump_left_img = nil
+ @animate_right = nil
+ @animate_left = nil
+ @dash_speed = 0
+ @jump_speed = 0
+ @fall_speed = 0
+ @is_fly = false
+ @direction = {:right => true, :left => false}
+ end
+
+
+ def put_screen(screen)
+ screen.put(@img, @x, @y) if @img
+ end
+
+ def dash(move_rate, animate_img, is_sp_update)
+ return if slip(move_rate)
+ set_direction(move_rate)
+ @dash_speed = move_rate if @dash_speed.zero?
+ @dash_speed += move_rate if is_sp_update
+ animate_dash(animate_img, @dash_speed)
+ x_move(@dash_speed)
+ end
+
+ def jump
+ unless @is_fly
+ @is_fly = true
+ change_img(@jump_left_img) if @direction[:left] and @jump_left_img
+ change_img(@jump_right_img) if @direction[:right] and @jump_right_img
+ agravity
+ else
+ @fall_speed -= 2 if (@frame % 4).zero? and @fall_speed < 0
+ end
+ end
+
+ def gravity
+ fall
+ end
+
+ def agravity
+ @fall_speed = -15
+ y_move(-2)
+ end
+
+ def frame_reset
+ @frame = 0
+ end
+
+ def force_notfall
+ @fall_speed = 0
+ end
+
+ def stand_up(floor)
+ @y = floor.y - @h - 1
+ @fall_speed = 0
+ @is_fly = false
+ end
+
+ def fall
+ @is_fly = true if @fall_speed.nonzero?
+ y_move(@fall_speed)
+ @fall_speed += 1 if @fall_speed < 15
+ end
+
+ def state
+ "x=#{@x} y=#{@y}"
+ end
+
+ def head_range
+ {:x_range => (@x+@w/6)..(@x+@w-@w/6), :y_range => @y..(@y+@h/6), :event => ("collide_#{extract_class_name(self)}_head".to_sym)}
+ end
+
+ def foot_range
+ {:x_range => (@x+@w/6)..(@x+@w-@w/6), :y_range => (@y+@h-@h/6)..(@y+@h), :event => ("collide_#{extract_class_name(self)}_foot".to_sym)}
+ end
+
+ def leftside_range
+ {:x_range => @x..(@x+@w/6), :y_range => (@y+@h/6)..(@y+@h-@h/6), :event => ("collide_#{extract_class_name(self)}_left".to_sym)}
+ end
+
+ def rightside_range
+ {:x_range => (@x+@w-@w/6)..(@x+@w), :y_range => (@y+@h/6)..(@y+@h-@h/6), :event => ("collide_#{extract_class_name(self)}_right".to_sym)}
+ end
+
+ #collision event
+ def collide_floor_head(f) stand_up(f) end
+ def collide_floor_left(f) @x = (f.x - @w); @dash_speed = 0; end
+ def collide_floor_right(f) @x = f.x + f.w; @dash_speed = 0; end
+ alias collide_weakblock_head collide_floor_head
+ alias collide_weakblock_left collide_floor_left
+ alias collide_weakblock_right collide_floor_right
+ alias collide_itembox_head collide_floor_head
+ alias collide_itembox_left collide_floor_left
+ alias collide_itembox_right collide_floor_right
+ alias collide_strongblock_head collide_floor_head
+ alias collide_strongblock_left collide_floor_left
+ alias collide_strongblock_right collide_floor_right
+ alias collide_pipe_head collide_floor_head
+ alias collide_pipe_left collide_floor_left
+ alias collide_pipe_right collide_floor_right
+
+ private
+ # frame % ? == 0: get ? parameter
+ def get_dash_frame(dash_speed)
+ step_rate = 4
+ [[(4..7), 3], [(8..10), 2], [Range.new(11, 100, true), 1]].each{|i| step_rate = i.last if i.first.include? dash_speed.abs}
+ step_rate
+ end
+
+ def animate_dash(m_imgs, dash_speed)
+ return if @is_fly
+ animate(m_imgs, get_dash_frame(dash_speed))
+ end
+
+ def slip(move_rate)
+ # not turn?
+ return false unless (move_rate < 0 and @dash_speed > 0) or (move_rate > 0 and @dash_speed < 0)
+
+ #define slip_time. it's setting dash_speed
+ @slip_time = @dash_speed.abs unless @slip_time and @slip_time > 0
+
+ change_img(@slip_left_img) if @direction[:left] and !@is_fly
+ change_img(@slip_right_img) if @direction[:right] and !@is_fly
+ x_move(@dash_speed)
+ @dash_speed = 0 if (@slip_time -= 1).zero?
+ true
+ end
+
+ def set_direction(move_rate)
+ return if @is_fly
+ if move_rate >= 0
+ @direction[:right] = true
+ @direction[:left] = false
+ else
+ @direction[:right] = false
+ @direction[:left] = true
+ end
+ end
+
+ def force_jump
+ @is_fly = false
+ jump
+ end
+
+ def force_fall(w)
+ @fall_speed = -1
+ @y = w.y + w.h + 5
+ end
+ end
+
+ autoload :Nario, "life/nario"
+ autoload :Enemy, "life/enemy"
+ autoload :Can, "life/can"
+ autoload :Dustbin, "life/dustbin"
+ autoload :Carapace, "life/carapace"
+end
75 nario/life/can.rb
@@ -0,0 +1,75 @@
+module Nario::Life
+ class Can < Enemy
+ DASH_MAX_DASH_SPEED = 2
+ JUMP_MAX_SPEED = -15
+
+ def initialize(x, y)
+ im = SDL::Surface.load("nario/image/can.bmp")
+ super(x, y, clean_bg(im.copy_rect(0, 0, 50, 48)))
+ @animate_right = [im.copy_rect(0, 0, 50, 48), im.copy_rect(50, 0, 50, 48), 0]
+ @animate_right.map{|i| clean_bg(i) unless i == 0}
+ @animate_left = [im.copy_rect(0, 0, 50, 48), im.copy_rect(50, 0, 50, 48), 0]
+ @animate_left.map{|i| clean_bg(i) unless i == 0}
+ @dead_img = clean_bg(im.copy_rect(100, 0, 50, 48))
+ @dash_speed = DASH_MAX_DASH_SPEED
+ @direction = {:right => false, :left => true}
+ end
+
+ def action
+ send(@movie_event) if @movie_event
+ if @is_dead
+ @is_garbage = true if (@frame % 40).zero?
+ return
+ end
+ walk_left if @direction[:left]
+ walk_right if @direction[:right]
+ end
+
+ # collision parts
+ def head_range; {:x_range => @x..(@x+@w), :y_range => (@y+10)..(@y+@h/2), :event => :collide_can_head}; end
+
+ # collision event
+ def collide_nario_foot(nario)
+ frame_reset
+ @is_dead = true
+ @movie_event = :compress
+ end
+
+ def collide_floor_head(floor)
+ walk_right if ((floor.x)..(floor.x + 3)).include? @x
+ walk_left if ((floor.x + floor.w - 3)..(floor.x + floor.w)).include?((@x+@w))
+ stand_up(floor)
+ end
+
+ def collide_weakblock_head(w)
+ if w.movie_event.to_s == "bound"
+ @is_dead = true
+ change_img(clean_bg(@img.rotate_surface(180, [255, 255, 255])))
+ frame_reset
+ return force_jump
+ end
+ stand_up(w)
+ end
+ alias collide_itembox_head collide_weakblock_head
+
+ private
+ def get_dash_frame(dash_speed)
+ step_rate = 6
+ end
+
+ def compress
+ change_img(@dead_img)
+ force_notfall
+ end
+
+ def walk_left
+ @dash_speed = -DASH_MAX_DASH_SPEED
+ dash(-1, @animate_left, false)
+ end
+
+ def walk_right
+ @dash_speed = DASH_MAX_DASH_SPEED
+ dash(1, @animate_right, false)
+ end
+ end
+end
77 nario/life/carapace.rb
@@ -0,0 +1,77 @@
+module Nario::Life
+ class Carapace < Enemy
+ DASH_MAX_DASH_SPEED = 11
+ JUMP_MAX_SPEED = -15
+
+ def initialize(x, y)
+ im = SDL::Surface.load("nario/image/dustbin.bmp")
+ super(x, y, clean_bg(im.copy_rect(100, 0, 54, 43)))
+ @animate_right = [im.copy_rect(100, 0, 54, 43), 0]
+ @animate_right.map{|i| clean_bg(i) unless i == 0}
+ @animate_left = [im.copy_rect(100, 0, 54, 43), 0]
+ @animate_left.map{|i| clean_bg(i) unless i == 0}
+ @dead_img = clean_bg(im.copy_rect(100, 0, 54, 43))
+ @dash_speed = 0
+ @direction = {:right => false, :left => false}
+ end
+
+ def action
+ slip_left if @direction[:left]
+ slip_right if @direction[:right]
+ end
+
+ def violence?
+ return @dash_speed.nonzero?
+ end
+
+ # collision parts
+ def head_range; {:x_range => (@x+@w/2-10)..(@x+@w/2+10), :y_range => (@y+10)..(@y+@h/2), :event => :collide_can_head}; end
+
+ # collision event
+ def collide_nario_foot(m); stop; end
+ def collide_nario_right(m); set_direction(1); end
+ def collide_nario_left(m); set_direction(-1); end
+ undef collide_can_left
+ undef collide_can_right
+ undef collide_dustbin_left
+ undef collide_dustbin_right
+ def collide_carapace_left(c); collide_strongblock_left(c); end;
+ def collide_carapace_right(c); collide_strongblock_right(c); end;
+
+ def collide_weakblock_head(w)
+ if w.movie_event.to_s == "bound"
+ stop
+ return force_jump
+ end
+ stand_up(w)
+ end
+
+ def clash(carapace)
+ @is_dead = true
+ change_img(clean_bg(@img.rotate_surface(180, [255, 255, 255])))
+ frame_reset
+ return force_jump
+ end
+
+ private
+ def get_dash_frame(dash_speed)
+ step_rate = 1000
+ end
+
+ def stop
+ @dash_speed = 0
+ @direction[:left] = false
+ @direction[:right] = false
+ end
+
+ def slip_left
+ @dash_speed = -DASH_MAX_DASH_SPEED
+ dash(-1, @animate_left, false)
+ end
+
+ def slip_right
+ @dash_speed = DASH_MAX_DASH_SPEED
+ dash(1, @animate_right, false)
+ end
+ end
+end
65 nario/life/dustbin.rb
@@ -0,0 +1,65 @@
+module Nario::Life
+ class Dustbin < Enemy
+ DASH_MAX_DASH_SPEED = 2
+ JUMP_MAX_SPEED = -15
+
+ def initialize(x, y)
+ im = SDL::Surface.load("nario/image/dustbin.bmp")
+ super(x, y, clean_bg(im.copy_rect(0, 0, 50, 69)))
+ @animate_right = [im.copy_rect(0, 70, 50, 69), im.copy_rect(50, 70, 50, 69), 0]
+ @animate_right.map{|i| clean_bg(i) unless i == 0}
+ @animate_left = [im.copy_rect(0, 0, 50, 69), im.copy_rect(50, 0, 50, 69), 0]
+ @animate_left.map{|i| clean_bg(i) unless i == 0}
+ @dash_speed = DASH_MAX_DASH_SPEED
+ @direction = {:right => false, :left => true}
+ end
+
+ def action
+ send(@movie_event) if @movie_event
+ if @is_dead
+ @is_garbage = true if (@frame % 40).zero?
+ return
+ end
+ walk_left if @direction[:left]
+ walk_right if @direction[:right]
+ end
+
+ # collision event
+ def collide_nario_foot(nario)
+ @now_scene.in(:enemy, Carapace.new(@x, @y+20))
+ @img = nil
+ @is_dead = true
+ end
+
+ def collide_floor_head(floor)
+ walk_right if ((floor.x)..(floor.x + 3)).include? @x
+ walk_left if ((floor.x + floor.w - 3)..(floor.x + floor.w)).include?((@x+@w))
+ stand_up(floor)
+ end
+
+ def collide_weakblock_head(w)
+ if w.movie_event.to_s == "bound"
+ @now_scene.in(:enemy, Carapace.new(@x, @y+20))
+ @img = nil
+ @is_dead = true
+ end
+ stand_up(w)
+ end
+ alias collide_itembox_head collide_weakblock_head
+
+ private
+ def get_dash_frame(dash_speed)
+ step_rate = 6
+ end
+
+ def walk_left
+ @dash_speed = -DASH_MAX_DASH_SPEED
+ dash(-1, @animate_left, false)
+ end
+
+ def walk_right
+ @dash_speed = DASH_MAX_DASH_SPEED
+ dash(1, @animate_right, false)
+ end
+ end
+end
34 nario/life/enemy.rb
@@ -0,0 +1,34 @@
+module Nario::Life
+ class Enemy < Life
+ #collision events
+ def collide_strongblock_left(s) set_direction(-1) end
+ def collide_strongblock_right(s) set_direction(1) end
+ def collide_floor_head(f) stand_up(f) end
+
+ def collide_carapace_left(c)
+ return clash(c) if c.violence?
+ collide_strongblock_left(c)
+ end
+
+ def collide_carapace_right(c)
+ return clash(c) if c.violence?
+ collide_strongblock_right(c)
+ end
+
+ alias collide_weakblock_head collide_floor_head
+ alias collide_itembox_head collide_weakblock_head
+ alias collide_can_left collide_strongblock_left
+ alias collide_can_right collide_strongblock_right
+ alias collide_dustbin_left collide_strongblock_left
+ alias collide_dustbin_right collide_strongblock_right
+ alias collide_pipe_left collide_strongblock_left
+ alias collide_pipe_right collide_strongblock_right
+
+ def clash(carapace)
+ @is_dead = true
+ change_img(clean_bg(@img.rotate_surface(180, [255, 255, 255])))
+ frame_reset
+ return force_jump
+ end
+ end
+end
162 nario/life/nario.rb
@@ -0,0 +1,162 @@
+module Nario::Life
+ class Nario < Life
+ DASH_MAX_DASH_SPEED = 5
+ B_DASH_MAX_DASH_SPEED = 9
+
+ #limit break
+ #B_DASH_MAX_DASH_SPEED = 100
+
+ def initialize(x, y)
+ im = SDL::Surface.load("nario/image/chibi_nario.bmp")
+ super(x, y, clean_bg(im.copy_rect(0, 0, 50, 50)))
+ @slip_right_img = clean_bg(im.copy_rect(200, 0, 50, 50))
+ @slip_left_img = clean_bg(im.copy_rect(200, 51, 50, 50))
+ @jump_right_img = clean_bg(im.copy_rect(250, 0, 50, 50))
+ @jump_left_img = clean_bg(im.copy_rect(250, 51, 50, 50))
+ @def_right_img = clean_bg(im.copy_rect(0, 0, 50, 50))
+ @def_left_img = clean_bg(im.copy_rect(0, 51, 50, 50))
+ @animate_right = [im.copy_rect(50, 0, 50, 50), im.copy_rect(100, 0, 50, 50), im.copy_rect(150, 0, 50, 50), 0]
+ @animate_right.map{|i| clean_bg(i) unless i == 0}
+ @animate_left = [im.copy_rect(50, 51, 50, 50), im.copy_rect(100, 51, 50, 50), im.copy_rect(150, 51, 50, 50), 0]
+ @animate_left.map{|i| clean_bg(i) unless i == 0}
+ @dead_img = clean_bg(im.copy_rect(300, 0, 50, 50))
+ @goal_img = clean_bg(im.copy_rect(300, 51, 50, 50))
+ @dash_speed = 0
+ @is_controll = true
+ @is_goal = false
+ @is_jumpping = false
+ end
+
+ # collision event
+ def collide_can_right(k) @movie_event = :movie_die end
+ alias collide_can_left collide_can_right
+ alias collide_can_foot collide_can_right
+ def collide_can_head(k) force_jump end
+ alias collide_dustbin_right collide_can_right
+ alias collide_dustbin_left collide_can_left
+ alias collide_dustbin_foot collide_can_foot
+ alias collide_dustbin_head collide_can_head
+ def collide_carapace_right(c) @movie_event = :movie_die if c.violence?; c.x-=10; end
+ def collide_carapace_left(c) @movie_event = :movie_die if c.violence?; c.x+=10; end
+ def collide_weakblock_foot(w) force_fall(w) end
+ alias collide_itembox_foot collide_weakblock_foot
+ def collide_goal_right(c) @is_goal = true end
+ alias collide_goal_left collide_goal_right
+ alias collide_goal_head collide_goal_right
+ alias collide_goal_foot collide_goal_right
+ def collide_pole_left(p) @movie_event = :movie_goal unless @movie_event; @x = p.x-40; end
+
+ # collision range
+ def foot_range
+ {:x_range => (@x+@w/6)..(@x+@w-@w/6), :y_range => (@y+@h-@h/6)..(@y+@h), :event => :collide_nario_foot}
+ end
+
+ # relation controller
+ def b_dash_right
+ dash(1, @animate_right, ((@frame % 10).zero? and @dash_speed < B_DASH_MAX_DASH_SPEED))
+ end
+
+ def b_dash_left
+ dash(-1, @animate_left, ((@frame % 10).zero? and @dash_speed > -(B_DASH_MAX_DASH_SPEED)))
+ end
+
+ def dash_right
+ # map deploy reserch
+ # puts "x:#{@x} y:#{@y}"
+ dash(1, @animate_right, ((@frame % 10).zero? and @dash_speed < DASH_MAX_DASH_SPEED))
+ end
+
+ def dash_left
+ dash(-1, @animate_left, ((@frame % 10).zero? and @dash_speed > -(DASH_MAX_DASH_SPEED)))
+ end
+
+ def jump
+ unless @is_fly or @jump_lock
+ frame_reset
+ @is_fly = true
+ @jump_lock = true
+ change_img(@jump_left_img) if @direction[:left]
+ change_img(@jump_right_img) if @direction[:right]
+ agravity
+ else
+ @fall_speed -= 2 if (@frame % 4).zero? and @fall_speed < 0
+ end
+ end
+
+ def goal?
+ @is_goal
+ end
+
+ def controll?
+ @is_controll
+ end
+
+ def jump_unlock
+ @jump_lock = false if !@is_fly
+ end
+
+ def free
+ return dash_stop
+ end
+
+ def dash_stop
+ x_move(@dash_speed)
+ return if (@frame % get_dash_frame(@dash_speed)).nonzero?
+
+ if @dash_speed > 0
+ @dash_speed -= 1
+ animate_dash(@animate_right, @dash_speed)
+ elsif @dash_speed < 0
+ @dash_speed += 1
+ animate_dash(@animate_left, @dash_speed)
+ else
+ change_img(@def_left_img) if @direction[:left] and !@is_fly
+ change_img(@def_right_img) if @direction[:right] and !@is_fly
+ end
+ end
+
+ def movie_goal
+ @frame = 1 if @is_controll
+ if (@frame % 80).zero?
+ @movie_event = :movie_dash_goal
+ end
+ force_notfall
+ @is_controll = false
+ change_img(@goal_img)
+ y_move(5)
+ end
+
+ def movie_dash_goal
+ @dash_speed = DASH_MAX_DASH_SPEED
+ dash(1, @animate_right, @dash_speed)
+ end
+
+ def movie_die
+ unless @is_dead
+ @frame = 1
+ @is_dead = true
+ end
+ force_notfall
+ if (@frame % 40).zero?
+ 3.times{ force_jump }
+ movie_end
+ end
+ change_img(@dead_img)
+ end
+
+ def force_jump
+ @is_fly = false
+ jump_unlock
+ jump
+ end
+
+ def force_fall(w)
+ @fall_speed = -1
+ @y = w.y + w.h + 5
+ end
+
+ def state
+ "x=#{@x} y=#{@y} dash_speed=#{@dash_speed} fall_speed=#{@fall_speed} fly? #{@is_fly}"
+ end
+ end
+end
5 nario/map.rb
@@ -0,0 +1,5 @@
+module Nario::Map
+end
+
+require_relative "map/title"
+require_relative "map/map1_1"
93 nario/map/map1_1.rb
@@ -0,0 +1,93 @@
+module Nario
+ module Map
+ MAP1_1 = lambda {|s|
+ sky 12000
+ ground 12000, 600
+
+ block Material::ItemBox.new(800, 420)
+ block Material::WeakBlock.new(1000, 420)
+ block Material::ItemBox.new(1047, 420)
+ block Material::WeakBlock.new(1094, 420)
+ block Material::ItemBox.new(1141, 420)
+ block Material::WeakBlock.new(1188, 420)
+ block Material::ItemBox.new(1094, 240)
+ block Material::Pipe.new(1370, 505)
+ block Material::Pipe.new(1840, 460)
+ block Material::Pipe.new(2280, 415)
+ block Material::Pipe.new(2720, 415)
+ block Material::WeakBlock.new(3730, 420)
+ block Material::ItemBox.new(3777, 420)
+ block Material::WeakBlock.new(3824, 420)
+ block Material::WeakBlock.new(3871, 240)
+ block Material::WeakBlock.new(3918, 240)
+ block Material::WeakBlock.new(3965, 240)
+ block Material::WeakBlock.new(4012, 240)
+ block Material::WeakBlock.new(4059, 240)
+ block Material::WeakBlock.new(4106, 240)
+ block Material::WeakBlock.new(4153, 240)
+ block Material::WeakBlock.new(4200, 240)
+ block Material::WeakBlock.new(4400, 240)
+ block Material::WeakBlock.new(4447, 240)
+ block Material::WeakBlock.new(4494, 240)
+ block Material::ItemBox.new(4541, 240)
+ block Material::WeakBlock.new(4541, 420)
+ block Material::WeakBlock.new(4900, 420)
+ block Material::WeakBlock.new(4947, 420)
+ block Material::ItemBox.new(5200, 420)
+ block Material::ItemBox.new(5300, 420)
+ block Material::ItemBox.new(5300, 240)
+ block Material::ItemBox.new(5400, 420)
+ block Material::WeakBlock.new(5600, 420)
+ block Material::WeakBlock.new(5750, 240)
+ block Material::WeakBlock.new(5797, 240)
+ block Material::WeakBlock.new(5844, 240)
+ block Material::WeakBlock.new(6050, 240)
+ block Material::ItemBox.new(6097, 240)
+ block Material::ItemBox.new(6144, 240)
+ block Material::WeakBlock.new(6191, 240)
+ block Material::WeakBlock.new(6097, 420)
+ block Material::WeakBlock.new(6144, 420)
+ block Material::Pipe.new(7900, 505)
+ block Material::WeakBlock.new(8150, 420)
+ block Material::WeakBlock.new(8197, 420)
+ block Material::ItemBox.new(8244, 420)
+ block Material::WeakBlock.new(8291, 420)
+ block Material::Pipe.new(8700, 505)
+
+
+ floor Material::Floor.new_fill_image(0, 600, 3270, 100, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(3420, 600, 700, 100, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(4300, 600, 3000, 100, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(7450, 600, 3000, 100, SDL::Surface.load("nario/image/floor_block.bmp"))
+
+
+ left_triangle_block Material::StrongBlock, 6350, 4
+ right_triangle_block Material::StrongBlock, 6650, 4
+ left_triangle_block Material::StrongBlock, 7082, 4, 5
+ right_triangle_block Material::StrongBlock, 7450, 4
+ left_triangle_block Material::StrongBlock, 8820, 8, 9
+
+ goal 9860
+
+ enemy Life::Can.new(900, 550)
+ enemy Life::Can.new(2000, 550)
+ enemy Life::Can.new(2500, 550)
+ enemy Life::Can.new(2560, 550)
+ enemy Life::Can.new(3830, 200)
+ enemy Life::Can.new(3890, 200)
+ enemy Life::Can.new(4670, 550)
+ enemy Life::Can.new(4730, 550)
+ enemy Life::Dustbin.new(5100, 550)
+ enemy Life::Can.new(5430, 550)
+ enemy Life::Can.new(5490, 550)
+ enemy Life::Can.new(5750, 550)
+ enemy Life::Can.new(5810, 550)
+ enemy Life::Can.new(6100, 550)
+ enemy Life::Can.new(6160, 550)
+ enemy Life::Can.new(8300, 550)
+ enemy Life::Can.new(8360, 550)
+
+ player Life::Nario.new(200, 550)
+ }
+ end
+end
7 nario/map/title.rb
@@ -0,0 +1,7 @@
+module Nario
+ module Map
+ TITLE = lambda {|s|
+ background Material::BackGround.new_single_image(0, 0, SDL::Surface.load("nario/image/title.bmp"))
+ }
+ end
+end
90 nario/material.rb
@@ -0,0 +1,90 @@
+require_relative 'factor'
+
+module Nario::Material
+ class Material < Nario::Factor
+ attr_accessor :img, :fill_mtls, :color
+
+ def initialize(x, y, w, h, img=nil, color=nil)
+ @fill_mtls = nil
+ @img = nil
+ img.set_color_key(SDL::SRCCOLORKEY, [255, 255, 255]) if img
+ super(x, y, w, h, img)
+ @color = color
+ end
+
+ def self.new_color(x, y, w, h, color)
+ self.new(x, y, w, h, nil, color)
+ end
+
+ def self.new_single_image(x, y, img)
+ mt = self.new(x, y, img.w, img.h, img)
+ mt
+ end
+
+ def self.new_fill_image(x, y, w, h, img)
+ mt = self.new(x, y, w, h, img)
+ mt.fill_material
+ mt
+ end
+
+ def fill_material
+ x = @x; y = @y; max_x = @x + @w; max_y = @y + @h
+ @fill_mtls = []
+ while max_x > x
+ while max_y > y
+ cp_im = @img.copy_rect(0, 0, @img.w, @img.h)
+ clip_w = (x + @img.w) > max_x ? (x + @img.w) - max_x : nil;
+ clip_h = (y + @img.h) > max_y ? (y + @img.h) - max_y : nil;
+ cp_im = cp_im.copy_rect(0, 0, clip_w, @img.h) if clip_w
+ cp_im = cp_im.copy_rect(0, 0, @img.w, clip_h) if clip_h
+ @fill_mtls << Material.new(x, y, 0, 0, cp_im)
+ y += @img.h
+ end
+ x += @img.w
+ y = @y
+ end
+ @img = nil
+ end
+
+ def put_screen(screen)
+ case
+ when @img
+ screen.put(@img, @x, @y)
+ when @fill_mtls
+ @fill_mtls.each {|mtl|
+ screen.put(mtl.img, mtl.x, mtl.y)
+ }
+ when @color
+ screen.fill_rect(@x, @y, @w, @h, @color)
+ end
+ end
+
+ def xy_move(add_x, add_y)
+ @x += add_x
+ @y += add_y
+ if @fill_mtls
+ @fill_mtls.each {|mtl|
+ mtl.xy_move(add_x, add_y)
+ }
+ end
+ end
+
+ def x_move(add_x)
+ xy_move(add_x, 0)
+ end
+
+ def y_move(add_y)
+ xy_move(0, add_y)
+ end
+ end
+
+ autoload :BackGround, "material/background"
+ autoload :Floor, "material/floor"
+ autoload :WeakBlock, "material/weakblock"
+ autoload :ItemBox, "material/itembox"
+ autoload :JumpCoin, "material/jumpcoin"
+ autoload :StrongBlock, "material/strongblock"
+ autoload :Pipe, "material/pipe"
+ autoload :Pole, "material/pole"
+ autoload :Goal, "material/goal"
+end
4 nario/material/background.rb
@@ -0,0 +1,4 @@
+module Nario::Material
+ class BackGround < Material
+ end
+end
7 nario/material/floor.rb
@@ -0,0 +1,7 @@
+module Nario::Material
+ class Floor < Material
+ def head_range
+ {:x_range => @x..(@x+@w), :y_range => (@y-1)..(@y+10), :event => :collide_floor_head}
+ end
+ end
+end
11 nario/material/goal.rb
@@ -0,0 +1,11 @@
+module Nario::Material
+ class Goal < Material
+ def initialize(x, y, img=SDL::Surface.load("nario/image/goal.bmp"))
+ super(x, y, img.w, img.h, img)
+ end
+
+ def leftside_range
+ {:x_range => (@x+@w-@w/6)..(@x+@w), :y_range => (@y+@h/6)..(@y+@h-@h/6), :event => ("collide_#{extract_class_name(self)}_left".to_sym)}
+ end
+ end
+end
40 nario/material/itemblock.rb
@@ -0,0 +1,40 @@
+module Nario::Material
+ class ItemBlock < Material
+ BOUND_SPEED_RATE = -5
+
+ def initialize(x, y, img=SDL::Surface.load("nario/image/item_block.bmp"))
+ im = clean_bg(img.copy_rect(0, 0, 48, 46))
+ @empty_img = clean_bg(img.copy_rect(144, 0, 48, 46))
+ im1 = clean_bg(img.copy_rect(48, 0, 48, 46))
+ im2 = clean_bg(img.copy_rect(96, 0, 48, 46))
+ @blink_imgs = [im, im1, im2, im1, im, 0]
+ super(x, y, im.w, im.h, im)
+ @bound_speed = BOUND_SPEED_RATE
+ @movie_event = :blinking
+ @item = JumpCoin.new(@x + 7, @y - 70)
+ end
+
+ def collide_nario_head(m)
+ change_img(@empty_img)
+ @movie_event = :bound
+ @bound_prev_y = @y
+ @frame = 0
+ @now_scene.in(:item, @item)
+ undef :collide_nario_head
+ end
+
+ def blinking
+ animate(@blink_imgs, 9)
+ end
+
+ def bound
+ y_move(@bound_speed)
+ @bound_speed += 3 if (@frame % 4).zero?
+ if @y > @bound_prev_y
+ @bound_speed = BOUND_SPEED_RATE
+ @y = @bound_prev_y
+ movie_end
+ end
+ end
+ end
+end
46 nario/material/itembox.rb
@@ -0,0 +1,46 @@
+module Nario::Material
+ class ItemBox < Material
+ BOUND_SPEED_RATE = -5
+
+ def initialize(x, y, img=SDL::Surface.load("nario/image/item_block.bmp"))
+ im = clean_bg(img.copy_rect(0, 0, 48, 46))
+ @empty_img = clean_bg(img.copy_rect(144, 0, 48, 46))
+ @empyt_item = false
+ im1 = clean_bg(img.copy_rect(48, 0, 48, 46))
+ im2 = clean_bg(img.copy_rect(96, 0, 48, 46))
+ @blink_imgs = [im, im1, im2, im1, im, 0]
+ super(x, y, im.w, im.h, im)
+ @bound_speed = BOUND_SPEED_RATE
+ @movie_event = :blinking
+ end
+
+ def foot_range
+ {:x_range => (@x+@w/4)..(@x+@w-@w/4), :y_range => (@y+@h-@h/6)..(@y+@h), :event => :collide_itembox_foot}
+ end
+
+ def collide_nario_head(m)
+ return if @empyt_item
+ change_img(@empty_img)
+ @movie_event = :bound
+ @bound_prev_y = @y
+ @frame = 0
+ @item = JumpCoin.new(@x + 7, @y - 70)
+ @now_scene.in(:item, @item)
+ @empyt_item = true
+ end
+
+ def blinking
+ animate(@blink_imgs, 9)
+ end
+
+ def bound
+ y_move(@bound_speed)
+ @bound_speed += 3 if (@frame % 4).zero?
+ if @y > @bound_prev_y
+ @bound_speed = BOUND_SPEED_RATE
+ @y = @bound_prev_y
+ movie_end
+ end
+ end
+ end
+end
29 nario/material/jumpcoin.rb
@@ -0,0 +1,29 @@
+module Nario::Material
+ class JumpCoin < Material
+ BOUND_SPEED_RATE = -12
+
+ def initialize(x, y, img=SDL::Surface.load("nario/image/coin.bmp"))
+ im = clean_bg(img.copy_rect(0, 0, 25, 42))
+ im1 = clean_bg(img.copy_rect(25, 0, 25, 42))
+ im2 = clean_bg(img.copy_rect(50, 0, 25, 42))
+ im3 = clean_bg(img.copy_rect(75, 0, 25, 42))
+ @bound_imgs = [im, im1, im2, im3, im2, im1, 0]
+ super(x, y, im.w, im.h, im)
+ @bound_speed = BOUND_SPEED_RATE
+ @is_dead = true
+ @bound_prev_y = @y
+ @movie_event = :bound
+ end
+
+ def bound
+ animate(@bound_imgs, 9)
+ y_move(@bound_speed)
+ @bound_speed += 3 if (@frame % 4).zero?
+ if @y > @bound_prev_y
+ @img = nil
+ @is_garbage = true
+ movie_end
+ end
+ end
+ end
+end
8 nario/material/pipe.rb
@@ -0,0 +1,8 @@
+module Nario::Material
+ class Pipe < Material
+ def initialize(x, y, img=SDL::Surface.load("nario/image/pipe.bmp"))
+ clean_bg(img)
+ super(x, y, img.w, img.h, img)
+ end
+ end
+end
31 nario/material/pole.rb
@@ -0,0 +1,31 @@
+module Nario::Material
+ class Pole < Material
+ def initialize(x, y)
+ img = clean_bg(SDL::Surface.load("nario/image/pole.bmp"))
+ super(x, y, img.w, img.h, img)
+ @flag = BackGround.new_single_image(x-37, y+25, SDL::Surface.load("nario/image/flag.bmp"))
+ end
+
+ def collide_nario_right(m); @movie_event = :movie_flag_down; end
+
+ def movie_flag_down
+ return movie_end if (@flag.y+@flag.h) > (@y + @h)
+ @flag.y_move(5)
+ end
+
+ def y_move(y)
+ @y += y
+ @flag.y += y
+ end
+
+ def x_move(x)
+ @x += x
+ @flag.x += x
+ end
+
+ def put_screen(screen)
+ screen.put(@img, @x, @y)
+ screen.put(@flag.img, @flag.x, @flag.y)
+ end
+ end
+end
7 nario/material/strongblock.rb
@@ -0,0 +1,7 @@
+module Nario::Material
+ class StrongBlock < Material
+ def initialize(x, y, img=SDL::Surface.load("nario/image/strong_block.bmp"))
+ super(x, y, img.w, img.h, img)
+ end
+ end
+end
30 nario/material/weakblock.rb
@@ -0,0 +1,30 @@
+module Nario::Material
+ class WeakBlock < Material
+ BOUND_SPEED_RATE = -5
+
+ def initialize(x, y, img=SDL::Surface.load("nario/image/weak_block.bmp"))
+ super(x, y, img.w, img.h, img)
+ @bound_speed = BOUND_SPEED_RATE
+ end
+
+ def foot_range
+ {:x_range => (@x+@w/4)..(@x+@w-@w/4), :y_range => (@y+@h-@h/6)..(@y+@h), :event => :collide_itembox_foot}
+ end
+
+ def collide_nario_head(m)
+ @movie_event = :bound
+ @bound_prev_y = @y
+ @frame = 0
+ end
+
+ def bound
+ y_move(@bound_speed)
+ @bound_speed += 3 if (@frame % 4).zero?
+ if @y > @bound_prev_y
+ @bound_speed = BOUND_SPEED_RATE
+ @y = @bound_prev_y
+ movie_end
+ end
+ end
+ end
+end
214 nario/scene.rb
@@ -0,0 +1,214 @@
+#example map define
+# map = Scene::Builder.new{
+# mapping :title, Scene::Title.new {
+# success :map_1
+# }
+# mapping :map_1, Scene::FlowWorld.new{
+# success :map_2
+# }
+# }.scene_map
+
+module Nario
+ module Scene
+ SCREEN_WIDTH = 760
+ SCREEN_HIGHT = 670
+
+ class Scene
+ attr_accessor :backgrounds, :actions, :blocks, :enemys, :flows, :makers, :player, :renders
+
+ def initialize(&block)
+ init
+ instance_eval(&block)
+ end
+
+ def init
+ @backgrounds = []
+ @actions = []
+ @blocks = []
+ @enemys = []
+ @flows = []
+ @makers = []
+ @floors = []
+ @player = nil
+ @renders = [@flows]
+ @lazy_deploys = []
+ end
+
+ def success(nxt)
+ @success = nxt
+ end
+
+ def miss(nxt)
+ @miss = nxt
+ end
+
+ def in(type, *args)
+ send(type, *args)
+ end
+
+ def rebuild
+ init
+ instance_eval(&@build_code)
+ self
+ end
+
+ def build_scene(&block)
+ @build_code = block
+ instance_eval(&block)
+ self
+ end
+
+ private
+ def background(bg)
+ code = lambda {
+ bg.now_scene = self
+ @backgrounds << bg
+ }
+ @flows << bg
+ add_lazydeploy(bg, code)
+ end
+
+ def floor(fl)
+ code = lambda {
+ fl.now_scene = self
+ @blocks << fl
+ }
+ @floors << fl
+ @flows << fl
+ add_lazydeploy(fl, code)
+ end
+
+ def player(player)
+ player.now_scene = self
+ @player = player
+ end
+
+ def enemy(enemy)
+ code = lambda {
+ enemy.now_scene = self
+ @actions << enemy
+ @enemys << enemy
+ }
+ @flows << enemy
+ add_lazydeploy(enemy, code)
+ end
+
+ def block(block)
+ code = lambda {
+ block.now_scene = self
+ @blocks << block
+ @actions << block
+ }
+ @floors << block
+ @flows << block
+ add_lazydeploy(block, code)
+ end
+
+ def item(it)
+ code = lambda {
+ it.now_scene = self
+ @flows << it
+ @actions << it
+ }
+ add_lazydeploy(it, code)
+ end
+
+ def goal(x)
+ b = Material::BackGround.new_single_image(x, 0, SDL::Surface.load("nario/image/castle.bmp"))
+ g = Material::Goal.new(x + 100, 0)
+ sb = Material::StrongBlock.new(x - 200, 0)
+ p = Material::Pole.new(x - 188, 0)
+ background set_floor_up_y(b)
+ block set_floor_up_y(g)
+ block set_floor_up_y(sb)
+ block set_floor_up_y(p)
+ end
+
+ def left_triangle_block(klass, x, step, floor_num=nil)
+ floor_num ||= step
+ while step.nonzero?
+ x_b = x
+ obj = nil
+ floor_num.times{|i|
+ obj = klass.new(x_b, 0)
+ block set_floor_up_y(obj)
+ x_b += obj.h + 1
+ }
+ floor_num-=1
+ x += obj.h
+ step-=1
+ end
+ end
+
+ def right_triangle_block(klass, x, step, floor_num=nil)
+ floor_num ||= step
+ while step.nonzero?
+ x_b = x
+ obj = nil
+ floor_num.times{|i|
+ obj = klass.new(x_b, 0)
+ block set_floor_up_y(obj)
+ x_b += obj.h + 1
+ }
+ floor_num-=1
+ step-=1
+ end
+ end
+
+ def sky(max_x)
+ background Material::BackGround.new_color(0, 0, 11000, 800, [0xff, 0xff, 0xfe])
+ x = 0
+ while max_x > 0
+ x+=300
+ background Material::BackGround.new_single_image(x, 100, SDL::Surface.load("nario/image/cloud1.bmp"))
+ x+=300
+ background Material::BackGround.new_single_image(x, 50, SDL::Surface.load("nario/image/cloud3.bmp"))
+ x+=400
+ background Material::BackGround.new_single_image(x, 30, SDL::Surface.load("nario/image/cloud2.bmp"))
+ max_x-=(300+300+400)
+ end
+ end
+
+ def ground(max_x, floor)
+ x = 0
+ while max_x > 0
+ b1 = Material::BackGround.new_single_image(x, floor, SDL::Surface.load("nario/image/bush2.bmp"))
+ x+=500
+ b1.y_move(-b1.h)
+ background b1
+ m = Material::BackGround.new_single_image(x, floor, SDL::Surface.load("nario/image/mountain.bmp"))
+ x+=500
+ m.y_move(-m.h)
+ background m
+ max_x-=(300+400)
+ end
+ end
+
+ def deploy
+ @lazy_deploys.each_with_index {|e, i|
+ if e[:object].x < (SCREEN_WIDTH + SCREEN_WIDTH/2)
+ e[:deploy_code].call
+ @lazy_deploys[i] = nil
+ end
+ }
+ @lazy_deploys.compact!
+ end
+
+ def add_lazydeploy(object, deploy_code)
+ @lazy_deploys << {:object => object, :deploy_code => deploy_code}
+ end
+
+ def set_floor_up_y(s)
+ y = SCREEN_HIGHT
+ @floors.each{|b| y = b.y if ((b.x)..(b.x+b.w)).include? s.x and y > b.y}
+ y -= s.h
+ s.y_move(y)
+ s
+ end
+ end
+
+ autoload :Builder, "scene/builder"
+ autoload :Title, "scene/title"
+ autoload :FlowWorld, "scene/flowworld"
+ end
+end
97 nario/scene/flowworld.rb
@@ -0,0 +1,97 @@
+module Nario::Scene
+ class FlowWorld < Scene
+ def act(controller)
+ deploy
+ countup_frame
+ action
+ control_player(controller) unless @player.dead? or !@player.controll?
+ gravity
+ collision_event
+ flow_right
+ garbage_sweep if(@player.frame % 100).zero?
+ return @miss if @player.goal?
+ return @success if @player.y > SCREEN_HIGHT*2
+ nil
+ end
+
+ def render(screen)
+ @renders.each{|re| re.each{|o| o.put_screen(screen) if o.x < SCREEN_WIDTH } }
+ puts "player: #{@player.state}" if $DEBUG_PLAYER_WATCH_MODE
+ @player.put_screen(screen)
+ end
+
+ private
+ def control_player(controller)
+ @player.jump if controller.a
+ @player.jump_unlock unless controller.a
+ case
+ when (controller.right and controller.b)
+ @player.b_dash_right
+ when (controller.left and controller.b)
+ @player.b_dash_left
+ when controller.right
+ @player.dash_right
+ when controller.left
+ @player.dash_left
+ else
+ @player.free
+ end
+ end
+
+ def countup_frame
+ @actions.each{|a| a.countup_frame }
+ @player.countup_frame
+ end
+
+ def action
+ @actions.each{|a| a.action if a.x < SCREEN_WIDTH} unless @player.dead?
+ @player.action
+ end
+
+ def gravity
+ @enemys.each{|l| l.gravity }
+ @player.gravity
+ end
+
+ def collision_event
+ @blocks.each{|bl|
+ @enemys.each{|l| l.collision_event(bl) }
+ @player.collision_event(bl)
+ }
+ @enemys.each{|li| @player.collision_event(li) }
+ @enemys.size.times{|i| @enemys.size.times{|j| @enemys[i].collision_event(@enemys[j]) if j != i}}
+ end
+
+ def garbage_sweep
+ @actions.size.times{|i| sweep(@actions, i) }
+ @blocks.size.times{|i| sweep(@blocks, i) }
+ @enemys.size.times{|i| sweep(@enemys, i) }
+ @flows.size.times{|i| sweep(@flows, i) }
+ @actions.compact!
+ @blocks.compact!
+ @enemys.compact!
+ @flows.compact!
+ end
+
+ def sweep(arry, index)
+ arry[index].is_garbage = true if arry[index].y > SCREEN_HIGHT
+ arry[index] = nil if arry[index].garbage?
+ end
+
+ def flow_right
+ @player.x = 0 if @player.x < 0
+ screen_harf = SCREEN_WIDTH/2
+ shift = @player.x - screen_harf if @player.x > screen_harf
+ if shift
+ @flows.each{|fl| shift_material(fl, shift) }
+ @player.x = screen_harf
+ end
+ end
+
+ def shift_material(mt, shift)
+ mt.x_move(-shift)
+ mt.is_garbage = true if (mt.x + mt.w) < 0
+ mt.is_garbage = true if mt.y > SCREEN_HIGHT
+ end
+ end
+end
15 nario/scene/title.rb
@@ -0,0 +1,15 @@
+module Nario::Scene
+ class Title < Scene
+ def start
+ end
+
+ def act(input)
+ deploy
+ return @success if input.ok
+ end
+
+ def render(screen)
+ @backgrounds.each{|bg| bg.put_screen(screen) }
+ end
+ end
+end
208 nario/test.rb
@@ -0,0 +1,208 @@
+require_relative 'life'
+
+class Input
+ define_key SDL::Key::ESCAPE, :exit
+ define_key SDL::Key::LEFT, :left
+ define_key SDL::Key::RIGHT, :right
+ define_key SDL::Key::UP, :up
+ define_key SDL::Key::DOWN, :down
+ define_key SDL::Key::RETURN, :ok
+ define_key SDL::Key::A, :a
+ define_key SDL::Key::B, :b
+end
+
+module Nari
+ def self.test_screen(*proc)
+ SDL.init(SDL::INIT_VIDEO|SDL::INIT_JOYSTICK)
+ SDL::TTF.init
+
+ if defined?(SDL::RELEASE_MODE)
+ SDL::Mouse.hide
+ screen = SDL.set_video_mode(Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT, 16, SDL::HWSURFACE|SDL::DOUBLEBUF|SDL::FULLSCREEN)
+ else
+ screen = SDL.set_video_mode(Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT, 16, SDL::SWSURFACE|SDL::DOUBLEBUF)
+ end
+
+ @input = Input.new
+ timer = FPSTimerLight.new
+ timer.reset
+ loop do
+ @input.poll
+ break if @input[:exit]
+ proc.each{|p|
+ p.call(@input, screen)
+ }
+ timer.wait_frame{
+ if defined?(SDL::RELEASE_MODE)
+ screen.flip
+ else
+ screen.update_rect(0, 0, Scene::SCREEN_WIDTH, Scene::SCREEN_HIGHT)
+ end
+ }
+ end
+ end
+
+ test_fill_material = lambda {|input, screen|
+ mt = Material::BackGround.new_fill_image(30, 230, 230, 200, SDL::Surface.load("nario/image/floor_block.bmp"))
+ mt.put_screen(screen)
+ }
+
+ test_img_material = lambda {|input, screen|
+ mt = Material::BackGround.new_single_image(30, 130, SDL::Surface.load("nario/image/floor_block.bmp"))
+ mt.put_screen(screen)
+ }
+
+ test_color_material = lambda {|input, screen|
+ mt = Material::BackGround.new_color(200, 0, 100, 300, [100, 10, 0])
+ mt.put_screen(screen)
+ }
+
+ mt_sfm = Material::BackGround.new_fill_image(100, 0, 100, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ test_scroll_fill_material = lambda {|input, screen|
+ mt_sfm.scroll(1, 1)
+ mt_sfm.put_screen(screen)
+ }
+
+ mt_sim = Material::BackGround.new_single_image(130, 0, SDL::Surface.load("nario/image/floor_block.bmp"))
+ test_scroll_img_material = lambda {|input, screen|
+ mt_sim.scroll(20, 0)
+ mt_sim.put_screen(screen)
+ }
+
+ mt_scm = Material::BackGround.new_color(20, 0, 100, 300, [100, 10, 0])
+ test_scroll_color_material = lambda {|input, screen|
+ mt_scm.scroll(2, 1)
+ mt_scm.put_screen(screen)
+ }
+
+ reset_background = lambda {|input, screen|
+ screen.fill_rect(0, 0, 1000, 1000, [0, 0, 0])
+ }
+
+ chibi_nario_test = {}
+ chibi_nario_test[:map_1] = ::Scene::FlowWorld.new{ success :map_1 }
+ chibi_nario_test[:map_1].build_scene {|s|
+ background Material::BackGround.new_color(0, 0, 10000, 800, [0x00, 0x99, 0xff])
+ floor Material::Floor.new_fill_image(0, 600, 200, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(350, 600, 500, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(900, 600, 500, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(1500, 600, 200, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(1800, 600, 400, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(2600, 600, 400, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(3200, 600, 400, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(3800, 600, 400, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(4400, 600, 400, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ floor Material::Floor.new_fill_image(5000, 600, 400, 300, SDL::Surface.load("nario/image/floor_block.bmp"))
+ # floor Material::Floor.new_color(0, 600, 800, 300, [0xcc, 0x66, 0x66])
+ # floor Material::Floor.new_color(1000, 600, 800, 300, [0xcc, 0x66, 0x66])
+ enemy Life::Can.new(500, 200)
+ player Life::Nario.new(40, 200)
+ }