hyper space
This commit is contained in:
76
player/player.gd
Normal file
76
player/player.gd
Normal file
@ -0,0 +1,76 @@
|
||||
extends Area2D
|
||||
|
||||
signal died
|
||||
signal shield_changed
|
||||
|
||||
@onready var screensize = get_viewport_rect().size
|
||||
|
||||
@export var speed = 150
|
||||
@export var cooldown = 0.25
|
||||
@export var bullet_scene: PackedScene
|
||||
|
||||
@export var max_shield = 10
|
||||
|
||||
var shield = max_shield:
|
||||
set = set_shield
|
||||
|
||||
var can_shoot = true
|
||||
|
||||
func _ready():
|
||||
start()
|
||||
|
||||
func _process(delta):
|
||||
var input = Input.get_vector("left", "right", "up", "down")
|
||||
if input.x > 0:
|
||||
$Ship.frame = 2
|
||||
$Ship/Boosters.animation = "right"
|
||||
elif input.x < 0:
|
||||
$Ship.frame = 0
|
||||
$Ship/Boosters.animation = "left"
|
||||
else:
|
||||
$Ship.frame = 1
|
||||
$Ship/Boosters.animation = "forward"
|
||||
position += input * speed * delta
|
||||
position = position.clamp(Vector2(8, 8), screensize-Vector2(8, 8))
|
||||
|
||||
if Input.is_action_pressed("shoot"):
|
||||
shoot()
|
||||
|
||||
func start():
|
||||
show()
|
||||
shield = max_shield
|
||||
position = Vector2(screensize.x / 2, screensize.y - 64)
|
||||
$GunCooldown.wait_time = cooldown
|
||||
|
||||
func shoot():
|
||||
if not can_shoot:
|
||||
return
|
||||
can_shoot = false
|
||||
$GunCooldown.start()
|
||||
var b = bullet_scene.instantiate()
|
||||
get_tree().root.add_child(b)
|
||||
b.start(position + Vector2(0, -8))
|
||||
|
||||
func set_shield(value):
|
||||
shield = min(max_shield, value)
|
||||
shield_changed.emit(max_shield, shield)
|
||||
if shield <= 0:
|
||||
hide()
|
||||
died.emit()
|
||||
|
||||
func _on_gun_cooldown_timeout():
|
||||
can_shoot = true
|
||||
|
||||
|
||||
|
||||
func _on_player_area_entered(area):
|
||||
if area.is_in_group("enemies"):
|
||||
area.explode()
|
||||
shield -= max_shield / 2 # Replace with function body.
|
||||
|
||||
|
||||
func _on_area_entered(area):
|
||||
if area.is_in_group("enemies"):
|
||||
area.explode()
|
||||
shield -= max_shield / 2 # Replace with function body.
|
||||
|
95
player/player.tscn
Normal file
95
player/player.tscn
Normal file
@ -0,0 +1,95 @@
|
||||
[gd_scene load_steps=15 format=3 uid="uid://bp5q1dm5nm1q7"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bhigo5rya0wic" path="res://assets/Player ship/Player_ship (16 x 16).png" id="1_jhnuv"]
|
||||
[ext_resource type="Script" path="res://player/player.gd" id="1_s8ptw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bts6qcq761ji2" path="res://bullet/bullet.tscn" id="2_rlc4m"]
|
||||
[ext_resource type="Texture2D" uid="uid://c2v2u7s7r8qsa" path="res://assets/Player ship/Boosters (16 x 16).png" id="3_4r7rv"]
|
||||
[ext_resource type="Texture2D" uid="uid://dlj1rn2xxgyj2" path="res://assets/Player ship/Boosters_left (16 x 16).png" id="4_a5ggp"]
|
||||
[ext_resource type="Texture2D" uid="uid://bha3rynxwdueg" path="res://assets/Player ship/Boosters_right (16 x 16).png" id="5_txrj4"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0v0l2"]
|
||||
atlas = ExtResource("3_4r7rv")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_r8out"]
|
||||
atlas = ExtResource("3_4r7rv")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_vyuqh"]
|
||||
atlas = ExtResource("4_a5ggp")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_aeky0"]
|
||||
atlas = ExtResource("4_a5ggp")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_822yu"]
|
||||
atlas = ExtResource("5_txrj4")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_uauq2"]
|
||||
atlas = ExtResource("5_txrj4")
|
||||
region = Rect2(16, 0, 16, 16)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_dfu82"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_0v0l2")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_r8out")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"forward",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_vyuqh")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_aeky0")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"left",
|
||||
"speed": 12.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_822yu")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_uauq2")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"right",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_t7btk"]
|
||||
radius = 8.0
|
||||
|
||||
[node name="Player" type="Area2D"]
|
||||
script = ExtResource("1_s8ptw")
|
||||
bullet_scene = ExtResource("2_rlc4m")
|
||||
|
||||
[node name="Ship" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("1_jhnuv")
|
||||
hframes = 3
|
||||
frame = 1
|
||||
|
||||
[node name="Boosters" type="AnimatedSprite2D" parent="Ship"]
|
||||
position = Vector2(0, 15)
|
||||
sprite_frames = SubResource("SpriteFrames_dfu82")
|
||||
animation = &"forward"
|
||||
autoplay = "forward"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_t7btk")
|
||||
|
||||
[node name="GunCooldown" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="timeout" from="GunCooldown" to="." method="_on_gun_cooldown_timeout"]
|
Reference in New Issue
Block a user