SlideShare ist ein Scribd-Unternehmen logo
1 von 128
Downloaden Sie, um offline zu lesen
rubyconf 2009
2d video game
development
with
MacRuby
matt aimonetti
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
video games on
OSX
OLD SCHOOL
from scratch
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
keyboard
GameData
Sunday, November 22, 2009
Sunday, November 22, 2009
game loop
Sunday, November 22, 2009
game loop
174
❶ update
layers
Sunday, November 22, 2009
game loop
174
❶ update
layers
update
game items
Sunday, November 22, 2009
game loop
174
❶ update
layers
repositionupdate
game items
Sunday, November 22, 2009
game loop
174
❶ update
layers
repositionupdate
game items
❷ collisions
Sunday, November 22, 2009
game loop
174
❶ update
layers
repositionupdate
game items
❷ collisions
lives
points
sound
Sunday, November 22, 2009
LOOP playDATA
GAME
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
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
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

Weitere ähnliche Inhalte

Ähnlich wie 2D Video Games with MacRuby

Django, Pinax, and Humble Pie
Django, Pinax, and Humble PieDjango, Pinax, and Humble Pie
Django, Pinax, and Humble Piephredcode
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009Caue Guerra
 
Realtime 3D on the web - a toy or a useful tool?
Realtime 3D on the web - a toy or a useful tool?Realtime 3D on the web - a toy or a useful tool?
Realtime 3D on the web - a toy or a useful tool?Jens Brynildsen
 
Ruby On Rails Presentation Barcamp Antwerp.Key
Ruby On Rails Presentation Barcamp Antwerp.KeyRuby On Rails Presentation Barcamp Antwerp.Key
Ruby On Rails Presentation Barcamp Antwerp.KeyBert Goethals
 
Tkinter Does Not Suck
Tkinter Does Not SuckTkinter Does Not Suck
Tkinter Does Not SuckRichard Jones
 

Ähnlich wie 2D Video Games with MacRuby (6)

Django, Pinax, and Humble Pie
Django, Pinax, and Humble PieDjango, Pinax, and Humble Pie
Django, Pinax, and Humble Pie
 
Cloudera Desktop
Cloudera DesktopCloudera Desktop
Cloudera Desktop
 
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 20092009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
2009, o ano do Ruby on Rails no Brasil - CaelumDay 2009
 
Realtime 3D on the web - a toy or a useful tool?
Realtime 3D on the web - a toy or a useful tool?Realtime 3D on the web - a toy or a useful tool?
Realtime 3D on the web - a toy or a useful tool?
 
Ruby On Rails Presentation Barcamp Antwerp.Key
Ruby On Rails Presentation Barcamp Antwerp.KeyRuby On Rails Presentation Barcamp Antwerp.Key
Ruby On Rails Presentation Barcamp Antwerp.Key
 
Tkinter Does Not Suck
Tkinter Does Not SuckTkinter Does Not Suck
Tkinter Does Not Suck
 

Mehr von Matt Aimonetti

Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Matt Aimonetti
 
Future Of Ruby And Rails
Future Of Ruby And RailsFuture Of Ruby And Rails
Future Of Ruby And RailsMatt Aimonetti
 
Rails3: Stepping off of the golden path
Rails3: Stepping off of the golden pathRails3: Stepping off of the golden path
Rails3: Stepping off of the golden pathMatt Aimonetti
 
Macruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich KilmerMacruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich KilmerMatt Aimonetti
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMatt Aimonetti
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The EnterpriseMatt Aimonetti
 
Merb presentation at ORUG
Merb presentation at ORUGMerb presentation at ORUG
Merb presentation at ORUGMatt Aimonetti
 

Mehr von Matt Aimonetti (9)

Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010Macruby - RubyConf Presentation 2010
Macruby - RubyConf Presentation 2010
 
Future Of Ruby And Rails
Future Of Ruby And RailsFuture Of Ruby And Rails
Future Of Ruby And Rails
 
Rails3: Stepping off of the golden path
Rails3: Stepping off of the golden pathRails3: Stepping off of the golden path
Rails3: Stepping off of the golden path
 
Macruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich KilmerMacruby& Hotcocoa presentation by Rich Kilmer
Macruby& Hotcocoa presentation by Rich Kilmer
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The Enterprise
 
Merb presentation at ORUG
Merb presentation at ORUGMerb presentation at ORUG
Merb presentation at ORUG
 
Merb Plugins 101
Merb Plugins 101Merb Plugins 101
Merb Plugins 101
 
Lazy Indexing
Lazy IndexingLazy Indexing
Lazy Indexing
 

Kürzlich hochgeladen

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Kürzlich hochgeladen (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

2D Video Games with MacRuby