Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- Mr Monocle
- And His Marvelous
- Madcap Underground Race
- Ludum Dare #15 entry by "Deps"
- Written in Ruby using the Gosu graphics module
- =end
- ENV["RUBYOPT"] = "-rrubygems"
- ROOT_PATH = File.dirname(File.expand_path(__FILE__))
- $:.unshift File.join(ROOT_PATH, "lib")
- begin # In case you use Gosu via RubyGems.
- require 'rubygems' unless RUBY_VERSION =~ /1.9/
- rescue LoadError
- end
- begin
- require 'gosu'
- rescue LoadError
- require File.join(ROOT_PATH, 'lib', 'gosu')
- end
- %w{misc logger}.each do |file|
- require File.join(ROOT_PATH, 'lib', file)
- end
- %w{rect.rb entity.rb player.rb cavern.rb food.rb weapon.rb treasure.rb instrument.rb song.rb fx.rb enemy.rb highscore.rb}.each do |file|
- require File.join(ROOT_PATH, 'models', file)
- end
- %w{controller.rb player_controller.rb jukebox.rb state.rb bullet_controller.rb enemy_patterns.rb}.each do |file|
- require File.join(ROOT_PATH, 'controllers', file)
- end
- class MyWindow < Gosu::Window
- attr_reader :font, :music, :menubg, :bounce_ticks, :scores
- def initialize
- super(640, 480, false)
- self.caption = 'Mr Monocle - Madcap Race'
- clear_keybuf
- @music = JukeBox.new(self)
- @music.play
- @paused = false
- @bounce_ticks = {}
- @scores = HighScore.new
- @font = Gosu::Font.new(self, Gosu::default_font_name, 24)
- @font2 = Gosu::Font.new(self, Gosu::default_font_name, 56)
- @font3 = Gosu::Font.new(self, Gosu::default_font_name, 12)
- @menubg = Gosu::Image.new(self, "views/wallpaper.png", true )
- @snd_eat = Gosu::Sample.new(self, "views/eat.wav")
- @snd_item = Gosu::Sample.new(self, "views/pickup.wav")
- @snd_explosion = Gosu::Sample.new(self, "views/explosion.wav")
- @snd_gnome = Gosu::Sample.new(self, "views/gnome.wav")
- @snd_shoot = Gosu::Sample.new(self, "views/shoot.wav")
- @snd_death = Gosu::Sample.new(self, "views/death.wav")
- @snd_extralife = Gosu::Sample.new(self, "views/extralife.wav")
- State.register_window( self )
- State.change MainMenuState.new()
- end
- def sound( fx )
- eval "@snd_#{fx}.play"
- end
- def button_down( id )
- @keys[id] = true
- super(id)
- end
- def bounce( hud_item )
- @bounce_ticks[hud_item] = 20
- end
- def keyhit?( id )
- v = @keys[id]
- @keys[id] = false
- return v
- end
- def clear_keybuf()
- @keys = {}
- end
- def center_text( msg, x,y, use_font=nil )
- case use_font
- when :big
- @font2.draw(msg, x-@font2.text_width(msg)/2,y,0)
- when :small
- @font3.draw(msg, x-@font3.text_width(msg)/2,y,0)
- else
- @font.draw(msg, x-@font.text_width(msg)/2,y,0)
- end
- end
- def draw_bar( value, max, x,y, width, col = nil )
- p = value/max.to_f
- w2 = width*p
- c1 = Gosu::Color.new(255,0,0,0)
- if col
- c2 = Gosu::Color.new(255,col[0],col[1],col[2])
- else
- c2 = Gosu::Color.new(255,255,255,255)
- end
- self.draw_quad( x,y,c1, x+width,y,c1, x+width,y+10,c1, x,y+10,c1 )
- self.draw_quad( x+2,y+2,c2, x+w2,y+2,c2, x+w2,y+6,c2, x+2,y+6,c2 )
- end
- def draw_background
- 11.times do |x|
- 9.times do |y|
- n = Time.now.to_f
- @menubg.draw( -32+(x*64)+Math.cos(n)*32,-32+(y*64)+Math.sin(n)*32,0 )
- end
- end
- end
- def draw
- State.draw
- end
- def update
- @paused = !@paused if keyhit? Gosu::Button::KbP
- @music.update
- State.update unless @paused
- close() if State.empty
- end
- end
- log "Creating game main class"
- w = MyWindow.new
- log "Entering game loop", "INFO"
- w.show
- log "Game loop ended", "INFO"
Add Comment
Please, Sign In to add comment