Added vegetation, small crates, coins, enemies
This commit is contained in:
1 parent
a999312c69
commit
0d6ffa22df
43 files changed
+672
-172
No files matched your search
@@ -0,0 +1,9 @@
|
||||
class_name Coin
|
||||
extends Area2D
|
||||
|
||||
signal coin_collected(body, coin)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print_debug("body connected with coin")
|
||||
if body is Player:
|
||||
coin_collected.emit(body, self)
|
||||
@@ -0,0 +1 @@
|
||||
uid://dpcuif8u6kqj5
|
||||
@@ -1,5 +1,7 @@
|
||||
extends Node2D
|
||||
|
||||
var coins_collected : int = 0
|
||||
var total_coins : int = 0
|
||||
|
||||
func _on_trigger_fired(intent: Variant, body: PhysicsBody2D) -> void:
|
||||
print("Game controller knows %s trigger fired " % intent)
|
||||
@@ -10,3 +12,21 @@ func _on_trigger_fired(intent: Variant, body: PhysicsBody2D) -> void:
|
||||
body.queue_free()
|
||||
"powerup":
|
||||
print("Power this thing up!")
|
||||
|
||||
func on_coin_collected(_body, coin) -> void:
|
||||
print_debug("GC knows coin collected")
|
||||
coins_collected += 1
|
||||
print_debug("Coins collected: %s" % str(coins_collected))
|
||||
print_debug("There are %s coins remaining" % str(total_coins - coins_collected))
|
||||
coin.queue_free()
|
||||
if coins_collected >= total_coins:
|
||||
print_debug("You win!")
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
get_tree().call_deferred("reload_current_scene")
|
||||
|
||||
func on_player_slimed(body, slime) -> void:
|
||||
print_debug("GC knows player slimed")
|
||||
|
||||
func set_total_coins(value) -> void:
|
||||
total_coins = value
|
||||
print_debug("There are %s coins in the level" % str(total_coins))
|
||||
+26
-10
@@ -1,4 +1,5 @@
|
||||
class_name Player extends CharacterBody2D
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
## Character controller.
|
||||
## TODO: fix bullet cooldown timer
|
||||
|
||||
@@ -6,7 +7,7 @@ const SPEED = 200.0
|
||||
const JUMP_VELOCITY = -500.0
|
||||
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
enum State{IDLE, WALK, JUMP, FALLING, SHOOT_STILL, SHOOT_RUN}
|
||||
enum State{IDLE, WALK, JUMP, FALLING, SHOOT_STILL, SHOOT_RUN, SHOVE}
|
||||
|
||||
@export var BUMP_POWER := 50
|
||||
@export var SHOVE_POWER := 300
|
||||
@@ -41,6 +42,7 @@ func _physics_process(delta: float) -> void:
|
||||
handle_collisions()
|
||||
update_state()
|
||||
update_animation()
|
||||
update_debug()
|
||||
|
||||
func handle_input() -> void:
|
||||
|
||||
@@ -60,14 +62,18 @@ func handle_input() -> void:
|
||||
facing = FaceDirection.RIGHT
|
||||
|
||||
# Handle shoving.
|
||||
if Input.is_action_just_pressed("shove") and push_enabled == true:
|
||||
var shove_direction : int
|
||||
match facing:
|
||||
FaceDirection.RIGHT:
|
||||
shove_direction = 1
|
||||
FaceDirection.LEFT:
|
||||
shove_direction = -1
|
||||
push_target.apply_central_impulse(Vector2(shove_direction, 0) * SHOVE_POWER)
|
||||
if Input.is_action_just_pressed("shove"):
|
||||
print_debug("Shoving!")
|
||||
if push_enabled == true:
|
||||
var shove_direction : int
|
||||
match facing:
|
||||
FaceDirection.RIGHT:
|
||||
shove_direction = 1
|
||||
FaceDirection.LEFT:
|
||||
shove_direction = -1
|
||||
print_debug("Shoving %s" % push_target.name)
|
||||
current_state = State.SHOVE
|
||||
push_target.apply_central_impulse(Vector2(shove_direction, 0) * SHOVE_POWER)
|
||||
|
||||
# Handle shooting
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
@@ -177,6 +183,11 @@ func update_state() -> void:
|
||||
await player_sprite.animation_finished
|
||||
current_state = State.WALK
|
||||
|
||||
# Player shoving
|
||||
State.SHOVE:
|
||||
await player_sprite.animation_finished
|
||||
current_state = State.IDLE
|
||||
|
||||
func update_animation() -> void:
|
||||
match facing:
|
||||
FaceDirection.LEFT:
|
||||
@@ -196,3 +207,8 @@ func update_animation() -> void:
|
||||
player_sprite.play("shoot_still")
|
||||
State.SHOOT_RUN:
|
||||
player_sprite.play("shoot_run")
|
||||
State.SHOVE:
|
||||
player_sprite.play("punch")
|
||||
|
||||
func update_debug():
|
||||
%StateLabel.text = "Current state: %s" % current_state
|
||||
@@ -7,6 +7,26 @@ var bullet_array = []
|
||||
var total_allowed_bullets : int = 7
|
||||
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var coins: Node = $"../Coins"
|
||||
@onready var enemies: Node = $"../Enemies"
|
||||
|
||||
func _ready() -> void:
|
||||
build_level()
|
||||
|
||||
func build_level() -> void:
|
||||
var total_coins : int = 0
|
||||
if coins:
|
||||
for coin in coins.get_children():
|
||||
if coin is Coin:
|
||||
total_coins += 1
|
||||
coin.coin_collected.connect(game.on_coin_collected)
|
||||
game.set_total_coins(total_coins)
|
||||
var total_enemies : int = 0
|
||||
if enemies:
|
||||
for enemy in enemies.get_children():
|
||||
if enemy is Slimer:
|
||||
total_enemies += 1
|
||||
enemy.player_slimed.connect(game.on_player_slimed)
|
||||
|
||||
func make_bullet(_bullet_position, _bullet_speed) -> void:
|
||||
print("make a bullet; put it in the world")
|
||||
@@ -32,7 +52,6 @@ func bullet_factory() -> Bullet:
|
||||
bullet_array.push_front(my_bullet)
|
||||
return my_bullet
|
||||
|
||||
|
||||
func _on_world_boundary_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
var current_scene = get_tree()
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class_name Slimer
|
||||
extends Area2D
|
||||
|
||||
signal player_slimed(body, slime)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body is Player:
|
||||
print_debug("Player hit Slimer")
|
||||
player_slimed.emit(body, self)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bcxorf6dwnwbv
|
||||
Reference in new issue
Block a user