class MiniGL::GameObject

box, and having all the attributes required for using the Movement module.
commonly used in games. It defines an object with a rectangular bounding
This class represents an object with a set of properties and methods

def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0)

will be drawn on top of the ones with smaller z-orders.
[z_index] The z-order to draw the object. Objects with larger z-orders
to draw it vertically flipped.
[flip] Specify +:horiz+ to draw the image horizontally flipped or +:vert+
its center.
[angle] A rotation, in degrees, to be applied to the image, relative to
will be darkened, for example.
reddish colors with slight or no change, whereas bluish colors
will turn all colors to black. A red (0xff0000) filter will keep
will keep all colors unchanged, while a black (0x000000) filter
[color] A color filter to apply to the image. A white (0xffffff) filter
vary from 0 (fully transparent) to 255 (fully opaque).
[alpha] The opacity with which the image will be drawn. Valid values
[scale_y] A scale factor to be applied vertically to the image.
[scale_x] A scale factor to be applied horizontally to the image.
position of the camera).
and y coordinates of the image will be changed according to the
[map] A Map object, relative to which the object will be drawn (the x
Parameters:

Draws the game object in the screen.
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0)
  color = (alpha << 24) | color
  if angle
    @img[@img_index].draw_rot @x.round + (flip == :horiz ? -1 : 1) * @img_gap.x - (map ? map.cam.x : 0) + (flip == :horiz ? scale_x * @w : 0),
                              @y.round + (flip == :vert ? -1 : 1) * @img_gap.y - (map ? map.cam.y : 0) + (flip == :vert ? scale_y * @h : 0),
                              z_index, angle, 0.5, 0.5, (flip == :horiz ? -scale_x : scale_x),
                              (flip == :vert ? -scale_y : scale_y), color
  else
    @img[@img_index].draw @x.round + (flip == :horiz ? -1 : 1) * @img_gap.x - (map ? map.cam.x : 0) + (flip == :horiz ? scale_x * @w : 0),
                          @y.round + (flip == :vert ? -1 : 1) * @img_gap.y - (map ? map.cam.y : 0) + (flip == :vert ? scale_y * @h : 0),
                          z_index, (flip == :horiz ? -scale_x : scale_x),
                          (flip == :vert ? -scale_y : scale_y), color
  end
end

def initialize(x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil, mass = 1.0)

in the Movement module.
[mass] The mass of the object. Details on how it is used can be found
image is not a spritesheet.
[sprite_rows] The number of rows in the spritesheet. Use +nil+ if the
image is not a spritesheet.
[sprite_cols] The number of columns in the spritesheet. Use +nil+ if the
will be drawn at position (95, 45) of the screen.
y = 50 and img_gap = Vector.new(-5, -5)
image. For example, an object with x = 100,
left corner of the bounding box and the coordinates of the
[img_gap] A Vector object representing the difference between the top
[img] The image or spritesheet for the object.
[h] The height of the object's bounding box.
[w] The width of the object's bounding box.
later via the +y+ attribute.
[y] The y-coordinate of the object's bounding box. This can be modified
later via the +x+ attribute.
[x] The x-coordinate of the object's bounding box. This can be modified
Parameters:

Creates a new game object.
def initialize(x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil, mass = 1.0)
  super x, y, img, sprite_cols, sprite_rows
  @w = w; @h = h
  @img_gap =
    if img_gap.nil?
      Vector.new 0, 0
    else
      img_gap
    end
  @mass = mass
  @speed = Vector.new 0, 0
  @max_speed = Vector.new 15, 15
  @stored_forces = Vector.new 0, 0
end

def set_animation(index)

[index] The image index to be set.
Parameters:

the specified value.
Resets the animation timer and immediately changes the image index to
def set_animation(index)
  @anim_counter = 0
  @img_index = index
  @index_index = 0
end

def visible?(map = nil)

returns whether the object is visible on the screen.
viewport determined by the camera of the given map). If no map is given,
Returns whether this object is visible in the given map (i.e., in the
def visible?(map = nil)
  r = Rectangle.new @x.round + @img_gap.x, @y.round + @img_gap.y, @img[0].width, @img[0].height
  return Rectangle.new(0, 0, G.window.width, G.window.height).intersect? r if map.nil?
  map.cam.intersect? r
end