-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cats run away when you take damage (#657)
- Loading branch information
1 parent
49fc32e
commit 9966126
Showing
5 changed files
with
148 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
extends KinematicBody2D | ||
|
||
export var velocity := Vector2.ZERO | ||
export var jump_force := -300 | ||
export var gravity_vec := Vector2.DOWN * 270 | ||
|
||
export var sound_db := -1 | ||
export var sound_pitch_scale := 0.85 | ||
|
||
export var escape_time := 0.5 #The cat can not be recollected for this many seconds after it spawns, to avoid immediately recollecting it | ||
|
||
export(PackedScene) var cat_scene = preload("res://scenes/friends/Cat.tscn") | ||
|
||
var collected := false | ||
|
||
onready var escape_timer := $Timer | ||
onready var audio_meow := $MeowStream | ||
|
||
|
||
func _ready(): | ||
escape_timer.start(escape_time) | ||
|
||
audio_meow.volume_db = sound_db | ||
audio_meow.pitch_scale = sound_pitch_scale | ||
|
||
audio_meow.play() | ||
|
||
|
||
func _physics_process(delta): | ||
velocity += gravity_vec * delta | ||
move_and_slide(velocity, Vector2.UP) | ||
if is_on_floor(): | ||
velocity.y = jump_force | ||
audio_meow.play() | ||
if is_on_wall(): | ||
velocity.x *= -1 | ||
if is_on_ceiling(): #BONK! You fall down now | ||
velocity.y = max(0, velocity.y) | ||
|
||
|
||
func collect(): | ||
collected = true | ||
|
||
visible = false | ||
set_physics_process(false) | ||
|
||
audio_meow.volume_db = 0 | ||
audio_meow.pitch_scale = 1.05 | ||
audio_meow.play() | ||
|
||
|
||
func _on_PlayerHitbox_body_entered(body : KinematicBody2D): | ||
if collected: | ||
return | ||
if escape_timer.time_left > 0: | ||
return | ||
if not body is Player: | ||
return | ||
|
||
var cat = cat_scene.instance() | ||
get_parent().call_deferred("add_child", cat) | ||
cat.set_player(body) | ||
cat.global_position = global_position | ||
|
||
collect() | ||
|
||
|
||
|
||
func _on_MeowStream_finished(): | ||
if collected: | ||
queue_free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[gd_scene load_steps=6 format=2] | ||
|
||
[ext_resource path="res://sprites/cat-ears.png" type="Texture" id=1] | ||
[ext_resource path="res://sprites/box-cat.png" type="Texture" id=2] | ||
[ext_resource path="res://scenes/friends/ScaredyCat.gd" type="Script" id=3] | ||
[ext_resource path="res://audio/sfx/meow.wav" type="AudioStream" id=4] | ||
|
||
[sub_resource type="RectangleShape2D" id=1] | ||
extents = Vector2( 8, 8 ) | ||
|
||
[node name="ScaredyCat" type="KinematicBody2D"] | ||
collision_layer = 0 | ||
collision_mask = 2 | ||
script = ExtResource( 3 ) | ||
|
||
[node name="PlayerHitbox" type="Area2D" parent="."] | ||
collision_layer = 0 | ||
collision_mask = 64 | ||
monitorable = false | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerHitbox"] | ||
shape = SubResource( 1 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource( 1 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
scale = Vector2( 0.25, 0.25 ) | ||
texture = ExtResource( 2 ) | ||
|
||
[node name="Sprite2" type="Sprite" parent="."] | ||
position = Vector2( 0, -16 ) | ||
scale = Vector2( 0.25, 0.25 ) | ||
texture = ExtResource( 1 ) | ||
|
||
[node name="Timer" type="Timer" parent="."] | ||
process_mode = 0 | ||
one_shot = true | ||
|
||
[node name="MeowStream" type="AudioStreamPlayer2D" parent="."] | ||
stream = ExtResource( 4 ) | ||
bus = "sfx" | ||
area_mask = 2 | ||
|
||
[connection signal="body_entered" from="PlayerHitbox" to="." method="_on_PlayerHitbox_body_entered"] | ||
[connection signal="finished" from="MeowStream" to="." method="_on_MeowStream_finished"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9966126
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Deployed on https://pr-658--little-mario.netlify.app