diff --git a/assets/graphics/player/idle/Player Idle 48x48.png b/assets/graphics/player/idle/Player Idle 48x48.png new file mode 100644 index 0000000..b618511 Binary files /dev/null and b/assets/graphics/player/idle/Player Idle 48x48.png differ diff --git a/assets/graphics/player/idle/Player Idle 48x48.png.import b/assets/graphics/player/idle/Player Idle 48x48.png.import new file mode 100644 index 0000000..276d930 --- /dev/null +++ b/assets/graphics/player/idle/Player Idle 48x48.png.import @@ -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 diff --git a/assets/graphics/player/run/player run 48x48.png b/assets/graphics/player/run/player run 48x48.png new file mode 100644 index 0000000..aca5b55 Binary files /dev/null and b/assets/graphics/player/run/player run 48x48.png differ diff --git a/assets/graphics/player/run/player run 48x48.png.import b/assets/graphics/player/run/player run 48x48.png.import new file mode 100644 index 0000000..11e140c --- /dev/null +++ b/assets/graphics/player/run/player run 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b74hvan7k63nk" +path="res://.godot/imported/player run 48x48.png-6d66612d48bfa4c8721495ba557ab7c6.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-6d66612d48bfa4c8721495ba557ab7c6.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 diff --git a/character_body_2d.tscn b/character_body_2d.tscn deleted file mode 100644 index cba6334..0000000 --- a/character_body_2d.tscn +++ /dev/null @@ -1,18 +0,0 @@ -[gd_scene format=3 uid="uid://cd5y08qaxwfny"] - -[ext_resource type="Script" uid="uid://f42eg5a0cckl" path="res://scripts/player_guy.gd" id="1_f50pn"] - -[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_80nbo"] - -[node name="CharacterBody2D" type="CharacterBody2D" unique_id=199789825] -script = ExtResource("1_f50pn") -metadata/_edit_group_ = true - -[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1058155484] -shape = SubResource("CapsuleShape2D_80nbo") - -[node name="rightcast" type="RayCast2D" parent="." unique_id=1229058621] -target_position = Vector2(55, 0) - -[node name="leftcast" type="RayCast2D" parent="." unique_id=1093993947] -target_position = Vector2(-43, 0) diff --git a/cube.tscn b/cube.tscn index 721546a..b268d9c 100644 --- a/cube.tscn +++ b/cube.tscn @@ -6,7 +6,6 @@ size = Vector2(129, 132) [node name="cube" type="RigidBody2D" unique_id=1851497894 groups=["fragile"]] -position = Vector2(11, 12) script = ExtResource("1_jbd7x") metadata/_edit_group_ = true diff --git a/game.tscn b/game.tscn index 1d73ab7..4f7c249 100644 --- a/game.tscn +++ b/game.tscn @@ -6,6 +6,7 @@ [ext_resource type="PackedScene" uid="uid://d0wbtenf13iol" path="res://cube.tscn" id="3_7jktm"] [ext_resource type="Script" uid="uid://cdxh14mtlvhl6" path="res://scripts/trigger_circle.gd" id="3_feb5d"] [ext_resource type="PackedScene" uid="uid://d4nnj62h6fjcq" path="res://scene/character_body_2d.tscn" id="4_ryrav"] +[ext_resource type="PackedScene" uid="uid://c5mayb1i4ypqm" path="res://grenade.tscn" id="7_eow3j"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_mwb40"] size = Vector2(368.333, 64.236694) @@ -16,10 +17,9 @@ size = Vector2(368.333, 64.236694) radius = 153.83757 [node name="Game" type="Node2D" unique_id=1249397989] -position = Vector2(-101, -18) script = ExtResource("1_fc0e3") -[node name="scene manager" type="Node2D" parent="." unique_id=1165789663] +[node name="SceneManager" type="Node2D" parent="." unique_id=1165789663] unique_name_in_owner = true position = Vector2(661, 24) scale = Vector2(0.97016877, 1.0195743) @@ -34,7 +34,7 @@ metadata/_edit_group_ = true shape = SubResource("RectangleShape2D_mwb40") [node name="left wall" type="StaticBody2D" parent="." unique_id=1287017623] -position = Vector2(250, 402.99994) +position = Vector2(-143, 215) rotation = 1.4884713 script = ExtResource("1_e2o6t") metadata/_edit_group_ = true @@ -43,7 +43,7 @@ metadata/_edit_group_ = true shape = SubResource("RectangleShape2D_mwb40") [node name="right wall" type="StaticBody2D" parent="." unique_id=820553779] -position = Vector2(567, 388.99994) +position = Vector2(-483, 92) rotation = -1.6017642 script = ExtResource("1_e2o6t") metadata/_edit_group_ = true @@ -58,7 +58,7 @@ scale = Vector2(0.86305076, 3.6811934) constant_linear_velocity = Vector2(250, 0) [node name="wall left" type="CollisionShape2D" parent="conveyor" unique_id=482160421] -position = Vector2(231.63736, -442.00055) +position = Vector2(406.85486, -406.34064) rotation = 1.6034058 scale = Vector2(0.9552965, 0.99587345) shape = SubResource("RectangleShape2D_mwb40") @@ -70,9 +70,6 @@ metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="world border" unique_id=1075301728] shape = SubResource("WorldBoundaryShape2D_mwb40") -[node name="CharacterBody2D" parent="." unique_id=44928680 instance=ExtResource("4_ryrav")] -position = Vector2(373, 474.99994) - [node name="Area2D" type="Area2D" parent="." unique_id=733267557] position = Vector2(945, 535) script = ExtResource("3_feb5d") @@ -84,16 +81,22 @@ shape = SubResource("CircleShape2D_e2o6t") [node name="cube container" type="Node2D" parent="." unique_id=22976120] [node name="cube" parent="cube container" unique_id=1851497894 instance=ExtResource("3_7jktm")] -position = Vector2(366.99994, 37.99997) +position = Vector2(429.00003, 372) scale = Vector2(0.97196096, 1.0195743) [node name="cube2" parent="cube container" unique_id=1345370216 instance=ExtResource("3_7jktm")] -position = Vector2(348.99994, -235.00003) +position = Vector2(921, -508.99997) scale = Vector2(0.97196096, 1.0195743) [node name="cube3" parent="cube container" unique_id=321996969 instance=ExtResource("3_7jktm")] -position = Vector2(342.99997, -106.00003) +position = Vector2(978.99994, -294) scale = Vector2(0.97196096, 1.0195743) +[node name="CharacterBody2D" parent="." unique_id=44928680 instance=ExtResource("4_ryrav")] +position = Vector2(263, 481) + +[node name="grenade" parent="." unique_id=1844025628 instance=ExtResource("7_eow3j")] +position = Vector2(-37, 236) + [connection signal="body_entered" from="Area2D" to="Area2D" method="_on_body_entered"] [connection signal="triggerActiveSignal" from="Area2D" to="." method="on_trigger"] diff --git a/grenade.tscn b/grenade.tscn new file mode 100644 index 0000000..f8dbbfd --- /dev/null +++ b/grenade.tscn @@ -0,0 +1,16 @@ +[gd_scene format=3 uid="uid://c5mayb1i4ypqm"] + +[ext_resource type="Script" uid="uid://wctwda5bor10" path="res://scripts/grenade.gd" id="1_gju2f"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_pu16u"] + +[node name="grenade" type="RigidBody2D" unique_id=1844025628] +contact_monitor = true +max_contacts_reported = 3 +script = ExtResource("1_gju2f") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=953914170] +shape = SubResource("CircleShape2D_pu16u") +debug_color = Color(0.45701438, 0.5945938, 3.85046e-07, 0.41960785) + +[connection signal="body_entered" from="." to="." method="_on_body_entered"] diff --git a/project.godot b/project.godot index accda76..0629f79 100644 --- a/project.godot +++ b/project.godot @@ -25,7 +25,12 @@ folder_colors={ "magic push"={ "deadzone": 0.2, -"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(449, 17),"global_position":Vector2(458, 65),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(404, 16),"global_position":Vector2(413, 64),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) +] +} +chuck={ +"deadzone": 0.2, +"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(227, 2),"global_position":Vector2(236, 50),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } diff --git a/scene/character_body_2d.tscn b/scene/character_body_2d.tscn index ddd95e4..f297f1a 100644 --- a/scene/character_body_2d.tscn +++ b/scene/character_body_2d.tscn @@ -1,12 +1,174 @@ [gd_scene format=3 uid="uid://d4nnj62h6fjcq"] [ext_resource type="Script" uid="uid://f42eg5a0cckl" path="res://scripts/player_guy.gd" id="1_j5628"] +[ext_resource type="Texture2D" uid="uid://p72rbg7thsvi" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_qug0s"] +[ext_resource type="Texture2D" uid="uid://b74hvan7k63nk" path="res://assets/graphics/player/run/player run 48x48.png" id="3_gd05a"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_80nbo"] +[sub_resource type="AtlasTexture" id="AtlasTexture_gd05a"] +atlas = ExtResource("2_qug0s") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_86iwx"] +atlas = ExtResource("2_qug0s") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_318mt"] +atlas = ExtResource("2_qug0s") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_b8c3x"] +atlas = ExtResource("2_qug0s") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ogaei"] +atlas = ExtResource("2_qug0s") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_mjxbh"] +atlas = ExtResource("2_qug0s") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_pykq2"] +atlas = ExtResource("2_qug0s") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_7y57j"] +atlas = ExtResource("2_qug0s") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_1hjxj"] +atlas = ExtResource("2_qug0s") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0npi7"] +atlas = ExtResource("2_qug0s") +region = Rect2(432, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_mu2pl"] +atlas = ExtResource("3_gd05a") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_joior"] +atlas = ExtResource("3_gd05a") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_kvipg"] +atlas = ExtResource("3_gd05a") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wpf5e"] +atlas = ExtResource("3_gd05a") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yb3qs"] +atlas = ExtResource("3_gd05a") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_js44f"] +atlas = ExtResource("3_gd05a") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_rs0n8"] +atlas = ExtResource("3_gd05a") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_022hi"] +atlas = ExtResource("3_gd05a") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="SpriteFrames" id="SpriteFrames_mu2pl"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_gd05a") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_86iwx") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_318mt") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_b8c3x") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ogaei") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_mjxbh") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_pykq2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_7y57j") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_1hjxj") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_0npi7") +}], +"loop": true, +"name": &"idle", +"speed": 12.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_mu2pl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_joior") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_kvipg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wpf5e") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_yb3qs") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_js44f") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_rs0n8") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_022hi") +}], +"loop": true, +"name": &"run", +"speed": 12.0 +}] + [node name="CharacterBody2D" type="CharacterBody2D" unique_id=44928680] +position = Vector2(-33, 19) script = ExtResource("1_j5628") metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=547069058] shape = SubResource("CapsuleShape2D_80nbo") + +[node name="RightCast" type="RayCast2D" parent="." unique_id=1862370013] +target_position = Vector2(34, 1) + +[node name="LeftCast" type="RayCast2D" parent="." unique_id=2108646942] +target_position = Vector2(-39, 1) + +[node name="rightspawn" type="Marker2D" parent="." unique_id=1690283250] +position = Vector2(18, -8) + +[node name="leftspawn" type="Marker2D" parent="." unique_id=1655353827] +position = Vector2(-20, -8) + +[node name="player graphic" type="AnimatedSprite2D" parent="." unique_id=1007399411] +texture_filter = 1 +position = Vector2(2, -26) +scale = Vector2(2.5208335, 2.3541667) +sprite_frames = SubResource("SpriteFrames_mu2pl") +animation = &"run" +autoplay = "idle" diff --git a/scripts/grenade.gd b/scripts/grenade.gd new file mode 100644 index 0000000..ef03bb4 --- /dev/null +++ b/scripts/grenade.gd @@ -0,0 +1,22 @@ +class_name grenade extends RigidBody2D + +var timer = Timer.new() + +func _ready() -> void: + add_child(timer) + + timer.wait_time = 2 + + timer.one_shot = true + timer.connect("timeout", explode) + timer.start() + +func explode()->void: + print("boom boom") + self.queue_free() + +func _on_body_entered(body: Node) -> void: + print("the grenade collision works") + if body.is_in_group("fragile"): + body.queue_free() + explode() diff --git a/scripts/grenade.gd.uid b/scripts/grenade.gd.uid new file mode 100644 index 0000000..96b9f2c --- /dev/null +++ b/scripts/grenade.gd.uid @@ -0,0 +1 @@ +uid://wctwda5bor10 diff --git a/scripts/player_guy.gd b/scripts/player_guy.gd index 0cf230c..694c23f 100644 --- a/scripts/player_guy.gd +++ b/scripts/player_guy.gd @@ -1,51 +1,99 @@ class_name Player extends CharacterBody2D -@onready var rightcast: RayCast2D = $rightcast -@onready var leftcast: RayCast2D = $leftcast - - const SPEED =200.0 -const JUMP_VELOCITY = -300.0 +const JUMP_VELOCITY = -500.0 var direction enum FaceDirection{LEFT, RIGHT} -var facing:FaceDirection = FaceDirection +var facing:FaceDirection = FaceDirection.RIGHT +enum player_state{IDLE,RUNNING} +var current_player_state:player_state = player_state.IDLE +@onready var player_graphic: AnimatedSprite2D = $"player graphic" + +@onready var rightspawn: Marker2D = $rightspawn +@onready var leftspawn: Marker2D = $leftspawn + +@onready var right_cast: RayCast2D = $RightCast +@onready var left_cast: RayCast2D = $LeftCast +var pushTarget +var pushEnabled:bool=false + +func _ready() -> void: + print(right_cast) + func _physics_process(delta: float) -> void: handle_input() handle_movement(delta) + handle_state() + handle_animation() move_and_slide() handle_collisions() func handle_input()->void: + if Input.is_action_just_pressed("chuck"): + print("chuck grenade") + %SceneManager.makeGrenade(rightspawn.global_transform, 1) + if Input.is_action_just_pressed("ui_accept"): velocity.y = JUMP_VELOCITY - if Input.is_action_just_pressed("magic push"): - print ("may the force be with you") + if Input.is_action_just_pressed("magic push") and pushEnabled: + print("I want to shove") + var shoveDirection:int + match facing: + FaceDirection.RIGHT: + shoveDirection = 1 + FaceDirection.LEFT: + shoveDirection = -1 + pushTarget.apply_central_impulse(Vector2(shoveDirection,0)*700) # 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("ui_left", "ui_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_movement(delta)->void: if not is_on_floor(): velocity += get_gravity() * delta # Handle jump. - + if direction: velocity.x = direction * SPEED else: velocity.x = move_toward(velocity.x, 0, SPEED) - + func handle_collisions()->void: - if rightcast.is_colliding() and facing==FaceDirection.RIGHT: - print("yay") - move_and_slide() + if right_cast.is_colliding() && facing==FaceDirection.RIGHT: + var collider = right_cast.get_collider() + if collider is Node && collider is RigidBody2D: + pushTarget = collider + pushEnabled = true + if left_cast.is_colliding() && facing==FaceDirection.LEFT: + var collider = left_cast.get_collider() + if collider is Node && collider is RigidBody2D: + pushTarget = collider + pushEnabled = true for i in get_slide_collision_count(): var c = get_slide_collision(i) if c.get_collider() is RigidBody2D: #deliver the impact c.get_collider().apply_central_impulse(-c.get_normal() * 100) + +func handle_state()->void: + match current_player_state: + player_state.IDLE when velocity.x !=0: + print("runnnnnn") + current_player_state = player_state.RUNNING + player_state.RUNNING when velocity.x ==0: + current_player_state = player_state.IDLE + +func handle_animation()->void: + match current_player_state: + player_state.IDLE: + player_graphic.play("idle") + player_state.RUNNING: + player_graphic.play("run") diff --git a/scripts/scenemanager.gd b/scripts/scenemanager.gd index 02e67ef..5aa253a 100644 --- a/scripts/scenemanager.gd +++ b/scripts/scenemanager.gd @@ -1,4 +1,6 @@ class_name SM extends Node2D + +var grenade = preload("res://grenade.tscn") @onready var game: Node2D = $".." @onready var cube_container: Node2D = $"../cube container" @@ -23,3 +25,9 @@ func updateCube()->void: _CubeTotal +=1 print ("Number of cubes: "+str(_CubeTotal)) +func makeGrenade(_grenadeposition, _grenadedirection)->void: + print("grenade time") + var myGrenade:grenade = grenade.instantiate() + owner.add_child(myGrenade) + myGrenade.transform = _grenadeposition + myGrenade.apply_central_impulse(Vector2(_grenadedirection, -1)*400)