Class: AGL::GameObject

Inherits:
Sprite
  • Object
show all
Includes:
Movement
Defined in:
lib/minigl/game_object.rb

Instance Attribute Summary

Attributes included from Movement

#bottom, #h, #left, #passable, #right, #speed, #stored_forces, #top, #w, #x, #y

Attributes inherited from Sprite

#img_index, #x, #y

Instance Method Summary collapse

Methods included from Movement

#bounds, #check_contact, #cycle, #find_down_limit, #find_left_limit, #find_right_limit, #find_up_limit, #move, #move_carrying, #move_free

Methods inherited from Sprite

#animate

Constructor Details

#initialize(x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil) ⇒ GameObject

Returns a new instance of GameObject.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/minigl/game_object.rb', line 50

def initialize x, y, w, h, img, img_gap = nil, sprite_cols = nil, sprite_rows = nil
  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
  @speed = Vector.new 0, 0
  @min_speed = Vector.new 0.01, 0.01
  @max_speed = Vector.new 15, 15
  @stored_forces = Vector.new 0, 0
end

Instance Method Details

#draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/minigl/game_object.rb', line 76

def draw map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil
  color = (alpha << 24) | color
  if map
    if angle
      @img[@img_index].draw_rot @x.round + @img_gap.x - map.cam.x,
                                @y.round + @img_gap.y - map.cam.y,
                                0, angle, 0.5, 0.5, scale_x, scale_y, color
    else
      @img[@img_index].draw @x.round + @img_gap.x - map.cam.x, @y.round + @img_gap.y - map.cam.y, 0, scale_x, scale_y, color
    end
  elsif angle
    @img[@img_index].draw_rot @x.round + @img_gap.x, @y.round + @img_gap.y, 0, angle, 0.5, 0.5, scale_x, scale_y, color
  else
    @img[@img_index].draw @x.round + @img_gap.x, @y.round + @img_gap.y, 0, scale_x, scale_y, color
  end
end

#is_visible(map) ⇒ Object



71
72
73
74
# File 'lib/minigl/game_object.rb', line 71

def is_visible map
  return map.cam.intersects @active_bounds if @active_bounds
  false
end

#set_animation(index) ⇒ Object



65
66
67
68
69
# File 'lib/minigl/game_object.rb', line 65

def set_animation index
  @anim_counter = 0
  @img_index = index
  @index_index = 0
end