added coins, new parallax graphics, etc.
This commit is contained in:
1 parent
2461fd278a
commit
2014ed0b37
28 files changed
+853
-11
No files matched your search
@@ -2,10 +2,16 @@ class_name Bullet extends Area2D
|
||||
|
||||
signal bulletHitSignal(body, bullet)
|
||||
|
||||
@onready var bullet_graphic: Sprite2D = $BulletGraphic
|
||||
|
||||
var SPEED: float = 700.0
|
||||
|
||||
func setSpeed(new_speed: float):
|
||||
SPEED = new_speed
|
||||
if new_speed < 0:
|
||||
bullet_graphic.flip_h = true
|
||||
if new_speed > 0:
|
||||
bullet_graphic.flip_h = false
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
position += transform.x * SPEED * delta
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class_name Coin extends Area2D
|
||||
|
||||
signal coinCollectedSignal(body, coin)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
coinCollectedSignal.emit(body, self)
|
||||
@@ -0,0 +1 @@
|
||||
uid://t0jdd3a3km2a
|
||||
@@ -4,6 +4,8 @@ extends Node2D
|
||||
|
||||
signal playerDamage
|
||||
|
||||
var score := 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
@@ -24,3 +26,8 @@ func _on_trigger(effect: Variant, body: Variant) -> void:
|
||||
func onBulletHitSignal(body: Node, bullet: Bullet):
|
||||
body.queue_free()
|
||||
|
||||
func onCoinCollected(body, coin: Coin):
|
||||
if body is Player:
|
||||
score += 1
|
||||
coin.queue_free()
|
||||
|
||||
+2
-2
@@ -94,12 +94,12 @@ func handle_movement(delta: float):
|
||||
|
||||
func handle_input():
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
jump_buffer.start()
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
direction = Input.get_axis("ui_left", "ui_right")
|
||||
direction = Input.get_axis("move_left", "move_right")
|
||||
|
||||
if direction > 0:
|
||||
facing = FaceDirection.RIGHT
|
||||
|
||||
@@ -5,25 +5,36 @@ const bullet_scene = preload("res://scenes/bullet.tscn")
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var triggers: Node2D = $"../triggers"
|
||||
|
||||
@onready var coins: Node2D = $"../coins"
|
||||
|
||||
var MAX_BULLET := 50
|
||||
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:
|
||||
for trig in triggers.get_children():
|
||||
if trig is Trigger:
|
||||
trig.areaTriggerSignal.connect(game._on_trigger)
|
||||
|
||||
if coins:
|
||||
for coin in coins.get_children():
|
||||
if coin is Coin:
|
||||
coin.coinCollectedSignal.connect(game.onCoinCollected)
|
||||
|
||||
|
||||
func make_bullet(start_position: Transform2D, speed: int):
|
||||
var new_bullet = bullet_factory(start_position, speed)
|
||||
if new_bullet:
|
||||
owner.add_child(new_bullet)
|
||||
new_bullet.setSpeed(speed)
|
||||
|
||||
func reload_bullet(bullet: Bullet):
|
||||
available_bullets.push(bullet)
|
||||
@@ -31,7 +42,6 @@ func reload_bullet(bullet: Bullet):
|
||||
func bullet_factory(start_position: Transform2D, speed: int) -> Bullet:
|
||||
var shot_bullet = available_bullets.pop_back()
|
||||
shot_bullet.global_transform = start_position
|
||||
shot_bullet.setSpeed(speed)
|
||||
|
||||
available_bullets.push_front(shot_bullet)
|
||||
|
||||
|
||||
Reference in new issue
Block a user