player damage, player death, badguy dictionary, badguy damage, badguy death, user intererface, paler damage animation, player death animation
This commit is contained in:
1 parent
aea4379c6d
commit
898803a622
22 files changed
+412
-41
No files matched your search
@@ -1,6 +1,7 @@
|
||||
class_name Bullet extends Area2D
|
||||
var speed = 700
|
||||
|
||||
signal bulletDamageSignal(body, bullet)
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
@@ -10,3 +11,9 @@ func setSpeed(value):
|
||||
speed = value
|
||||
func _physics_process(delta: float) -> void:
|
||||
position += transform.x * speed * delta
|
||||
|
||||
|
||||
func _on_area_entered(area):
|
||||
print("bullet is hitting area")
|
||||
if area is Slime:
|
||||
bulletDamageSignal.emit(area,self)
|
||||
@@ -14,12 +14,15 @@ const JUMP_VELOCITY = -400.0
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing:FaceDirection = FaceDirection.RIGHT
|
||||
|
||||
enum State{IDLE, RUN, JUMP, FALLING}
|
||||
enum State{IDLE, RUN, JUMP, FALLING, HURT, DEATH}
|
||||
var current_state:State = State.IDLE
|
||||
var pushTarget
|
||||
var pushEnable = false
|
||||
var direction
|
||||
var upJump = false
|
||||
|
||||
signal deathAnimationCompleteSignal
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
#game loop
|
||||
handle_input()
|
||||
@@ -71,15 +74,15 @@ func handle_collisions():
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100 )
|
||||
|
||||
if right_cast.is_colliding() && facing == FaceDirection.RIGHT:
|
||||
print("right cast collision")
|
||||
#print("right cast collision")
|
||||
# get the thing i am colliding with
|
||||
var collider = right_cast.get_collider()
|
||||
if collider is Node && collider is RigidBody2D:
|
||||
print("i can shove this right")
|
||||
#print("i can shove this right")
|
||||
pushTarget = collider
|
||||
pushEnable = true
|
||||
if left_cast.is_colliding() && facing == FaceDirection.LEFT:
|
||||
print("left cast collision")
|
||||
#print("left cast collision")
|
||||
var collider = left_cast.get_collider()
|
||||
if collider is Node && collider is RigidBody2D:
|
||||
print("i can shove this left")
|
||||
@@ -113,6 +116,10 @@ func update_animation():
|
||||
player_graphic.play("Jump")
|
||||
State.FALLING:
|
||||
player_graphic.play("Falling")
|
||||
State.HURT:
|
||||
player_graphic.play("hurt")
|
||||
State.DEATH:
|
||||
player_graphic.play("death")
|
||||
func update_states():
|
||||
match current_state:
|
||||
#idle when movment in x
|
||||
@@ -135,10 +142,16 @@ func _on_animation_finished() -> void:
|
||||
match current_state:
|
||||
State.JUMP:
|
||||
upJump = false
|
||||
|
||||
State.HURT:
|
||||
current_state = State.IDLE
|
||||
State.DEATH:
|
||||
deathAnimationCompleteSignal.emit()
|
||||
|
||||
|
||||
func playerTakesDamage(health):
|
||||
print("player sees remainting health"+str(health))
|
||||
current_state = State.HURT
|
||||
func playerDies():
|
||||
print("player sees he ded.")
|
||||
current_state = State.DEATH
|
||||
|
||||
@@ -13,5 +13,4 @@ func _process(delta: float) -> void:
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print ("Coin sees collision")
|
||||
coinCollectedSignal.emit(body, self)
|
||||
@@ -0,0 +1 @@
|
||||
class_name Crate extends RigidBody2D
|
||||
@@ -0,0 +1 @@
|
||||
uid://cov5urwm68y3l
|
||||
+47
-15
@@ -4,22 +4,27 @@ extends Node2D
|
||||
var totalCoinsAvailable = 0
|
||||
|
||||
var timer = Timer.new()
|
||||
var timeAvailable = 30
|
||||
var timeAvailable
|
||||
var level="res://scenes/game.tscn"
|
||||
var levelTwo = "res://scenes/level2.tscn"
|
||||
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
|
||||
var timers = [30,20,15]
|
||||
var currentLevel = 0
|
||||
var startingCoins = 0
|
||||
|
||||
signal destroySignal(body)
|
||||
signal levelChangeSignal(level)
|
||||
signal playerTakeDamageSignal(health)
|
||||
signal playerDiesSignal
|
||||
|
||||
signal bulletDamageEnemySignal(body)
|
||||
signal countDownSignal(timeRemaining)
|
||||
signal coinCountSignal(coinsRemaining, startingCoins)
|
||||
var player:Characterstats
|
||||
var enemy:Characterstats
|
||||
|
||||
var playerHealth:int
|
||||
|
||||
var enemiesDict = {}
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
player = load("res://scripts/rscs/playerstats.tres")
|
||||
@@ -36,13 +41,16 @@ func _ready() -> void:
|
||||
func secondCounter() -> void:
|
||||
|
||||
timeAvailable -=1
|
||||
countDownSignal.emit(timeAvailable)
|
||||
if timeAvailable <= 0:
|
||||
print ("YOU LOSE")
|
||||
#get_tree().call_deferred("change_scene_to_file", levels[currentLevel])
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
#reload the current scene
|
||||
func reset() -> void:
|
||||
startingCoins=0
|
||||
timeAvailable = timers[currentLevel]
|
||||
playerHealth = player.starting_health
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
@@ -61,25 +69,49 @@ func _on_areatrigger(effect, body) -> void:
|
||||
print("player health is now"+str(playerHealth))
|
||||
|
||||
func totalCoinCount(totalCoins):
|
||||
|
||||
if startingCoins == 0:
|
||||
startingCoins = totalCoins
|
||||
totalCoinsAvailable = totalCoins
|
||||
func coinCollected(body, coin):
|
||||
|
||||
destroySignal.emit(coin)
|
||||
totalCoinsAvailable -= 1
|
||||
if totalCoinsAvailable <=0:
|
||||
print("YOU WIN")
|
||||
currentLevel +=1
|
||||
if currentLevel >= levels.size():
|
||||
currentLevel =0
|
||||
|
||||
#get_tree().call_deferred("change_scene_to_file", levels[currentLevel])
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
if not body is Crate:
|
||||
|
||||
destroySignal.emit(coin)
|
||||
totalCoinsAvailable -= 1
|
||||
coinCountSignal.emit(totalCoinsAvailable, startingCoins)
|
||||
if totalCoinsAvailable <=0:
|
||||
print("YOU WIN")
|
||||
currentLevel +=1
|
||||
if currentLevel >= levels.size():
|
||||
currentLevel =0
|
||||
|
||||
#get_tree().call_deferred("change_scene_to_file", levels[currentLevel])
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
|
||||
func playerAttacked(body, slime):
|
||||
print("GC knows player attacked")
|
||||
playerHealth -= enemy.meleeDamage
|
||||
playerHealth -= enemiesDict[slime].damage
|
||||
if playerHealth<=0:
|
||||
playerDiesSignal.emit()
|
||||
else:
|
||||
playerTakeDamageSignal.emit(playerHealth)
|
||||
func playerDead():
|
||||
levelChangeSignal.emit(levels[currentLevel] )
|
||||
|
||||
func bulletDamage(area, bullet):
|
||||
print("Gc Knows bullet hit something"+str(player.rangeDamage))
|
||||
print("GC Knows BG health is :"+str( enemiesDict[area].health))
|
||||
enemiesDict[area].health -= player.rangeDamage
|
||||
if enemiesDict[area].health<=0:
|
||||
destroySignal.emit(area)
|
||||
enemiesDict.erase(area)
|
||||
else:
|
||||
bulletDamageEnemySignal.emit(area)
|
||||
func addEnemyToLevel(slime):
|
||||
var randHealth:int = randi() % 20
|
||||
var randDamage:int = randi() % 10
|
||||
var enemyStat = {
|
||||
"health":enemy.starting_health+ randHealth,
|
||||
"damage":enemy.meleeDamage + randDamage
|
||||
|
||||
}
|
||||
enemiesDict[slime]= enemyStat
|
||||
@@ -7,7 +7,8 @@ var totalAllowedBullets = 7
|
||||
@onready var coins: Node2D = $"../Coins"
|
||||
@onready var enemies: Node2D = $"../Enemies"
|
||||
@onready var player: Player = $"../Player"
|
||||
|
||||
@onready var ui = $"../CanvasLayer/Ui"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Gamecontroller.reset()
|
||||
@@ -18,11 +19,19 @@ func _ready() -> void:
|
||||
for obj in enemies.get_children():
|
||||
if obj is Slime:
|
||||
obj.playerDamageSignal.connect(Gamecontroller.playerAttacked)
|
||||
Gamecontroller.addEnemyToLevel(obj)
|
||||
Gamecontroller.bulletDamageEnemySignal.connect(obj.takeDamage)
|
||||
|
||||
updateCoins()
|
||||
Gamecontroller.destroySignal.connect(destroyItem)
|
||||
Gamecontroller.levelChangeSignal.connect(changeScene)
|
||||
Gamecontroller.playerTakeDamageSignal.connect(player.playerTakesDamage)
|
||||
if ui:
|
||||
Gamecontroller.playerTakeDamageSignal.connect(ui.healthUpdate)
|
||||
Gamecontroller.countDownSignal.connect(ui.timerUpdate)
|
||||
Gamecontroller.coinCountSignal.connect(ui.coinsUpdate)
|
||||
Gamecontroller.playerDiesSignal.connect(player.playerDies)
|
||||
player.deathAnimationCompleteSignal.connect(Gamecontroller.playerDead)
|
||||
#call this anytimes the coins change
|
||||
func updateCoins() ->void:
|
||||
var coinCount = 0
|
||||
@@ -43,6 +52,7 @@ func bulletFactory():
|
||||
var mybullet
|
||||
if bulletArray.size() < totalAllowedBullets:
|
||||
mybullet = bullet.instantiate()
|
||||
mybullet.bulletDamageSignal.connect(Gamecontroller.bulletDamage )
|
||||
owner.add_child(mybullet)
|
||||
else:
|
||||
mybullet = bulletArray.pop_back()
|
||||
|
||||
+13
-5
@@ -5,6 +5,7 @@ class_name Slime extends Area2D
|
||||
@onready var left_down_cast: RayCast2D = $"slimeGraphic/Left DownCast"
|
||||
@onready var right_down_cast: RayCast2D = $"slimeGraphic/Right DownCast"
|
||||
|
||||
|
||||
var speed:int = 100
|
||||
var direction = 1
|
||||
|
||||
@@ -17,6 +18,7 @@ func _ready() -> void:
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
if not right_down_cast.is_colliding():
|
||||
direction = -1
|
||||
slime_graphic.flip_h = true
|
||||
@@ -24,15 +26,21 @@ func _process(delta: float) -> void:
|
||||
direction = 1
|
||||
slime_graphic.flip_h = false
|
||||
if right_side_cast.is_colliding():
|
||||
direction = -1
|
||||
slime_graphic.flip_h = true
|
||||
if not right_side_cast.get_collider() is Player && not right_side_cast.get_collider() is Slime:
|
||||
direction = -1
|
||||
slime_graphic.flip_h = true
|
||||
if left_side_cast.is_colliding():
|
||||
direction = 1
|
||||
slime_graphic.flip_h = false
|
||||
position.x += direction * speed * delta
|
||||
if not left_side_cast.get_collider() is Player && not left_side_cast.get_collider() is Slime:
|
||||
direction = 1
|
||||
slime_graphic.flip_h = false
|
||||
position.x += direction * speed * delta
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
print("player attacked")
|
||||
playerDamageSignal.emit(body, self)
|
||||
func takeDamage(body):
|
||||
if body == self:
|
||||
slime_graphic.play("hurt")
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
extends Control
|
||||
@onready var health = $VBoxContainer/HBoxContainer/MarginContainer/Health
|
||||
@onready var timer = $VBoxContainer/HBoxContainer/MarginContainer2/Timer
|
||||
@onready var coins = $VBoxContainer/HBoxContainer/MarginContainer3/Coins
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass
|
||||
func healthUpdate(healthRemaining):
|
||||
health.text = "Health: "+str(healthRemaining)
|
||||
|
||||
func timerUpdate(timeRemaining):
|
||||
timer.text= str(timeRemaining)
|
||||
func coinsUpdate(coinsRemaining, startingCoins):
|
||||
coins.text="coins: "+str(coinsRemaining)+"/"+str(startingCoins)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uid://du5ut0qfft7le
|
||||
Reference in new issue
Block a user