-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.gd
42 lines (31 loc) · 804 Bytes
/
bullet.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extends KinematicBody2D
var motion
var pos
var tank_class = preload("res://tank.gd")
var hitted = false
const BULLET_SPEED = 200
func _fixed_process(delta):
var angle = get_rot()
if (is_colliding() and ! hitted):
hitted = true
var body = get_collider()
if body extends tank_class:
body.hit()
#queue_free()
var anim = get_node("Sprite/anim")
if !anim.is_playing():
anim.play("hit")
#hax because function of anim does not work
if hitted and ! get_node("Sprite/anim").is_playing():
queue_free()
if !hitted:
motion = BULLET_SPEED * Vector2(-sin(angle),-cos(angle)) * delta
move(motion)
func _ready():
set_fixed_process(true)
func _on_Timer_timeout():
queue_free()
#this function is not working... therefore the hax in line 24
func hit():
print("hit")
queue_free()