bad guys, collectibles, levels
This commit is contained in:
1 parent
bf048e3e7b
commit
ce71477b76
16 files changed
+879
-25
No files matched your search
@@ -0,0 +1,8 @@
|
||||
class_name Coin extends Area2D
|
||||
|
||||
signal coinCollected
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("player"):
|
||||
coinCollected.emit()
|
||||
queue_free()
|
||||
@@ -1,41 +1,74 @@
|
||||
extends Node2D
|
||||
var totalBoxes = 3
|
||||
var timer:= Timer.new()
|
||||
var countdown = 10
|
||||
var totalCrates = 0
|
||||
var totalCrates := 0
|
||||
var cratesDestroyed := 0
|
||||
var totalCoins := 0
|
||||
var totalCoinsCollected := 0
|
||||
|
||||
var totalEnemies := 0
|
||||
#level information
|
||||
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn"]
|
||||
var timers = [10,15]
|
||||
var currentLevel = 0
|
||||
|
||||
var player:Resource
|
||||
# signals from game controller
|
||||
signal destroyBox(body)
|
||||
|
||||
signal levelComplete(levelToLoad)
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
player = load("res://scripts/res/playerstats.tres")
|
||||
print("Player health: "+str(player.health))
|
||||
print("Number of levels: "+str(levels.size()))
|
||||
reset()
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
timer.connect("timeout", secondCounter)
|
||||
# timer.start()
|
||||
timer.start()
|
||||
|
||||
func reset():
|
||||
countdown = timers[currentLevel]
|
||||
func secondCounter():
|
||||
countdown -=1
|
||||
print("minus one")
|
||||
if countdown <=0:
|
||||
print("you lose")
|
||||
get_tree().reload_current_scene()
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
func _on_trigger_alert(body):
|
||||
totalBoxes -=1
|
||||
body.queue_free()
|
||||
if totalBoxes <=0:
|
||||
print("you won")
|
||||
get_tree().reload_current_scene()
|
||||
func coinCollected():
|
||||
print("gane cotroller knows coin collected")
|
||||
totalCoinsCollected+=1
|
||||
|
||||
func playerDamaged():
|
||||
player.health -= 20
|
||||
print("game controller knows player damaged, health is now "+str(player.health))
|
||||
|
||||
func bulletHit(body):
|
||||
print("game controller knows bullet hit something")
|
||||
if body.is_in_group("destructable"):
|
||||
destroyBox.emit(body)
|
||||
|
||||
func coutnCrates(value):
|
||||
totalCrates -=1
|
||||
cratesDestroyed +=1
|
||||
body.queue_free()
|
||||
if totalCrates <=0:
|
||||
print("you won")
|
||||
#refactor this --make it a single
|
||||
currentLevel +=1
|
||||
if currentLevel >= levels.size():
|
||||
currentLevel = 0
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
else:
|
||||
print("crates remaining: "+str(totalCrates))
|
||||
# scene manager stuff
|
||||
func countCrates(value):
|
||||
totalCrates = value
|
||||
func countCoins(value):
|
||||
totalCoins = value
|
||||
@@ -0,0 +1,27 @@
|
||||
class_name purpleslime extends Area2D
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var rightray: RayCast2D = $rightray
|
||||
@onready var leftray: RayCast2D = $leftray
|
||||
@onready var rightfloorray: RayCast2D = $rightfloorray
|
||||
@onready var leftfloorray: RayCast2D = $leftfloorray
|
||||
const speed = 60
|
||||
var direction = 1
|
||||
#signals
|
||||
signal playerDamage
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not rightfloorray.is_colliding():
|
||||
direction = -1
|
||||
sprite.flip_h = true
|
||||
#about to fall on the right
|
||||
if not leftfloorray.is_colliding():
|
||||
direction = 1
|
||||
sprite.flip_h = false
|
||||
#about to fall on the right
|
||||
position.x += direction * speed * delta
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("player"):
|
||||
print("bad guy collected")
|
||||
playerDamage.emit()
|
||||
if body.is_in_group("destructable"):
|
||||
print("box hit")
|
||||
@@ -0,0 +1,5 @@
|
||||
class_name CharacterStats extends Resource
|
||||
|
||||
@export var max_health:int = 100
|
||||
@export var starting_health:int = 100
|
||||
@export var health:int = 100
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://bamuvf71pw641"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_6olhj"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_6olhj")
|
||||
max_health = 100
|
||||
starting_health = 100
|
||||
health = 100
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://u3yqeui6rnih"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_smxrk"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_smxrk")
|
||||
max_health = 60
|
||||
starting_health = 50
|
||||
health = 50
|
||||
@@ -1,22 +1,40 @@
|
||||
extends Node
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var crates: Node2D = $"../crates"
|
||||
@onready var coins: Node2D = $"../coins"
|
||||
@onready var enemies: Node2D = $"../enemies"
|
||||
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array = []
|
||||
var bulletMadeTotal:= 0
|
||||
|
||||
var totalCrates := 0
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
game.destroyBox.connect(boxDestroy)
|
||||
#give game controller number of crates
|
||||
Gamecontroller.destroyBox.connect(boxDestroy)
|
||||
for obj in crates.get_children():
|
||||
if obj.is_in_group("destructable"):
|
||||
#increase box counter
|
||||
totalCrates +=1
|
||||
var totalCoins = 0
|
||||
for obj in coins.get_children():
|
||||
if obj.is_in_group("collectibles"):
|
||||
totalCoins+=1
|
||||
obj.coinCollected.connect(Gamecontroller.coinCollected)
|
||||
var totalEnemies = 0
|
||||
for obj in enemies.get_children():
|
||||
if obj.is_in_group("enemies"):
|
||||
totalEnemies += 1
|
||||
obj.playerDamage.connect(Gamecontroller.playerDamaged)
|
||||
|
||||
Gamecontroller.countCrates(totalCrates)
|
||||
|
||||
#subscribe to vital events from the game controller
|
||||
Gamecontroller.levelComplete.connect(changeLevel)
|
||||
Gamecontroller.reset()
|
||||
|
||||
|
||||
func changeLevel(level):
|
||||
get_tree().change_scene_to_file(level)
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
@@ -45,7 +63,7 @@ func onBulletHit(bullet, body):
|
||||
bullet.setSpeed(0)
|
||||
|
||||
print("Scene manager knows bullet hit")
|
||||
game.bulletHit(body)
|
||||
Gamecontroller.bulletHit(body)
|
||||
|
||||
func boxDestroy(body):
|
||||
body.queue_free()
|
||||
Reference in new issue
Block a user