first Prototype

This commit is contained in:
Exobyt 2025-08-02 12:27:49 +02:00
parent 89503407e7
commit c887a2168c
78 changed files with 2494 additions and 2 deletions

View file

@ -0,0 +1,22 @@
class_name Enemy extends "res://scenes/spaceShip/spaceShip.gd"
@onready var visionAreaStop: VisionArea = $VisionAreas/VisionAreaStop
@onready var raycast: RayCast2D = $RayCast2D
func _physics_process(delta: float) -> void:
if Globals.getPlayer() != null:
look_at(Globals.getPlayer().global_position)
var direction = Vector2.RIGHT.rotated(rotation)
rotation += PI / 2
if not visionAreaStop.has_overlapping_bodies():
velocity = velocity.lerp(direction * speed, acceleration * delta)
else:
if not raycast.is_colliding():
attack()
velocity = velocity.lerp(Vector2.ZERO, acceleration * delta)
move_and_slide()
func _on_hurt_area_hurt(amount: int) -> void:
damage(amount)

View file

@ -0,0 +1 @@
uid://djlqf2g8ho05r

View file

@ -0,0 +1,46 @@
[gd_scene load_steps=8 format=3 uid="uid://bodpgjdjhfn4w"]
[ext_resource type="PackedScene" uid="uid://csacin2gx2tum" path="res://scenes/spaceShip/spaceShip.tscn" id="1_5w6ng"]
[ext_resource type="Script" uid="uid://djlqf2g8ho05r" path="res://scenes/spaceShip/enemy/enemy.gd" id="2_2erf0"]
[ext_resource type="Texture2D" uid="uid://cfwyw1sr6x2np" path="res://icon.svg" id="2_u13ds"]
[ext_resource type="PackedScene" uid="uid://k5fr6bfn6kkd" path="res://scenes/spaceShip/enemy/visionArea/visionArea.tscn" id="4_hybmu"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2erf0"]
size = Vector2(112, 112)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_u13ds"]
size = Vector2(112, 112)
[sub_resource type="CircleShape2D" id="CircleShape2D_hybmu"]
radius = 448.071
[node name="Enemy" groups=["enemy"] instance=ExtResource("1_5w6ng")]
modulate = Color(1, 0, 1, 1)
collision_layer = 36
collision_mask = 35
script = ExtResource("2_2erf0")
speed = 700
[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("RectangleShape2D_2erf0")
[node name="CollisionShape2D" parent="hurtArea" index="0"]
shape = SubResource("RectangleShape2D_u13ds")
[node name="Sprite2D" parent="." index="2"]
texture = ExtResource("2_u13ds")
[node name="VisionAreas" type="Node2D" parent="." index="5"]
[node name="VisionAreaStop" parent="VisionAreas" index="0" instance=ExtResource("4_hybmu")]
[node name="CollisionShape2D" parent="VisionAreas/VisionAreaStop" index="0"]
shape = SubResource("CircleShape2D_hybmu")
[node name="RayCast2D" type="RayCast2D" parent="." index="6"]
target_position = Vector2(0, -448)
[connection signal="hurt" from="hurtArea" to="." method="_on_hurt_area_hurt"]
[editable path="hurtArea"]
[editable path="VisionAreas/VisionAreaStop"]

View file

@ -0,0 +1,10 @@
[gd_scene load_steps=2 format=3 uid="uid://k5fr6bfn6kkd"]
[ext_resource type="Script" uid="uid://cuaw6yqjnk70w" path="res://scenes/spaceShip/enemy/visionArea/vision_area.gd" id="1_4ovtj"]
[node name="VisionArea" type="Area2D"]
collision_layer = 64
collision_mask = 8
script = ExtResource("1_4ovtj")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View file

@ -0,0 +1 @@
class_name VisionArea extends Area2D

View file

@ -0,0 +1 @@
uid://cuaw6yqjnk70w

View file

@ -0,0 +1,42 @@
class_name Player extends "res://scenes/spaceShip/spaceShip.gd"
@onready var dashCooldown = $dashCooldown
@onready var spawnPointPool = $spawnPointPool
@export var spawnDistance: int = 1000
func _ready() -> void:
randomize()
func _init() -> void:
pass
func _physics_process(delta: float) -> void:
if Input.is_action_pressed("attack"):
attack()
look_at(get_global_mouse_position())
rotation += PI / 2
var direction = Input.get_vector("moveLeft", "moveRight", "moveForward", "moveBackward").normalized().rotated(rotation)
if Input.is_action_just_pressed("dash") and dashCooldown.is_stopped():
dash()
velocity = velocity.lerp(direction * speed, acceleration * delta)
move_and_slide()
if timeGhost != null:
moveTimeGhost(global_position, rotation)
func _on_hurt_area_hurt(amount: int) -> void:
damage(amount)
func dash():
dashCooldown.start()
global_position += Vector2.UP.rotated(rotation) * 1000
func getRandomSpawnPointPosition() -> Vector2:
var rng = RandomNumberGenerator.new()
print(deg_to_rad(rng.randi_range(0, 360)))
print(Vector2.UP.rotated(deg_to_rad(rng.randi_range(0, 360))) * spawnDistance)
return global_position + Vector2.UP.rotated(deg_to_rad(rng.randi_range(0, 360))) * spawnDistance
#return spawnPointPool.get_children()[rng.randi_range(0, spawnPointPool.get_children().size()-1)].global_position

View file

@ -0,0 +1 @@
uid://0i8gdbb8f6ic

View file

@ -0,0 +1,53 @@
[gd_scene load_steps=6 format=3 uid="uid://bmc2exqutt6vu"]
[ext_resource type="PackedScene" uid="uid://csacin2gx2tum" path="res://scenes/spaceShip/spaceShip.tscn" id="1_nnn47"]
[ext_resource type="Script" uid="uid://0i8gdbb8f6ic" path="res://scenes/spaceShip/player/player.gd" id="2_acneu"]
[ext_resource type="Texture2D" uid="uid://cfwyw1sr6x2np" path="res://icon.svg" id="3_0gv45"]
[sub_resource type="CircleShape2D" id="CircleShape2D_0gv45"]
radius = 56.5685
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0gv45"]
size = Vector2(112, 112)
[node name="Player" groups=["player"] instance=ExtResource("1_nnn47")]
collision_layer = 12
collision_mask = 3
motion_mode = 1
script = ExtResource("2_acneu")
spawnDistance = 1000
[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("CircleShape2D_0gv45")
[node name="CollisionShape2D" parent="hurtArea" index="0"]
shape = SubResource("RectangleShape2D_0gv45")
[node name="Sprite2D" parent="." index="2"]
texture = ExtResource("3_0gv45")
[node name="dashCooldown" type="Timer" parent="." index="5"]
wait_time = 10.0
one_shot = true
autostart = true
[node name="Camera2D" type="Camera2D" parent="." index="6"]
[node name="spawnPointPool" type="Node2D" parent="." index="7"]
[node name="spawnPoint" type="Marker2D" parent="spawnPointPool" index="0"]
position = Vector2(360, -176)
[node name="spawnPoint2" type="Marker2D" parent="spawnPointPool" index="1"]
position = Vector2(392, 256)
[node name="spawnPoint3" type="Marker2D" parent="spawnPointPool" index="2"]
position = Vector2(-416, 224)
[node name="spawnPoint4" type="Marker2D" parent="spawnPointPool" index="3"]
position = Vector2(-408, -168)
[connection signal="hurt" from="hurtArea" to="." method="_on_hurt_area_hurt"]
[connection signal="timeout" from="dashCooldown" to="." method="_on_dash_cooldown_timeout"]
[editable path="hurtArea"]

View file

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=3 uid="uid://ih6mpdh1paql"]
[sub_resource type="CircleShape2D" id="CircleShape2D_oytj4"]
radius = 64.0
[node name="SpawnPoint" type="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_oytj4")

View file

@ -0,0 +1,95 @@
class_name Spaceship extends CharacterBody2D
@onready var hurtArea = $hurtArea
@onready var sprite = $Sprite2D
@onready var weaponNode = $weaponNode
@onready var invincibleTimer = $invincibleTimer
@export var minHealth: int = 0
@export var maxHealth: int = 100
@export var health: int = maxHealth
@export var speed: int = 800
@export var acceleration: float = 0.8
@export var pushback: int = 500
@export var timeGhost: TimeGhost = null
@export var weapon: Weapon = null
@export var invincible: bool = false
signal destroyed
func _ready() -> void:
invincibleTimer.wait_time = Globals.currentDelay * 3
func damage(amount: int):
if not invincible:
if health - amount <= minHealth:
if timeGhost == null:
emit_signal("destroyed")
destroy()
health = minHealth
shortInvincibility()
else:
health -= amount
func heal(amount: int):
if health + amount >= maxHealth:
health = maxHealth
else:
health += amount
func destroy():
if timeGhost == null:
queue_free()
else:
timeGhost.destroy()
func attack():
if weapon != null:
weapon.attack()
await get_tree().create_timer(Globals.currentDelay).timeout
if timeGhost != null:
timeGhost.attack()
func moveTimeGhost(_position: Vector2, _rotation: float):
await get_tree().create_timer(Globals.currentDelay).timeout
if timeGhost != null:
timeGhost.global_position = _position
timeGhost.rotation = _rotation
timeGhost.moveTimeGhost(_position, _rotation)
func changeWeapon(_weapon: PackedScene):
var newWeapon = _weapon.instantiate()
for i in weaponNode.get_children():
i.queue_free()
weaponNode.add_child(newWeapon)
weapon = newWeapon
await get_tree().create_timer(Globals.currentDelay).timeout
if timeGhost != null:
timeGhost.changeWeapon(_weapon)
func addTimeGhost(_timeGhost: TimeGhost):
if timeGhost == null:
timeGhost = _timeGhost
timeGhost.setSpaceship(self)
else:
timeGhost.addTimeGhost(_timeGhost)
func shortInvincibility():
if invincibleTimer.is_stopped():
invincible = true
invincibleTimer.start()
func _on_invincible_timer_timeout() -> void:
invincible = false
func _on_hurt_area_area_entered(area: Area2D) -> void:
if area.get_parent().is_in_group("obstacle"):
velocity = Vector2.UP.rotated(rotation) * -pushback
area.get_parent().queue_free()

View file

@ -0,0 +1 @@
uid://quxft75411y7

View file

@ -0,0 +1,23 @@
[gd_scene load_steps=3 format=3 uid="uid://csacin2gx2tum"]
[ext_resource type="Script" uid="uid://quxft75411y7" path="res://scenes/spaceShip/spaceShip.gd" id="1_a2e5l"]
[ext_resource type="PackedScene" uid="uid://cglnd1ekr5u6r" path="res://scenes/areas/hurtArea/hurtArea.tscn" id="2_b8guf"]
[node name="Spaceship" type="CharacterBody2D" groups=["spaceShip"]]
collision_layer = 4
script = ExtResource("1_a2e5l")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="hurtArea" parent="." instance=ExtResource("2_b8guf")]
[node name="Sprite2D" type="Sprite2D" parent="."]
[node name="weaponNode" type="Node2D" parent="."]
[node name="invincibleTimer" type="Timer" parent="."]
one_shot = true
autostart = true
[connection signal="area_entered" from="hurtArea" to="." method="_on_hurt_area_area_entered"]
[connection signal="timeout" from="invincibleTimer" to="." method="_on_invincible_timer_timeout"]

View file

@ -0,0 +1,17 @@
class_name TimeGhost extends "res://scenes/spaceShip/spaceShip.gd"
@export var spaceShip: Spaceship = null
#func _init(_speed: int, _acceleration: float) -> void:
# speed = _speed
#acceleration = _acceleration
func _physics_process(delta: float) -> void:
move_and_slide()
func setSpaceship(_spaceShip: Spaceship):
spaceShip = _spaceShip
speed = spaceShip.speed
acceleration = spaceShip.acceleration
global_position = spaceShip.global_position
sprite.texture = spaceShip.sprite.texture

View file

@ -0,0 +1 @@
uid://m3hn5tl2nidk

View file

@ -0,0 +1,33 @@
[gd_scene load_steps=6 format=3 uid="uid://dms0cw7opfd64"]
[ext_resource type="PackedScene" uid="uid://csacin2gx2tum" path="res://scenes/spaceShip/spaceShip.tscn" id="1_bm7fr"]
[ext_resource type="Script" uid="uid://m3hn5tl2nidk" path="res://scenes/spaceShip/timeGhost/timeghost.gd" id="2_57067"]
[ext_resource type="PackedScene" uid="uid://eqo7k2ronf8k" path="res://scenes/areas/damageArea/damageArea.tscn" id="3_5nmba"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_5nmba"]
size = Vector2(50, 50)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_m3s7j"]
size = Vector2(50, 50)
[node name="Timeghost" groups=["timeGhost"] instance=ExtResource("1_bm7fr")]
modulate = Color(0, 1, 1, 1)
collision_layer = 20
script = ExtResource("2_57067")
invincible = true
[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("RectangleShape2D_5nmba")
disabled = true
[node name="hurtArea" parent="." index="1"]
visible = false
[node name="DamageArea" parent="." index="4" instance=ExtResource("3_5nmba")]
damage = 10
[node name="CollisionShape2D" parent="DamageArea" index="0"]
shape = SubResource("RectangleShape2D_m3s7j")
disabled = true
[editable path="DamageArea"]