Class: AGL::Map

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(t_w, t_h, t_x_count, t_y_count, scr_w = 800, scr_h = 600) ⇒ Map

Returns a new instance of Map.



7
8
9
10
11
12
13
# File 'lib/minigl/map.rb', line 7

def initialize t_w, t_h, t_x_count, t_y_count, scr_w = 800, scr_h = 600
	@tile_size = Vector.new t_w, t_h
	@size = Vector.new t_x_count, t_y_count
	@cam = Rectangle.new 0, 0, scr_w, scr_h
	@max_x = t_x_count * t_w - scr_w
	@max_y = t_y_count * t_h - scr_h
end

Instance Attribute Details

#camObject (readonly)

Returns the value of attribute cam.



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

def cam
  @cam
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#tile_sizeObject (readonly)

Returns the value of attribute tile_size.



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

def tile_size
  @tile_size
end

Instance Method Details

#foreachObject



47
48
49
50
51
52
53
# File 'lib/minigl/map.rb', line 47

def foreach
	for j in @min_vis_y..@max_vis_y
		for i in @min_vis_x..@max_vis_x
			yield i, j, i * @tile_size.x - @cam.x, j * @tile_size.y - @cam.y
		end
	end
end

#get_absolute_sizeObject



15
16
17
# File 'lib/minigl/map.rb', line 15

def get_absolute_size
	Vector.new(@tile_size.x * @size.x, @tile_size.y * @size.y)
end

#get_centerObject



19
20
21
# File 'lib/minigl/map.rb', line 19

def get_center
	Vector.new(@tile_size.x * @size.x / 2, @tile_size.y * @size.y / 2)
end

#get_map_pos(scr_x, scr_y) ⇒ Object



27
28
29
# File 'lib/minigl/map.rb', line 27

def get_map_pos scr_x, scr_y
	Vector.new((scr_x + @cam.x) / @tile_size.x, (scr_y + @cam.y) / @tile_size.y)
end

#get_screen_pos(map_x, map_y) ⇒ Object



23
24
25
# File 'lib/minigl/map.rb', line 23

def get_screen_pos map_x, map_y
	Vector.new(map_x * @tile_size.x - @cam.x, map_y * @tile_size.y - @cam.y)
end

#is_in_map(v) ⇒ Object



31
32
33
# File 'lib/minigl/map.rb', line 31

def is_in_map v
	v.x >= 0 && v.y >= 0 && v.x < @size.x && v.y < @size.y
end

#move_camera(x, y) ⇒ Object



41
42
43
44
45
# File 'lib/minigl/map.rb', line 41

def move_camera x, y
	@cam.x += x
	@cam.y += y
	set_bounds
end

#set_camera(cam_x, cam_y) ⇒ Object



35
36
37
38
39
# File 'lib/minigl/map.rb', line 35

def set_camera cam_x, cam_y
	@cam.x = cam_x
	@cam.y = cam_y
	set_bounds
end