chingu_vectors

Enables you to place and move your game objects via vectors. Also speed and hastening are not declared as pixels per frame but in pixels per second.

Get it

You know how you get it:

gem install chingu_vectors

Use it

After

require "chingu_vectors"

The trait :vectors is available:

class Player < Chingu::GameObject

    trait :vectors

    #This method will make the player move 20 pixes left per second
    def move_left
        self.speed = [0,-20]
    end

end

Another example

This would be a method that lets a ball follow another ball (“follow”) nice and smoothly. See example b for how it looks

def update
  radii = size + follow.size
  link = (follow.position - position)
  if link.length < radii
    self.speed = Vector::ZERO
  else
    link = link - link.normalize * radii # Connection between edges
    self.speed = link * Game.speed
  end
end

Changelog

1.1.1
  • Applies on default

  • Fixed eql? and hash for Vector

1.1.0
  • Fixed a problem where vectors would prevent other traits from executing update_trait

1.0.2
  • Fixed problem with gemspec

  • Fixed Example a

1.0.0
  • Vector no longer inherits from Array

  • Vector is constructable via []

  • Added debug mode

  • Added example for debug mode

  • General trimming of code

  • Improved documentation by using YARD tags

  • As indicated by version number not longer compatible with older versions 0.0.x