player animations, variable triggers, & working bullets

This commit is contained in:
KevinGorman committed 2025-03-10 21:05:26 -04:00
1 parent de7312cf8e
commit 467fca0e07
23 files changed
+553 -93

No files matched your search

+15 -1
View File
@@ -1,4 +1,5 @@
extends CharacterBody2D
class_name Player extends CharacterBody2D
@onready var playerGraphic: AnimatedSprite2D = $AnimatedSprite2D
const SPEED = 300.0
@@ -9,6 +10,7 @@ var faceLeft=false
var pushRightEnabled = false
var pushLeftEnabled = false
var pushTarget
var isJumping = false
@onready var right_target: Node2D = $rightTarget_Node2D
@onready var left_target: Node2D = $leftTarget_Node2D
@@ -22,10 +24,14 @@ func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
isJumping = false
# Handle jump.right_cast
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
isJumping = true
playerGraphic.play("jump")
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
@@ -51,10 +57,18 @@ func _physics_process(delta: float) -> void:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if direction:
if not isJumping:
playerGraphic.play("run")
if direction ==0:
if not isJumping:
playerGraphic.play("idle")
if direction<0:
faceLeft=true
playerGraphic.flip_h = true
if direction>0:
faceLeft=false
playerGraphic.flip_h = false
move_and_slide()
+1
View File
@@ -0,0 +1 @@
class_name Crate extends RigidBody2D
-27
View File
@@ -1,27 +0,0 @@
extends Node2D
# Game Data
var totalcrates=4
var cratesdestroyed = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger_areatrigger(body) -> void:
print("game conroller knows about crate destruction")
cratesdestroyed +=1
totalcrates -=1
#kill
body.queue_free()
if totalcrates <=0:
print("you won")
+43
View File
@@ -0,0 +1,43 @@
class_name GameController extends Node2D
# Game Data
var totalcrates=4
var cratesdestroyed = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger_areatrigger(effect, body) -> void:
print("Do effect " +effect)
match effect:
"destroy":
#write code to destroy
if body is Crate:
%SceneManager.destroy(body)
cratesdestroyed +=1
"powerup":
#write code to power up
if body is Player:
print ("power up the player")
func bulletHit(body):
print("Game Controller knows bullet hit")
if body is Crate:
print ("you hit a crate")
cratesdestroyed +=1
%SceneManager.destroy(body)
print("Crates remaining::"+str(totalcrates - cratesdestroyed))
func numberofCrates (value):
totalcrates = value
print("Game Controller knows crates "+str(totalcrates))
+25
View File
@@ -1,4 +1,7 @@
extends Node
@onready var gameController: GameController = $".."
@onready var crates: Node2D = $"../crates"
@onready var triggers: Node2D = $"../Triggers"
var bulletsFiredTotal = 0
var bulletsMadeTotal = 0
@@ -29,3 +32,25 @@ func makeBullet(position,speed):
newBullet.transform = position
func bulletHit(bullet, body):
print("tell game controller we hit something")
gameController.bulletHit(body)
bullet.setSpeed(0)
bullet.position = Vector2(-100,-100)
func destroy(body):
body.queue_free()
func buildLevel():
#how many crates?
var totalCrates = 0
for obj in crates.get_children():
if obj is Crate:
totalCrates +=1
gameController.numberofCrates(totalCrates)
#wire up the triggers
for obj in triggers.get_children():
if obj is Trigger:
#wire out to GC
obj.areatrigger.connect(gameController._on_trigger_areatrigger)
func _ready() -> void:
buildLevel()
+5 -3
View File
@@ -1,6 +1,7 @@
extends Area2D
class_name Trigger extends Area2D
@export var effect = "alert"
signal areatrigger(Object)
signal areatrigger(effect, Object)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
print("Trigger is here")
@@ -13,4 +14,5 @@ func _process(delta: float) -> void:
func _on_body_entered(body: Node2D) -> void:
print("Body Collision in trigger")
areatrigger.emit(body)
areatrigger.emit(effect, body)