Started a Godot Project to remake Tailgunner.

This commit is contained in:
KingGurke 2025-04-02 12:36:05 +02:00
commit 9621323983
67 changed files with 976 additions and 0 deletions

72
scripts/flyer.gd Normal file
View file

@ -0,0 +1,72 @@
class_name Flyer
extends CharacterBody2D
# constants
## Maximum angle in degrees that the flyer can tilt.
@export var max_tilt = 45
## Maximum acceleration of the flyer in vertical directions. Measured in pixels per second.
@export var vertical_accelleration = 5
## Maximum acceleration of the flyer in horizontal directions. Measured in pixels per second.
@export var horizontal_accelleration = 15
## Default deceleration of the flyer in vertical directions when no input is given. Measured in pixels per second.
@export var vertical_decelleration = 8
## Default deceleration of the flyer in horizontal directions when no input is given. Measured in pixels per second.
@export var horizontal_decelleration = 20
## Maximum speed of the flyer in vertical directions. Measured in pixels per second.
@export var vertical_max_speed = 300
## Maximum speed of the flyer in horizontal directions. Measured in pixels per second.
@export var horizontal_max_speed = 300
@export var max_hp = 100
@export var weapons: Array[Weapon]
@export var friendly = false
#@export var panAudio = true
# gameplay variables
var tilt
var speed
var hp
var directionInput
func _ready() -> void:
hp = max_hp
max_tilt = deg_to_rad(max_tilt)
directionInput = Vector2(0,0)
func _physics_process(delta: float) -> void:
# convert control input to movement
var verticalIn = directionInput.y
var horizontalIn = directionInput.x
if verticalIn:
if (verticalIn / velocity.y) < 0:
velocity.y = move_toward(velocity.y, vertical_max_speed, verticalIn * (vertical_decelleration))
else:
velocity.y = move_toward(velocity.y, sign(verticalIn) * vertical_max_speed, sign(verticalIn) * verticalIn * vertical_accelleration)
else:
velocity.y = move_toward(velocity.y, 0, vertical_decelleration)
if horizontalIn:
if (horizontalIn / velocity.x) < 0:
velocity.x = move_toward(velocity.x, horizontal_max_speed, horizontalIn * (horizontal_decelleration))
else:
velocity.x = move_toward(velocity.x, sign(horizontalIn) * horizontal_max_speed, sign(horizontalIn) * horizontalIn * horizontal_accelleration)
else:
velocity.x = move_toward(velocity.x, 0, horizontal_decelleration)
#print_debug("current velocity: ", velocity, ", current input: ", Vector2(horizontalIn, verticalIn), ", input signs: ", Vector2(sign(horizontalIn), sign(verticalIn)))
move_and_collide(velocity * delta)
# tilt the flyer according to vertical movement.
tilt = velocity.y / vertical_max_speed * max_tilt
rotation = tilt
func shoot(index):
if weapons.size() > index:
weapons[index].shoot()
func deal_damage(amount):
hp -= amount
if hp <= 0:
die()
func die():
return
#TODO: implement death

1
scripts/flyer.gd.uid Normal file
View file

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

View file

@ -0,0 +1,23 @@
@tool
class_name FlyerController
extends Node
# references
@export var controlled_flyer: Flyer:
set(new_flyer):
controlled_flyer = new_flyer
update_configuration_warnings()
func _ready() -> void:
if Engine.is_editor_hint():
var parent = get_parent()
if (parent is Flyer):
controlled_flyer = parent
update_configuration_warnings()
func _get_configuration_warnings():
var warnings = []
if controlled_flyer == null:
warnings.append("Please select a flyer to be controlled by this controller.")
return warnings

View file

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

View file

@ -0,0 +1,11 @@
@tool
class_name PlayerController
extends FlyerController
func _physics_process(delta: float) -> void:
if not Engine.is_editor_hint():
controlled_flyer.directionInput = Vector2(Input.get_axis("plane_left","plane_right"), Input.get_axis("plane_up","plane_down"))
if InputMap.has_action("shoot_primary") and Input.is_action_just_pressed("shoot_primary"):
controlled_flyer.shoot(1)
if InputMap.has_action("shoot_secondary") and Input.is_action_just_pressed("shoot_secondary"):
controlled_flyer.shoot(2)

View file

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

18
scripts/projectile.gd Normal file
View file

@ -0,0 +1,18 @@
class_name Projectile
extends CharacterBody2D
# constants
@export var speed = 10
@export var damage = 5
@export var friendly = false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func _physics_process(delta: float) -> void:
var target = move_and_collide(velocity * delta).get_collider()
if target is Flyer && friendly != target.friendly:
target.deal_damage(damage)
queue_free()

View file

@ -0,0 +1 @@
uid://8y2wqva60nom

41
scripts/weapon.gd Normal file
View file

@ -0,0 +1,41 @@
class_name Weapon
extends Node2D
# constants
@export var max_ammo = 1
## Number of seconds until the weapon can be used again.
@export var cooldown = 1
@export var shot: Projectile
@export var shot_spawn: Node2D
@export var audio: AudioStreamRandomizer
# gameplay variables
var ammo
var timer = 0.0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
ammo = max_ammo
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
timer += delta
# Creates and returns an instance of the weapon's projectile.
func shoot() -> Projectile:
if timer > cooldown && ammo > 0:
timer = 0
var new_shot = shot.instantiate()
owner.add_child(new_shot)
new_shot.transform = shot_spawn.transform
ammo -= 1
audio.play()
return new_shot
else:
return null
func add_ammo(amount):
ammo += amount
if ammo > max_ammo:
ammo = max_ammo

1
scripts/weapon.gd.uid Normal file
View file

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