Ship can now warp

This commit is contained in:
2024-05-13 20:31:41 -04:00
parent 914a6e4010
commit 3ad6004836
5 changed files with 40 additions and 6 deletions

View File

@ -1,7 +1,5 @@
extends Area2D
# FIXME: Tweak speed and LifeTimer values
@export var speed := 1400.00
var direction := Vector2.UP

View File

@ -1,6 +1,5 @@
extends Node2D
# TODO: Make a small title screen that starts before the game scene
# TODO: MAYBE track high score in a file & show it on HUD
# TODO: MAYBE make ufo enemey that randomly flies in from ones sode to the other

View File

@ -1,6 +1,5 @@
extends CharacterBody2D
# TODO: Add the ability to "warp"
# FIXME: Tweak speed and floatyness4
signal crashed
@ -11,7 +10,13 @@ const BULLET = preload("res://scenes/bullet.tscn")
@export var max_speed := 350.0
@export var rotation_speed := 200.0
var viewport_size : Vector2
var can_shoot := true
var can_warp := true
func _ready() -> void:
viewport_size = get_viewport_rect().size
func _physics_process(delta: float) -> void:
# Controls
@ -21,6 +26,9 @@ func _physics_process(delta: float) -> void:
if Input.is_action_pressed("ui_accept") and can_shoot:
fire_gun($Gun.global_position, self.global_rotation)
if Input.is_action_pressed("ui_cancel") and can_warp:
warp()
# Movement Logic
## Accleration
velocity += accleration_direction.rotated(rotation) * accleration * delta
@ -34,7 +42,6 @@ func _physics_process(delta: float) -> void:
move_and_slide()
# Screen Wrap
var viewport_size := get_viewport_rect().size
position.x = wrap(position.x, 0, viewport_size.x)
position.y = wrap(position.y, 0,viewport_size.y)
@ -47,7 +54,15 @@ func fire_gun(pos : Vector2, rot : float) -> void:
can_shoot = false
$ShotCooldown.start()
func crash():
func warp() -> void:
var random_position := Vector2.ZERO
random_position.x = randf_range(0, viewport_size.x)
random_position.y = randf_range(0, viewport_size.y)
position = random_position
can_warp = false
$WarpCooldown.start()
func crash() -> void:
# TODO: Make some kind of crash animation or crashed sprite
crashed.emit()
$AnimationPlayer.play("crash")
@ -55,3 +70,6 @@ func crash():
func _on_shot_cooldown_timeout() -> void:
can_shoot = true
func _on_warp_cooldown_timeout() -> void:
can_warp = true