--- CptnRuby.rb 2007-08-31 21:53:16.859375000 -0700 +++ CptnNuby.rb 2007-08-31 22:30:47.687500000 -0700 @@ -1,3 +1,12 @@ +# +# NOTE: +# This is the CptnRuby demo from Gosu-0.7.4, slightly +# modified to allow free up/down movement, instead of +# jumping & gravity. +# +# Get Gosu at: http://code.google.com/p/gosu/ +# + begin # In case you use Gosu via RubyGems. require 'rubygems' @@ -34,7 +43,7 @@ require 'gosu' include Gosu -module CptnRuby +module CptnNuby module Tiles Grass = 0 @@ -76,7 +85,7 @@ def draw(screen_x, screen_y) # Flip vertically when facing to the left. - if @dir == :left then + if @dir == :left || @dir == :up then offs_x = -25 factor = 1.0 else @@ -93,7 +102,7 @@ not @map.solid?(@x + offs_x, @y + offs_y - 45) end - def update(move_x) + def update(move_x, move_y) # Select image depending on action if (move_x == 0) @cur_image = @standing @@ -114,17 +123,28 @@ (-move_x).times { if would_fit(-1, 0) then @x -= 1 end } end + # Directional walking, vertical movement + if move_y > 0 then + @dir = :down + move_y.times { if would_fit(0, 1) then @y += 1 end } + end + if move_y < 0 then + @dir = :up + (-move_y).times { if would_fit(0, -1) then @y -= 1 end } + end + # Acceleration/gravity # By adding 1 each frame, and (ideally) adding vy to y, the player's # jumping curve will be the parabole we want it to be. - @vy += 1 - # Vertical movement - if @vy > 0 then - @vy.times { if would_fit(0, 1) then @y += 1 else @vy = 0 end } - end - if @vy < 0 then - (-@vy).times { if would_fit(0, -1) then @y -= 1 else @vy = 0 end } - end + # + # @vy += 1 + # # Vertical movement + # if @vy > 0 then + # @vy.times { if would_fit(0, 1) then @y += 1 else @vy = 0 end } + # end + # if @vy < 0 then + # (-@vy).times { if would_fit(0, -1) then @y -= 1 else @vy = 0 end } + # end end def try_to_jump @@ -198,7 +218,7 @@ def initialize super(640, 480, false, 20) - self.caption = "Cptn. Ruby" + self.caption = "Cptn. Nuby" @map = Map.new(self, "media/CptnRuby Map.txt") @cptn = CptnRuby.new(self, 400, 100) # Scrolling is stored as the position of the top left corner of the screen. @@ -208,7 +228,10 @@ move_x = 0 move_x -= 5 if button_down? Button::KbLeft move_x += 5 if button_down? Button::KbRight - @cptn.update(move_x) + move_y = 0 + move_y -= 5 if button_down? Button::KbUp + move_y += 5 if button_down? Button::KbDown + @cptn.update(move_x, move_y) @cptn.collect_gems(@map.gems) # Scrolling follows player @screen_x = [[@cptn.x - 320, 0].max, @map.width * 50 - 640].min @@ -219,12 +242,12 @@ @cptn.draw @screen_x, @screen_y end def button_down(id) - if id == Button::KbUp then @cptn.try_to_jump end + # if id == Button::KbUp then @cptn.try_to_jump end if id == Button::KbEscape then close end end end end -CptnRuby::Game.new.show +CptnNuby::Game.new.show