added grenades and running animations|

This commit is contained in:
edgul 2026-05-04 20:57:02 -04:00
parent 321df5b9bd
commit a245ebc135
14 changed files with 365 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dio2ufnpnihce"
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1021 B

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://b5v0iuihwx8he"
path="res://.godot/imported/player jump 48x48.png-1388ce43fe6472dcf429db288011a472.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/idle/player jump 48x48.png"
dest_files=["res://.godot/imported/player jump 48x48.png-1388ce43fe6472dcf429db288011a472.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bl7p2n2kgw2qx"
path="res://.godot/imported/player run 48x48.png-4f561e0e1388a4aabd0657ab1641869d.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/graphics/player/idle/player run 48x48.png"
dest_files=["res://.godot/imported/player run 48x48.png-4f561e0e1388a4aabd0657ab1641869d.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

View File

@ -46,6 +46,11 @@ right={
, 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":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
]
}
chuck={
"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":71,"key_label":0,"unicode":103,"location":0,"echo":false,"script":null)
]
}
[physics]

View File

@ -5,6 +5,7 @@
[ext_resource type="Script" uid="uid://sj5x7sv6o6yb" path="res://scripts/scene_manager.gd" id="2_k3dxm"]
[ext_resource type="PackedScene" uid="uid://bhsvqyhsemekq" path="res://scenes/player.tscn" id="3_k3dxm"]
[ext_resource type="Script" uid="uid://gkpbb5sf4gu7" path="res://scripts/area_2d.gd" id="3_v0i7m"]
[ext_resource type="PackedScene" uid="uid://cncmlpntwxxx5" path="res://scenes/grenade.tscn" id="6_1aljj"]
[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_elsnr"]
@ -92,5 +93,8 @@ metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="platforms/platform4" unique_id=1906028968]
shape = SubResource("RectangleShape2D_elsnr")
[node name="grenade" parent="." unique_id=781159040 instance=ExtResource("6_1aljj")]
position = Vector2(385, 240)
[connection signal="body_entered" from="area" to="area" method="_on_body_entered"]
[connection signal="triggerActiveSignal" from="area" to="." method="_on_area_2d_trigger_active_signal"]

18
scenes/grenade.tscn Normal file
View File

@ -0,0 +1,18 @@
[gd_scene format=3 uid="uid://cncmlpntwxxx5"]
[ext_resource type="Script" uid="uid://bwjaypkvgpb6t" path="res://scripts/grenade.gd" id="1_cvyik"]
[sub_resource type="CircleShape2D" id="CircleShape2D_1xt3t"]
radius = 5.0
[node name="grenade" type="RigidBody2D" unique_id=781159040]
contact_monitor = true
max_contacts_reported = 3
script = ExtResource("1_cvyik")
metadata/_edit_group_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=346573127]
shape = SubResource("CircleShape2D_1xt3t")
debug_color = Color(0.8627451, 0.03137255, 0.20392157, 0.41960785)
[connection signal="body_entered" from="." to="." method="_on_body_entered"]

View File

@ -1,9 +1,150 @@
[gd_scene format=3 uid="uid://bhsvqyhsemekq"]
[ext_resource type="Script" uid="uid://dlmf1p0vfitcx" path="res://scripts/player.gd" id="1_3vyb7"]
[ext_resource type="Texture2D" uid="uid://dio2ufnpnihce" path="res://assets/graphics/player/idle/Player Idle 48x48.png" id="2_g2els"]
[ext_resource type="Texture2D" uid="uid://bl7p2n2kgw2qx" path="res://assets/graphics/player/idle/player run 48x48.png" id="3_qhqgy"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_elsnr"]
[sub_resource type="AtlasTexture" id="AtlasTexture_qhqgy"]
atlas = ExtResource("2_g2els")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_dqkch"]
atlas = ExtResource("2_g2els")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qlg0r"]
atlas = ExtResource("2_g2els")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_tuyoq"]
atlas = ExtResource("2_g2els")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fjrip"]
atlas = ExtResource("2_g2els")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_smehm"]
atlas = ExtResource("2_g2els")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_ur7pv"]
atlas = ExtResource("2_g2els")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_y4r1p"]
atlas = ExtResource("2_g2els")
region = Rect2(336, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_d2wvv"]
atlas = ExtResource("2_g2els")
region = Rect2(384, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_3v2ag"]
atlas = ExtResource("2_g2els")
region = Rect2(432, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_jej6c"]
atlas = ExtResource("3_qhqgy")
region = Rect2(0, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"]
atlas = ExtResource("3_qhqgy")
region = Rect2(48, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_oprun"]
atlas = ExtResource("3_qhqgy")
region = Rect2(96, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"]
atlas = ExtResource("3_qhqgy")
region = Rect2(144, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_qfm1y"]
atlas = ExtResource("3_qhqgy")
region = Rect2(192, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_fulsm"]
atlas = ExtResource("3_qhqgy")
region = Rect2(240, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_4r5pv"]
atlas = ExtResource("3_qhqgy")
region = Rect2(288, 0, 48, 48)
[sub_resource type="AtlasTexture" id="AtlasTexture_60mlk"]
atlas = ExtResource("3_qhqgy")
region = Rect2(336, 0, 48, 48)
[sub_resource type="SpriteFrames" id="SpriteFrames_jej6c"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_qhqgy")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_dqkch")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qlg0r")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_tuyoq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fjrip")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_smehm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ur7pv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_y4r1p")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_d2wvv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_3v2ag")
}],
"loop": true,
"name": &"idle",
"speed": 12.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_jej6c")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_f1ej7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_oprun")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_a8ls1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qfm1y")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fulsm")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4r5pv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_60mlk")
}],
"loop": true,
"name": &"run",
"speed": 12.0
}]
[node name="player" type="CharacterBody2D" unique_id=395957349]
script = ExtResource("1_3vyb7")
metadata/_edit_group_ = true
@ -17,3 +158,17 @@ target_position = Vector2(20, 0)
[node name="raycastLeft" type="RayCast2D" parent="." unique_id=1511802462]
target_position = Vector2(-20, 0)
[node name="right_marker" type="Marker2D" parent="." unique_id=1266802678]
position = Vector2(10, -12)
[node name="left_marker" type="Marker2D" parent="." unique_id=1663104896]
position = Vector2(-10, -12)
[node name="graphic" type="AnimatedSprite2D" parent="." unique_id=2045696763]
texture_filter = 1
position = Vector2(0, -1)
sprite_frames = SubResource("SpriteFrames_jej6c")
animation = &"run"
autoplay = "idle"
frame_progress = 0.8670586

24
scripts/grenade.gd Normal file
View File

@ -0,0 +1,24 @@
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("explode")
self.queue_free()
func _process(delta: float) -> void:
pass
func _on_body_entered(body: Node) -> void:
print("collision with grenade")
if body.is_in_group("destructable"):
body.queue_free()
explode()

1
scripts/grenade.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://bwjaypkvgpb6t

View File

@ -2,6 +2,9 @@ class_name Player extends CharacterBody2D
@onready var raycast_left: RayCast2D = $raycastLeft
@onready var raycast_right: RayCast2D = $raycastRight
@onready var left_marker: Marker2D = $left_marker
@onready var right_marker: Marker2D = $right_marker
@onready var graphic: AnimatedSprite2D = $graphic
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
@ -9,10 +12,14 @@ var direction : float = 0
enum FaceDirection { LEFT, RIGHT }
var facing: FaceDirection = FaceDirection.LEFT
var shove_target: RigidBody2D
enum State { IDLE, RUNNING }
var state: State = State.IDLE
func _physics_process(delta: float):
handle_input()
handle_movement(delta)
handle_state()
handle_animation()
move_and_slide() # pre-calc next position from velocity
handle_collisions()
@ -23,13 +30,22 @@ func handle_input():
shove_target.apply_central_impulse(Vector2(shove_normal,0)*700)
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
if Input.is_action_just_pressed("chuck"):
if facing == FaceDirection.LEFT:
print("Chuck grenade left")
%SceneManager.make_grenade(left_marker.global_transform, -1)
else:
print("Chuck grenade right")
%SceneManager.make_grenade(right_marker.global_transform, 1)
# 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
graphic.flip_h = true
elif direction > 0:
facing = FaceDirection.RIGHT
graphic.flip_h = false
func handle_movement(delta: float):
# Add the gravity.
@ -53,3 +69,17 @@ func handle_collisions():
var c = get_slide_collision(i)
if c.get_collider() is RigidBody2D:
c.get_collider().apply_central_impulse(-c.get_normal() * 100)
func handle_state():
match state:
State.IDLE when velocity.x != 0:
state = State.RUNNING
State.RUNNING when velocity.x == 0:
state = State.IDLE
func handle_animation():
match state:
State.IDLE:
graphic.play("idle")
State.RUNNING:
graphic.play("run")

View File

@ -2,6 +2,7 @@ class_name SceneManager extends Node2D
@onready var game_node: Node2D = $".."
@onready var crates: Node2D = $"../crates"
var grenade = preload("res://scenes/grenade.tscn")
func _ready() -> void:
print("scene manager is ready")
@ -14,6 +15,13 @@ func _process(delta: float) -> void:
func build_level() -> void:
update_crates()
func make_grenade(grenade_pos: Transform2D, grenade_dir: int) -> void:
print("scene manager making grenade")
var g:Grenade = grenade.instantiate()
g.transform = grenade_pos
owner.add_child(g)
g.apply_central_impulse(Vector2(grenade_dir, 1)*400)
func update_crates() -> void:
var crate_total:int = 0
if crates: