Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit, game 99% finished

  • Loading branch information...
commit 42fac8bbc1188e6335c352b38671324b86bf612d 0 parents
@ippa authored
1  build.bat
@@ -0,0 +1 @@
+ocra start_game.rb --windows media\** src\** lib\**
BIN  media/Thumbs.db
Binary file not shown
BIN  media/acid.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  media/acid_drop.bmp
Binary file not shown
BIN  media/die.wav
Binary file not shown
BIN  media/drop.bmp
Binary file not shown
BIN  media/falling.wav
Binary file not shown
BIN  media/jump.wav
Binary file not shown
BIN  media/land.wav
Binary file not shown
BIN  media/level1.bmp
Binary file not shown
BIN  media/level2.bmp
Binary file not shown
BIN  media/level22.bmp
Binary file not shown
BIN  media/level3.bmp
Binary file not shown
BIN  media/level4.bmp
Binary file not shown
BIN  media/level5.bmp
Binary file not shown
BIN  media/level6.bmp
Binary file not shown
BIN  media/level7.bmp
Binary file not shown
BIN  media/level8.bmp
Binary file not shown
BIN  media/level9.bmp
Binary file not shown
BIN  media/level_air.bmp
Binary file not shown
BIN  media/level_air2.bmp
Binary file not shown
BIN  media/level_up.bmp
Binary file not shown
BIN  media/player.bmp
Binary file not shown
BIN  media/player.gal
Binary file not shown
BIN  media/poop.bmp
Binary file not shown
BIN  media/poop.wav
Binary file not shown
BIN  media/small_acid.bmp
Binary file not shown
13 src/enemy.rb
@@ -0,0 +1,13 @@
+class Enemy < Chingu::GameObject
+ has_trait :collision_detection
+ has_trait :velocity
+ has_trait :bounding_box, :debug => true
+
+ def initialize(options = {})
+ super
+
+ self.image.retrofy
+ self.zorder = 0
+ self.factor = $window.factor
+ end
+end
206 src/level.rb
@@ -0,0 +1,206 @@
+class Level < GameState
+ has_trait :timer
+
+ def initialize(options = {})
+ super
+
+ @bg2 = Color.new(0xFFBB0C25)
+ @bg1 = Color.new(0xFF720817)
+
+ @entry_x = player.x
+ @entry_y = player.y
+ end
+
+ def level_image
+ @level_image || "#{self.to_s.downcase}.bmp"
+ end
+
+ def background=(image)
+ @background = GameObject.create(:image => image, :rotation_center => :top_left, :zorder => 20, :factor => $window.factor)
+ end
+
+ def player
+ $window.player
+ end
+ def height
+ $window.height
+ end
+ def width
+ $window.width
+ end
+ def map
+ $window.map
+ end
+ def draw
+ super
+ fill_gradient(:from => @bg1, :to => @bg2, :zorder => -1)
+ end
+
+ def update
+ super
+
+ if player.x >= width # RIGHT
+ player.x = 1
+ player.y -= 5
+ switch_game_state(map.right)
+ elsif player.x < 0 # LEFT
+ player.y -= 5
+ player.x = width-1
+ switch_game_state(map.left)
+ elsif player.y > height # DOWN
+ player.y = 1
+ switch_game_state(map.down)
+ elsif player.y < 0 # UP
+ player.y = height-1
+ switch_game_state(map.up)
+ end
+
+ player.each_collision(Enemy) do |player, enemy|
+ unless player.paused?
+ player.pause!
+ Sound["die.wav"].play(0.1)
+ after(1000) { player.velocity_y = 0; player.x = @entry_x; player.y = @entry_y; player.unpause!; }
+ end
+ end
+
+ game_objects.destroy_if { |game_object| game_object.outside_window? }
+
+ # $window.caption = "towards nirvana. #{self.class} - x/y #{$window.player.x}/#{$window.player.y} FPS: #{$window.fps} - Game objects: #{game_objects.size}"
+ end
+
+ def pixel_collision_at?(x, y)
+ x = (x / $window.factor).to_i
+ y = (y / $window.factor).to_i
+ return false if outside_window?(x, y)
+ not @background.image.transparent_pixel?(x, y)
+ end
+
+ def distance_to_surface(x, y, max_steps = nil)
+ steps = 0
+ steps += 1 while pixel_collision_at?(x, y - steps) && (y - steps) > 0
+ return steps
+ end
+
+ def outside_window?(x, y)
+ x <= 0 || x >= @background.image.width || y <= 0 || y >= @background.image.height
+ end
+
+end
+
+class Level1 < Level
+ has_trait :timer
+ def setup
+ player.show!
+ self.background = "level1.bmp"
+ every(2000) { Enemy.create(:image => "drop.bmp", :x => 300, :velocity_y => 5) }
+ end
+end
+
+class LevelUp < Level
+ def setup
+ self.background = "level_up.bmp"
+ end
+end
+
+class LevelAir < Level
+ def setup
+ self.background = "level_air.bmp"
+ end
+end
+
+class LevelAir2 < Level
+ def setup
+ self.background = "level_air2.bmp"
+ end
+end
+
+class Level2 < Level
+ def setup
+ self.background = "level2.bmp"
+ every(1000) { Enemy.create(:image => "drop.bmp", :x => 200, :velocity_y => 5) }
+ every(1500) { Enemy.create(:image => "drop.bmp", :x => 300, :velocity_y => 5) }
+ every(1500) { Enemy.create(:image => "drop.bmp", :x => 500, :velocity_y => 5) }
+ end
+end
+
+class Level22 < Level
+ def setup
+ self.background = "level22.bmp"
+ end
+end
+
+class Level3 < Level
+ def setup
+ self.background = "level3.bmp"
+ end
+end
+
+class Level4 < Level
+ def setup
+ self.background = "level4.bmp"
+ Enemy.create(:image => "acid.png", :rotation_center => :top_left, :x => 200, :y => 400)
+ end
+end
+
+class Level5 < Level
+ def setup
+ self.background = "level5.bmp"
+ end
+end
+
+class Level6 < Level
+ def setup
+ self.background = "level6.bmp"
+ end
+end
+
+class Level7 < Level
+ def setup
+ self.background = "level7.bmp"
+ every(1000) { Enemy.create(:image => "acid_drop.bmp", :x => 150, :velocity_y => 5) }
+ every(1500) { Enemy.create(:image => "acid_drop.bmp", :x => 250, :velocity_y => 5) }
+ every(2000) { Enemy.create(:image => "acid_drop.bmp", :x => 350, :velocity_y => 5) }
+ end
+end
+
+class Level8 < Level
+ def setup
+ self.background = "level8.bmp"
+ Enemy.create(:image => "small_acid.bmp", :rotation_center => :top_left, :x => 260, :y => 250)
+ end
+end
+
+class Level9 < Level
+ def setup
+ self.background = "level9.bmp"
+ end
+end
+
+class Poop < Level
+ def setup
+ Sound["poop.wav"].play(0.1)
+ self.background = "poop.bmp"
+ @landed = false
+
+ player.pause!
+ player.input = {}
+ player.factor = 1
+ $window.factor = 1
+ player.x = 127 * 3
+ player.y = 114 * 3
+
+ every(500, :name => :falling) {
+ Sound["falling.wav"].play(0.1)
+ player.y += 7
+ }
+ end
+
+ def update
+ super
+ if player.y > 153 * 3 && @landed == false
+ stop_timer(:falling)
+ Sound["land.wav"].play(0.1)
+ @landed = true
+ end
+ end
+end
35 src/map.rb
@@ -0,0 +1,35 @@
+class Map
+ attr_reader :row, :col
+ attr_accessor :map
+
+ def initialize(options = {})
+ @row = options[:row] || 1
+ @col = options[:col] || 0
+ @map = options[:map] || [ [ ] ]
+ end
+
+ def current
+ @map[@row][@col] rescue nil
+ end
+
+ def right
+ @col += 1
+ current
+ end
+
+ def left
+ @col -= 1
+ current
+ end
+
+ def up
+ @row -= 1
+ current
+ end
+
+ def down
+ @row += 1
+ current
+ end
+
+end
107 src/player.rb
@@ -0,0 +1,107 @@
+class Player < Chingu::GameObject
+ has_traits :timer, :velocity, :collision_detection
+ has_trait :bounding_box#, :debug => true, :scale => 0.70
+
+ def initialize(options)
+ super
+
+ self.input = { :holding_left => :left,
+ :holding_right => :right,
+ :up => :jump }
+
+ @animation = Hash.new
+ @animation[:full] = Animation.new(:file => "player.bmp", :size => [8,9], :delay => 40).retrofy
+ @animation[:running] = @animation[:full][0..3]
+ @image = @animation[:full].first
+
+ @speed = 2
+ self.rotation_center = :center_center
+ self.factor = $window.factor
+ self.acceleration_y = 0.3
+ self.max_velocity = 10
+ @previous_bounding_box = self.bounding_box
+ @jumping = false
+ cache_bounding_box
+ end
+
+ def jump
+ unless @jumping
+ self.velocity_y = -7
+ @jumping = true
+ Sound["jump.wav"].play(0.05)
+ end
+ end
+
+ def left
+ self.velocity_x = -@speed
+ self.factor_x = -$window.factor
+ @image = @animation[:running].next
+ end
+
+ def right
+ self.velocity_x = @speed
+ self.factor_x = $window.factor
+ @image = @animation[:running].next
+ end
+
+ def distance_to_surface
+ $window.current_game_state.distance_to_surface(bb.centerx, bb.bottom)
+ end
+
+ def collision_left?
+ #(self.bounding_box.top.to_i .. self.bounding_box.bottom.to_i).each do |y|
+ # return true if $window.current_game_state.pixel_collision_at?(self.bounding_box.left, y)
+ #end
+ #return false
+ collision = false
+ image.line bb.left, bb.top, bb.left, bb.bottom, :color_control => proc { |c| if c[3] != 0; collision = true; end; :none }
+ end
+
+ def collision_right?
+ #(bb.top.to_i .. bb.bottom.to_i).each do |y|
+ # return true if $window.current_game_state.pixel_collision_at?(bb.right, y)
+ #end
+ #return false
+
+ collision = false
+ image.line bb.right, bb.top, bb.right, bb.bottom, :color_control => proc { |c| if c[3] != 0; collision = true; end; :none }
+ end
+
+ def collision_bottom?
+ #(self.bounding_box.left.to_i .. self.bounding_box.right.to_i).each do |x|
+ # return true if $window.current_game_state.pixel_collision_at?(x, self.bounding_box.bottom)
+ #end
+ #return false
+ $window.current_game_state.pixel_collision_at?(bb.centerx, bb.bottom)
+ end
+ def collision_top?
+ #(self.bounding_box.left.to_i .. self.bounding_box.right.to_i).each do |x|
+ # return true if $window.current_game_state.pixel_collision_at?(x, self.bounding_box.top.to_i)
+ #end
+ #return false
+ $window.current_game_state.pixel_collision_at?(bb.centerx, bb.top)
+ end
+
+ def update
+ if collision_bottom?
+ @jumping = false
+ self.velocity_y = 0
+ @y = self.previous_y
+ end
+
+ if self.velocity_y < 0 && collision_top?
+ self.velocity_y = 0
+ end
+
+ if collision_left? || collision_right?
+ if ((dy = distance_to_surface) < 7)
+ @y -= dy
+ else
+ @x = self.previous_x
+ end
+ end
+
+ self.velocity_x = 0
+ end
+
+end
56 start_game.rb
@@ -0,0 +1,56 @@
+#
+#
+#
+require 'rubygems'
+require 'opengl'
+require 'texplay'
+
+#begin
+# require '../chingu/lib/chingu'
+#rescue LoadError
+ require 'chingu'
+#end
+
+ENV['PATH'] = File.join(ROOT,"lib") + ";" + ENV['PATH']
+
+include Gosu
+include Chingu
+
+require_all File.join(ROOT, 'src')
+
+class Game < Chingu::Window
+ attr_reader :player, :map
+ attr_accessor :factor
+
+ def initialize
+ @factor = 3
+ super(320 * 3, 180 * 3, false)
+
+ $window.caption = "the light at the end of the tunnel. ~~ http://ippa.se/gaming ~~ a LD#16 entry, theme 'Exploration'."
+
+ self.input = { :esc => :close, :p => Chingu::GameStates::Pause, :f1 => :next_level }
+ @player = Player.create(:x => 100, :y => 100, :zorder => 100, :visible => false)
+
+ Sound["jump.wav"] # <-- lame caching untill chingu gets "cache_media()" or simular
+ Sound["land.wav"]
+ Sound["die.wav"]
+ Sound["falling.wav"]
+ Sound["poop.wav"]
+
+ map = [ [LevelUp, nil, nil, nil],
+ [Level1, Level2,Level22, nil],
+ [LevelAir, nil, Level3, nil],
+ [LevelAir2, Level5, Level4, nil],
+ [nil, Level6, Level7, nil],
+ [nil, Level8, Level9, Poop],
+ ]
+
+ @map = Map.new(:map => map, :row => 1, :col => 0)
+ switch_game_state(@map.current)
+
+ #switch_game_state(Level8)
+ end
+
+end
+
+Game.new.show
Please sign in to comment.
Something went wrong with that request. Please try again.