graphics
This commit is contained in:
1 parent
abd5200f21
commit
08d24bc467
15 files changed
+491
-22
No files matched your search
+58
-5
@@ -6,23 +6,60 @@ const bullet_scene = preload("res://Scenes/bullet.tscn")
|
||||
@onready var left_cast: RayCast2D = $LeftCast
|
||||
@onready var bullet_spawn_point_right: Node2D = $BulletSpawnPointRight
|
||||
@onready var bullet_spawn_point_left: Node2D = $BulletSpawnPointLeft
|
||||
@onready var jump_buffer_timer: Timer = $jumpbuffertimer
|
||||
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
|
||||
|
||||
const SPEED = 300.0
|
||||
const JUMP_VELOCITY = -400.0
|
||||
const PUSH_POWER = 2000
|
||||
var upJump:bool = false
|
||||
@export var acceleration:int=5
|
||||
|
||||
var direction: float
|
||||
enum FaceDirection{LEFT, RIGHT}
|
||||
var facing: FaceDirection = FaceDirection.RIGHT
|
||||
var pushTarget: Object
|
||||
var pushEnabled: bool = false
|
||||
|
||||
enum State{IDLE,RUN,JUMP,FALLING}
|
||||
var current_state:State = State.IDLE
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
handle_input(delta)
|
||||
handle_movement(delta)
|
||||
handle_states()
|
||||
handle_animation()
|
||||
handle_collisions(delta)
|
||||
|
||||
func handle_states() -> void:
|
||||
match current_state:
|
||||
State.IDLE when velocity.x !=0:
|
||||
current_state = State.RUN
|
||||
State.RUN:
|
||||
if velocity.x == 0:
|
||||
current_state = State.IDLE
|
||||
#player steps off ledge
|
||||
if not is_on_floor() && velocity.y >0:
|
||||
current_state = State.FALLING
|
||||
State.FALLING when is_on_floor():
|
||||
if velocity.x == 0:
|
||||
current_state = State.IDLE
|
||||
else:
|
||||
current_state = State.RUN
|
||||
State.JUMP when velocity.y >0:
|
||||
current_state = State.FALLING
|
||||
|
||||
func handle_animation() -> void:
|
||||
match current_state:
|
||||
State.IDLE:
|
||||
player_graphic.play("IDLE")
|
||||
State.RUN:
|
||||
player_graphic.play("RUN")
|
||||
State.FALLING:
|
||||
player_graphic.play("FALL")
|
||||
State.JUMP:
|
||||
if upJump:
|
||||
player_graphic.play("JUMP")
|
||||
|
||||
func handle_input(delta: float) -> void:
|
||||
var dir: int = 0
|
||||
match facing:
|
||||
@@ -33,7 +70,7 @@ func handle_input(delta: float) -> void:
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jump_buffer_timer.start()
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
@@ -41,8 +78,10 @@ func handle_input(delta: float) -> void:
|
||||
|
||||
if direction < 0:
|
||||
facing = FaceDirection.LEFT
|
||||
player_graphic.flip_h = true
|
||||
elif direction > 0:
|
||||
facing = FaceDirection.RIGHT
|
||||
player_graphic.flip_h = false
|
||||
|
||||
if Input.is_action_just_pressed("ForcePush") && pushEnabled:
|
||||
pushTarget.apply_central_impulse(Vector2(dir, 0) * PUSH_POWER)
|
||||
@@ -57,10 +96,18 @@ func handle_input(delta: float) -> void:
|
||||
|
||||
func handle_movement(delta: float) -> void:
|
||||
handle_gravity(delta)
|
||||
if direction:
|
||||
velocity.x = direction * SPEED
|
||||
if direction ==0:
|
||||
velocity.x = move_toward(velocity.x,0, acceleration)
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.x = move_toward(velocity.x, SPEED * direction, acceleration)
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
if is_on_floor() && jump_buffer_timer.time_left >0:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jump_buffer_timer.stop()
|
||||
current_state = State.JUMP
|
||||
upJump = true
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func handle_collisions(delta: float) -> void:
|
||||
@@ -90,3 +137,9 @@ func handle_gravity(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
match current_state:
|
||||
State.JUMP:
|
||||
upJump = false
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
signal playerDamage
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
@@ -13,6 +13,11 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_trigger(effect: Variant, body: Variant) -> void:
|
||||
print("GC see trigger " + effect)
|
||||
match effect:
|
||||
"player_hurt":
|
||||
if body is Player:
|
||||
print("hurt the player")
|
||||
playerDamage.emit()
|
||||
if body.name == "world-boundary":
|
||||
return
|
||||
if not body is Player:
|
||||
|
||||
@@ -2,7 +2,14 @@ class_name SCENEMANAGER extends Node2D
|
||||
|
||||
const bulletscn = preload("res://Scenes/bullet.tscn")
|
||||
@onready var game: Node2D = $".."
|
||||
@onready var triggers: Node2D = $"../Triggers"
|
||||
|
||||
func _ready() -> void:
|
||||
if triggers:
|
||||
for obj in triggers.get_children():
|
||||
if obj is Trigger:
|
||||
obj.areaTriggerSignal.connect(game._on_trigger)
|
||||
|
||||
var bullets: Array[Bullet] = []
|
||||
const MAX_BULLETS = 10
|
||||
var current_bullet = 0
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
extends Area2D
|
||||
class_name Trigger extends Area2D
|
||||
|
||||
@export var effect := "destroy"
|
||||
|
||||
|
||||
Reference in new issue
Block a user