Your SlideShare is downloading. ×
0
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Rapid Game Development with RUby and Gosu – Ruby Manor 4
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Rapid Game Development with RUby and Gosu – Ruby Manor 4

11,320

Published on

Rapid Game Development with RUby and Gosu – Ruby Manor 4

Rapid Game Development with RUby and Gosu – Ruby Manor 4

Published in: Technology, Design
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,320
On Slideshare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
37
Comments
0
Likes
6
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Rapid Game Development with Ruby and Gosu Belén Albeza @ladybenko
  • 2. Aren’t games coded in C++?
  • 3. Minecraft (Java)
  • 4. To the Moon (RPG Maker)
  • 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. Prototyping • One Game A Month www.onegameamonth.com • Experimental Gameplay www.experimentalgameplay.com • Ludum Dare www.ludumdare.com
  • 7. Introducing Gosu
  • 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. 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. Show demo
  • 11. Gosu 101 https://github.com/belen-albeza/gosu-rubymanor
  • 12. The Game Loop snippets/create_window.rb
  • 13. Get player input 60 FPS Update game Draw game
  • 14. require 'rubygems' require 'gosu' class Game < Gosu::Window # ... end game = Game.new game.show
  • 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. Images snippets/draw_image.rb
  • 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. Input snippets/input.rb
  • 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. Delta time snippets/delta_time.rb
  • 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. 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. 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. Game Dev Techniques
  • 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. 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. 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. 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. 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. event = { :type => :talk_to, :data => :friend } click call talk_to_friend
  • 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. 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. Physics + Gosu • Use Box2D (low-level) or Chipmunk • Chipmunk integration tutorial at https:// github.com/jlnr/gosu/wiki/Ruby-ChipmunkIntegration
  • 34. The Golden Rule of Game Dev If you can fake it, then fake it.
  • 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. Thanks! Questions?

×