daily pastebin goal
2%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 178 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2.         Mr Monocle
  3.         And His Marvelous
  4.         Madcap Underground Race
  5.  
  6.         Ludum Dare #15 entry by "Deps"
  7.        
  8.         Written in Ruby using the Gosu graphics module
  9.  
  10. =end
  11.  
  12.  
  13. ENV["RUBYOPT"] = "-rrubygems"
  14. ROOT_PATH = File.dirname(File.expand_path(__FILE__))
  15. $:.unshift File.join(ROOT_PATH, "lib")
  16.  
  17. begin # In case you use Gosu via RubyGems.
  18.   require 'rubygems'  unless RUBY_VERSION =~ /1.9/
  19. rescue LoadError
  20. end
  21.  
  22. begin
  23.   require 'gosu'
  24. rescue LoadError
  25.   require File.join(ROOT_PATH, 'lib', 'gosu')
  26. end
  27.  
  28.  
  29. %w{misc logger}.each do |file|
  30.   require File.join(ROOT_PATH, 'lib', file)
  31. end
  32. %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|
  33.   require File.join(ROOT_PATH, 'models', file)
  34. end
  35. %w{controller.rb player_controller.rb jukebox.rb state.rb bullet_controller.rb enemy_patterns.rb}.each do |file|
  36.   require File.join(ROOT_PATH, 'controllers', file)
  37. end
  38.  
  39.  
  40. class MyWindow < Gosu::Window
  41.  
  42.   attr_reader :font, :music, :menubg, :bounce_ticks, :scores
  43.  
  44.   def initialize
  45.     super(640, 480, false)
  46.     self.caption = 'Mr Monocle - Madcap Race'
  47.  
  48.     clear_keybuf
  49.    
  50.     @music = JukeBox.new(self)    
  51.     @music.play
  52.    
  53.     @paused = false
  54.    
  55.     @bounce_ticks = {}
  56.  
  57.     @scores = HighScore.new
  58.    
  59.     @font = Gosu::Font.new(self, Gosu::default_font_name, 24)
  60.     @font2 = Gosu::Font.new(self, Gosu::default_font_name, 56)
  61.     @font3 = Gosu::Font.new(self, Gosu::default_font_name, 12)
  62.    
  63.     @menubg = Gosu::Image.new(self, "views/wallpaper.png", true )
  64.    
  65.     @snd_eat = Gosu::Sample.new(self, "views/eat.wav")
  66.     @snd_item = Gosu::Sample.new(self, "views/pickup.wav")
  67.     @snd_explosion = Gosu::Sample.new(self, "views/explosion.wav")
  68.     @snd_gnome = Gosu::Sample.new(self, "views/gnome.wav")
  69.     @snd_shoot = Gosu::Sample.new(self, "views/shoot.wav")
  70.     @snd_death = Gosu::Sample.new(self, "views/death.wav")
  71.     @snd_extralife = Gosu::Sample.new(self, "views/extralife.wav")
  72.    
  73.     State.register_window( self )
  74.     State.change MainMenuState.new()
  75.   end
  76.  
  77.   def sound( fx )
  78.     eval "@snd_#{fx}.play"
  79.   end
  80.  
  81.   def button_down( id )
  82.     @keys[id] = true
  83.     super(id)
  84.   end
  85.  
  86.   def bounce( hud_item )
  87.     @bounce_ticks[hud_item] = 20
  88.   end
  89.  
  90.   def keyhit?( id )
  91.     v = @keys[id]
  92.     @keys[id] = false
  93.     return v
  94.   end
  95.  
  96.   def clear_keybuf()
  97.     @keys = {}
  98.   end
  99.  
  100.   def center_text( msg, x,y, use_font=nil )
  101.     case use_font
  102.     when :big
  103.       @font2.draw(msg, x-@font2.text_width(msg)/2,y,0)
  104.     when :small
  105.       @font3.draw(msg, x-@font3.text_width(msg)/2,y,0)
  106.     else
  107.       @font.draw(msg, x-@font.text_width(msg)/2,y,0)
  108.     end
  109.   end
  110.  
  111.  
  112.   def draw_bar( value, max, x,y, width, col = nil )
  113.     p = value/max.to_f
  114.     w2 = width*p
  115.     c1 = Gosu::Color.new(255,0,0,0)
  116.     if col
  117.       c2 = Gosu::Color.new(255,col[0],col[1],col[2])
  118.     else
  119.       c2 = Gosu::Color.new(255,255,255,255)
  120.     end
  121.    
  122.     self.draw_quad( x,y,c1, x+width,y,c1, x+width,y+10,c1, x,y+10,c1 )
  123.     self.draw_quad( x+2,y+2,c2, x+w2,y+2,c2, x+w2,y+6,c2, x+2,y+6,c2 )
  124.    
  125.   end
  126.  
  127.  
  128.   def draw_background
  129.     11.times do |x|
  130.       9.times do |y|
  131.         n = Time.now.to_f
  132.         @menubg.draw( -32+(x*64)+Math.cos(n)*32,-32+(y*64)+Math.sin(n)*32,0 )
  133.       end
  134.     end
  135.   end
  136.  
  137.  
  138.   def draw
  139.     State.draw
  140.    
  141.   end
  142.  
  143.   def update
  144.    
  145.     @paused = !@paused if keyhit? Gosu::Button::KbP
  146.    
  147.     @music.update
  148.     State.update unless @paused
  149.     close() if State.empty
  150.   end
  151. end
  152.  
  153. log "Creating game main class"
  154. w = MyWindow.new
  155. log "Entering game loop", "INFO"
  156. w.show
  157. log "Game loop ended", "INFO"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top