Sha256: 2ddf5e4d0b00415a9334350c163795c4b0cc81952ab1c62201d96471ac15c56e

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

module CyberarmEngine
  module Common
    def push_state(klass, options={})
      $window.push_state(klass, options)
    end

    def current_state
      $window.current_state
    end

    def previous_state
      $window.previous_state
    end

    def pop_state
      $window.pop_state
    end

    def show_cursor
      $window.show_cursor
    end

    def show_cursor=boolean
      $window.show_cursor = boolean
    end

    def draw_rect(x, y, width, height, color, z = 0)
      $window.draw_rect(x,y,width,height,color,z)
    end

    def fill(color, z = 0)
      draw_rect(0, 0, $window.width, $window.height, color, z)
    end

    def lighten(color, amount = 25)
      if defined?(color.alpha)
        return Gosu::Color.rgba(color.red+amount, color.green+amount, color.blue+amount, color.alpha)
      else
        return Gosu::Color.rgb(color.red+amount, color.green+amount, color.blue+amount)
      end
    end

    def darken(color, amount = 25)
      if defined?(color.alpha)
        return Gosu::Color.rgba(color.red-amount, color.green-amount, color.blue-amount, color.alpha)
      else
        return Gosu::Color.rgb(color.red-amount, color.green-amount, color.blue-amount)
      end
    end

    def get_asset(path, hash, klass)
      asset = nil
      hash.detect do |_asset, instance|
        if _asset == path
          asset = instance
          true
        end
      end

      unless asset
        instance = klass.new(path)
        hash[path] = instance
        asset = instance
      end

      return asset
    end

    def get_image(path)
      get_asset(path, Engine::IMAGES, Gosu::Image)
    end

    def get_sample(path)
      get_asset(path, Engine::SAMPLES, Gosu::Sample)
    end

    def get_song(path)
      get_asset(path, Engine::SONGS, Gosu::Song)
    end

    def window
      $window
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cyberarm_engine-0.3.0 lib/cyberarm_engine/common.rb
cyberarm_engine-0.2.0 lib/cyberarm_engine/common.rb
cyberarm_engine-0.1.0 lib/cyberarm_engine/common.rb