Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

2D Video Games with MacRuby

on

  • 4,689 views

Demonstration of how to write a simple 2D game using MacRuby and CoreAnimation.

Demonstration of how to write a simple 2D game using MacRuby and CoreAnimation.

Statistics

Views

Total Views
4,689
Views on SlideShare
4,634
Embed Views
55

Actions

Likes
4
Downloads
38
Comments
0

3 Embeds 55

http://coderwall.com 40
http://www.slideshare.net 14
http://translate.googleusercontent.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

2D Video Games with MacRuby 2D Video Games with MacRuby Presentation Transcript

  • 2d video game development with MacRuby matt aimonetti rubyconf 2009 Sunday, November 22, 2009
  • test your memory Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Video Games are fun Sunday, November 22, 2009
  • Ruby Programming is fun Sunday, November 22, 2009
  • You have a mac Sunday, November 22, 2009
  • (if not, get one!) Sunday, November 22, 2009
  • OOL SCH OLD video games on OSX at ch s cr m f ro Sunday, November 22, 2009
  • truth Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • but Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • popular games Sunday, November 22, 2009
  • Massively Multiplayer online role-playing games (MMORPG) Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • too much work for a hacking project Sunday, November 22, 2009
  • first person shooter Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • new types of games Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • online games Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • iphone games Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • demo Sunday, November 22, 2009
  • MacRuby Sunday, November 22, 2009
  • Ruby for SCottish Sunday, November 22, 2009
  • Laurent Sansonetti Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • on obj-c runtime and GC Sunday, November 22, 2009
  • COCOA Apple's Objective-C based programming environment for Mac OS X Sunday, November 22, 2009
  • VIDEO GAME Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • keyboard Sunday, November 22, 2009
  • key event keyboard Sunday, November 22, 2009
  • key event GameData keyboard Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • game loop Sunday, November 22, 2009
  • ❶ update 174 layers game loop Sunday, November 22, 2009
  • ❶ update 174 layers game loop update game items Sunday, November 22, 2009
  • ❶ update 174 layers game loop update reposition game items Sunday, November 22, 2009
  • ❶ update 174 layers game loop update reposition ❷ collisions game items Sunday, November 22, 2009
  • ❶ update 174 layers game loop update reposition ❷ collisions lives points game items sound Sunday, November 22, 2009
  • GAME DATA LOOP play Sunday, November 22, 2009
  • GAME PLAY Sunday, November 22, 2009
  • ⇧ ⇧ ⇧ Sunday, November 22, 2009
  • NSView subclass Interface Builder Sunday, November 22, 2009
  • NSView subclass Interface Builder Sunday, November 22, 2009
  • class KeyboardControlView < NSView def keyDown(event) end end Sunday, November 22, 2009
  • class KeyboardControlView < NSView ⇧ ⇧ def keyDown(event) end end Sunday, November 22, 2009
  • acceleration Sunday, November 22, 2009
  • relative positioning Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • GAME LOOP Sunday, November 22, 2009
  • usual workflow Sunday, November 22, 2009
  • usual workflow Sunday, November 22, 2009
  • video game Sunday, November 22, 2009
  • video game Sunday, November 22, 2009
  • 30 x per second Sunday, November 22, 2009
  • moves player moves objects resolves collisions updates score/level redraws graphics plays sounds Sunday, November 22, 2009
  • 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
  • cocoa class method time interval NSTimer.scheduledTimerWithTimeInterval 0.03, target: self, method to call selector: 'refresh_screen:', on the target userInfo: nil, repeats: true some stuff we don’t care about ;) Sunday, November 22, 2009
  • IntervalTimer.new(0.03, :target => self, :selector => 'refresh_screen:') Sunday, November 22, 2009
  • 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
  • GameData.all_layers.each do |layer| layer.update end Sunday, November 22, 2009
  • collided_bombs, collided_rubies = GameData.collisions Sunday, November 22, 2009
  • def collide_with?(other_rect) NSIntersectsRect(rect_version, other_rect) end Sunday, November 22, 2009
  • if !collided_bombs.empty? loose_a_life collided_bombs.each do |layer| layer.item.reset! end Sunday, November 22, 2009
  • else collided_rubies.each do |layer| GameData.increase_points(layer.item.points) update_points_display layer.item.reset! end Sunday, November 22, 2009
  • unless collided_rubies.empty? SoundEffects.frog(0.2) end level_change! if change_level? end Sunday, November 22, 2009
  • module SoundEffects module_function @frog = NSSound.soundNamed("Frog") def frog(delay=0) @frog.performSelector(:play, withObject: nil, afterDelay: delay) end end Sunday, November 22, 2009
  • GAME DATA Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • module GameData module_function end Sunday, November 22, 2009
  • class GameController def awakeFromNib GameData.register_controller(self) end end Sunday, November 22, 2009
  • GameData.all_layers Sunday, November 22, 2009
  • class GameController def display_item(item) new_layer = ImageLayer.alloc.initWithItem(item) GameData.all_layers << new_layer # [...] end end Sunday, November 22, 2009
  • 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
  • cocoa hax Sunday, November 22, 2009
  • CocoaClass =~ RubyClass Sunday, November 22, 2009
  • don’t like an API? Sunday, November 22, 2009
  • Wrap it Sunday, November 22, 2009
  • 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
  • compilation Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • PATH="$PATH:/usr/local/bin" macruby_deploy "$TARGET_BUILD_DIR/ $PROJECT_NAME.app" --embed --no-stdlib --compile Sunday, November 22, 2009
  • wanna hack? Sunday, November 22, 2009
  • best score post score Sunday, November 22, 2009
  • gosu framework Sunday, November 22, 2009
  • chipmunk physics Sunday, November 22, 2009
  • http://github.com/ mattetti/phileas_frog Sunday, November 22, 2009
  • Sunday, November 22, 2009
  • Thanks Sunday, November 22, 2009