Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Chingu, a gosu framework!

Hi, i'm going to present you the work of Ippa (http://github.com/ippa ) who created a nice framework to ease your life with gosu, called chingu:

here is the project page: http://github.com/ippa/chingu

and the documentation page: http://rdoc.info/projects/ippa/chingu , where everything is explained in details.

I'm using it quite a lot now, since i'm playing with Gosu now.. :) and I suggest that everyone else does!

The guy also created a website+API, to store highscores online made with gosu / chingu, ( with in mind a future feature for an achievement system ) ( www.gamercv.com )

Anyway use it, and enjoy it ! :shades:
 

arev

Sponsor

Well, although it does present some benefits I'm quite used to the bare Gosu for now. Maybe I'll try Chingu in the next project, but for now I'll stick with what I've done already (saying it's a framework would be too much, but it's more convenient that Gosu is at startup).

\m/ Gosu Power \m/
 
Here's an example on Chingu on how to change from one GameState ("Scene") to another one. You can go forward or backward as needed.

The image I included as a character bitmap was a modified PNG file, Actors1.png, that only included Ralph...

Edit...

For an updated version you might visit my topic named Chingu On Action...

[rgss]#!/usr/bin/env ruby
# by Kyonides
# tools :  Chingu, Gosu & Ruby on a Linux OS
# Title Picture taken from  http://www.thoe.net/img/
# Game Over Picture taken from http://www.lpi.usra.edu/education/timel ... ry/images/
require 'rubygems'
require 'chingu'
require 'modules'
require 'player_attr'
include Gosu, Chingu, KyoVocab
class Chingu::Window < Gosu::Window
    alias kyon_chwin_init initialize
  def initialize(width=800, height=600, fullscreen=false, update_interval=16.666666)
    KyoVocab.window = super(width, height, fullscreen, update_interval)
        kyon_chwin_init(width, height, fullscreen, update_interval)
  end
end
 
class Chingu::Text
    def create_image
        @max_width=KyoVocab.window.width if @max_width == nil
        @image = Gosu::Image.from_text(KyoVocab.window, @text, @font, @height,
          @line_spacing=8, @max_width, @align)
    end
end
 
class Kyon < Chingu::Window
    attr_reader :factor
    def initialize
        super(640,480,false)
        self.caption = 'KyoGame'
    @factor = 2
    switch_game_state(Title)
    end
end
 
class Title < Chingu::GameState
    def setup
        super
        self.input = {:escape => :exit, :enter => :new_scene}
        @title  = Image['images/nightsky640.png']
        welcome = 'Welcome to Game'
        @text   = Text.new(welcome, :x=>0, :y=>50, :zorder=>55, :size=>28, :align=>:center)
    end
   
    def draw
        @title.draw(0, 0, 0)
        @text.draw
        super
    end
   
    def new_scene
        switch_game_state(Scene)
    end
end
 
class Scene < Chingu::GameState
  has_trait :debug => true
  def setup
    super
    self.input = {:escape => :exit,
                  :enter => :new_scene,
                  :backspace => :title,
                  :f1 => :debug}
    @night = Image['images/nightsky640.png']
    msg = "The Scene\ninsert the code in some\nChingu::GameState class like this one"
    @text = Text.new(msg, :x => 0, :y => 50, :align => :center,
                     :zorder => 55, :size => 30, :max_width => 250)
    @hp = Text.new('HP', :x => 10, :y => 437, :zorder => 200, :size => 20,
                   :align => :left, :max_width => 100)
    @mp = Text.new('MP', :x => 10, :y => 455, :zorder => 200, :size => 20,
                   :align => :left, :max_width => 100)
    @bg0, @bg1, @bg2 = Color.new(0xFF000000), Color.new(0xFFCE28FF), Color.new(0xFF013E87)
    @rect = Rect[5,434,160,41]
    @hp_rect = [40,KyoVocab.window.height-40,100,10]
    @mp_rect = [40,KyoVocab.window.height-20,100,10]
    @player = Hero.create#(Image['ralph.png']) # the parent class includes an image filename
    # but this allows the scripter to test if the parameters are passed correctly
  end
 
  def draw
    @night.draw(0, 0, 0)
    @text.draw
    @hp.draw
    @mp.draw
    fill_gradient:)rect => @rect, :eek:rientation => :horizontal, :zorder => 150)
    fill_gradient:)from => @bg1, :to => @bg2, :rect => @hp_rect, :eek:rientation => :horizontal,
                  :zorder => 150)
    fill_gradient:)from => @bg2, :to => @bg1, :rect => @mp_rect, :eek:rientation => :horizontal,
                  :zorder => 150)
    super
  end
 
  def update
    super
    KyoVocab.window.caption = "City Battle! Player x/y: #{@player.x}/#{@player.y}"
  end
   
    def new_scene
        push_game_state(GameOver)
    end
 
  def title
    switch_game_state(Title)
  end
 
#   def debug # ignore it, it doesn't work
#     push_game_state(GameState::Debug)
#   end
end
 
class GameOver < Chingu::GameState  
    def setup
        super
        self.input = {:escape => :exit, :return => :retry, :enter => :new_scene}
        @over = Image['images/desert.png']
        @gameover = Text.new('GAME OVER', :x=>0, :y=>50, :align=>:center, :zorder=>55, :size=>36)
        @gameover.color = 0xFF000000
        @tryagain = Text.new('Press Return to try again', :x => 0, :y => 250,
                             :align => :center, :zorder => 55, :size => 36)
    end
   
    def draw
        @over.draw(0, 0, 0)
        @gameover.draw
        @tryagain.draw
        super
    end
   
    def retry
        pop_game_state
    end
   
    def new_scene
        KyoVocab.window.close
    end
end
 
class Hero < Game::Hero
  has_traits :velocity
  attr_accessor :x, :y
    def initialize(image=nil, options={})
    super(image=nil, options)
    self.factor = KyoVocab.window.factor/1.5
    if options == {}
      @x, @y = 300, 200
    else
      @x, @y = options[:x], options[:y]
      @hp, @mp, @ap = options[:hp], options[:mp], options[:ap]
    end
        self.input = {
      :holding_left => :left,
      :holding_right => :right,
      :holding_up => :up,
      :holding_down => :down}
        @max_velocity = 2
    end
 
  def up;    self.velocity_y = -@max_velocity; end
       
  def down;  self.velocity_y = @max_velocity;  end
 
  def right; self.velocity_x = @max_velocity;  end
 
  def left;  self.velocity_x = -@max_velocity; end
 
  def update
    super
    self.velocity_y *= 0.6
    self.velocity_x *= 0.6
    @x = @last_x  if @x < 0 || @x > KyoVocab.window.width
    @y = @last_y  if @y < 0 || @y > KyoVocab.window.height
    @last_x, @last_y = @x, @y
    @image.draw(@x, @y, 0)
  end
end
Kyon.new.show # Should be the last line in the main script
[/rgss]
 

ippa

Member

Thanks for the push trebor777!

Chingu is in a very expansive period now, a lot of stuff has happened in the last months. Currently there's a lot of polishing going on and some heavy work being done optimizing collision detection.

I'm also very open for feedback, suggestions and patches. Patches needs to serve a general purpose, align with basic ideas of chingu and (of course) be documented.

If anyone have questions about Chingu I usually hang out on #gosu @ Freenode irc network. You could also msg me on github.com/ippa .. I recommend looking through some of the 16 examples if you're very new too Chingu, they show off the correct way of using a lot of what Chingu has to offer.
 
Thanks for coming, ippa.

Well, I already posted a link to download my first demo, but you would consider it an alpha release he he he.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top