-
Notifications
You must be signed in to change notification settings - Fork 0
/
spaceship.gd
95 lines (84 loc) · 2.84 KB
/
spaceship.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
88
89
90
91
92
93
94
95
extends KinematicBody2D
class_name player
export(PackedScene) var Bullet
export var verticalspeed : float = 250.0
export var horizontalspeed : float = 400.0
export var isp1 : bool = true
var Velocity : Vector2 = Vector2.ZERO
var direction
func _ready() -> void:
if isp1:
modulate = Color.red
else:
modulate = Color.blue
func _physics_process(delta: float) -> void:
var prefix : String = "p1_" if isp1 else "p2_"
direction = Vector2.ZERO
direction.x = Input.get_action_strength(prefix+"right") - Input.get_action_strength(prefix+"left")
direction.y = Input.get_action_strength(prefix+"down") - Input.get_action_strength(prefix+"up")
direction = direction.normalized()
Velocity = Velocity.move_toward(direction * 1000, 80 if direction != Vector2.ZERO else 20)
Velocity.y = clamp(Velocity.y, -verticalspeed, verticalspeed)
Velocity.x = clamp(Velocity.x, -horizontalspeed, horizontalspeed)
move_and_slide(Velocity, Vector2.UP)
position.x = clamp(position.x, 80, 640)
position.y = clamp(position.y, 512, 720)
func _on_firetime_timeout() -> void:
fire()
pass # Replace with function body.
func set_firerate(new : float):
$firetime.wait_time = new
func get_firerate():
return $firetime.wait_time
var buffness : int = 0
func buff():
set_firerate(get_firerate() * 0.8)
buffness += 1
$buffness.emitting = true
$buffness.amount = buffness
func debuff():
set_firerate(1.0)
buffness = 0
$buffness.emitting = false
func fire():
randomize()
$pew.pitch_scale = rand_range(0.9, 1.1)
$pew.play()
if !canfire:
return
$shotpuff.emitting = true
var projectile : Projectile = Bullet.instance()
projectile.position = position
projectile.velocity = Vector2.UP * 1000
projectile.firer = self
projectile.modulate = (Color.red if isp1 else Color.blue) * 2
$projectiles.add_child(projectile)
func _process(delta: float) -> void:
randomize()
var newpos = position + Vector2(rand_range(-jitteriness, jitteriness), rand_range(-jitteriness, jitteriness)).normalized() * jitteriness
while (newpos.x < 80 || newpos.x > 640 || newpos.y < 512 || newpos.y > 720):
newpos = position + Vector2(rand_range(-jitteriness, jitteriness), rand_range(-jitteriness, jitteriness)).normalized() * jitteriness
position = newpos
jitteriness = lerp(jitteriness, 0.0, delta / 2)
var jitteriness = 0.0
var canfire : bool = true
func _hurt():
$hurted.play()
get_node("../../CanvasLayer3/score").reduce_score(self, 80)
# print("shahwhada")
var newscore : Label = preload('res://scoretext.tscn').instance()
get_node("../../CanvasLayer3").add_child(newscore)
newscore.rect_position = position
newscore.text = "-80"
newscore.modulate = Color.purple
var alang = $bang.duplicate()
add_child(alang)
alang.emitting = true
debuff()
set_physics_process(false)
canfire = false
jitteriness += 5
yield(get_tree().create_timer(1.5),'timeout')
canfire = true
alang.queue_free()
set_physics_process(true)