Add combat combo gameplay
This commit is contained in:
42
scenes/combat/player_projectile.gd
Normal file
42
scenes/combat/player_projectile.gd
Normal file
@@ -0,0 +1,42 @@
|
||||
class_name PlayerProjectile
|
||||
extends Node2D
|
||||
|
||||
const EFFECT_TEXTURE := preload("res://assets/art/effects/effect_sheet.png")
|
||||
const FRAME_COUNT := 4
|
||||
const FRAME_TIME := 0.06
|
||||
const LIFE_TIME := 1.2
|
||||
|
||||
var direction := Vector2.RIGHT
|
||||
var speed := 360.0
|
||||
var _age := 0.0
|
||||
var _sprite: Sprite2D
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_create_sprite()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("player_projectiles")
|
||||
if _sprite == null:
|
||||
_create_sprite()
|
||||
|
||||
|
||||
func _create_sprite() -> void:
|
||||
_sprite = Sprite2D.new()
|
||||
_sprite.texture = EFFECT_TEXTURE
|
||||
_sprite.hframes = 6
|
||||
_sprite.vframes = 2
|
||||
_sprite.centered = true
|
||||
_sprite.scale = Vector2(2.0, 2.0)
|
||||
add_child(_sprite)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_age += delta
|
||||
position += direction.normalized() * speed * delta
|
||||
_sprite.frame = int(_age / FRAME_TIME) % FRAME_COUNT
|
||||
if direction.x < 0.0:
|
||||
_sprite.flip_h = true
|
||||
if _age >= LIFE_TIME:
|
||||
queue_free()
|
||||
Reference in New Issue
Block a user