greandes, dyanmic instantiation, statemachine
This commit is contained in:
parent
4dada35f76
commit
ed9a99e192
14
Scenes/crate.tscn
Normal file
14
Scenes/crate.tscn
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[gd_scene format=3 uid="uid://bsroh4vsjwblh"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://vwu0qtoxeqcn" path="res://Scripts/crate.gd" id="1_wp72f"]
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ebmjs"]
|
||||||
|
|
||||||
|
[node name="RigidBody2D" type="RigidBody2D" unique_id=2099388145 groups=["destructible"]]
|
||||||
|
rotation = -1.7350631
|
||||||
|
script = ExtResource("1_wp72f")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=414521394]
|
||||||
|
shape = SubResource("RectangleShape2D_ebmjs")
|
||||||
|
debug_color = Color(0.8238579, 0.39945692, 0.031017382, 0.41960785)
|
||||||
@ -1,8 +1,11 @@
|
|||||||
[gd_scene format=3 uid="uid://bcisk0tho1stb"]
|
[gd_scene format=3 uid="uid://bcisk0tho1stb"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://b4efh8nwneqkf" path="res://Scripts/player.gd" id="1_ebmjs"]
|
|
||||||
[ext_resource type="Script" uid="uid://ctdwfmqkny8rc" path="res://Scripts/game controller.gd" id="1_qxrlw"]
|
[ext_resource type="Script" uid="uid://ctdwfmqkny8rc" path="res://Scripts/game controller.gd" id="1_qxrlw"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://bsroh4vsjwblh" path="res://Scenes/crate.tscn" id="2_wowpa"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dmk1mp1hqm62b" path="res://Scenes/player.tscn" id="3_i6g32"]
|
||||||
[ext_resource type="Script" uid="uid://kb3v21msvi17" path="res://Scripts/trigger.gd" id="3_wrm1d"]
|
[ext_resource type="Script" uid="uid://kb3v21msvi17" path="res://Scripts/trigger.gd" id="3_wrm1d"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://ceyxo0mrrrd6d" path="res://Scenes/grenade.tscn" id="4_3dryh"]
|
||||||
|
[ext_resource type="Script" uid="uid://qhll446powxt" path="res://Scripts/scene_manager.gd" id="6_1l0tm"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2poj3"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2poj3"]
|
||||||
size = Vector2(82, 20)
|
size = Vector2(82, 20)
|
||||||
@ -11,14 +14,17 @@ size = Vector2(82, 20)
|
|||||||
|
|
||||||
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_2poj3"]
|
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_2poj3"]
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"]
|
|
||||||
|
|
||||||
[sub_resource type="CircleShape2D" id="CircleShape2D_3dryh"]
|
[sub_resource type="CircleShape2D" id="CircleShape2D_3dryh"]
|
||||||
radius = 18.110771
|
radius = 18.110771
|
||||||
|
|
||||||
[node name="Game" type="Node2D" unique_id=1323011736]
|
[node name="Game" type="Node2D" unique_id=1323011736]
|
||||||
script = ExtResource("1_qxrlw")
|
script = ExtResource("1_qxrlw")
|
||||||
|
|
||||||
|
[node name="SceneManager" type="Node2D" parent="." unique_id=711947929]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
position = Vector2(-39, 148)
|
||||||
|
script = ExtResource("6_1l0tm")
|
||||||
|
|
||||||
[node name="platfrom" type="StaticBody2D" parent="." unique_id=446401574]
|
[node name="platfrom" type="StaticBody2D" parent="." unique_id=446401574]
|
||||||
position = Vector2(399, 122)
|
position = Vector2(399, 122)
|
||||||
constant_linear_velocity = Vector2(10, 0)
|
constant_linear_velocity = Vector2(10, 0)
|
||||||
@ -27,14 +33,8 @@ metadata/_edit_group_ = true
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="platfrom" unique_id=1022493365]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="platfrom" unique_id=1022493365]
|
||||||
shape = SubResource("RectangleShape2D_2poj3")
|
shape = SubResource("RectangleShape2D_2poj3")
|
||||||
|
|
||||||
[node name="RigidBody2D" type="RigidBody2D" parent="." unique_id=193574446]
|
[node name="RigidBody2D" parent="." unique_id=2099388145 instance=ExtResource("2_wowpa")]
|
||||||
position = Vector2(360, 27.000004)
|
position = Vector2(331, 234)
|
||||||
rotation = -1.7350631
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D" unique_id=73164979]
|
|
||||||
shape = SubResource("RectangleShape2D_ebmjs")
|
|
||||||
debug_color = Color(0.8238579, 0.39945692, 0.031017382, 0.41960785)
|
|
||||||
|
|
||||||
[node name="RigidBody2D2" type="RigidBody2D" parent="." unique_id=1977575109]
|
[node name="RigidBody2D2" type="RigidBody2D" parent="." unique_id=1977575109]
|
||||||
position = Vector2(428.99997, 26)
|
position = Vector2(428.99997, 26)
|
||||||
@ -52,14 +52,8 @@ metadata/_edit_group_ = true
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1935948289]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D" unique_id=1935948289]
|
||||||
shape = SubResource("WorldBoundaryShape2D_2poj3")
|
shape = SubResource("WorldBoundaryShape2D_2poj3")
|
||||||
|
|
||||||
[node name="CharacterBody2D" type="CharacterBody2D" parent="." unique_id=793835080]
|
[node name="Player" parent="." unique_id=872670144 instance=ExtResource("3_i6g32")]
|
||||||
position = Vector2(399, 75)
|
position = Vector2(399, 75)
|
||||||
script = ExtResource("1_ebmjs")
|
|
||||||
metadata/_edit_group_ = true
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="CharacterBody2D" unique_id=75435339]
|
|
||||||
shape = SubResource("CircleShape2D_2poj3")
|
|
||||||
debug_color = Color(0.25014314, 0.63459045, 0.102719225, 0.41960785)
|
|
||||||
|
|
||||||
[node name="Area2D" type="Area2D" parent="." unique_id=1630381885]
|
[node name="Area2D" type="Area2D" parent="." unique_id=1630381885]
|
||||||
position = Vector2(447, 155)
|
position = Vector2(447, 155)
|
||||||
@ -70,5 +64,8 @@ metadata/_edit_group_ = true
|
|||||||
shape = SubResource("CircleShape2D_3dryh")
|
shape = SubResource("CircleShape2D_3dryh")
|
||||||
debug_color = Color(0.77940935, 0.23498747, 0.906131, 0.41960785)
|
debug_color = Color(0.77940935, 0.23498747, 0.906131, 0.41960785)
|
||||||
|
|
||||||
|
[node name="Grenade" parent="." unique_id=1054741787 instance=ExtResource("4_3dryh")]
|
||||||
|
position = Vector2(346, 91)
|
||||||
|
|
||||||
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
[connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"]
|
||||||
[connection signal="triggerActiveSignal" from="Area2D" to="." method="_on_triggerSignal"]
|
[connection signal="triggerActiveSignal" from="Area2D" to="." method="_on_triggerSignal"]
|
||||||
|
|||||||
17
Scenes/grenade.tscn
Normal file
17
Scenes/grenade.tscn
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
[gd_scene format=3 uid="uid://ceyxo0mrrrd6d"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://86lxae5ujqvq" path="res://Scripts/grenade.gd" id="1_v44n1"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_wrm1d"]
|
||||||
|
radius = 12.88
|
||||||
|
|
||||||
|
[node name="Grenade" type="RigidBody2D" unique_id=1054741787]
|
||||||
|
contact_monitor = true
|
||||||
|
max_contacts_reported = 3
|
||||||
|
script = ExtResource("1_v44n1")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=560084486]
|
||||||
|
shape = SubResource("CircleShape2D_wrm1d")
|
||||||
|
debug_color = Color(0.8306428, 0.39345673, 0, 0.41960785)
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||||
169
Scenes/player.tscn
Normal file
169
Scenes/player.tscn
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
[gd_scene format=3 uid="uid://dmk1mp1hqm62b"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://b4efh8nwneqkf" path="res://Scripts/player.gd" id="1_v0iea"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://p72rbg7thsvi" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_cvnsp"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b74hvan7k63nk" path="res://assets/graphics/player/Run/player run 48x48.png" id="3_6t5aa"]
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_2poj3"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_6t5aa"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(0, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_vgqql"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(48, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fkybt"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(96, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_x3wgy"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(144, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_3smsa"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(192, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_8erm5"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(240, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_f1ek2"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(288, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_tx1dd"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(336, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_gymyn"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(384, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_pu2lt"]
|
||||||
|
atlas = ExtResource("2_cvnsp")
|
||||||
|
region = Rect2(432, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_ukyrk"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(0, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_7dp3o"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(48, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_h4iuc"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(96, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fd4e3"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(144, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_qqcod"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(192, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_igrcy"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(240, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_fs7ks"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(288, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_l6n3p"]
|
||||||
|
atlas = ExtResource("3_6t5aa")
|
||||||
|
region = Rect2(336, 0, 48, 48)
|
||||||
|
|
||||||
|
[sub_resource type="SpriteFrames" id="SpriteFrames_ukyrk"]
|
||||||
|
animations = [{
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_6t5aa")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_vgqql")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_fkybt")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_x3wgy")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_3smsa")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_8erm5")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_f1ek2")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_tx1dd")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_gymyn")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_pu2lt")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"idle",
|
||||||
|
"speed": 12.0
|
||||||
|
}, {
|
||||||
|
"frames": [{
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_ukyrk")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_7dp3o")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_h4iuc")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_fd4e3")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_qqcod")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_igrcy")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_fs7ks")
|
||||||
|
}, {
|
||||||
|
"duration": 1.0,
|
||||||
|
"texture": SubResource("AtlasTexture_l6n3p")
|
||||||
|
}],
|
||||||
|
"loop": true,
|
||||||
|
"name": &"run",
|
||||||
|
"speed": 12.0
|
||||||
|
}]
|
||||||
|
|
||||||
|
[node name="Player" type="CharacterBody2D" unique_id=872670144]
|
||||||
|
script = ExtResource("1_v0iea")
|
||||||
|
metadata/_edit_group_ = true
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=894201673]
|
||||||
|
shape = SubResource("CircleShape2D_2poj3")
|
||||||
|
debug_color = Color(0.25014314, 0.63459045, 0.102719225, 0.41960785)
|
||||||
|
|
||||||
|
[node name="RightSpawn" type="Marker2D" parent="." unique_id=320859586]
|
||||||
|
position = Vector2(10, -8)
|
||||||
|
|
||||||
|
[node name="LeftSpawn" type="Marker2D" parent="." unique_id=2027988010]
|
||||||
|
position = Vector2(-17, -8)
|
||||||
|
|
||||||
|
[node name="PlayerGraphic" type="AnimatedSprite2D" parent="." unique_id=867519932]
|
||||||
|
texture_filter = 1
|
||||||
|
position = Vector2(0, -6)
|
||||||
|
sprite_frames = SubResource("SpriteFrames_ukyrk")
|
||||||
|
animation = &"run"
|
||||||
|
autoplay = "idle"
|
||||||
|
frame = 1
|
||||||
|
frame_progress = 0.18516552
|
||||||
11
Scripts/crate.gd
Normal file
11
Scripts/crate.gd
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
class_name Crate extends RigidBody2D
|
||||||
|
|
||||||
|
|
||||||
|
# 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
Scripts/crate.gd.uid
Normal file
1
Scripts/crate.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://vwu0qtoxeqcn
|
||||||
@ -1,5 +1,6 @@
|
|||||||
extends Node2D
|
class_name GameController extends Node2D
|
||||||
|
|
||||||
|
signal destroySignal(body)
|
||||||
|
|
||||||
# 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:
|
||||||
@ -13,5 +14,10 @@ func _process(delta: float) -> void:
|
|||||||
|
|
||||||
func _on_triggerSignal(body: Variant, intentMessage: Variant) -> void:
|
func _on_triggerSignal(body: Variant, intentMessage: Variant) -> void:
|
||||||
print("GC knows about a trigger!")
|
print("GC knows about a trigger!")
|
||||||
if not body is Player and intentMessage == "destroy":
|
if body.is_in_group("destructible") and intentMessage == "destroy":
|
||||||
body.queue_free()
|
destroySignal.emit(body)
|
||||||
|
|
||||||
|
func totalCrates(numberOfCrates:int)->void:
|
||||||
|
print("GC knows total crates: "+str(numberOfCrates))
|
||||||
|
if numberOfCrates <=0:
|
||||||
|
print("You WON!!!!")
|
||||||
|
|||||||
24
Scripts/grenade.gd
Normal file
24
Scripts/grenade.gd
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
class_name Grenade extends RigidBody2D
|
||||||
|
|
||||||
|
var timer = Timer.new()
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
add_child(timer)
|
||||||
|
#how long
|
||||||
|
timer.wait_time = 2
|
||||||
|
#one time onlu
|
||||||
|
timer.one_shot = true
|
||||||
|
timer.connect("timeout",explode)
|
||||||
|
timer.start()
|
||||||
|
|
||||||
|
func explode()->void:
|
||||||
|
print('ima spolde')
|
||||||
|
self.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_body_entered(body: Node) -> void:
|
||||||
|
print("collision w Grenade!!")
|
||||||
|
|
||||||
|
if body.is_in_group("destructible"):
|
||||||
|
body.queue_free()
|
||||||
|
explode()
|
||||||
1
Scripts/grenade.gd.uid
Normal file
1
Scripts/grenade.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://86lxae5ujqvq
|
||||||
@ -3,20 +3,33 @@ class_name Player extends CharacterBody2D
|
|||||||
|
|
||||||
const SPEED = 300.0
|
const SPEED = 300.0
|
||||||
const JUMP_VELOCITY = -400.0
|
const JUMP_VELOCITY = -400.0
|
||||||
|
@onready var right_spawn: Marker2D = $RightSpawn
|
||||||
|
@onready var left_spawn: Marker2D = $LeftSpawn
|
||||||
|
@onready var player_graphic: AnimatedSprite2D = $PlayerGraphic
|
||||||
|
|
||||||
|
var direction
|
||||||
|
enum FaceDirection{LEFT,RIGHT}
|
||||||
|
var facing:FaceDirection = FaceDirection.RIGHT
|
||||||
|
enum PlayerState{IDLE,RUNNING}
|
||||||
|
var current_player_state:PlayerState = PlayerState.IDLE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
|
handle_input()
|
||||||
|
|
||||||
|
handle_state()
|
||||||
|
handle_animation()
|
||||||
|
|
||||||
# Add the gravity.
|
# Add the gravity.
|
||||||
if not is_on_floor():
|
if not is_on_floor():
|
||||||
velocity += get_gravity() * delta
|
velocity += get_gravity() * delta
|
||||||
|
|
||||||
# Handle jump.
|
|
||||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
|
||||||
velocity.y = JUMP_VELOCITY
|
|
||||||
|
|
||||||
# Get the input direction and handle the movement/deceleration.
|
# Get the input direction and handle the movement/deceleration.
|
||||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||||
var direction := Input.get_axis("ui_left", "ui_right")
|
|
||||||
if direction:
|
if direction:
|
||||||
velocity.x = direction * SPEED
|
velocity.x = direction * SPEED
|
||||||
else:
|
else:
|
||||||
@ -28,3 +41,35 @@ func _physics_process(delta: float) -> void:
|
|||||||
if c.get_collider() is RigidBody2D:
|
if c.get_collider() is RigidBody2D:
|
||||||
#deliver the impact
|
#deliver the impact
|
||||||
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
|
||||||
|
func handle_input()->void:
|
||||||
|
if Input.is_action_just_pressed("Chuck"):
|
||||||
|
print("chuck a grenade")
|
||||||
|
%SceneManager.makeGrenade(right_spawn.global_transform, 1)
|
||||||
|
|
||||||
|
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||||
|
velocity.y = JUMP_VELOCITY
|
||||||
|
|
||||||
|
# Get the input direction and handle the movement/deceleration.
|
||||||
|
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||||
|
direction = Input.get_axis("left", "right")
|
||||||
|
if direction<0:
|
||||||
|
facing = FaceDirection.LEFT
|
||||||
|
player_graphic.flip_h = true
|
||||||
|
if direction>0:
|
||||||
|
facing = FaceDirection.RIGHT
|
||||||
|
player_graphic.flip_h = false
|
||||||
|
|
||||||
|
func handle_state()->void:
|
||||||
|
match current_player_state:
|
||||||
|
PlayerState.IDLE when velocity.x !=0:
|
||||||
|
#change to running
|
||||||
|
current_player_state = PlayerState.RUNNING
|
||||||
|
PlayerState.RUNNING when velocity.x ==0:
|
||||||
|
current_player_state = PlayerState.IDLE
|
||||||
|
|
||||||
|
func handle_animation()->void:
|
||||||
|
match current_player_state:
|
||||||
|
PlayerState.IDLE:
|
||||||
|
player_graphic.play("idle")
|
||||||
|
PlayerState.RUNNING:
|
||||||
|
player_graphic.play("run")
|
||||||
|
|||||||
34
Scripts/scene_manager.gd
Normal file
34
Scripts/scene_manager.gd
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
class_name SceneManager extends Node2D
|
||||||
|
@onready var game: Node2D = $".."
|
||||||
|
@onready var crates: Node2D = $"../Crates"
|
||||||
|
var grenade = preload("res://Scenes/grenade.tscn")
|
||||||
|
func _ready() -> void:
|
||||||
|
print("Scene manager is ready!")
|
||||||
|
game.destroySignal.connect(destroy)
|
||||||
|
buildLevel()
|
||||||
|
|
||||||
|
func destroy(body)->void:
|
||||||
|
if body is Crate:
|
||||||
|
body.queue_free()
|
||||||
|
|
||||||
|
func buildLevel()->void:
|
||||||
|
updateCrates()
|
||||||
|
|
||||||
|
func updateCrates()->void:
|
||||||
|
#is there a crate holder?
|
||||||
|
var _crateTotal:int = 0
|
||||||
|
if crates:
|
||||||
|
for obj in crates.get_children():
|
||||||
|
if obj is Crate:
|
||||||
|
if not obj.tree_exited.is_connected(updateCrates):
|
||||||
|
obj.tree_exited.connect(updateCrates)
|
||||||
|
_crateTotal +=1
|
||||||
|
print("Number of crates: "+str(_crateTotal))
|
||||||
|
game.totalCrates(_crateTotal)
|
||||||
|
|
||||||
|
func makeGrenade(_greandePosition, _grenadeDirection)->void:
|
||||||
|
print("SM wants to make a grenade")
|
||||||
|
var myGrenade:Grenade = grenade.instantiate()
|
||||||
|
owner.add_child(myGrenade)
|
||||||
|
myGrenade.transform = _greandePosition
|
||||||
|
myGrenade.apply_central_impulse(Vector2(_grenadeDirection, -1)*200)
|
||||||
1
Scripts/scene_manager.gd.uid
Normal file
1
Scripts/scene_manager.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://qhll446powxt
|
||||||
BIN
assets/graphics/player/Run/player run 48x48.png
Normal file
BIN
assets/graphics/player/Run/player run 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
40
assets/graphics/player/Run/player run 48x48.png.import
Normal file
40
assets/graphics/player/Run/player run 48x48.png.import
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://b74hvan7k63nk"
|
||||||
|
path="res://.godot/imported/player run 48x48.png-9cdb65892fab1af92f7870c2e357debf.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/graphics/player/Run/player run 48x48.png"
|
||||||
|
dest_files=["res://.godot/imported/player run 48x48.png-9cdb65892fab1af92f7870c2e357debf.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
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/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
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
assets/graphics/player/idle/Player Idle 48x48.png
Normal file
BIN
assets/graphics/player/idle/Player Idle 48x48.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
40
assets/graphics/player/idle/Player Idle 48x48.png.import
Normal file
40
assets/graphics/player/idle/Player Idle 48x48.png.import
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://p72rbg7thsvi"
|
||||||
|
path="res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://assets/graphics/player/idle/Player Idle 48x48.png"
|
||||||
|
dest_files=["res://.godot/imported/Player Idle 48x48.png-9f43f14976963a2821a06ddf8579a76a.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
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/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
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
|
||||||
@ -21,6 +21,29 @@ folder_colors={
|
|||||||
"res://Scripts/": "red"
|
"res://Scripts/": "red"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
Chuck={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [null, null, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
shove={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
left={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
right={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[physics]
|
[physics]
|
||||||
|
|
||||||
3d/physics_engine="Jolt Physics"
|
3d/physics_engine="Jolt Physics"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user