player death, player hurt, ui
This commit is contained in:
parent
ce71477b76
commit
321259532e
BIN
GodotProject/assets/graphics/player/death/Player Death 64x64.png
Normal file
BIN
GodotProject/assets/graphics/player/death/Player Death 64x64.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dmatixjfu6l4x"
|
||||||
|
path="res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/graphics/player/death/Player Death 64x64.png"
|
||||||
|
dest_files=["res://.godot/imported/Player Death 64x64.png-0c6ff54e7d9aad74b66dce47376541f8.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
BIN
GodotProject/assets/graphics/player/hurt/Player Hurt 48x48.png
Normal file
BIN
GodotProject/assets/graphics/player/hurt/Player Hurt 48x48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,34 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://dbrn5rtx4ncnb"
|
||||||
|
path="res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/graphics/player/hurt/Player Hurt 48x48.png"
|
||||||
|
dest_files=["res://.godot/imported/Player Hurt 48x48.png-a720e51cb19103e76b22ab6c1b81302d.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
@ -20,4 +20,5 @@ rotation = 3.14159
|
|||||||
scale = Vector2(0.117753, 0.117753)
|
scale = Vector2(0.117753, 0.117753)
|
||||||
texture = ExtResource("2_pcjo1")
|
texture = ExtResource("2_pcjo1")
|
||||||
|
|
||||||
|
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=15 format=4 uid="uid://cxnmaxykhbgaq"]
|
[gd_scene load_steps=16 format=4 uid="uid://cxnmaxykhbgaq"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://63qb2drh1l33" path="res://scenes/crate.tscn" id="1_0wmww"]
|
[ext_resource type="PackedScene" uid="uid://63qb2drh1l33" path="res://scenes/crate.tscn" id="1_0wmww"]
|
||||||
[ext_resource type="Script" path="res://scripts/Trigger.gd" id="3_4laji"]
|
[ext_resource type="Script" path="res://scripts/Trigger.gd" id="3_4laji"]
|
||||||
@ -10,6 +10,7 @@
|
|||||||
[ext_resource type="Texture2D" uid="uid://c7gfcwmohp6th" path="res://assets/graphics/terrains/Terrain (32x32).png" id="7_ogiiy"]
|
[ext_resource type="Texture2D" uid="uid://c7gfcwmohp6th" path="res://assets/graphics/terrains/Terrain (32x32).png" id="7_ogiiy"]
|
||||||
[ext_resource type="PackedScene" uid="uid://crtf2vkqussp6" path="res://scenes/coin.tscn" id="9_5tydy"]
|
[ext_resource type="PackedScene" uid="uid://crtf2vkqussp6" path="res://scenes/coin.tscn" id="9_5tydy"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cydfsa8y0pare" path="res://scenes/purpleslime.tscn" id="10_6gyln"]
|
[ext_resource type="PackedScene" uid="uid://cydfsa8y0pare" path="res://scenes/purpleslime.tscn" id="10_6gyln"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dc1gigufw7iv6" path="res://scenes/ui.tscn" id="11_stjw2"]
|
||||||
|
|
||||||
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_06fpy"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_06fpy"]
|
||||||
texture = ExtResource("7_ogiiy")
|
texture = ExtResource("7_ogiiy")
|
||||||
@ -395,6 +396,10 @@ radius = 34.1321
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("6_duuox")
|
script = ExtResource("6_duuox")
|
||||||
|
|
||||||
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
[node name="ui" parent="CanvasLayer" instance=ExtResource("11_stjw2")]
|
||||||
|
|
||||||
[node name="Background" type="Parallax2D" parent="."]
|
[node name="Background" type="Parallax2D" parent="."]
|
||||||
scroll_scale = Vector2(0.1, 1)
|
scroll_scale = Vector2(0.1, 1)
|
||||||
repeat_size = Vector2(320, 0)
|
repeat_size = Vector2(320, 0)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
[gd_scene load_steps=15 format=4 uid="uid://o0v5c7tcpi8o"]
|
[gd_scene load_steps=16 format=4 uid="uid://o0v5c7tcpi8o"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="1_rlteh"]
|
[ext_resource type="Script" path="res://scripts/scene_manager.gd" id="1_rlteh"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dc1gigufw7iv6" path="res://scenes/ui.tscn" id="2_n27lq"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cpnkcukncgjj6" path="res://assets/graphics/terrains/backgrounds/skystrip.png" id="2_yeti2"]
|
[ext_resource type="Texture2D" uid="uid://cpnkcukncgjj6" path="res://assets/graphics/terrains/backgrounds/skystrip.png" id="2_yeti2"]
|
||||||
[ext_resource type="Texture2D" uid="uid://xfytknjv7u4t" path="res://assets/graphics/terrains/backgrounds/forestbackground.png" id="3_r50tl"]
|
[ext_resource type="Texture2D" uid="uid://xfytknjv7u4t" path="res://assets/graphics/terrains/backgrounds/forestbackground.png" id="3_r50tl"]
|
||||||
[ext_resource type="Texture2D" uid="uid://ywtw6acl17qh" path="res://assets/graphics/terrains/backgrounds/trees.png" id="4_axi0m"]
|
[ext_resource type="Texture2D" uid="uid://ywtw6acl17qh" path="res://assets/graphics/terrains/backgrounds/trees.png" id="4_axi0m"]
|
||||||
@ -395,6 +396,10 @@ radius = 34.1321
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
script = ExtResource("1_rlteh")
|
script = ExtResource("1_rlteh")
|
||||||
|
|
||||||
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
[node name="ui" parent="CanvasLayer" instance=ExtResource("2_n27lq")]
|
||||||
|
|
||||||
[node name="Background" type="Parallax2D" parent="."]
|
[node name="Background" type="Parallax2D" parent="."]
|
||||||
scroll_scale = Vector2(0.1, 1)
|
scroll_scale = Vector2(0.1, 1)
|
||||||
repeat_size = Vector2(320, 0)
|
repeat_size = Vector2(320, 0)
|
||||||
|
@ -1,12 +1,70 @@
|
|||||||
[gd_scene load_steps=28 format=3 uid="uid://c1cuiluq1fcpk"]
|
[gd_scene load_steps=44 format=3 uid="uid://c1cuiluq1fcpk"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://scripts/player.gd" id="1_s1kdl"]
|
[ext_resource type="Script" path="res://scripts/player.gd" id="1_s1kdl"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dmatixjfu6l4x" path="res://assets/graphics/player/death/Player Death 64x64.png" id="2_cy83k"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cv2rxkxb3qt8d" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_h20by"]
|
[ext_resource type="Texture2D" uid="uid://cv2rxkxb3qt8d" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_h20by"]
|
||||||
[ext_resource type="Texture2D" uid="uid://cnya66cp8q1jw" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_fr7w2"]
|
[ext_resource type="Texture2D" uid="uid://cnya66cp8q1jw" path="res://assets/graphics/player/jump/player jump 48x48.png" id="3_fr7w2"]
|
||||||
[ext_resource type="Texture2D" uid="uid://ds0ii0prt3pij" path="res://assets/graphics/player/run/player run 48x48.png" id="3_gom75"]
|
[ext_resource type="Texture2D" uid="uid://ds0ii0prt3pij" path="res://assets/graphics/player/run/player run 48x48.png" id="3_gom75"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dbrn5rtx4ncnb" path="res://assets/graphics/player/hurt/Player Hurt 48x48.png" id="3_krvug"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_y4y41"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_y4y41"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_u6c1c"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(0, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_3fhqy"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(48, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_e287b"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(96, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_133il"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(144, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_0kl6l"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(192, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_3s0rc"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(240, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_w1lsm"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(288, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_twkd7"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(336, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_otxiu"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(384, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_jhl08"]
|
||||||
|
atlas = ExtResource("2_cy83k")
|
||||||
|
region = Rect2(432, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_d2i3x"]
|
||||||
|
atlas = ExtResource("3_krvug")
|
||||||
|
region = Rect2(0, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_kdvla"]
|
||||||
|
atlas = ExtResource("3_krvug")
|
||||||
|
region = Rect2(48, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_bbh0j"]
|
||||||
|
atlas = ExtResource("3_krvug")
|
||||||
|
region = Rect2(96, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_52xvf"]
|
||||||
|
atlas = ExtResource("3_krvug")
|
||||||
|
region = Rect2(144, 0, 48, 48)
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mww1u"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_mww1u"]
|
||||||
atlas = ExtResource("2_h20by")
|
atlas = ExtResource("2_h20by")
|
||||||
region = Rect2(0, 0, 48, 48)
|
region = Rect2(0, 0, 48, 48)
|
||||||
@ -95,6 +153,58 @@ region = Rect2(336, 0, 48, 48)
|
|||||||
animations = [{
|
animations = [{
|
||||||
"frames": [{
|
"frames": [{
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_u6c1c")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_3fhqy")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_e287b")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_133il")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_0kl6l")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_3s0rc")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_w1lsm")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_twkd7")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_otxiu")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_jhl08")
|
||||||
|
}],
|
||||||
|
"loop": false,
|
||||||
|
"name": &"death",
|
||||||
|
"speed": 6.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_d2i3x")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_kdvla")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_bbh0j")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_52xvf")
|
||||||
|
}],
|
||||||
|
"loop": false,
|
||||||
|
"name": &"hurt",
|
||||||
|
"speed": 12.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
"texture": SubResource("AtlasTexture_mww1u")
|
"texture": SubResource("AtlasTexture_mww1u")
|
||||||
}, {
|
}, {
|
||||||
"duration": 1.0,
|
"duration": 1.0,
|
||||||
@ -194,13 +304,15 @@ position = Vector2(10, -5)
|
|||||||
position = Vector2(-10, -5)
|
position = Vector2(-10, -5)
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
offset = Vector2(0, -60)
|
offset = Vector2(0, -20)
|
||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
position = Vector2(0, -5)
|
position = Vector2(0, -5)
|
||||||
sprite_frames = SubResource("SpriteFrames_gcr48")
|
sprite_frames = SubResource("SpriteFrames_gcr48")
|
||||||
animation = &"jump"
|
animation = &"death"
|
||||||
autoplay = "jump"
|
autoplay = "jump"
|
||||||
frame = 2
|
frame = 9
|
||||||
frame_progress = 1.0
|
frame_progress = 1.0
|
||||||
|
|
||||||
|
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]
|
||||||
|
46
GodotProject/scenes/ui.tscn
Normal file
46
GodotProject/scenes/ui.tscn
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://dc1gigufw7iv6"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://scripts/ui.gd" id="1_t3bu7"]
|
||||||
|
|
||||||
|
[node name="Control" type="Control"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
script = ExtResource("1_t3bu7")
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 10
|
||||||
|
anchor_right = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="health" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "HEALTH"
|
||||||
|
|
||||||
|
[node name="MarginContainer3" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="timer" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer3"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "10"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="MarginContainer2" type="MarginContainer" parent="VBoxContainer/HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="coins" type="Label" parent="VBoxContainer/HBoxContainer/MarginContainer2"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "COINS"
|
||||||
|
horizontal_alignment = 2
|
@ -3,6 +3,7 @@ class_name Bullet extends Area2D
|
|||||||
|
|
||||||
var speed = 700
|
var speed = 700
|
||||||
signal hit
|
signal hit
|
||||||
|
signal badguyhit(area)
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@ -25,6 +26,10 @@ func setSpeed(value):
|
|||||||
|
|
||||||
|
|
||||||
func _on_body_entered(body: Node2D) -> void:
|
func _on_body_entered(body: Node2D) -> void:
|
||||||
print("hit")
|
|
||||||
if not body.is_in_group("player"):
|
if not body.is_in_group("player"):
|
||||||
hit.emit(self, body)
|
hit.emit(self, body)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_area_entered(area: Area2D) -> void:
|
||||||
|
if area.is_in_group("enemies"):
|
||||||
|
badguyhit.emit(area)
|
||||||
|
@ -9,13 +9,21 @@ var totalCoinsCollected := 0
|
|||||||
var totalEnemies := 0
|
var totalEnemies := 0
|
||||||
#level information
|
#level information
|
||||||
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn"]
|
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn"]
|
||||||
var timers = [10,15]
|
var timers = [20,15]
|
||||||
var currentLevel = 0
|
var currentLevel = 0
|
||||||
|
|
||||||
var player:Resource
|
var player:Resource
|
||||||
# signals from game controller
|
# signals from game controller
|
||||||
|
signal destroyBadguy(area)
|
||||||
signal destroyBox(body)
|
signal destroyBox(body)
|
||||||
signal levelComplete(levelToLoad)
|
signal levelComplete(levelToLoad)
|
||||||
|
|
||||||
|
signal playerHurt(amt)
|
||||||
|
signal playerDeath
|
||||||
|
|
||||||
|
signal tick(timeRemaining)
|
||||||
|
signal coinsUpdate(coinsCollected, coinsAvailable)
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
player = load("res://scripts/res/playerstats.tres")
|
player = load("res://scripts/res/playerstats.tres")
|
||||||
@ -30,9 +38,15 @@ func _ready():
|
|||||||
|
|
||||||
func reset():
|
func reset():
|
||||||
countdown = timers[currentLevel]
|
countdown = timers[currentLevel]
|
||||||
|
player.health = player.starting_health
|
||||||
|
totalCoinsCollected = 0
|
||||||
|
tick.emit.call_deferred(countdown)
|
||||||
|
coinsUpdate.emit.call_deferred(totalCoinsCollected,totalCoins)
|
||||||
|
playerHurt.emit.call_deferred(player.health)
|
||||||
|
|
||||||
func secondCounter():
|
func secondCounter():
|
||||||
countdown -=1
|
countdown -=1
|
||||||
print("minus one")
|
tick.emit(countdown)
|
||||||
if countdown <=0:
|
if countdown <=0:
|
||||||
print("you lose")
|
print("you lose")
|
||||||
levelComplete.emit(levels[currentLevel])
|
levelComplete.emit(levels[currentLevel])
|
||||||
@ -44,12 +58,20 @@ func _process(delta):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
func coinCollected():
|
func coinCollected():
|
||||||
print("gane cotroller knows coin collected")
|
|
||||||
totalCoinsCollected+=1
|
totalCoinsCollected+=1
|
||||||
|
coinsUpdate.emit(totalCoinsCollected, totalCoins)
|
||||||
|
print(totalCoinsCollected)
|
||||||
|
|
||||||
func playerDamaged():
|
func playerDamaged():
|
||||||
player.health -= 20
|
player.health -= 20
|
||||||
print("game controller knows player damaged, health is now "+str(player.health))
|
print("game controller knows player damaged, health is now "+str(player.health))
|
||||||
|
if player.health > 0:
|
||||||
|
playerHurt.emit(player.health)
|
||||||
|
else:
|
||||||
|
playerDeath.emit()
|
||||||
|
|
||||||
|
func bullethitBadguy(area):
|
||||||
|
destroyBadguy.emit(area)
|
||||||
|
|
||||||
func bulletHit(body):
|
func bulletHit(body):
|
||||||
print("game controller knows bullet hit something")
|
print("game controller knows bullet hit something")
|
||||||
@ -72,3 +94,7 @@ func countCrates(value):
|
|||||||
totalCrates = value
|
totalCrates = value
|
||||||
func countCoins(value):
|
func countCoins(value):
|
||||||
totalCoins = value
|
totalCoins = value
|
||||||
|
|
||||||
|
func playerDead():
|
||||||
|
print("gc knows player is dead")
|
||||||
|
levelComplete.emit(levels[currentLevel])
|
||||||
|
@ -25,40 +25,58 @@ var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
|||||||
|
|
||||||
var isJumping = false
|
var isJumping = false
|
||||||
|
|
||||||
func _physics_process(delta):
|
var living = true
|
||||||
if not is_on_floor():
|
var animPlaying = "idle"
|
||||||
velocity.y += gravity * delta
|
|
||||||
else:
|
|
||||||
isJumping = false
|
|
||||||
|
|
||||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
signal deathAnimationComplete
|
||||||
velocity.y = JUMP_VELOCITY
|
|
||||||
animation.play("jump")
|
func hurtPlayer(_amt):
|
||||||
isJumping = true
|
if _amt < 100:
|
||||||
|
animPlaying = "hurt"
|
||||||
# shove attack
|
animation.play(animPlaying)
|
||||||
if Input.is_action_just_pressed("shove"):
|
|
||||||
if pushRightEnabled && faceleft == false:
|
func killPlayer():
|
||||||
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 2)
|
print("player character is killed")
|
||||||
if pushLeftEnabled && faceleft:
|
if living:
|
||||||
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2)
|
living = false
|
||||||
var direction = Input.get_axis("left", "right")
|
animPlaying = "death"
|
||||||
if direction:
|
animation.play(animPlaying)
|
||||||
velocity.x = direction * SPEED
|
|
||||||
if direction<0:
|
func _physics_process(delta):
|
||||||
|
if living and not animPlaying == "hurt":
|
||||||
|
if not is_on_floor():
|
||||||
|
velocity.y += gravity * delta
|
||||||
|
else:
|
||||||
|
isJumping = false
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||||
|
velocity.y = JUMP_VELOCITY
|
||||||
|
animation.play("jump")
|
||||||
|
isJumping = true
|
||||||
|
|
||||||
|
# shove attack
|
||||||
|
if Input.is_action_just_pressed("shove"):
|
||||||
|
if pushRightEnabled && faceleft == false:
|
||||||
|
pushTarget.apply_central_impulse(Vector2(1,0) * PUSH_FORCE * 2)
|
||||||
|
if pushLeftEnabled && faceleft:
|
||||||
|
pushTarget.apply_central_impulse(Vector2(-1,0) * PUSH_FORCE * 2)
|
||||||
|
var direction = Input.get_axis("left", "right")
|
||||||
|
if direction:
|
||||||
|
velocity.x = direction * SPEED
|
||||||
|
if direction<0:
|
||||||
|
if not isJumping:
|
||||||
|
animation.play("run")
|
||||||
|
faceleft = true
|
||||||
|
animation.flip_h = true
|
||||||
|
if direction>0:
|
||||||
|
if not isJumping:
|
||||||
|
animation.play("run")
|
||||||
|
faceleft = false
|
||||||
|
animation.flip_h = false
|
||||||
|
else:
|
||||||
if not isJumping:
|
if not isJumping:
|
||||||
animation.play("run")
|
animation.play("idle")
|
||||||
faceleft = true
|
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||||
animation.flip_h = true
|
|
||||||
if direction>0:
|
|
||||||
if not isJumping:
|
|
||||||
animation.play("run")
|
|
||||||
faceleft = false
|
|
||||||
animation.flip_h = false
|
|
||||||
else:
|
|
||||||
if not isJumping:
|
|
||||||
animation.play("idle")
|
|
||||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
|
||||||
|
|
||||||
|
|
||||||
# shoot
|
# shoot
|
||||||
@ -96,3 +114,10 @@ func _physics_process(delta):
|
|||||||
var c = get_slide_collision(i)
|
var c = get_slide_collision(i)
|
||||||
if c.get_collider() is RigidBody2D:
|
if c.get_collider() is RigidBody2D:
|
||||||
c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_FORCE)
|
c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_FORCE)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_animation_finished() -> void:
|
||||||
|
if animPlaying == "hurt":
|
||||||
|
animPlaying = "idle"
|
||||||
|
if animPlaying == "death":
|
||||||
|
deathAnimationComplete.emit()
|
||||||
|
@ -2,6 +2,8 @@ extends Node
|
|||||||
@onready var crates: Node2D = $"../crates"
|
@onready var crates: Node2D = $"../crates"
|
||||||
@onready var coins: Node2D = $"../coins"
|
@onready var coins: Node2D = $"../coins"
|
||||||
@onready var enemies: Node2D = $"../enemies"
|
@onready var enemies: Node2D = $"../enemies"
|
||||||
|
@onready var player: CharacterBody2D = $"../CharacterBody2D"
|
||||||
|
@onready var ui: Control = $"../CanvasLayer/ui"
|
||||||
|
|
||||||
|
|
||||||
var bullet = preload("res://scenes/bullet.tscn")
|
var bullet = preload("res://scenes/bullet.tscn")
|
||||||
@ -28,9 +30,23 @@ func _ready() -> void:
|
|||||||
obj.playerDamage.connect(Gamecontroller.playerDamaged)
|
obj.playerDamage.connect(Gamecontroller.playerDamaged)
|
||||||
|
|
||||||
Gamecontroller.countCrates(totalCrates)
|
Gamecontroller.countCrates(totalCrates)
|
||||||
|
Gamecontroller.countCoins(totalCoins)
|
||||||
|
|
||||||
|
#Player interactions
|
||||||
|
Gamecontroller.playerHurt.connect(player.hurtPlayer)
|
||||||
|
Gamecontroller.playerDeath.connect(player.killPlayer)
|
||||||
|
|
||||||
#subscribe to vital events from the game controller
|
#subscribe to vital events from the game controller
|
||||||
Gamecontroller.levelComplete.connect(changeLevel)
|
Gamecontroller.levelComplete.connect(changeLevel)
|
||||||
|
player.deathAnimationComplete.connect(Gamecontroller.playerDead)
|
||||||
|
|
||||||
|
#ui events
|
||||||
|
Gamecontroller.tick.connect(ui.timerUpdate)
|
||||||
|
Gamecontroller.playerHurt.connect(ui.healthUpdate)
|
||||||
|
Gamecontroller.playerDeath.connect(ui.healthGone)
|
||||||
|
Gamecontroller.coinsUpdate.connect(ui.coinsUpdate)
|
||||||
|
Gamecontroller.destroyBadguy.connect(killBadguy)
|
||||||
|
|
||||||
Gamecontroller.reset()
|
Gamecontroller.reset()
|
||||||
|
|
||||||
func changeLevel(level):
|
func changeLevel(level):
|
||||||
@ -45,6 +61,7 @@ func bulletFactory():
|
|||||||
if bulletArray.size() < 4:
|
if bulletArray.size() < 4:
|
||||||
myBullet = bullet.instantiate()
|
myBullet = bullet.instantiate()
|
||||||
myBullet.connect("hit", onBulletHit)
|
myBullet.connect("hit", onBulletHit)
|
||||||
|
myBullet.connect("badguyhit", Gamecontroller.bullethitBadguy)
|
||||||
owner.add_child(myBullet)
|
owner.add_child(myBullet)
|
||||||
else:
|
else:
|
||||||
myBullet = bulletArray.pop_back()
|
myBullet = bulletArray.pop_back()
|
||||||
@ -65,5 +82,8 @@ func onBulletHit(bullet, body):
|
|||||||
print("Scene manager knows bullet hit")
|
print("Scene manager knows bullet hit")
|
||||||
Gamecontroller.bulletHit(body)
|
Gamecontroller.bulletHit(body)
|
||||||
|
|
||||||
|
func killBadguy (area):
|
||||||
|
area.queue_free()
|
||||||
|
|
||||||
func boxDestroy(body):
|
func boxDestroy(body):
|
||||||
body.queue_free()
|
body.queue_free()
|
||||||
|
21
GodotProject/scripts/ui.gd
Normal file
21
GodotProject/scripts/ui.gd
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
extends Control
|
||||||
|
@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer3/timer
|
||||||
|
@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/health
|
||||||
|
@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer2/coins
|
||||||
|
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready() -> void:
|
||||||
|
pass # Replace with function body.
|
||||||
|
|
||||||
|
func timerUpdate(timeRemaining):
|
||||||
|
timer.text=str(timeRemaining)
|
||||||
|
|
||||||
|
func healthUpdate(_healthRemaining):
|
||||||
|
health.text="HEALTH "+str(_healthRemaining)
|
||||||
|
|
||||||
|
func healthGone():
|
||||||
|
health.text="HEALTH 0"
|
||||||
|
|
||||||
|
func coinsUpdate(coinsCollectedTotal, coinsAvailableTotal):
|
||||||
|
coins.text=str(coinsCollectedTotal)+" of "+str(coinsAvailableTotal)
|
Loading…
Reference in New Issue
Block a user