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. 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
  2. Components of DragonEggs • Game Window • Eggs • Baskets

    • Collision + Game logic • Asthetics
  3. 1. Game Window a.) CONFIG FILE! ! game:! x_par: 800!

    y_par: 600! gravity: 5! ! eggs:! count: 100! ! ! baskets:! count: 500! speed: 4! !
  4. 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!
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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