graphics!

This commit is contained in:
StevenSoroka committed 2025-08-18 21:05:53 -04:00
1 parent 9f023c62fb
commit 37cc95175e
15 files changed
+470 -12

No files matched your search

+5 -1
View File
@@ -1,5 +1,6 @@
extends Node2D
signal playerDamage
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -14,7 +15,10 @@ func _process(delta: float) -> void:
func _on_area_2d_area_trigger_signal(effect: String, body: Node2D) -> void:
if body.name == "world-boundary":
return
if body is Player:
if body is Player && effect == "player_hurt":
playerDamage.emit()
body.health -= 1
print(body.health)
return
print("GC sees trigger " + effect + " on " + body.name)
body.queue_free()
+53 -5
View File
@@ -6,13 +6,20 @@ const bullet_scene = preload("res://scenes/bullet.tscn")
@onready var left_cast: RayCast2D = $LeftCast
@onready var bullet_spawn_point_right: Node2D = $BulletSpawnPointRight
@onready var bullet_spawn_point_left: Node2D = $BulletSpawnPointLeft
@onready var jump_buffer_timer: Timer = $JumpBufferTimer
@onready var player_animation: AnimatedSprite2D = $PlayerAnimation
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
const PUSH_POWER= 2000
@export var acceleration: int = 5
@export var health: int = 100
var direction: float
enum FaceDirection{LEFT, RIGHT}
enum State{IDLE, RUN, JUMP, FALL}
var state: State = State.IDLE
var facing: FaceDirection = FaceDirection.RIGHT
var pushTarget: Object
var pushEnabled: bool = false
@@ -20,6 +27,8 @@ var pushEnabled: bool = false
func _physics_process(delta: float) -> void:
handle_input(delta)
handle_movement(delta)
handle_state(delta)
handle_animation(delta)
handle_collisions(delta)
func handle_gravity(delta: float) -> void:
@@ -35,15 +44,17 @@ func handle_input(delta: float) -> void:
FaceDirection.RIGHT:
dir = 1
if Input.is_action_just_pressed("ui_accept"):
jump_buffer_timer.start()
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
direction = Input.get_axis("ui_left", "ui_right")
if direction < 0:
facing = FaceDirection.LEFT
elif direction > 0:
facing = FaceDirection.RIGHT
player_animation.flip_h = facing == FaceDirection.LEFT
if Input.is_action_just_pressed("ForcePush") && pushEnabled:
(pushTarget as RigidBody2D).apply_central_impulse(Vector2(dir, 0) * PUSH_POWER)
@@ -64,10 +75,19 @@ func handle_movement(delta: float) -> void:
handle_gravity(delta)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
if direction:
velocity.x = direction * SPEED
if direction == 0:
# not moving
velocity.x = move_toward(velocity.x, 0, acceleration)
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.x = move_toward(velocity.x, SPEED * direction, acceleration)
if jump_buffer_timer.time_left > 0 and is_on_floor():
velocity.y = JUMP_VELOCITY
jump_buffer_timer.stop()
upJump = true
state = State.JUMP
move_and_slide()
func handle_collisions(delta: float) -> void:
@@ -89,3 +109,31 @@ func handle_collisions(delta: float) -> void:
else:
pushEnabled = false
pushTarget = null
func handle_state(delta: float) -> void:
match state:
State.IDLE when velocity.x != 0:
state = State.RUN
if velocity.y > 0:
state = State.FALL
if velocity.y == 0 && velocity.x == 0:
state = State.IDLE
elif velocity.y == 0:
state = State.RUN
func handle_animation(delta: float) -> void:
match state:
State.IDLE:
player_animation.play("idle")
State.RUN:
player_animation.play("run")
State.JUMP:
if upJump:
player_animation.play("jump")
upJump = false
State.FALL:
player_animation.play("fall")
var upJump: bool = false
#func _on_animation_finished() -> void:
+7
View File
@@ -2,11 +2,18 @@ class_name SceneManager extends Node2D
const BulletScn = preload("res://scenes/bullet.tscn")
@onready var game: Node2D = $".."
@onready var triggers: Node2D = $"../triggers"
var bullets: Array[Bullet] = []
const MAX_BULLETS = 10
var current_bullet = 0
func _ready() -> void:
if triggers:
for obj in triggers.get_children():
if obj is Trigger:
obj.areaTriggerSignal.connect(game._on_area_2d_area_trigger_signal)
# makes and recycles bullets
func bulletFactory() -> Bullet:
if len(bullets) < MAX_BULLETS:
+1 -1
View File
@@ -1,4 +1,4 @@
extends Area2D
class_name Trigger extends Area2D
@export var effect := "destroy"