diff --git a/graphics/animations/Player Jab 48x48.png b/graphics/animations/Player Jab 48x48.png new file mode 100644 index 0000000..0ace3f0 Binary files /dev/null and b/graphics/animations/Player Jab 48x48.png differ diff --git a/graphics/animations/Player Jab 48x48.png.import b/graphics/animations/Player Jab 48x48.png.import new file mode 100644 index 0000000..70d5a41 --- /dev/null +++ b/graphics/animations/Player Jab 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://b27fd4xvrp2ov" +path="res://.godot/imported/Player Jab 48x48.png-a092fdd9a110293df667baca50431cc7.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/animations/Player Jab 48x48.png" +dest_files=["res://.godot/imported/Player Jab 48x48.png-a092fdd9a110293df667baca50431cc7.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/project.godot b/project.godot index 65ef13f..8bf18b8 100644 --- a/project.godot +++ b/project.godot @@ -60,7 +60,7 @@ jump={ "events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null) ] } -shove={ +punch={ "deadzone": 0.2, "events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null) ] diff --git a/scenes/game.tscn b/scenes/game.tscn index fa2a9db..aaf0b3e 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -511,18 +511,19 @@ intent = "powerup" [node name="Crates" type="Node" parent="."] -[node name="SmallCrate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")] +[node name="SmallCrate" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")] z_index = 10 +position = Vector2(-86, 25) -[node name="SmallCrate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")] +[node name="SmallCrate2" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")] z_index = 10 position = Vector2(229, -140) -[node name="SmallCrate3" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")] +[node name="SmallCrate3" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")] z_index = 10 position = Vector2(431, -222) -[node name="SmallCrate4" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_u5sy4")] +[node name="SmallCrate4" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_u5sy4")] z_index = 10 position = Vector2(-7, -210) diff --git a/scenes/level_2.tscn b/scenes/level_2.tscn index 8e8ab4a..45cde61 100644 --- a/scenes/level_2.tscn +++ b/scenes/level_2.tscn @@ -511,19 +511,19 @@ intent = "powerup" [node name="Crates" type="Node" parent="."] -[node name="SmallCrate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")] +[node name="SmallCrate" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")] z_index = 10 position = Vector2(-146, -162) -[node name="SmallCrate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")] +[node name="SmallCrate2" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")] z_index = 10 position = Vector2(226, 60) -[node name="SmallCrate3" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")] +[node name="SmallCrate3" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")] z_index = 10 position = Vector2(623, 7) -[node name="SmallCrate4" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_guvtl")] +[node name="SmallCrate4" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_guvtl")] z_index = 10 position = Vector2(-433, -201) diff --git a/scenes/level_3.tscn b/scenes/level_3.tscn index 3873470..fd126dd 100644 --- a/scenes/level_3.tscn +++ b/scenes/level_3.tscn @@ -511,18 +511,18 @@ intent = "powerup" [node name="Crates" type="Node" parent="."] -[node name="SmallCrate" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")] +[node name="SmallCrate" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")] z_index = 10 -[node name="SmallCrate2" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")] +[node name="SmallCrate2" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")] z_index = 10 position = Vector2(216, 52) -[node name="SmallCrate3" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")] +[node name="SmallCrate3" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")] z_index = 10 position = Vector2(-253, 10) -[node name="SmallCrate4" parent="Crates" groups=["explodable", "pushable"] instance=ExtResource("7_5xqnf")] +[node name="SmallCrate4" parent="Crates" groups=["explodable", "punchable"] instance=ExtResource("7_5xqnf")] z_index = 10 position = Vector2(-82, -5) diff --git a/scenes/player.tscn b/scenes/player.tscn index 1cfa640..6e9716e 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,9 +1,9 @@ -[gd_scene load_steps=56 format=3 uid="uid://d3y1iqmpknpyo"] +[gd_scene load_steps=58 format=3 uid="uid://d3y1iqmpknpyo"] [ext_resource type="Script" uid="uid://d3hp5rjoph7hg" path="res://scripts/player.gd" id="1_3vyb7"] [ext_resource type="Texture2D" uid="uid://dr3rp5hv7rexv" path="res://graphics/animations/player_idle/Player Idle 48x48.png" id="2_g2els"] [ext_resource type="Texture2D" uid="uid://uxdt2cgxicmt" path="res://graphics/animations/player_jump/player jump 48x48.png" id="3_dqkch"] -[ext_resource type="Texture2D" uid="uid://bnnj3lw3souky" path="res://graphics/animations/player_punch/Player Punch 64x64(1).png" id="4_fjrip"] +[ext_resource type="Texture2D" uid="uid://b27fd4xvrp2ov" path="res://graphics/animations/Player Jab 48x48.png" id="4_fjrip"] [ext_resource type="Texture2D" uid="uid://bgp8oow6hgh5o" path="res://graphics/animations/player_run/player run 48x48.png" id="4_qlg0r"] [ext_resource type="Texture2D" uid="uid://dadvc8tsvmkb6" path="res://graphics/animations/player_shoot/Player Running Shooting 48x48.png" id="5_tuyoq"] [ext_resource type="Texture2D" uid="uid://crll0t2wjtsly" path="res://graphics/animations/player_shoot/player shoot 2H 48x48.png" id="6_fjrip"] @@ -62,35 +62,43 @@ region = Rect2(0, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_2dvfe"] atlas = ExtResource("4_fjrip") -region = Rect2(0, 0, 64, 64) +region = Rect2(0, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_giy8y"] atlas = ExtResource("4_fjrip") -region = Rect2(64, 0, 64, 64) +region = Rect2(48, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_fdfoy"] atlas = ExtResource("4_fjrip") -region = Rect2(128, 0, 64, 64) +region = Rect2(96, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_hhpqf"] atlas = ExtResource("4_fjrip") -region = Rect2(192, 0, 64, 64) +region = Rect2(144, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_g5jhy"] atlas = ExtResource("4_fjrip") -region = Rect2(256, 0, 64, 64) +region = Rect2(192, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_holxr"] atlas = ExtResource("4_fjrip") -region = Rect2(320, 0, 64, 64) +region = Rect2(240, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_mx1m4"] atlas = ExtResource("4_fjrip") -region = Rect2(384, 0, 64, 64) +region = Rect2(288, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_4gjji"] atlas = ExtResource("4_fjrip") -region = Rect2(448, 0, 64, 64) +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_u2ulf"] +atlas = ExtResource("4_fjrip") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6e8lb"] +atlas = ExtResource("4_fjrip") +region = Rect2(432, 0, 48, 48) [sub_resource type="AtlasTexture" id="AtlasTexture_a8ls1"] atlas = ExtResource("4_qlg0r") @@ -273,6 +281,12 @@ animations = [{ }, { "duration": 1.0, "texture": SubResource("AtlasTexture_4gjji") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_u2ulf") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_6e8lb") }], "loop": false, "name": &"punch", @@ -399,7 +413,7 @@ position = Vector2(-16, -7) sprite_frames = SubResource("SpriteFrames_3vyb7") animation = &"punch" autoplay = "idle" -frame = 7 +frame = 9 frame_progress = 1.0 [node name="Camera2D" type="Camera2D" parent="."] diff --git a/scripts/player.gd b/scripts/player.gd index 572bc16..7814c64 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -1,24 +1,36 @@ class_name Player extends CharacterBody2D ## Character controller. -## TODO: fix bullet cooldown timer +## +## Controls the player character in this 2D side-scrolling platformer + +enum FaceDirection { + LEFT, + RIGHT +} +enum State { + IDLE, + RUN, + JUMP, + FALL, + SHOOT_STILL, + SHOOT_RUN, + PUNCH +} -const SPEED = 200.0 const JUMP_VELOCITY = -500.0 +const SPEED = 200.0 -enum FaceDirection{LEFT, RIGHT} -enum State{IDLE, WALK, JUMP, FALLING, SHOOT_STILL, SHOOT_RUN, SHOVE} - -@export var BUMP_POWER := 50 -@export var SHOVE_POWER := 300 +@export var BUMP_POWER := 50 ## Power from bumping into objects +@export var PUNCH_POWER := 300 ## Power from shoving objects @export var ACCELERATION := 10 ## Amount of "slide-y-ness" in side-to-side-movement -@export var HARD_GRAVITY := 2 +@export var HARD_GRAVITY := 2 ## Factor applied during FALL state var current_state: State = State.IDLE var facing : FaceDirection = FaceDirection.RIGHT var direction : float = 0.0 -var push_target : RigidBody2D -var push_enabled : bool = false +var punch_target : RigidBody2D +var punch_enabled : bool = false var jump_buffer_timer : Timer var shoot_cooldown_timer : Timer @@ -62,18 +74,19 @@ func handle_input() -> void: facing = FaceDirection.RIGHT # Handle shoving. - if Input.is_action_just_pressed("shove"): - print_debug("Shoving!") - if push_enabled == true: - var shove_direction : int + if Input.is_action_just_pressed("punch"): + print_debug("Trying to punch") + if punch_enabled == true: + print_debug("Punching enabled") + var punch_direction : int match facing: FaceDirection.RIGHT: - shove_direction = 1 + punch_direction = 1 FaceDirection.LEFT: - shove_direction = -1 - print_debug("Shoving %s" % push_target.name) - current_state = State.SHOVE - push_target.apply_central_impulse(Vector2(shove_direction, 0) * SHOVE_POWER) + punch_direction = -1 + print_debug("Punching %s" % punch_target.name) + current_state = State.PUNCH + punch_target.apply_central_impulse(Vector2(punch_direction, 0) * PUNCH_POWER) # Handle shooting if Input.is_action_just_pressed("shoot"): @@ -118,10 +131,10 @@ func handle_movement(delta) -> void: # Character is jumping; apply normal gravity velocity += get_gravity() * delta if velocity.y > 0: - current_state = State.FALLING + current_state = State.FALL else: # Character falling; apply hard gravity - current_state = State.FALLING + current_state = State.FALL velocity += get_gravity() * HARD_GRAVITY * delta func handle_collisions() -> void: @@ -132,46 +145,51 @@ func handle_collisions() -> void: c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_POWER) if right_cast.is_colliding() and facing == FaceDirection.RIGHT: + #print_debug("Colliding with something to the right") var collider = right_cast.get_collider() - # check if this is OK - if collider is Node and collider is RigidBody2D and collider.is_in_group("pushable"): - push_target = collider - push_enabled = true + #print_debug("Colliding with %s " % collider.name) + if collider is Node and collider is RigidBody2D and collider.is_in_group("punchable"): + print_debug("We have a punch target") + punch_target = collider + punch_enabled = true if left_cast.is_colliding() and facing == FaceDirection.LEFT: + #print_debug("Colliding with something to the left") var collider = left_cast.get_collider() - if collider is Node and collider is RigidBody2D and collider.is_in_group("pushable"): - push_target = collider - push_enabled = true + #print_debug("Colliding with %s " % collider.name) + if collider is Node and collider is RigidBody2D and collider.is_in_group("punchable"): + print_debug("We have a punch target") + punch_target = collider + punch_enabled = true if not right_cast.is_colliding() and not left_cast.is_colliding(): - push_enabled = false + punch_enabled = false func update_state() -> void: match current_state: # If player is moving left or right State.IDLE when velocity.x !=0: - current_state = State.WALK + current_state = State.RUN # If player stops walking, or starts falling - State.WALK: + State.RUN: # If not moving left or right if velocity.x == 0: current_state = State.IDLE # If falling if not is_on_floor() and velocity.y > 0: - current_state = State.FALLING + current_state = State.FALL # When jump peaks, we start to fall State.JUMP when velocity.y > 0: - current_state = State.FALLING + current_state = State.FALL # Player lands, either still or moving - State.FALLING when is_on_floor(): + State.FALL when is_on_floor(): if velocity.x == 0: current_state = State.IDLE else: - current_state = State.WALK + current_state = State.RUN # Player shooting State.SHOOT_STILL: @@ -181,10 +199,10 @@ func update_state() -> void: # Player shooting while moving State.SHOOT_RUN: await player_sprite.animation_finished - current_state = State.WALK + current_state = State.RUN # Player shoving - State.SHOVE: + State.PUNCH: await player_sprite.animation_finished current_state = State.IDLE @@ -197,18 +215,18 @@ func update_animation() -> void: match current_state: State.IDLE: player_sprite.play("idle") - State.WALK: + State.RUN: player_sprite.play("run") State.JUMP: player_sprite.play("jump") - State.FALLING: + State.FALL: player_sprite.play("fall") State.SHOOT_STILL: player_sprite.play("shoot_still") State.SHOOT_RUN: player_sprite.play("shoot_run") - State.SHOVE: + State.PUNCH: player_sprite.play("punch") func update_debug(): - %StateLabel.text = "Current state: %s" % current_state + %StateLabel.text = "Current state: %s" % State.keys()[current_state]