This repository has been archived by the owner on Oct 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.gd
64 lines (55 loc) · 1.95 KB
/
Player.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
extends Node2D
var Bullet = preload("res://Bullet.tscn")
export var PLAYER = 0
var CONTROLLER = 0
export (String, MULTILINE) var TEXT = ""
export (Color) var COLOR
var shoot_timer = 0
var score = 0
var alive = true
func _enter_tree():
$sprite.position.y = 200
$sprite.position.x = 60+PLAYER*100
$score.margin_left = PLAYER*100
$sprite/title.set_text(TEXT)
$sprite.modulate = COLOR
$sprite/title.modulate = COLOR
$score.modulate = COLOR
func _process(delta):
if not (Input.is_joy_button_pressed(CONTROLLER, 0) or Input.is_key_pressed(KEY_SPACE)):
shoot_timer += delta
var s = "%02d" % score
$score.text = s
$sprite/title.visible = Globals.show_title
if alive:
visible = true
if Input.get_joy_axis(CONTROLLER,0) < -0.1:
$sprite.position.x += delta * 100 * Input.get_joy_axis(CONTROLLER,0)
if Input.get_joy_axis(CONTROLLER,0) > 0.1:
$sprite.position.x += delta * 100 * Input.get_joy_axis(CONTROLLER,0)
if (Input.is_joy_button_pressed(CONTROLLER, 0) or Input.is_key_pressed(KEY_SPACE)) and shoot_timer>0.01 and $bullets.get_child_count()< min(4,(Globals.get_level()/4 + 1)):
$fire.play()
var bullet = Bullet.instance()
bullet.position = $sprite.position
bullet.position.y -= 20
bullet.modulate = COLOR
bullet.player = PLAYER
$bullets.add_child(bullet)
shoot_timer=0
if Input.is_key_pressed(KEY_LEFT) or Input.is_joy_button_pressed(CONTROLLER, JOY_DPAD_LEFT):
$sprite.position.x -= delta * 100
elif Input.is_key_pressed(KEY_RIGHT) or Input.is_joy_button_pressed(CONTROLLER, JOY_DPAD_RIGHT):
$sprite.position.x += delta * 100
else:
visible = false
if (Input.is_joy_button_pressed(CONTROLLER, 0) or Input.is_key_pressed(KEY_SPACE)): # and shoot_timer>1 and $bullets.get_child_count()<3:
$spawn.play()
alive = true
score = 0
$sprite.position.x = clamp($sprite.position.x, 10, 410)
func _on_sprite_area_entered(area):
if score > 1 and alive:
alive = false
$sprite.position.x = 60+PLAYER*100
score = 0
$die.play()