added timer, multilevel, slimes, custom resources
This commit is contained in:
1 parent
2014ed0b37
commit
2ebdf0cc0c
16 files changed
+1291
-15
No files matched your search
+2
-1
@@ -3,4 +3,5 @@ class_name Coin extends Area2D
|
||||
signal coinCollectedSignal(body, coin)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
coinCollectedSignal.emit(body, self)
|
||||
if body is Player:
|
||||
coinCollectedSignal.emit(body, self)
|
||||
@@ -3,21 +3,52 @@ extends Node2D
|
||||
@onready var player: Player = $player
|
||||
|
||||
signal playerDamage
|
||||
signal destroySignal(body)
|
||||
signal levelChangeSignal(level)
|
||||
|
||||
var score := 0
|
||||
|
||||
var totalCoin := 0
|
||||
var coinCollected := 0
|
||||
|
||||
var timer := Timer.new()
|
||||
var timeAvailable: int = 5
|
||||
|
||||
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
|
||||
var timers = [60, 10, 9]
|
||||
var currentLevel = 0
|
||||
|
||||
#caracter stats
|
||||
var enemy_stats: CharacterStats
|
||||
var player_stats: CharacterStats
|
||||
|
||||
var player_current_health: int
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
enemy_stats = load("res://scripts/rscs/slimeStats.tres")
|
||||
player_stats = load("res://scripts/rscs/playerStats.tres")
|
||||
player_current_health = player_stats.starting_health
|
||||
reset()
|
||||
print("in _ready")
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
timer.connect("timeout", secondCounter)
|
||||
timer.start()
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func secondCounter():
|
||||
timeAvailable -= 1
|
||||
if timeAvailable <= 0:
|
||||
print("you lose")
|
||||
reset()
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
|
||||
func _on_trigger(effect: Variant, body: Variant) -> void:
|
||||
print("game controller sees trigger "+effect+" "+body.name)
|
||||
if effect == "destroy" && not body is Player:
|
||||
body.queue_free()
|
||||
elif effect == "player_hurt":
|
||||
@@ -27,7 +58,24 @@ func onBulletHitSignal(body: Node, bullet: Bullet):
|
||||
body.queue_free()
|
||||
|
||||
func onCoinCollected(body, coin: Coin):
|
||||
if body is Player:
|
||||
score += 1
|
||||
coin.queue_free()
|
||||
destroySignal.emit(coin)
|
||||
|
||||
func setTotalCoinCount(coinCount: int):
|
||||
totalCoin = coinCount
|
||||
if totalCoin == 0:
|
||||
print("you win!")
|
||||
currentLevel += 1
|
||||
if currentLevel >= levels.size():
|
||||
currentLevel = 0
|
||||
levelChangeSignal.emit(levels[currentLevel])
|
||||
|
||||
func reset():
|
||||
timeAvailable = timers[currentLevel]
|
||||
|
||||
func playerAttacked(body, slime):
|
||||
print("player was attacked")
|
||||
player_current_health -= enemy_stats.melee_damage
|
||||
if player_current_health <= 0:
|
||||
print("YOU ARE DEAD")
|
||||
else:
|
||||
print("remaining life: ", player_current_health)
|
||||
@@ -0,0 +1,9 @@
|
||||
class_name CharacterStats extends Resource
|
||||
|
||||
@export var health: int = 100
|
||||
@export var max_health: int = 100
|
||||
@export var starting_health: int = 100
|
||||
|
||||
# damage dealing
|
||||
@export var melee_damage: int = 10
|
||||
@export var range_damage: int = 0
|
||||
@@ -0,0 +1 @@
|
||||
uid://lgpdd5rgj2jq
|
||||
@@ -0,0 +1,12 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://dq3ppg3sgdb11"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://lgpdd5rgj2jq" path="res://scripts/rscs/characterstats.gd" id="1_01643"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_01643")
|
||||
health = 100
|
||||
max_health = 100
|
||||
starting_health = 100
|
||||
melee_damage = 10
|
||||
range_damage = 0
|
||||
metadata/_custom_type_script = "uid://lgpdd5rgj2jq"
|
||||
@@ -0,0 +1,12 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://brf6f5inl3irc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://lgpdd5rgj2jq" path="res://scripts/rscs/characterstats.gd" id="1_ppipo"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_ppipo")
|
||||
health = 100
|
||||
max_health = 100
|
||||
starting_health = 100
|
||||
melee_damage = 20
|
||||
range_damage = 0
|
||||
metadata/_custom_type_script = "uid://lgpdd5rgj2jq"
|
||||
@@ -2,10 +2,10 @@ class_name SceneManager extends Node2D
|
||||
|
||||
const bullet_scene = preload("res://scenes/bullet.tscn")
|
||||
|
||||
@onready var game: Node2D = $".."
|
||||
var game := Gamecontroller
|
||||
@onready var triggers: Node2D = $"../triggers"
|
||||
|
||||
@onready var coins: Node2D = $"../coins"
|
||||
@onready var ennemies: Node2D = $"../ennemies"
|
||||
|
||||
var MAX_BULLET := 50
|
||||
var available_bullets = []
|
||||
@@ -13,10 +13,10 @@ var available_bullets = []
|
||||
var score := 0
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
for i in range(MAX_BULLET):
|
||||
var new_bullet = bullet_scene.instantiate()
|
||||
new_bullet.bulletHitSignal.connect(game.onBulletHitSignal)
|
||||
print(new_bullet.bullet_graphic)
|
||||
available_bullets.push_front(new_bullet)
|
||||
|
||||
if triggers:
|
||||
@@ -24,11 +24,32 @@ func _ready() -> void:
|
||||
if trig is Trigger:
|
||||
trig.areaTriggerSignal.connect(game._on_trigger)
|
||||
|
||||
if ennemies:
|
||||
updateEnnemies()
|
||||
|
||||
if coins:
|
||||
for coin in coins.get_children():
|
||||
if coin is Coin:
|
||||
updateCoins()
|
||||
|
||||
game.destroySignal.connect(destroy)
|
||||
game.levelChangeSignal.connect(changeScene)
|
||||
|
||||
func updateEnnemies():
|
||||
print("pdate ennemies")
|
||||
for ennemy in ennemies.get_children():
|
||||
if ennemy is Slime:
|
||||
if not ennemy.playerDamageSignal.is_connected(game.playerAttacked):
|
||||
ennemy.playerDamageSignal.connect(game.playerAttacked)
|
||||
|
||||
func updateCoins():
|
||||
var coinCount := 0
|
||||
for coin in coins.get_children():
|
||||
if coin is Coin:
|
||||
coinCount += 1
|
||||
if not coin.coinCollectedSignal.is_connected(game.onCoinCollected):
|
||||
coin.coinCollectedSignal.connect(game.onCoinCollected)
|
||||
|
||||
if not coin.tree_exited.is_connected(updateCoins):
|
||||
coin.tree_exited.connect(updateCoins)
|
||||
game.setTotalCoinCount(coinCount)
|
||||
|
||||
func make_bullet(start_position: Transform2D, speed: int):
|
||||
var new_bullet = bullet_factory(start_position, speed)
|
||||
@@ -46,3 +67,11 @@ func bullet_factory(start_position: Transform2D, speed: int) -> Bullet:
|
||||
available_bullets.push_front(shot_bullet)
|
||||
|
||||
return shot_bullet
|
||||
|
||||
func destroy(body: Node2D):
|
||||
body.queue_free()
|
||||
|
||||
|
||||
func changeScene(level):
|
||||
get_tree().call_deferred("change_scene_to_file", level)
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
class_name Slime extends Area2D
|
||||
|
||||
@onready var slime_graphic: AnimatedSprite2D = $SlimeGraphic
|
||||
@onready var right_cast: RayCast2D = $RightCast
|
||||
@onready var left_cast: RayCast2D = $LeftCast
|
||||
@onready var left_cast_down: RayCast2D = $LeftCastDown
|
||||
@onready var right_cast_down: RayCast2D = $RightCastDown
|
||||
|
||||
signal playerDamageSignal(body, slime)
|
||||
|
||||
var SPEED: int = 100
|
||||
var direction = 1
|
||||
|
||||
# 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:
|
||||
position.x += direction * SPEED * delta
|
||||
|
||||
if right_cast.is_colliding():
|
||||
var collider = right_cast.get_collider()
|
||||
if collider is not Player:
|
||||
direction = -1
|
||||
if left_cast.is_colliding():
|
||||
var collider = left_cast.get_collider()
|
||||
if collider is not Player:
|
||||
direction = 1
|
||||
|
||||
if not right_cast_down.is_colliding():
|
||||
direction = -1
|
||||
if not left_cast_down.is_colliding():
|
||||
direction = 1
|
||||
|
||||
if direction == -1:
|
||||
slime_graphic.flip_h = true
|
||||
else:
|
||||
slime_graphic.flip_h = false
|
||||
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
playerDamageSignal.emit(body, self)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dp44amovxcpc6
|
||||
Reference in new issue
Block a user