Added player and a basic test level
This commit is contained in:
68
Entities/Player/player.gd
Normal file
68
Entities/Player/player.gd
Normal file
@@ -0,0 +1,68 @@
|
||||
class_name Player
|
||||
extends CharacterBody2D
|
||||
|
||||
signal move
|
||||
|
||||
#nodes
|
||||
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var hit_animation_player: AnimationPlayer = $HitAnimationPlayer
|
||||
@onready var camera_center: Marker2D = $Markers/CameraCenter
|
||||
@onready var center: Marker2D = $Markers/Center
|
||||
|
||||
#State Vars
|
||||
const GRAVITY: int = 700
|
||||
@export var speed: float = 1000
|
||||
@export var maxSpeed: float = 175
|
||||
@export var friction: int = 1000
|
||||
@export var airFriction: int = 250
|
||||
@export var jumpHight: float = -275
|
||||
@export var maxJumpCount: int = 1
|
||||
@export var ammo: int = 3
|
||||
|
||||
var deathEffect: PackedScene = preload("uid://dm4oirxl6bpnn")
|
||||
var camreaCenterPosition: Vector2
|
||||
var swordHitBoxXPos: float
|
||||
|
||||
func _ready() -> void:
|
||||
#connects the signal from scene manager to on spawn
|
||||
#sets the things to make player movement better
|
||||
set_floor_constant_speed_enabled(true)
|
||||
floor_snap_length = 2
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _physics_process(delta: float) -> void:
|
||||
#calls move and slide so the state scripts don't have to cause that causes bugs
|
||||
move_and_slide()
|
||||
#emits move purly for jump state cause that is dependent on exact move and slide in the code
|
||||
move.emit()
|
||||
|
||||
#kills the player when they get too low
|
||||
if global_position.y > 200:
|
||||
player_death()
|
||||
|
||||
#sets the players pos to the spawn pos so the player statrs on the correct door to the level
|
||||
func on_spawn(spawnPosition: Vector2):
|
||||
global_position = spawnPosition
|
||||
|
||||
func player_death() -> void:
|
||||
Util.add_effect_to_self(self, deathEffect)
|
||||
queue_free()
|
||||
|
||||
func _on_hurt_box_area_entered(area: Area2D) -> void:
|
||||
#this checks if the area is a bullet
|
||||
if !area.get_parent().is_in_group("Enemy Bullet"):
|
||||
return
|
||||
var body = area.get_parent() as Node
|
||||
hurt(body)
|
||||
|
||||
func _on_hurt_box_body_entered(body: Node2D) -> void:
|
||||
if !body.is_in_group("Enemy"):
|
||||
return
|
||||
hurt(body)
|
||||
|
||||
func hurt(enemy: Node2D) -> void:
|
||||
PlayerManager.decress_health(enemy.damage)
|
||||
hit_animation_player.play("hit")
|
||||
|
||||
if PlayerManager.currenthealth == 0:
|
||||
player_death()
|
||||
Reference in New Issue
Block a user