Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RubyConf 2009 - Writing 2D games for the OSX pl...

RubyConf 2009 - Writing 2D games for the OSX platform in Ruby

Are you a developer who would love to get into video games but get scared when he hears "OpenGL" or "rendering engines"? Or Maybe, you never considered writing a video game because you have heard Ruby was slow and you are not ready to give up on your favorite programming language. This talk is for you then. Together, we will build a very simple game using Ruby and the development tools offered by Apple. At the end of the presentation you will be ready to get started on your own project.

Video: http://www.confreaks.com/videos/192-rubyconf2009-writing-2d-games-for-the-osx-platform-in-ruby
Website: http://matt.aimonetti.net/posts/2009/11/21/rubyconf-2009-2d-games-for-os-x/

Matt Aimonetti

November 22, 2009
Tweet

More Decks by Matt Aimonetti

Other Decks in Programming

Transcript

  1. game loop 174 ❶ update layers reposition update game items

    ❷ collisions Sunday, November 22, 2009
  2. game loop 174 ❶ update layers reposition update game items

    ❷ collisions lives points sound Sunday, November 22, 2009
  3. module GameLoop def start_refreshing @timer = NSTimer.scheduledTimerWithTimeInterval 0.03, target: self,

    selector: 'refresh_screen:', userInfo: nil, repeats: true end def refresh_screen(timer=nil) #… end end Sunday, November 22, 2009
  4. NSTimer.scheduledTimerWithTimeInterval 0.03, target: self, selector: 'refresh_screen:', userInfo: nil, repeats: true

    cocoa class method time interval method to call on the target some stuff we don’t care about ;) Sunday, November 22, 2009
  5. def refresh_screen(timer=nil) GameData.all_layers.each{ |layer| layer.update } collided_bombs, collided_rubies=GameData.collisions if !collided_bombs.empty?

    loose_a_life collided_bombs.each{|layer| layer.item.reset! } else collided_rubies.each do |layer| GameData.increase_points(layer.item.points) points.attributedStringValue = GameData.points.to_s layer.item.reset! end SoundEffects.collision(0.2) unless collided_rubies.empty? level_change! if change_level? end end Sunday, November 22, 2009
  6. module GameConfig module_function def data @data ||= { :levels =>

    [ { :name => 'Pond', :rubies => 3, :bombs => 12, :score_limit => 30, :vehicle => 'nenuphar', :bomb_image => 'bomb', :bomb_ratio => 1, :ruby_ratio => 1.5, :player_width => 0.2, :player_height => 0.2 }] } end Sunday, November 22, 2009
  7. class NSButton def title_color=(color) current_font = self.attributedTitle.attribute(NSFontAttributeName, atIndex: 0, effectiveRange:

    nil) opts = { NSForegroundColorAttributeName => color, NSFontAttributeName => current_font } self.attributedTitle = NSAttributedString.alloc.initWithString( self.title, attributes: opts) end end Sunday, November 22, 2009