Added resource class to use in frame based sound routines. Created Actor class to extend for enemies and players.
This commit is contained in:
parent
5d0bc33cbf
commit
c4df444848
|
|
@ -9,6 +9,16 @@
|
||||||
config_version=4
|
config_version=4
|
||||||
|
|
||||||
_global_script_classes=[ {
|
_global_script_classes=[ {
|
||||||
|
"base": "KinematicBody2D",
|
||||||
|
"class": "Actor",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/actor.gd"
|
||||||
|
}, {
|
||||||
|
"base": "Resource",
|
||||||
|
"class": "FrameSoundEffects",
|
||||||
|
"language": "GDScript",
|
||||||
|
"path": "res://src/playerC/resources/FrameSounds.gd"
|
||||||
|
}, {
|
||||||
"base": "Reference",
|
"base": "Reference",
|
||||||
"class": "Movement",
|
"class": "Movement",
|
||||||
"language": "GDScript",
|
"language": "GDScript",
|
||||||
|
|
@ -40,6 +50,8 @@ _global_script_classes=[ {
|
||||||
"path": "res://src/state_modifier.gd"
|
"path": "res://src/state_modifier.gd"
|
||||||
} ]
|
} ]
|
||||||
_global_script_class_icons={
|
_global_script_class_icons={
|
||||||
|
"Actor": "",
|
||||||
|
"FrameSoundEffects": "",
|
||||||
"Movement": "",
|
"Movement": "",
|
||||||
"State": "",
|
"State": "",
|
||||||
"StateAnimatedActor": "",
|
"StateAnimatedActor": "",
|
||||||
|
|
|
||||||
17
src/actor.gd
Normal file
17
src/actor.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
class_name Actor
|
||||||
|
extends KinematicBody2D
|
||||||
|
|
||||||
|
|
||||||
|
# Declare member variables here. Examples:
|
||||||
|
# var a = 2
|
||||||
|
# var b = "text"
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
|
||||||
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
|
#func _process(delta):
|
||||||
|
# pass
|
||||||
|
|
@ -9,6 +9,8 @@ export var sprite_facing_right: bool = true
|
||||||
|
|
||||||
onready var movement_animations: AnimatedSprite = $AnimatedSprite
|
onready var movement_animations: AnimatedSprite = $AnimatedSprite
|
||||||
|
|
||||||
|
export(Array, Resource) var SoundEffects
|
||||||
|
|
||||||
onready var movement_state_machine: Node = $Controllers/state_machine
|
onready var movement_state_machine: Node = $Controllers/state_machine
|
||||||
|
|
||||||
onready var player_move_component = $Controllers/move_component
|
onready var player_move_component = $Controllers/move_component
|
||||||
|
|
@ -17,17 +19,24 @@ onready var player_hurtbox = $Hurtbox_Component/CollisionShape2D
|
||||||
|
|
||||||
onready var gun = $Gun
|
onready var gun = $Gun
|
||||||
|
|
||||||
onready var sound_effect_player = $AudioStreamPlayer
|
onready var sound_effect_player = $SE_Player
|
||||||
|
|
||||||
var sound_effects = preload("res://src/playerC/resources/sound_effects.tres")
|
#var sound_effects = preload("res://src/playerC/resources/sound_effects.tres")
|
||||||
|
var sound_effects_dict: Dictionary
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
movement_state_machine.init_animated_actor(self, movement_animations, player_move_component)
|
movement_state_machine.init_animated_actor(self, movement_animations, player_move_component)
|
||||||
player_move_component.player_number = player_number
|
player_move_component.player_number = player_number
|
||||||
sound_effect_player.stream = sound_effects.sounds["pew"]
|
|
||||||
|
# Experimenting with sound based resources I did this and it worked
|
||||||
|
#sound_effect_player.stream = sound_effects.sounds["pew"]
|
||||||
#print(sounds.sounds["pew"])
|
#print(sounds.sounds["pew"])
|
||||||
#sound_effects.play()
|
#sound_effects.play()
|
||||||
|
|
||||||
|
# Trying something new with a custom resourse.
|
||||||
|
for i in SoundEffects:
|
||||||
|
sound_effects_dict[i.animation_name + str(i.frame_number)] = i.sound
|
||||||
|
print (sound_effects_dict)
|
||||||
|
|
||||||
func _unhandled_input(event: InputEvent) -> void:
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
movement_state_machine.process_input(event)
|
movement_state_machine.process_input(event)
|
||||||
|
|
@ -57,6 +66,8 @@ func _physics_process(delta: float) -> void:
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
movement_state_machine.process_frame(delta)
|
movement_state_machine.process_frame(delta)
|
||||||
PlayerInfo.player_position = global_position
|
PlayerInfo.player_position = global_position
|
||||||
|
play_sound_frame(movement_animations.animation , movement_animations.frame)
|
||||||
|
|
||||||
|
|
||||||
##TODO: I don't like player class having do do this.
|
##TODO: I don't like player class having do do this.
|
||||||
## Figure out how to programatically signal subscribe
|
## Figure out how to programatically signal subscribe
|
||||||
|
|
@ -80,5 +91,21 @@ func shoot_projectile():
|
||||||
var is_shooting = false
|
var is_shooting = false
|
||||||
is_shooting = gun.shoot(direction.x)
|
is_shooting = gun.shoot(direction.x)
|
||||||
|
|
||||||
func play_sound():
|
#func play_sound():
|
||||||
sound_effects.stream = "res://assets/Sounds/crappy pew.wav"
|
# sound_effects.stream = "res://assets/Sounds/crappy pew.wav"
|
||||||
|
|
||||||
|
var last_sound_frame_animation: String = ''
|
||||||
|
var last_sound_frame: int = -1
|
||||||
|
func play_sound_frame(animation: String, frame: int ):
|
||||||
|
##DEBUG:
|
||||||
|
#if animation == 'run' and frame == 6:
|
||||||
|
# print("Do the thign! (", animation + str(frame), ")", " (", last_sound_frame_animation + str(last_sound_frame), ")")
|
||||||
|
if animation != last_sound_frame_animation or frame != last_sound_frame:
|
||||||
|
last_sound_frame = frame
|
||||||
|
last_sound_frame_animation = animation
|
||||||
|
var sound_index = animation + str(frame)
|
||||||
|
if sound_effects_dict.has(sound_index):
|
||||||
|
sound_effect_player.stream = sound_effects_dict[sound_index]
|
||||||
|
sound_effect_player.play()
|
||||||
|
print("Playing SE: ", sound_index)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
[gd_scene load_steps=87 format=2]
|
[gd_scene load_steps=90 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://src/playerC/Player-KinematicBody2D.gd" type="Script" id=1]
|
[ext_resource path="res://src/playerC/Player-KinematicBody2D.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://src/playerC/states/idle.gd" type="Script" id=2]
|
[ext_resource path="res://src/playerC/states/idle.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://assets/Sounds/crappy pew.wav" type="AudioStream" id=3]
|
||||||
[ext_resource path="res://src/playerC/states/fall.gd" type="Script" id=4]
|
[ext_resource path="res://src/playerC/states/fall.gd" type="Script" id=4]
|
||||||
[ext_resource path="res://src/playerC/states/move.gd" type="Script" id=5]
|
[ext_resource path="res://src/playerC/states/move.gd" type="Script" id=5]
|
||||||
[ext_resource path="res://src/playerC/player_move_component.gd" type="Script" id=6]
|
[ext_resource path="res://src/playerC/player_move_component.gd" type="Script" id=6]
|
||||||
|
|
@ -9,10 +10,17 @@
|
||||||
[ext_resource path="res://src/playerC/states/hurt.gd" type="Script" id=8]
|
[ext_resource path="res://src/playerC/states/hurt.gd" type="Script" id=8]
|
||||||
[ext_resource path="res://src/playerC/Gun.gd" type="Script" id=9]
|
[ext_resource path="res://src/playerC/Gun.gd" type="Script" id=9]
|
||||||
[ext_resource path="res://src/playerC/states/fire.gd" type="Script" id=10]
|
[ext_resource path="res://src/playerC/states/fire.gd" type="Script" id=10]
|
||||||
|
[ext_resource path="res://src/playerC/resources/FrameSounds.gd" type="Script" id=11]
|
||||||
[ext_resource path="res://src/components/Hurtbox_Component.tscn" type="PackedScene" id=12]
|
[ext_resource path="res://src/components/Hurtbox_Component.tscn" type="PackedScene" id=12]
|
||||||
[ext_resource path="res://src/state_modifier.gd" type="Script" id=13]
|
[ext_resource path="res://src/state_modifier.gd" type="Script" id=13]
|
||||||
[ext_resource path="res://src/state_machine_animated_actor.gd" type="Script" id=14]
|
[ext_resource path="res://src/state_machine_animated_actor.gd" type="Script" id=14]
|
||||||
|
|
||||||
|
[sub_resource type="Resource" id=148]
|
||||||
|
script = ExtResource( 11 )
|
||||||
|
animation_name = "run"
|
||||||
|
frame_number = 6
|
||||||
|
sound = ExtResource( 3 )
|
||||||
|
|
||||||
[sub_resource type="StreamTexture" id=75]
|
[sub_resource type="StreamTexture" id=75]
|
||||||
load_path = "res://.import/MegaMan.png-dc2c293e5a0f5d183ee961942ac90e4a.stex"
|
load_path = "res://.import/MegaMan.png-dc2c293e5a0f5d183ee961942ac90e4a.stex"
|
||||||
|
|
||||||
|
|
@ -409,6 +417,7 @@ extents = Vector2( 14, 18.5 )
|
||||||
[node name="Player" type="KinematicBody2D"]
|
[node name="Player" type="KinematicBody2D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
|
SoundEffects = [ SubResource( 148 ) ]
|
||||||
|
|
||||||
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
|
||||||
frames = SubResource( 147 )
|
frames = SubResource( 147 )
|
||||||
|
|
@ -513,4 +522,4 @@ points = PoolVector2Array( -5, 0, 5, 0 )
|
||||||
width = 2.0
|
width = 2.0
|
||||||
default_color = Color( 1, 0.607843, 0, 1 )
|
default_color = Color( 1, 0.607843, 0, 1 )
|
||||||
|
|
||||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
[node name="SE_Player" type="AudioStreamPlayer" parent="."]
|
||||||
|
|
|
||||||
9
src/playerC/resources/FrameSounds.gd
Normal file
9
src/playerC/resources/FrameSounds.gd
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
class_name FrameSoundEffects
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
#export(Array, Array, AudioStreamSample) var sound_effects
|
||||||
|
|
||||||
|
export (String) var animation_name
|
||||||
|
export(int) var frame_number
|
||||||
|
export (AudioStreamSample) var sound
|
||||||
|
|
||||||
8
src/playerC/resources/TestFrameSounds.tres
Normal file
8
src/playerC/resources/TestFrameSounds.tres
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
[gd_resource type="Resource" load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://src/playerC/resources/FrameSounds.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
animation_name = ""
|
||||||
|
frame_number = 0
|
||||||
|
|
@ -21,7 +21,9 @@ func enter() -> void:
|
||||||
$"../attack".enter()
|
$"../attack".enter()
|
||||||
modifier_stack_ref.push_front($"../attack")
|
modifier_stack_ref.push_front($"../attack")
|
||||||
##TODO: Hacky, don't do it this way.
|
##TODO: Hacky, don't do it this way.
|
||||||
parent.sound_effect_player.play()
|
#parent.sound_effect_player.play()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func process_input(_event: InputEvent) -> State:
|
func process_input(_event: InputEvent) -> State:
|
||||||
if move_component.wants_jump() and parent.is_on_floor():
|
if move_component.wants_jump() and parent.is_on_floor():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user