Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
Rapid Game
Development with
Ruby and Gosu
Belén Albeza
@ladybenko
Aren’t games coded in
C++?
Minecraft
(Java)
To the Moon
(RPG Maker)
So?
• Some games will require C++
• Some games won’t
• You can trade performance for:
• Better productivity (faster develo...
Prototyping
• One Game A Month

www.onegameamonth.com

• Experimental Gameplay

www.experimentalgameplay.com

• Ludum Dare...
Introducing Gosu
What is Gosu?
• Gosu is a minimalistic 2D game library
www.libgosu.org

• Free, Open source (MIT License)
• Multiplatform ...
Gosu’s API is very small
• ~100 methods in 9 classes
• Gosu provides a way to:
• Create an OpenGL window
• Load and draw i...
Show demo
Gosu 101

https://github.com/belen-albeza/gosu-rubymanor
The Game Loop
snippets/create_window.rb
Get player input

60 FPS

Update game

Draw game
require 'rubygems'
require 'gosu'
class Game < Gosu::Window
# ...
end
game = Game.new
game.show
class Game < Gosu::Window
def initialize
super(800, 600, false)
end
def draw # gets called every frame
end
def update # ge...
Images

snippets/draw_image.rb
Instance of Gosu::Window
# load
@img_bg =
Gosu::Image.new(self,‘space.png’)
# draw
@img_bg.draw(0, 0, 0)
@ship.draw_rot(40...
Input

snippets/input.rb
# callback for key up events
def button_up(key)
close if key == Gosu::KbEscape
end
# check if a key is being pressed
def u...
Delta time

snippets/delta_time.rb
4px / frame
= 12 px
4 px

4px

4 px
= 46 ms

13 ms

4px / frame @ 60 FPS
vs
240 pixels / second

16 ms

17 ms

240 px / se...
def update_delta
current_time = Gosu::milliseconds /
1000.0
# tip: always cap your delta
@delta = [current_time - @last_ti...
Distribution
• Mac: App wrapper with a Ruby on it

https://github.com/jlnr/gosu/wiki/RubyPackaging-on-OS-X

• Windows: OCR...
Game Dev Techniques
Bounding boxes
•

Quick collisions, but not
very accurate

•

Shapes can be combined
to increase accuracy

•

Beware of ro...
Finite State Machines
•
•
•

Patrol

Easy to implement,
cheap, lots of uses...
AI: character behaviors
Scene stack

seeing...
Tiles
•
•

Divide a level into a grid

•

Useful to save memory,
make a level editor,
implement simple
physics, etc.

Visu...
Path-finding
•

They are usually very
expensive... try to
minimise their use

•

Dijkstra is enough for
simple graphs (ie. ...
Scripting
• Scripting transforms a simple arcade level

into a mission or a quest (see Cave Story)

• Embed a VM into your...
event = {
:type => :talk_to,
:data => :friend
}

click

call
talk_to_friend
Scripting example
# this method is called when the event
# talk_to is triggered on the :pirate
# NPC
def talk_to_pirate
np...
Physics engine
•

Real physics for your
games! Done by smart
people! And free!

•

They are slow, so try to
minimise the a...
Physics + Gosu
• Use Box2D (low-level) or Chipmunk
• Chipmunk integration tutorial at https://

github.com/jlnr/gosu/wiki/...
The Golden Rule of Game Dev

If you can fake it,
then fake it.
Resources
• Chingu: game framework for Gosu https://
github.com/ippa/chingu

• Creative Commons art: http://

www.lostgard...
Thanks!
Questions?
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Prochain SlideShare
Chargement dans…5
×

Rapid Game Development with RUby and Gosu – Ruby Manor 4

14 207 vues

Publié le

Rapid Game Development with RUby and Gosu – Ruby Manor 4

Publié dans : Technologie, Design
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy &amp; Proven Way to Build Good Habits &amp; Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Rapid Game Development with RUby and Gosu – Ruby Manor 4

  1. 1. Rapid Game Development with Ruby and Gosu Belén Albeza @ladybenko
  2. 2. Aren’t games coded in C++?
  3. 3. Minecraft (Java)
  4. 4. To the Moon (RPG Maker)
  5. 5. So? • Some games will require C++ • Some games won’t • You can trade performance for: • Better productivity (faster development, prototypes to test ideas, etc.) • Happiness :)
  6. 6. Prototyping • One Game A Month www.onegameamonth.com • Experimental Gameplay www.experimentalgameplay.com • Ludum Dare www.ludumdare.com
  7. 7. Introducing Gosu
  8. 8. What is Gosu? • Gosu is a minimalistic 2D game library www.libgosu.org • Free, Open source (MIT License) • Multiplatform (Win, OS X, Linux) • Has bindings for Ruby and C++ • $gem install gosu
  9. 9. Gosu’s API is very small • ~100 methods in 9 classes • Gosu provides a way to: • Create an OpenGL window • Load and draw images and fonts • Load and play sounds • Gather player’s input
  10. 10. Show demo
  11. 11. Gosu 101 https://github.com/belen-albeza/gosu-rubymanor
  12. 12. The Game Loop snippets/create_window.rb
  13. 13. Get player input 60 FPS Update game Draw game
  14. 14. require 'rubygems' require 'gosu' class Game < Gosu::Window # ... end game = Game.new game.show
  15. 15. class Game < Gosu::Window def initialize super(800, 600, false) end def draw # gets called every frame end def update # gets called every frame end def button_up(key) # callback end end
  16. 16. Images snippets/draw_image.rb
  17. 17. Instance of Gosu::Window # load @img_bg = Gosu::Image.new(self,‘space.png’) # draw @img_bg.draw(0, 0, 0) @ship.draw_rot(400, 300, 0, 45) # note: audio and fonts follow the same # approach.
  18. 18. Input snippets/input.rb
  19. 19. # callback for key up events def button_up(key) close if key == Gosu::KbEscape end # check if a key is being pressed def update if self.button_down?(Gosu::KbLeft) move_left end end Instance of Gosu::Window
  20. 20. Delta time snippets/delta_time.rb
  21. 21. 4px / frame = 12 px 4 px 4px 4 px = 46 ms 13 ms 4px / frame @ 60 FPS vs 240 pixels / second 16 ms 17 ms 240 px / second = 11.04 px 3.12 px 3.84 px 4.08 px = 46 ms 13 ms 16 ms 17 ms
  22. 22. def update_delta current_time = Gosu::milliseconds / 1000.0 # tip: always cap your delta @delta = [current_time - @last_time, 0.25].min @last_time = current_time end # simple movement @x += SHIP_SPEED * @delta # with inertia @speed_x += SHIP_ACCELERATION * @delta @x += @speed_x * @delta
  23. 23. Distribution • Mac: App wrapper with a Ruby on it https://github.com/jlnr/gosu/wiki/RubyPackaging-on-OS-X • Windows: OCRA https://github.com/jlnr/ gosu/wiki/Ruby-Packaging-on-Windows
  24. 24. Game Dev Techniques
  25. 25. Bounding boxes • Quick collisions, but not very accurate • Shapes can be combined to increase accuracy • Beware of rotations! http://devmag.org.za/2009/04/13/basic-collisiondetection-in-2d-part-1/
  26. 26. Finite State Machines • • • Patrol Easy to implement, cheap, lots of uses... AI: character behaviors Scene stack seeing player? not seeing player? out of attacking distance? Chase Attack in attacking distance? http://www.generation5.org/content/2003/ fsm_tutorial.asp
  27. 27. Tiles • • Divide a level into a grid • Useful to save memory, make a level editor, implement simple physics, etc. Visual grid != Logic grid... but we can map them :) http://www-cs-students.stanford.edu/~amitp/ gameprog.html#tiles
  28. 28. Path-finding • They are usually very expensive... try to minimise their use • Dijkstra is enough for simple graphs (ie. an adventure) • A* for everything else (action RPG’s, strategy, etc.) http://theory.stanford.edu/~amitp/GameProgramming/
  29. 29. Scripting • Scripting transforms a simple arcade level into a mission or a quest (see Cave Story) • Embed a VM into your engine (most popular for games is Lua)... but Ruby is already a script language :D • Useful triggers: enter an area, exit an area, talk to NPC, pick up item, kill an enemy, etc.
  30. 30. event = { :type => :talk_to, :data => :friend } click call talk_to_friend
  31. 31. Scripting example # this method is called when the event # talk_to is triggered on the :pirate # NPC def talk_to_pirate npc_say(:pirate, ‘Aaaarrrr’) add_to_inventory(:rum) end
  32. 32. Physics engine • Real physics for your games! Done by smart people! And free! • They are slow, so try to minimise the amount of physical entities • You need to map your visual world into an invisible physical world (beware of units!)
  33. 33. Physics + Gosu • Use Box2D (low-level) or Chipmunk • Chipmunk integration tutorial at https:// github.com/jlnr/gosu/wiki/Ruby-ChipmunkIntegration
  34. 34. The Golden Rule of Game Dev If you can fake it, then fake it.
  35. 35. Resources • Chingu: game framework for Gosu https:// github.com/ippa/chingu • Creative Commons art: http:// www.lostgarden.com/search/label/free %20game%20graphics • More: http://www.libgosu.org/cgi-bin/mwf/ board_show.pl?bid=4
  36. 36. Thanks! Questions?

×