man has entered the forest

This commit is contained in:
KevinGorman committed 2025-02-10 19:19:43 -05:00
1 parent f6ad5142bf
commit f31033dd59
9 files changed
+330 -92

No files matched your search

+99 -71
View File
@@ -21,80 +21,108 @@ var bullet = preload("res://scenes/bullet.tscn")
var isJumping = false
var living = true
var animPlaying = "idle"
signal deathAnimDone
func hurtPlayer(_amt):
if living:
animPlaying = "playerHurt"
animation.play(animPlaying)
func killPlayer():
if living:
living = false
print("Oh no")
animPlaying = "playerDeath"
animation.play(animPlaying)
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
isJumping = false
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
isJumping = true
velocity.y = JUMP_VELOCITY
if pushTarget:
if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft:
print("shove left")
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 10)
pushLeftEnabled = false
if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft:
print("shove right")
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 15)
pushRightEnabled = false
if Input.is_action_just_pressed("Shoot"):
if faceLeft:
var _myBullet = %SceneManager.makeBullet(marker_left.global_transform, -700)
if living and not animPlaying == "playerHurt":
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
else:
var _myBullet = %SceneManager.makeBullet(marker_right.global_transform, 700)
isJumping = false
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
if direction < 0:
faceLeft = true
if direction > 0:
faceLeft = false
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
isJumping = true
velocity.y = JUMP_VELOCITY
animation.flip_h = faceLeft
if not isJumping:
animation.play("playerRun")
else:
animation.play("playerJump")
velocity.x = direction * SPEED
else:
if not isJumping:
animation.play("playerIdle")
else:
animation.play("playerJump")
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
for i in (get_slide_collision_count()):
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal()*BUMP_FORCE)
pushTarget = false
if left_ray.is_colliding():
var collider = left_ray.get_collider()
if collider is Node:
if collider.is_in_group("pushables"):
pushLeftEnabled = true
pushTarget = collider
else:
if pushTarget:
if Input.is_action_just_pressed("Shove") && pushLeftEnabled && faceLeft:
print("shove left")
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 10)
pushLeftEnabled = false
if right_ray.is_colliding():
var collider = right_ray.get_collider()
if collider is Node:
if collider.is_in_group("pushables"):
pushRightEnabled = true
pushTarget = collider
else:
if Input.is_action_just_pressed("Shove") && pushRightEnabled && not faceLeft:
print("shove right")
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 15)
pushRightEnabled = false
if Input.is_action_just_pressed("Shoot"):
if faceLeft:
var _myBullet = %SceneManager.makeBullet(marker_left.global_transform, -700)
else:
var _myBullet = %SceneManager.makeBullet(marker_right.global_transform, 700)
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
if direction < 0:
faceLeft = true
if direction > 0:
faceLeft = false
animation.flip_h = faceLeft
if not isJumping:
animation.play("playerRun")
else:
animation.play("playerJump")
velocity.x = direction * SPEED
else:
if not isJumping:
animation.play("playerIdle")
else:
animation.play("playerJump")
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
for i in (get_slide_collision_count()):
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal()*BUMP_FORCE)
pushTarget = false
if left_ray.is_colliding():
var collider = left_ray.get_collider()
if collider is Node:
if collider.is_in_group("pushables"):
pushLeftEnabled = true
pushTarget = collider
else:
pushLeftEnabled = false
if right_ray.is_colliding():
var collider = right_ray.get_collider()
if collider is Node:
if collider.is_in_group("pushables"):
pushRightEnabled = true
pushTarget = collider
else:
pushRightEnabled = false
func _on_animated_finished() -> void:
if animPlaying == "playerHurt":
animPlaying = "playerIdle"
if animPlaying == "playerDeath":
# emit death signal
deathAnimDone.emit()
+27 -9
View File
@@ -12,12 +12,14 @@ var player:Resource
# level info
var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn"]
var timers = [30, 30]
var timers = [90, 90]
var currentLevel = 0
#Gamecontroller signals
signal destroyBox(body)
signal levelComplete(leveltoLoad)
signal playerHurt(amt)
signal playerDeath()
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@@ -29,9 +31,12 @@ func _ready() -> void:
timer.one_shot = false
timer.connect("timeout", secondCounter)
timer.start()
func reset():
secondCount = timers[currentLevel]
player.health = player.starting_health
func secondCounter():
print("time left: ", secondCount)
@@ -40,17 +45,23 @@ func secondCounter():
print("TIME IS UP")
levelComplete.emit(levels[currentLevel])
func playerDamaged():
print("GC knows player took damage")
player.health = max(player.health-10, 0)
player.health = max(player.health-20, 0)
print("Player Health: "+str(player.health))
if player.health > 0:
playerHurt.emit(player.health)
else:
playerDeath.emit()
func coinCollected():
totalCoinsCollected += 1
print("DING! Coins collected: "+ str(totalCoinsCollected) )
func bulletHit(body):
print("Game controller knows bullet hit something")
if body.is_in_group("destructables"):
@@ -66,14 +77,21 @@ func bulletHit(body):
levelComplete.emit(levels[currentLevel])
else:
print("Crates Remaining: "+str(totalCrates) )
# Coming from scenemanager
func countCrates(value):
totalCrates = value
func countCoins(value):
totalCoins = value
func countBadGuys(value):
totalBadGuys = value
func playerDead():
print("GC knows player is dead")
levelComplete.emit(levels[currentLevel])
+9
View File
@@ -5,6 +5,8 @@ extends Node
@onready var coins: Node2D = $"../coins"
@onready var enemies: Node2D = $"../enemies"
@onready var player: CharacterBody2D = $"../CharacterBody2D"
var theBullet = preload("res://scenes/bullet.tscn")
var bulletArray:Array = []
@@ -33,8 +35,15 @@ func _ready() -> void:
GameController.countBadGuys(totalEnemies)
GameController.countCrates(totalCrates)
# Player interactions
GameController.playerHurt.connect(player.hurtPlayer)
GameController.playerDeath.connect(player.killPlayer)
# Subscribe to signals
GameController.levelComplete.connect(changeLevel)
player.deathAnimDone.connect(GameController.playerDead)
GameController.reset()
func changeLevel(level):
print("New level")