2017-07-29 23:10:31 +01:00
|
|
|
extends KinematicBody2D
|
|
|
|
|
2017-08-11 22:50:56 +01:00
|
|
|
var ExplosionEffect = load("res://ExplosionEffect.tscn")
|
|
|
|
|
2017-07-29 23:10:31 +01:00
|
|
|
var rect = Rect2(0, 0, 0, 0)
|
|
|
|
var velocity = Vector2(0, 0)
|
|
|
|
var rot_vel = 0
|
|
|
|
|
|
|
|
var max_vel = 6 # pixels per second?
|
|
|
|
var max_rot_vel = 2.5 # degrees per second
|
2017-08-01 22:28:11 +01:00
|
|
|
var health = 100
|
2017-07-29 23:10:31 +01:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
randomize()
|
2017-07-30 20:57:41 +01:00
|
|
|
velocity.x = floor(rand_range(-max_vel, max_vel))
|
|
|
|
velocity.y = floor(rand_range(-max_vel, max_vel))
|
2017-07-29 23:10:31 +01:00
|
|
|
rect.size.x = floor(rand_range(32, 64))
|
|
|
|
rect.size.y = floor(rand_range(32, 64))
|
2017-07-30 17:30:10 +01:00
|
|
|
rect.pos.x = -rect.size.x / 2
|
|
|
|
rect.pos.y = -rect.size.y / 2
|
2017-07-29 23:10:31 +01:00
|
|
|
rot_vel = deg2rad(floor(rand_range(1, max_rot_vel)))
|
|
|
|
set_fixed_process(true)
|
2017-07-29 23:14:42 +01:00
|
|
|
|
2017-07-30 19:11:15 +01:00
|
|
|
func type():
|
|
|
|
return "Asteroid"
|
|
|
|
|
2017-07-29 23:14:42 +01:00
|
|
|
func wrap(v, v_min, v_max):
|
|
|
|
if v < v_min:
|
|
|
|
return v_max - 1
|
|
|
|
elif v > v_max:
|
|
|
|
return v_min - 1
|
|
|
|
else:
|
|
|
|
return v
|
2017-08-01 22:28:11 +01:00
|
|
|
|
2017-08-11 22:10:43 +01:00
|
|
|
func on_explode():
|
2017-08-11 22:50:56 +01:00
|
|
|
# create bullet impact
|
|
|
|
var new_ee = ExplosionEffect.instance()
|
|
|
|
get_tree().get_root().add_child(new_ee)
|
|
|
|
new_ee.set_global_pos(get_global_pos())
|
2017-08-01 22:28:11 +01:00
|
|
|
queue_free()
|
2017-08-11 22:10:43 +01:00
|
|
|
|
|
|
|
func do_damage(v):
|
|
|
|
health -= v
|
2017-07-29 23:10:31 +01:00
|
|
|
|
|
|
|
func _fixed_process(delta):
|
2017-07-29 23:14:42 +01:00
|
|
|
|
2017-07-30 17:30:10 +01:00
|
|
|
# var cur_pos = get_pos()
|
|
|
|
# cur_pos.x = wrap(cur_pos.x, 1, get_viewport().get_rect().size.x)
|
|
|
|
# cur_pos.y = wrap(cur_pos.y, 1, get_viewport().get_rect().size.y)
|
|
|
|
# set_pos(cur_pos)
|
2017-07-29 23:14:42 +01:00
|
|
|
|
2017-08-01 22:28:11 +01:00
|
|
|
if health <= 0:
|
2017-08-11 22:10:43 +01:00
|
|
|
on_explode()
|
2017-08-01 22:28:11 +01:00
|
|
|
|
2017-07-29 23:10:31 +01:00
|
|
|
self.move(velocity)
|
|
|
|
self.rotate(rot_vel)
|
|
|
|
|
|
|
|
func _draw():
|
2017-07-31 15:49:04 +01:00
|
|
|
pass
|
|
|
|
#draw_rect(rect, Color(1, 1, 1))
|