fin
This commit is contained in:
1 parent
8768909429
commit
3607e63548
9 files changed
+138
-15
No files matched your search
@@ -0,0 +1,17 @@
|
||||
class_name Bullet extends Area2D
|
||||
|
||||
var speed := 700
|
||||
signal bulletDamageSignal(body, bullet)
|
||||
|
||||
# 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 += transform.x * speed * delta
|
||||
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("Bullet hit something " + body.to_string())
|
||||
bulletDamageSignal.emit(body, self)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ryrc3a88d0nh
|
||||
@@ -22,3 +22,10 @@ func _on_trigger(effect: Variant, Object: Variant) -> void:
|
||||
print("Trigger wants to teleport")
|
||||
if Object is Crate:
|
||||
teleportSignal.emit(Object)
|
||||
|
||||
func _on_bullet_hit(body, bullet) -> void:
|
||||
print("GC knows bullet hit")
|
||||
if body is Crate:
|
||||
body.queue_free()
|
||||
bullet.queue_free()
|
||||
|
||||
+53
-2
@@ -1,15 +1,39 @@
|
||||
class_name Player extends CharacterBody2D
|
||||
|
||||
@onready var right_cast: RayCast2D = $RightCast
|
||||
@onready var left_cast: RayCast2D = $LeftCast
|
||||
@onready var right_spawn: Marker2D = $RightSpawn
|
||||
@onready var left_spawn: Marker2D = $LeftSpawn
|
||||
|
||||
@export var shove_power:= 800
|
||||
@export var bump_power:= 50
|
||||
|
||||
enum FaceDirection {LEFT, RIGHT}
|
||||
var facing: FaceDirection = FaceDirection.RIGHT
|
||||
|
||||
var pushRightEnabled = false
|
||||
var pushLeftEnabled = false
|
||||
var pushTarget:Crate
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle shove.
|
||||
if Input.is_action_just_pressed("shove"):
|
||||
print("Player shove!")
|
||||
if pushRightEnabled and facing==FaceDirection.RIGHT:
|
||||
# shove it right
|
||||
pushTarget.apply_central_impulse(Vector2(1,0) * shove_power)
|
||||
if pushLeftEnabled and facing==FaceDirection.LEFT:
|
||||
# shove it left
|
||||
pushTarget.apply_central_impulse(Vector2(-1,0) * shove_power)
|
||||
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
@@ -19,6 +43,11 @@ func _physics_process(delta: float) -> void:
|
||||
var direction := Input.get_axis("ui_left", "ui_right")
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
# set player direction
|
||||
if direction < 0:
|
||||
facing = FaceDirection.LEFT
|
||||
if direction > 0:
|
||||
facing = FaceDirection.RIGHT
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
|
||||
@@ -27,4 +56,26 @@ func _physics_process(delta: float) -> void:
|
||||
for i in get_slide_collision_count():
|
||||
var c = get_slide_collision(i)
|
||||
if c.get_collider() is RigidBody2D:
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * 200)
|
||||
c.get_collider().apply_central_impulse(-c.get_normal() * bump_power)
|
||||
|
||||
if right_cast.is_colliding():
|
||||
print("Something on my right")
|
||||
# get the thing i can shove
|
||||
var collider = right_cast.get_collider()
|
||||
if collider is Node:
|
||||
pushRightEnabled = true
|
||||
pushTarget = collider
|
||||
else:
|
||||
pushRightEnabled = false
|
||||
|
||||
if left_cast.is_colliding():
|
||||
print("Something on my left")
|
||||
# get the thing i can shove
|
||||
var collider = left_cast.get_collider()
|
||||
if collider is Node:
|
||||
pushLeftEnabled = true
|
||||
pushTarget = collider
|
||||
else:
|
||||
pushLeftEnabled = false
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ class_name SceneManager extends Node2D
|
||||
|
||||
@onready var triggers: Node2D = $"../Triggers"
|
||||
@onready var game: GameController = $".."
|
||||
@onready var bullet: Bullet = $"../Bullet"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
buildLevel()
|
||||
game.teleportSignal.connect(teleport)
|
||||
bullet.bulletDamageSignal.connect(game._on_bullet_hit)
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
Reference in new issue
Block a user