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

Game Development - The Ruby Way..!!

Game Development - The Ruby Way..!!

The slides of the talk I gave at DeccanRubyConf, 2014. It includes game history, concepts of game programming and about GOSU.
GOSU is a 2D game development framework. It works well for c++ and Ruby.

rishi jain

July 19, 2014
Tweet

More Decks by rishi jain

Other Decks in Programming

Transcript

  1. GAME DEVELOPMENT
    - THE RUBY WAY !!!
    RISHI JAIN
    @jainrishi15
    Josh Software

    View Slide

  2. Full-Stack
    !
    Senior
    ,
    GameProgrammer
    https://www.flickr.com/photos/dolmansaxlil/6012147519/in/photolist-aagPZR-boiiM2-7YyHDy-aFAUqH-JLVaF-71PnxX-kHcKA-4hVY61-9PSLHY-fKcyFp-4szDkt-4HYGCQ-6xmG7C-9eUfHz-644Ln2-ecSjmW-FW7q9-e7rUxJ-2oWHox-mgLHRS-HV5dj-5aXsQ7-aKDgQZ-3LvJax-9AiEUa-
    bSoFUt-6DLpEU-5TR36L-6xmHDy-gdr3gf-hFyk5m-4szzQ9-68RKJD-7RMSYq-d9viHW-5qdqRX-6V9ka5-6V5g4P-adoaPq-6fARp1-7RJCa6-76E98-5rFMKK-2p1BDP-buG23u-5EZsty-nMan63-6xmF4o-6NWEiK-nTQgua

    View Slide

  3. HISTORY OF GAMES

    View Slide

  4. PINBALL
    https://www.flickr.com/photos/aloha75/8378526094/in/photolist-mRKQxW-rNPff-rNPmX-32V4bW-9ish8B-dLhCbz-dLo8Us-dLo8P9-4BE2sS-5b8mk-mbRi9-asJhSm-4J4bbG-6UDndE-bBYhFc-LMw8K-8f26YB-dBRj5a-8xtm1J-7KueEo-6Hfgx1-7Fq6ja-9vNZCf-CYNzw-

    View Slide

  5. https://www.flickr.com/photos/sibekokke/508363450/in/photolist-4s2Md3-4rXJw2-4s2May-iECMTJ-zb9gq-7tD1Th-LVuK5-dzCwFM-6iKhFP-69fTME-8ze5dG-6QAMrE-5Wr2rq-4s2M6L-4rXJsn-4rXJnv-4rXJuT-4s2Mc3-4s2M8U-4rXJpv-Cbu1x-7QhYcT-675tRb-7Yjo5-8ocxFu-6sQmF-t96na-21iH2k-zRzzG-

    View Slide

  6. http://wallpapershared.com/game-breakout-atari-voyager.html

    View Slide

  7. MY HISTORY OF
    GAMES

    View Slide

  8. Identify the
    game from the
    sound track.

    View Slide

  9. https://www.flickr.com/photos/arte/2423977915/sizes/l/

    View Slide

  10. Identify the
    game from the
    sound track.

    View Slide

  11. https://www.flickr.com/photos/somegeekintn/5427133506/in/photolist-9gztHm-9gztB7-4r9uUr-dgDKtR-7VDKCt-7VDKFZ-fUehZ6-5bdfcb-7u1MyT-9um6yx-8zDMqT-4J8aP4-8zGVEC-5VQpZ9-4E9yFM-7ta4ve-vWZfa-7Tmub5-6tJHjS-3En7yB-bKXT-aqx7mM-rFKvX-4Zpi9T-rFKw3-5eHJyQ-8tGEib-2oECWh-bQEtH-

    View Slide

  12. Identify the
    game from the
    sound track.

    View Slide

  13. View Slide

  14. I wanted to build a
    game,
    but why ?

    View Slide

  15. https://www.flickr.com/photos/anua22a/2450798106/in/photolist-4JyYTL-pqYJK-nVks3G-4U6yXA-iniaf-7xxKyM-g97Nph-7ZBRNo-apJzGm-9TDrt-7t5UhK-fvFntG-5ZbrEE-eqqmuT-dQUgdC-7tDeDQ-3fXbra-aSZmyn-6wYoR8-59efoV-apa43t-84AZHc-cMgbim-5h28wB-fz3bSd-9Le6DZ-7SeHkk-2xCwen-4GrWvo-duF3GG-jYVkhr-eZoKBJ-4GkuVZ-
    https://www.flickr.com/photos/isriya/7180133440/in/photolist-bWu4w9-bWu2FL-bWu41J-bWu34N-bWu3BE-bWu3du-bWu2eu-bWu3PG-bWu4fC-bWu23w-6TqHos-5ZU29M-6m71g-6m7cG-6GPYhV-6m7nP-6m7g2-6m76Y-6m7aD-dnN9WN-6m7jB-6m749-dz56wz-dzaHgN-

    View Slide

  16. a
    http://andrewschultz.com/wp-content/uploads/2012/10/fun_heart_blue.jpghttps://www.flickr.com/photos/isriya/7180133440/in/photolist-bWu4w9-bWu2FL-bWu41J-bWu34N-bWu3BE-bWu3du-bWu2eu-bWu3PG-bWu4fC-bWu23w-6TqHos-5ZU29M-6m71g-6m7cG-6GPYhV-6m7nP-6m7g2-6m76Y-6m7aD-dnN9WN-6m7jB-6m749-dz56wz-dzaHgN-

    View Slide

  17. Alright, lets code a
    game in …

    View Slide

  18. C++ or C#
    http://andrewschultz.com/wp-content/uploads/2012/10/fun_heart_blue.jpg

    View Slide

  19. Build a game +
    in RUBY
    http://www.weddingchicks.com/wp-content/uploads/2014/04/best-day-ever-entrance-550x366.jpg

    View Slide

  20. GOSU
    • 2D Game Development Library.
    • Originally written in C++ by Julian Raschke and
    Jan Lucker.
    • Official Website: http://www.libgosu.org
    • Official game board: http://www.libgosu.org/cgi-
    bin/mwf/board_show.pl?bid=2

    View Slide

  21. GOSU Showcase

    View Slide

  22. pop-the-balloon /
    carfight

    View Slide

  23. DragonEggs

    View Slide

  24. View Slide

  25. Captain Ruby

    View Slide

  26. Game Development
    Considerations:
    • Story
    • Design (look and feel)
    • Gameplay

    View Slide

  27. Game Development
    Concepts
    GAMELOOP

    View Slide

  28. The only concept..!!!
    INITIALIZE
    DRAW
    UPDATE

    View Slide

  29. Basic Gosu Methods
    • initialize!
    • draw!
    • update

    View Slide

  30. Components of
    DragonEggs
    • Game Window
    • Eggs
    • Baskets
    • Collision + Game logic
    • Asthetics

    View Slide

  31. 1. Game Window
    a.) CONFIG FILE!
    !
    game:!
    x_par: 800!
    y_par: 600!
    gravity: 5!
    !
    eggs:!
    count: 100!
    !
    !
    baskets:!
    count: 500!
    speed: 4!
    !

    View Slide

  32. 1. Game Window
    require 'gosu'!
    require ‘yaml'!
    !
    class Game < Gosu::Window!
    !
    def initialize!
    #load all constants!
    @config = YAML.load_file('config.yml')!
    !
    super @config[‘game']['x_par'],!
    ! ! ! ! @config[‘game']['y_par'],!
    ! ! ! ! false!
    !
    self.caption = 'Drop the damn egg.’!
    end!
    !
    end!

    View Slide

  33. !
    !
    def button_down(id)!
    close if id == Gosu::KbEscape!
    end
    Key Press Events

    View Slide

  34. KEY GOSU EVENT!
    Escape Gosu::KbEscape!
    !
    a/A Gosu::KbA!
    !
    b/B Gosu::KbB!
    !
    c/C Gosu::KbC!

    View Slide

  35. 2. Eggs
    • Initialize
    • Draw
    •Move & Drop a.k.a UPDATE

    View Slide

  36. Egg Initialization
    Egg.new(self, 400, 100)!
    !
    !
    !
    x-coordinate y-coordinate

    View Slide

  37. 0 x-axis 800
    800 y-axis 0!

    View Slide

  38. POSITION: (400, 100)

    View Slide

  39. Egg class
    class Egg!
    !
    attr_accessor :x, :y!
    !
    def initialize(window, x, y)!
    @x = x!
    @y = y!
    @image = Gosu::Image.new(window,!
    ‘bad_egg.png',!
    false)!
    end!
    !
    def draw!
    @image.draw(@x, @y, 1)!
    end!
    end

    View Slide

  40. Multiple Eggs
    #initialize the eggs array!
    @eggs = []!
    !
    !
    #set the starting positions of eggs!
    @config[‘eggs’][‘count'].times do |d|!
    @eggs << Egg.new(self, 400*d + 400, 100)!
    end!
    instance of Game Window

    View Slide

  41. 0 x-axis 800
    800 y-axis 0!

    View Slide

  42. Draw Eggs
    def draw!
    @eggs.each(&:draw)!
    end!

    View Slide

  43. Move Eggs
    def update_next_egg_position(position)!
    !
    #the egg has fallen, so increase fall count by 1!
    @fall_count += 1 !
    !
    #egg should move -400 to be visible at the screen!
    current_egg.x = current_egg.x - (400 * @fall_count)!
    !
    end

    View Slide

  44. Drop Egg
    !
    !
    def update_current_egg(egg)!
    egg.y = egg.y + @config['game']['gravity'] if egg.free_fall!
    !
    #when pressed space, current egg should fall!
    if button_down?(Gosu::KbSpace)!
    egg.free_fall!!
    #to move the curret egg left only when it is not free fall!
    elsif button_down?(Gosu::KbLeft) && !egg.free_fall!
    egg.x = egg.x - 10 if egg.x > 100!
    elsif button_down?(Gosu::KbRight) && !egg.free_fall!
    egg.x = egg.x + 10 if egg.x < 700!
    end!
    end

    View Slide

  45. Baskets
    Same thing really ..!!!!!

    View Slide

  46. Collision
    Gosu::Distance(x1, y1, x2, y2)
    or

    View Slide

  47. Collision
    !
    def egg_into_basket(egg, basket)!
    basket.x <= egg.x &&!
    (egg.x-basket.x).between?(0, 35) &&!
    egg.y <= basket.y &&!
    (basket.y - egg.y).between?(0, 15)!
    end

    View Slide

  48. 0 x-axis 800
    800 y-axis 0!
    x,y = 400,400
    x,y=380, 420

    View Slide

  49. Resources
    • https://github.com/jlnr/gosu/
    !
    • www.libgosu.org/
    !
    • http://github.com/rishijain
    !
    • https://www.youtube.com/watch?v=jJhbpY70miE

    View Slide

  50. THANK YOU!
    !
    @jainrishi15

    View Slide