Class: AGL::Sprite

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

Direct Known Subclasses

Effect, GameObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, img, sprite_cols = nil, sprite_rows = nil) ⇒ Sprite

Returns a new instance of Sprite.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/minigl/game_object.rb', line 8

def initialize x, y, img, sprite_cols = nil, sprite_rows = nil
	@x = x; @y = y
	@img =
		if sprite_cols.nil?
			[Res.img(img)]
		else
			Res.imgs img, sprite_cols, sprite_rows
		end
	@anim_counter = 0
	@img_index = 0
	@index_index = 0
end

Instance Attribute Details

#img_indexObject (readonly)

Returns the value of attribute img_index.



5
6
7
# File 'lib/minigl/game_object.rb', line 5

def img_index
  @img_index
end

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/minigl/game_object.rb', line 6

def x
  @x
end

#yObject

Returns the value of attribute y.



6
7
8
# File 'lib/minigl/game_object.rb', line 6

def y
  @y
end

Instance Method Details

#animate(indices, interval) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/minigl/game_object.rb', line 21

def animate indices, interval
	@anim_counter += 1
	if @anim_counter >= interval
		@index_index += 1
		@index_index = 0 if @index_index == indices.length
		@img_index = indices[@index_index]
		@anim_counter = 0
	end
end

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/minigl/game_object.rb', line 31

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 - map.cam.x, @y.round - map.cam.y, 0, angle, 0.5, 0.5, scale_x, scale_y, color
		else
			@img[@img_index].draw @x.round - map.cam.x, @y.round - map.cam.y, 0, scale_x, scale_y, color
		end
	elsif angle
		@img[@img_index].draw_rot @x.round, @y.round, 0, angle, 0.5, 0.5, scale_x, scale_y, color
	else
		@img[@img_index].draw @x.round, @y.round, 0, scale_x, scale_y, color
	end
end