blob: 407c473c9220bb5751408ba1001fdbad90a99146 (
plain)
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
|
extends RigidBody2D
export var spin_speed = -1
export var move_speed = 300
var start_position
var waiting_for_shoot = true
var power
var power_magnitude = 10
var spin_rotation = 0
var ready_to_shoot
var ready_to_hold
func _ready():
start_position = position
func toggle_mode():
if waiting_for_shoot:
waiting_for_shoot = false
shoot()
else:
global_variables.has_scored = false
waiting_for_shoot = true
set_use_custom_integrator(waiting_for_shoot)
func shoot():
apply_impulse(Vector2(10, 10), Vector2(power))
# Override the default physics when we want to manually set the position and rotation.
func _integrate_forces(state):
if waiting_for_shoot:
state.transform.origin = start_position
state.linear_velocity = Vector2()
state.angular_velocity = 0
# Temporary testing controls
func _process(delta):
if waiting_for_shoot:
$Sprite.rotation += spin_speed * delta
if Input.is_action_pressed("ui_left"):
start_position.x -= move_speed * delta
if Input.is_action_pressed("ui_right"):
start_position.x += move_speed * delta
start_position.x = clamp(start_position.x, 0, 1024)
func _input(event):
if event.is_action_released("shoot"):
if ready_to_shoot or !waiting_for_shoot:
power = (start_position - event.position) * power_magnitude
toggle_mode()
func on_OuterShape_mouse_entered():
ready_to_shoot = true
func _on_OuterShape_mouse_exited():
ready_to_shoot = false
func _on_InnerShape_mouse_entered():
ready_to_hold = true
func _on_InnerShape_mouse_exited():
ready_to_hold = false
|