Health and killing zones
This commit is contained in:
@ -1,12 +0,0 @@
|
|||||||
extends ParallaxBackground
|
|
||||||
|
|
||||||
const scrolling_seed = 100
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
#func _process(delta: float) -> void:
|
|
||||||
#scroll_offset.x -= scrolling_seed * delta
|
|
@ -1,11 +0,0 @@
|
|||||||
extends StaticBody2D
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta: float) -> void:
|
|
||||||
pass
|
|
@ -35,9 +35,10 @@ func _on_player_detection_body_exited(body: Node2D) -> void:
|
|||||||
|
|
||||||
func _on_killingzone_body_entered(body: Node2D) -> void:
|
func _on_killingzone_body_entered(body: Node2D) -> void:
|
||||||
if body.name == "Player":
|
if body.name == "Player":
|
||||||
if player.global_position.y < self.global_position.y - 10 :
|
if player.global_position.y < self.global_position.y - 20 :
|
||||||
get_node("AnimatedSprite2D").play("death")
|
get_node("AnimatedSprite2D").play("death")
|
||||||
alive = false
|
alive = false
|
||||||
|
self.collision_mask = 2
|
||||||
timer.start()
|
timer.start()
|
||||||
elif alive:
|
elif alive:
|
||||||
print("HURT")
|
print("HURT")
|
||||||
|
@ -139,7 +139,7 @@ shape = SubResource("CapsuleShape2D_o6lk6")
|
|||||||
debug_color = Color(0.987816, 0.0454308, 0.255515, 0.42)
|
debug_color = Color(0.987816, 0.0454308, 0.255515, 0.42)
|
||||||
|
|
||||||
[node name="Deathcounter" type="Timer" parent="."]
|
[node name="Deathcounter" type="Timer" parent="."]
|
||||||
wait_time = 0.6
|
wait_time = 2.0
|
||||||
|
|
||||||
[connection signal="body_entered" from="PlayerDetection" to="." method="_on_player_detection_body_entered"]
|
[connection signal="body_entered" from="PlayerDetection" to="." method="_on_player_detection_body_entered"]
|
||||||
[connection signal="body_exited" from="PlayerDetection" to="." method="_on_player_detection_body_exited"]
|
[connection signal="body_exited" from="PlayerDetection" to="." method="_on_player_detection_body_exited"]
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
const SPEED = 400.0
|
const SPEED = 400.0
|
||||||
const JUMP_VELOCITY = -400.0
|
const JUMP_VELOCITY = -400.0
|
||||||
|
|
||||||
var jumped = false
|
var jumped = false
|
||||||
@onready var animation = get_node("AnimatedSprite2D")
|
@onready var animation = get_node("AnimatedSprite2D")
|
||||||
|
@onready var healthBar: ProgressBar = $ProgressBar
|
||||||
|
|
||||||
|
|
||||||
|
var health = 100
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
animation.play("idle")
|
animation.play("idle")
|
||||||
|
|
||||||
@ -47,3 +49,13 @@ func _physics_process(delta: float) -> void:
|
|||||||
#print("DEAD")
|
#print("DEAD")
|
||||||
|
|
||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _on_enemy_hurt() -> void:
|
||||||
|
if health - 50 == 0:
|
||||||
|
get_tree().reload_current_scene()
|
||||||
|
else:
|
||||||
|
health -= 50
|
||||||
|
healthBar.value -= 50
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=28 format=3 uid="uid://cwhk7ysxws0s0"]
|
[gd_scene load_steps=30 format=3 uid="uid://cwhk7ysxws0s0"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scenes/Game/Player/player.gd" id="1_f437e"]
|
[ext_resource type="Script" path="res://scenes/Game/Player/player.gd" id="1_f437e"]
|
||||||
[ext_resource type="Texture2D" uid="uid://uobvqa86mtra" path="res://assets/Sunny Land Collection Files/Sunny Land Collection Files/Assets/Characters/Players/Squirrel/idle/spritesheet.png" id="2_r3s32"]
|
[ext_resource type="Texture2D" uid="uid://uobvqa86mtra" path="res://assets/Sunny Land Collection Files/Sunny Land Collection Files/Assets/Characters/Players/Squirrel/idle/spritesheet.png" id="2_r3s32"]
|
||||||
@ -173,6 +173,12 @@ animations = [{
|
|||||||
radius = 8.0
|
radius = 8.0
|
||||||
height = 24.0
|
height = 24.0
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nv1uy"]
|
||||||
|
bg_color = Color(1, 0, 0, 1)
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qoc3s"]
|
||||||
|
bg_color = Color(0, 1, 0, 1)
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D"]
|
[node name="Player" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_f437e")
|
script = ExtResource("1_f437e")
|
||||||
|
|
||||||
@ -185,3 +191,13 @@ autoplay = "idle"
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
position = Vector2(1, -11)
|
position = Vector2(1, -11)
|
||||||
shape = SubResource("CapsuleShape2D_gqjua")
|
shape = SubResource("CapsuleShape2D_gqjua")
|
||||||
|
|
||||||
|
[node name="ProgressBar" type="ProgressBar" parent="."]
|
||||||
|
offset_left = -14.0
|
||||||
|
offset_top = -33.0
|
||||||
|
offset_right = 12.0
|
||||||
|
offset_bottom = -27.0
|
||||||
|
theme_override_styles/background = SubResource("StyleBoxFlat_nv1uy")
|
||||||
|
theme_override_styles/fill = SubResource("StyleBoxFlat_qoc3s")
|
||||||
|
value = 100.0
|
||||||
|
show_percentage = false
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
extends CollisionShape2D
|
|
||||||
|
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready() -> void:
|
|
||||||
pass # Replace with function body.
|
|
||||||
|
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta: float) -> void:
|
|
||||||
pass
|
|
@ -1,10 +1,9 @@
|
|||||||
[gd_scene load_steps=12 format=3 uid="uid://cxni03aowykty"]
|
[gd_scene load_steps=11 format=3 uid="uid://cxni03aowykty"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cwhk7ysxws0s0" path="res://scenes/Game/Player/player.tscn" id="1_ol65m"]
|
[ext_resource type="PackedScene" uid="uid://cwhk7ysxws0s0" path="res://scenes/Game/Player/player.tscn" id="1_ol65m"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cyn664h8v4yjq" path="res://assets/Sunny Land Collection Files/Sunny Land Collection Files/Assets/Environments/Day-Platformer/PNG/tileset.png" id="2_2shen"]
|
[ext_resource type="Texture2D" uid="uid://cyn664h8v4yjq" path="res://assets/Sunny Land Collection Files/Sunny Land Collection Files/Assets/Environments/Day-Platformer/PNG/tileset.png" id="2_2shen"]
|
||||||
[ext_resource type="PackedScene" uid="uid://5bcs7peqaotp" path="res://scenes/Game/Background/parallax_background.tscn" id="2_7th7e"]
|
[ext_resource type="PackedScene" uid="uid://5bcs7peqaotp" path="res://scenes/Game/Background/parallax_background.tscn" id="2_7th7e"]
|
||||||
[ext_resource type="Script" path="res://scenes/Game/Background/static_body_2d.gd" id="4_4hn3y"]
|
[ext_resource type="Script" path="res://scenes/Game/killinzone.gd" id="4_rly4c"]
|
||||||
[ext_resource type="Script" path="res://scenes/Game/floor.gd" id="5_ehkb0"]
|
|
||||||
[ext_resource type="PackedScene" uid="uid://cwwrv2mwnu2q3" path="res://scenes/Game/Enemy/enemy.tscn" id="6_0idbk"]
|
[ext_resource type="PackedScene" uid="uid://cwwrv2mwnu2q3" path="res://scenes/Game/Enemy/enemy.tscn" id="6_0idbk"]
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_650cm"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_650cm"]
|
||||||
@ -150,7 +149,6 @@ layer_0/tile_data = PackedInt32Array(1507360, 196608, 4, 1507361, 196608, 4, 150
|
|||||||
position = Vector2(131, 104)
|
position = Vector2(131, 104)
|
||||||
|
|
||||||
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
[node name="StaticBody2D" type="StaticBody2D" parent="."]
|
||||||
script = ExtResource("4_4hn3y")
|
|
||||||
|
|
||||||
[node name="roof" type="CollisionShape2D" parent="StaticBody2D"]
|
[node name="roof" type="CollisionShape2D" parent="StaticBody2D"]
|
||||||
position = Vector2(575, -9)
|
position = Vector2(575, -9)
|
||||||
@ -166,13 +164,17 @@ position = Vector2(-9, 322.5)
|
|||||||
rotation = 1.5708
|
rotation = 1.5708
|
||||||
shape = SubResource("RectangleShape2D_5wtle")
|
shape = SubResource("RectangleShape2D_5wtle")
|
||||||
|
|
||||||
[node name="floor" type="CollisionShape2D" parent="StaticBody2D"]
|
[node name="Area2D" type="Area2D" parent="StaticBody2D"]
|
||||||
unique_name_in_owner = true
|
|
||||||
position = Vector2(602, 751)
|
position = Vector2(602, 751)
|
||||||
|
script = ExtResource("4_rly4c")
|
||||||
|
|
||||||
|
[node name="floor" type="CollisionShape2D" parent="StaticBody2D/Area2D"]
|
||||||
shape = SubResource("RectangleShape2D_igtsr")
|
shape = SubResource("RectangleShape2D_igtsr")
|
||||||
script = ExtResource("5_ehkb0")
|
|
||||||
|
|
||||||
[node name="mobs" type="Node" parent="."]
|
[node name="mobs" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="enemy" parent="mobs" instance=ExtResource("6_0idbk")]
|
[node name="enemy" parent="mobs" instance=ExtResource("6_0idbk")]
|
||||||
position = Vector2(439, 456)
|
position = Vector2(439, 456)
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="StaticBody2D/Area2D" to="StaticBody2D/Area2D" method="_on_body_entered"]
|
||||||
|
[connection signal="hurt" from="mobs/enemy" to="Player" method="_on_enemy_hurt"]
|
||||||
|
@ -5,8 +5,6 @@ extends Node2D
|
|||||||
func _on_quit_pressed() -> void:
|
func _on_quit_pressed() -> void:
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_play_pressed() -> void:
|
func _on_play_pressed() -> void:
|
||||||
get_tree().change_scene_to_file("res://scenes/Game/world.tscn")
|
get_tree().change_scene_to_file("res://scenes/Game/world.tscn")
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user