massive work towards godot 4
This commit is contained in:
49
scripts/equipment/equipment.gd
Normal file
49
scripts/equipment/equipment.gd
Normal file
@ -0,0 +1,49 @@
|
||||
class_name Equipment
|
||||
extends Node2D
|
||||
|
||||
signal sheath(bool)
|
||||
|
||||
@export
|
||||
var auto_z_index: bool = true
|
||||
|
||||
@export
|
||||
var auto_flip: bool = true
|
||||
|
||||
var _sheathed: bool = true
|
||||
|
||||
var _original_z_index: int
|
||||
|
||||
func init_equipment() -> void:
|
||||
self._original_z_index = self.z_index
|
||||
self._update_z_index()
|
||||
|
||||
func is_sheathed() -> bool:
|
||||
return self._sheathed
|
||||
|
||||
func toggle_sheath() -> void:
|
||||
self._sheathed = !self._sheathed
|
||||
|
||||
self._update_z_index()
|
||||
|
||||
self.sheath.emit(self._sheathed)
|
||||
|
||||
func _update_z_index() -> void:
|
||||
if self.auto_z_index:
|
||||
if self._sheathed:
|
||||
self.z_index = _original_z_index - 100
|
||||
else:
|
||||
self.z_index = _original_z_index
|
||||
|
||||
func is_facing_left() -> bool:
|
||||
return get_global_mouse_position().x < global_position.x
|
||||
|
||||
func process_equipment(_delta: float) -> void:
|
||||
self._update_z_index()
|
||||
|
||||
if auto_flip:
|
||||
if self.is_facing_left():
|
||||
self.scale.x = -1
|
||||
else:
|
||||
self.scale.x = 1
|
||||
else:
|
||||
self.scale.x = 1
|
77
scripts/equipment/pistol.gd
Normal file
77
scripts/equipment/pistol.gd
Normal file
@ -0,0 +1,77 @@
|
||||
class_name EquipmentGun
|
||||
extends Equipment
|
||||
|
||||
@export
|
||||
var bullet: PackedScene
|
||||
|
||||
@export
|
||||
var left_arm: Line2D
|
||||
|
||||
@export
|
||||
var right_arm: Line2D
|
||||
|
||||
@export
|
||||
var origin: Node2D
|
||||
|
||||
@export
|
||||
var bullet_spawning_point: Node2D
|
||||
|
||||
@export
|
||||
var pistol_handle: Node2D
|
||||
|
||||
@export
|
||||
var sprite: Sprite2D
|
||||
|
||||
@export
|
||||
var sheath_point: Node2D
|
||||
|
||||
@onready
|
||||
var _original_sprite_pos: Vector2 = sprite.position
|
||||
|
||||
@onready
|
||||
var _original_sprite_rotation: float = sprite.rotation
|
||||
|
||||
func _ready() -> void:
|
||||
self.init_equipment()
|
||||
|
||||
self.sheath.connect(self._on_sheath)
|
||||
self._on_sheath(self.is_sheathed())
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
self.process_equipment(delta)
|
||||
|
||||
if self.is_sheathed():
|
||||
return
|
||||
|
||||
self.origin.look_at(self.get_global_mouse_position())
|
||||
|
||||
self.right_arm.clear_points()
|
||||
self.right_arm.add_point(Vector2(2.5, 0))
|
||||
self.right_arm.add_point(to_local(self.pistol_handle.global_position))
|
||||
self.left_arm.clear_points()
|
||||
self.left_arm.add_point(Vector2(-2.5, 0))
|
||||
self.left_arm.add_point(to_local(self.pistol_handle.global_position))
|
||||
|
||||
self.sprite.flip_v = self.is_facing_left()
|
||||
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
var projectile: Node2D = self.bullet.instantiate()
|
||||
self.get_parent().get_parent().add_child(projectile)
|
||||
projectile.global_position = self.bullet_spawning_point.global_position
|
||||
projectile.rotation = origin.rotation
|
||||
|
||||
func _on_sheath(sheathed: bool):
|
||||
self.auto_flip = sheathed
|
||||
|
||||
if sheathed:
|
||||
self.origin.rotation = 0
|
||||
self.sprite.position = self.sheath_point.position
|
||||
self.sprite.rotation = self.sheath_point.rotation
|
||||
|
||||
self.right_arm.clear_points()
|
||||
self.left_arm.clear_points()
|
||||
else:
|
||||
self.sprite.position = self._original_sprite_pos
|
||||
self.sprite.rotation = self._original_sprite_rotation
|
||||
|
||||
|
33
scripts/equipment/saber.gd
Normal file
33
scripts/equipment/saber.gd
Normal file
@ -0,0 +1,33 @@
|
||||
class_name EquipmentSaber
|
||||
extends Equipment
|
||||
|
||||
@export
|
||||
var animation_player: AnimationPlayer
|
||||
|
||||
@export
|
||||
var area: Area2D
|
||||
|
||||
@export
|
||||
var damage: int = 1
|
||||
|
||||
func _ready() -> void:
|
||||
self.init_equipment()
|
||||
|
||||
self.area.body_entered.connect(self._on_body_entered)
|
||||
self._update_z_index()
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
self.process_equipment(delta)
|
||||
|
||||
if self.is_sheathed():
|
||||
if self.animation_player.current_animation != "sheathed":
|
||||
self.animation_player.play("sheathed")
|
||||
else:
|
||||
if not self.animation_player.current_animation in ["attack", "idle"]:
|
||||
self.animation_player.play("idle")
|
||||
if Input.is_action_just_pressed("attack"):
|
||||
self.animation_player.play("attack")
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.has_method("take_damage"):
|
||||
body.take_damage(self.damage)
|
Reference in New Issue
Block a user