forked from tralezab/probable-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathone_shot_johnny.gd
87 lines (76 loc) · 2.44 KB
/
one_shot_johnny.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
extends RigidBody2D
export var current = false
const SPEED = 200
const MAX_HEALTH = 1
var health = 1
const ATTACK_COOLDOWN = 50
var attack_timer = 0
var attack_damage = 999
onready var attacksprite = $Attack
onready var attackarea = $Attack_Area
onready var destination = get_parent().get_node("Destination")
var healthhud = null
var healthbar = null
# Called when the node enters the scene tree for the first time.
func _ready():
rotation = deg2rad(rand_range(-180,180))
mode = RigidBody2D.MODE_STATIC
func setup_vars():
healthhud = get_parent().get_node("bar")
healthbar = get_parent().get_node("bar").get_node("health")
healthhud.global_position = global_position - Vector2(0, -40)
healthbar.modulate = Color(0,1,0,1)
if current:
$Camera2D._set_current(true)
func _physics_process(delta):
attack_timer -= 1
if !current:
return
var direction_to = destination.global_position - global_position
if destination.visible != false:
rotation = direction_to.angle()
if abs(rad2deg(rotation)) > 90:
$Sprite.flip_v = true
else:
$Sprite.flip_v = false
##REMINDER: SET THE SHRIMP TO SLOWLY LOSE MOMENTUM FOR COLLISIONS
mode = RigidBody2D.MODE_RIGID
else:
mode = RigidBody2D.MODE_STATIC
if direction_to.length() < 10:
linear_velocity = Vector2.ZERO
destination.global_position = global_position
destination.visible = false
pass
else:
linear_velocity = direction_to.clamped(SPEED) * SPEED * delta
healthhud.global_position = global_position - Vector2(0, -40)
func _process(_delta):
if !current:
return
if Input.is_action_pressed("rightclick"):
destination.global_position = get_global_mouse_position()
destination.visible = true
if Input.is_action_just_pressed("leftclick") and attack_timer <= 0:
attack_move()
func attack_move():
attack_timer = ATTACK_COOLDOWN
attacksprite.visible = true
var attacked = attackarea.get_overlapping_bodies()
for shramp in attacked:
if shramp == attackarea.get_parent():
continue
if shramp is RigidBody2D:
shramp.health -= attack_damage
var percentage = float(shramp.health)/float(shramp.MAX_HEALTH)
shramp.healthbar.modulate = Color(1 - percentage,percentage,0,1)
if shramp.health <= 0:
shramp.get_parent().spawn_shrimp()
shramp.queue_free()
#shramp.healthhud.modulate = Color(0,0,0,0)
yield(get_tree().create_timer(0.5), "timeout")
attacksprite.visible = false
func set_current(boo):
current = boo
func set_player_name(new_name):
get_node("label").set_text(new_name)