ld-39-jam/Drawer.gd

39 lines
1.1 KiB
GDScript3
Raw Normal View History

extends Node2D
var entities
var cam_pos = Vector2(0, 0)
func _ready():
pass
2017-07-30 19:11:15 +01:00
func init(ents):
entities = ents
2017-07-30 19:11:15 +01:00
func it_changed():
cam_pos = get_tree().get_root().get_node("Game/Player").get_pos()
update()
func _draw():
var vp_rect = get_viewport().get_rect()
# draw player in center
var p_mw = ((vp_rect.size.x / 2) - 1) + 32
var p_mh = ((vp_rect.size.y / 2) - 1) + 32
draw_rect(Rect2(p_mw, p_mh, 2, 2), Color(0, 1, 0))
2017-08-09 21:54:24 +01:00
for e in entities:
var ent = e.get_ref()
2017-08-09 21:54:24 +01:00
var ent_pos = ent.get_global_pos()
var s_mw = vp_rect.size.x / 2
var s_mh = vp_rect.size.y / 2
var s_x = s_mw + (ent_pos.x / vp_rect.size.x) - (cam_pos.x / vp_rect.size.x) + 32
var s_y = s_mh + (ent_pos.y / vp_rect.size.y) - (cam_pos.y / vp_rect.size.y) + 32
2017-07-30 19:11:15 +01:00
2017-07-30 20:57:41 +01:00
var rect = Rect2(Vector2(48, 48), Vector2(vp_rect.size.x - 32, vp_rect.size.y - 32))
if rect.has_point(Vector2(s_x, s_y)):
if ent.type() == "Asteroid":
draw_rect(Rect2(s_x, s_y, 2, 2), Color(1, 1, 1))
elif ent.type() == "PowerStation":
draw_rect(Rect2(s_x, s_y, 4, 4), Color(0, 0, 1))
elif ent.type() == "EnemyGrunt":
draw_rect(Rect2(s_x, s_y, 2, 2), Color(1, 0, 0))