add sounds for monster 3

This commit is contained in:
Fusselkater 2022-07-20 00:43:24 +02:00
parent e1de3d0748
commit 60d660adbd
6 changed files with 15 additions and 270 deletions

View File

@ -42,6 +42,7 @@ func _physics_process(delta):
cooldown = true
# calculate bullet velocity
bullet_vector = ($monster.global_position - GlobalState.player.global_position).normalized()
$monster/CastSound.play()
$monster/Animation.play("shoot")
yield(get_tree().create_timer(cooldown_time), "timeout")
cooldown = false
@ -66,7 +67,6 @@ func _on_Animatio_finished(anim_name):
bullet.velocity = bullet_vector * bullet_speed
bullet.damage = damage
level.add_child(bullet)
print(bullet)
$monster/ShootSound.play()
$monster/Animation.play_backwards("shoot")

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://objects/characters/monsters/03/assets/sprite1.svg" type="Texture" id=1]
[ext_resource path="res://objects/characters/monsters/03/assets/sprite2.svg" type="Texture" id=2]
[ext_resource path="res://objects/characters/monsters/03/monster_03.gd" type="Script" id=3]
[ext_resource path="res://objects/characters/monsters/03/assets/cast.ogg" type="AudioStream" id=4]
[ext_resource path="res://objects/characters/monsters/03/assets/shoot.ogg" type="AudioStream" id=5]
[sub_resource type="SpriteFrames" id=1]
animations = [ {
@ -55,4 +57,12 @@ shape = SubResource( 2 )
playback_process_mode = 0
anims/shoot = SubResource( 3 )
[node name="CastSound" type="AudioStreamPlayer" parent="monster"]
stream = ExtResource( 4 )
volume_db = -25.0
[node name="ShootSound" type="AudioStreamPlayer" parent="monster"]
stream = ExtResource( 5 )
volume_db = -25.0
[connection signal="animation_finished" from="monster/Animation" to="." method="_on_Animatio_finished"]

View File

@ -1,189 +0,0 @@
extends "res://objects/characters/character.gd"
const SPEED = 400
const JUMP_HEIGHT = 1000
const STRIKED_HEIGHT = 400
export var background_scene : Resource
onready var level = get_parent()
onready var main = level.get_parent()
const ANIMATIONS = {
"idle": {
"animation": "idle",
"transistion": "idle",
"blocks": []
},
"run": {
"animation": "run",
"transistion": "run",
"blocks": []
},
"jump_start": {
"animation": "jump_start",
"transistion": "jump",
"blocks": ["idle", "run", "fall_start", "fall", "fall_end"]
},
"jump": {
"animation": "jump",
"transistion": "jump",
"blocks": ["idle", "run", "fall_start", "fall", "fall_end", "jump_start"]
},
"jump_end": {
"animation": "jump_end",
"transistion": "idle",
"blocks": ["idle", "run", "fall_start", "fall", "fall_end", "jump"]
},
"fall_start": {
"animation": "fall_start",
"transistion": "fall",
"blocks": ["idle", "run", "fall", "fall_end", "jump_start", "jump", "jump_end"]
},
"fall": {
"animation": "fall",
"transistion": "fall",
"blocks": ["idle", "run", "fall_start", "jump_start", "jump", "jump_end"]
},
"fall_end": {
"animation": "fall_end",
"transistion": "idle",
"blocks": ["idle", "run", "fall_start", "fall", "jump_start", "jump", "jump_end"]
},
"striked_start": {
"animation": "jump_start",
"transistion": "striked",
"blocks": ["idle", "run", "fall_start", "fall", "fall_end", "jump_start", "jump", "jump_end"]
},
"striked": {
"animation": "jump",
"transistion": "striked_end",
"blocks": ["idle", "run", "fall_start", "fall", "fall_end", "jump_start", "jump", "jump_end"]
},
"striked_end": {
"animation": "hurt",
"transistion": "idle",
"blocks": ["idle", "run", "fall_start", "fall", "fall_end", "jump_start", "jump", "jump_end"]
}
}
var player_state = "idle"
var invincible_hit = false
var score = 0
func _ready():
$Camera2D.add_child(background_scene.instance())
$Sprite.connect("animation_finished", self, "_next_player_state")
$Sprite.animation = ANIMATIONS[player_state]['animation']
$Camera2D.limit_left = level.camera_limit_left
$Camera2D.limit_right = level.camera_limit_right
$Camera2D.limit_top = level.camera_limit_top
$Camera2D.limit_bottom = level.camera_limit_bottom
yield(get_tree().create_timer(0.5), "timeout")
$Camera2D.smoothing_enabled = true
func _physics_process(delta):
# out-of-screen checking
if position.y > level.camera_limit_bottom and health > 0:
_add_damage(100)
# Fall animation if not on floor
if velocity.y > 1 and not is_on_floor():
_set_player_state("fall_start")
# Movement
if Input.is_action_pressed("move_left") and not Input.is_action_pressed("move_right") \
and not player_state in ["striked_start", "striked", "striked_end"]:
move_left(SPEED)
elif Input.is_action_pressed("move_right") and not Input.is_action_pressed("move_left") \
and not player_state in ["striked_start", "striked", "striked_end"]:
move_right(SPEED)
elif player_state in ["idle", "run", "jump", "jump_end", "fall_end", "striked_end"]:
move_stop()
# On floor detection
if is_on_floor() and not player_state in ["striked", "striked_start"]:
snap = SNAP
_end_animation()
# Jump
if Input.is_action_just_pressed("jump"):
if $RayBottomLeft.is_colliding() or $RayBottomRight.is_colliding() or $RayBottomCenter.is_colliding():
jump()
func _next_player_state():
player_state = ANIMATIONS[player_state]["transistion"]
$Sprite.animation = ANIMATIONS[player_state]['animation']
func _set_player_state(new_state):
if not new_state in ANIMATIONS[player_state]["blocks"]:
player_state = new_state
$Sprite.animation = ANIMATIONS[player_state]['animation']
return true
return false
func move_right(delta):
_set_player_state("run")
get_node("Sprite").set_flip_h(false)
if position.x < level.camera_limit_right:
velocity.x = delta
else:
velocity.x = 0
func move_left(delta):
_set_player_state("run")
get_node("Sprite").set_flip_h(true)
if position.x > level.camera_limit_left:
velocity.x = -delta
else:
velocity.x = 0
func move_stop():
_set_player_state("idle")
velocity.x = 0
func jump():
if _set_player_state("jump_start"):
snap = Vector2.ZERO
position.y += get_floor_velocity().y * get_physics_process_delta_time() \
- GRAVITY * get_physics_process_delta_time() - 3
velocity.y -= JUMP_HEIGHT
func _on_GroundCheck_body_entered(body):
_end_animation()
func _end_animation():
if velocity.y > 0 and player_state in ["jump_start", "jump"]:
_set_player_state("jump_end")
if velocity.y > 0 and player_state in ["fall_start", "fall"]:
_set_player_state("fall_end")
if velocity.y > 0 and player_state in ["striked_start", "striked"]:
_set_player_state("striked_end")
func monster_hit(direction : int, damage: int):
if not invincible_hit:
invincible_hit = true
_set_player_state("striked_start")
_add_damage(damage)
snap = Vector2.ZERO
velocity.y = -300
velocity.x = direction * 5
yield(get_tree().create_timer(1.0), "timeout")
invincible_hit = false
func _on_Enemy_Entered(body):
body.stomped_on_head()
_set_player_state("jump")
func coin_collected(value):
main.add_score(value)
func _add_damage(value):
health -= value
GlobalState.health = health
if health <= 0:
main.player_died()
func _on_screen_exited():
print("exited")
print($VisibilityNotifier2D.is_on_screen())
_add_damage(100)

View File

@ -1,76 +0,0 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://objects/characters/flopsy/flopsy.tres" type="SpriteFrames" id=1]
[ext_resource path="res://objects/characters/player.gd" type="Script" id=11]
[sub_resource type="CapsuleShape2D" id=4]
radius = 164.75
height = 138.75
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 190.5, 100.625 )
[sub_resource type="CircleShape2D" id=5]
radius = 79.0
[node name="Player" type="KinematicBody2D"]
z_index = 10
collision_mask = 4
script = ExtResource( 11 )
[node name="Sprite" type="AnimatedSprite" parent="."]
frames = ExtResource( 1 )
animation = "idle"
frame = 6
playing = true
__meta__ = {
"_edit_lock_": true
}
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( -14.75, -7.875 )
shape = SubResource( 4 )
[node name="GroundCheck" type="Area2D" parent="."]
collision_mask = 4
[node name="CollisionShape2D" type="CollisionShape2D" parent="GroundCheck"]
position = Vector2( -22.5, 323.375 )
shape = SubResource( 3 )
[node name="Camera2D" type="Camera2D" parent="."]
current = true
limit_left = 0
limit_bottom = 1080
limit_smoothed = true
[node name="RayBottomLeft" type="RayCast2D" parent="."]
position = Vector2( -184, 0 )
enabled = true
cast_to = Vector2( 0, 400 )
collision_mask = 6
collide_with_areas = true
[node name="RayBottomRight" type="RayCast2D" parent="."]
position = Vector2( 154, 0 )
enabled = true
cast_to = Vector2( 0, 400 )
collision_mask = 6
collide_with_areas = true
[node name="RayBottomCenter" type="RayCast2D" parent="."]
position = Vector2( -14, 0 )
enabled = true
cast_to = Vector2( 0, 400 )
collision_mask = 6
collide_with_areas = true
[node name="EnemyBottomCheck" type="Area2D" parent="."]
collision_mask = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyBottomCheck"]
position = Vector2( -13, 225 )
shape = SubResource( 5 )
[connection signal="body_entered" from="GroundCheck" to="." method="_on_GroundCheck_body_entered"]
[connection signal="body_entered" from="EnemyBottomCheck" to="." method="_on_Enemy_Entered"]

View File

@ -6,7 +6,7 @@
[ext_resource path="res://common/tiles/grasland.tres" type="TileSet" id=4]
[ext_resource path="res://objects/coin/coin.tscn" type="PackedScene" id=5]
[ext_resource path="res://objects/characters/monsters/01/monster_01.tscn" type="PackedScene" id=6]
[ext_resource path="res://objects/characters/player.tscn" type="PackedScene" id=7]
[ext_resource path="res://objects/characters/player/player.tscn" type="PackedScene" id=7]
[ext_resource path="res://objects/lift/lift.tscn" type="PackedScene" id=8]
[ext_resource path="res://objects/key/key.tscn" type="PackedScene" id=9]
[ext_resource path="res://objects/door/door.tscn" type="PackedScene" id=10]

View File

@ -2,7 +2,7 @@
[ext_resource path="res://scenes/levels/02/level_02.gd" type="Script" id=1]
[ext_resource path="res://common/tiles/grasland.tres" type="TileSet" id=2]
[ext_resource path="res://objects/characters/player.tscn" type="PackedScene" id=3]
[ext_resource path="res://objects/characters/player/player.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/levels/02/background_02.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenes/levels/02/CollidingMountain.tscn" type="PackedScene" id=5]
[ext_resource path="res://objects/characters/monsters/02/monster_02.tscn" type="PackedScene" id=6]