diff --git a/graphics/player_jump/player new jump 48x48.png b/graphics/player_jump/player new jump 48x48.png new file mode 100644 index 0000000..2551816 Binary files /dev/null and b/graphics/player_jump/player new jump 48x48.png differ diff --git a/graphics/player_jump/player new jump 48x48.png.import b/graphics/player_jump/player new jump 48x48.png.import new file mode 100644 index 0000000..cae0d18 --- /dev/null +++ b/graphics/player_jump/player new jump 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cmng5hu2bk4v6" +path="res://.godot/imported/player new jump 48x48.png-3f203c898ee16f04682fe6c95c556366.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/player_jump/player new jump 48x48.png" +dest_files=["res://.godot/imported/player new jump 48x48.png-3f203c898ee16f04682fe6c95c556366.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/graphics/player_shoot/Player Running Shooting 48x48.png b/graphics/player_shoot/Player Running Shooting 48x48.png new file mode 100644 index 0000000..280bae5 Binary files /dev/null and b/graphics/player_shoot/Player Running Shooting 48x48.png differ diff --git a/graphics/player_shoot/Player Running Shooting 48x48.png.import b/graphics/player_shoot/Player Running Shooting 48x48.png.import new file mode 100644 index 0000000..9caa919 --- /dev/null +++ b/graphics/player_shoot/Player Running Shooting 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dadvc8tsvmkb6" +path="res://.godot/imported/Player Running Shooting 48x48.png-47c63e435c65b23aebd6a86cf7f30ecb.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/player_shoot/Player Running Shooting 48x48.png" +dest_files=["res://.godot/imported/Player Running Shooting 48x48.png-47c63e435c65b23aebd6a86cf7f30ecb.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/graphics/player_shoot/player shoot 2H 48x48.png b/graphics/player_shoot/player shoot 2H 48x48.png new file mode 100644 index 0000000..62041bf Binary files /dev/null and b/graphics/player_shoot/player shoot 2H 48x48.png differ diff --git a/graphics/player_shoot/player shoot 2H 48x48.png.import b/graphics/player_shoot/player shoot 2H 48x48.png.import new file mode 100644 index 0000000..5705b80 --- /dev/null +++ b/graphics/player_shoot/player shoot 2H 48x48.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://crll0t2wjtsly" +path="res://.godot/imported/player shoot 2H 48x48.png-9803739eaed87b62419b05b35dcbe01e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graphics/player_shoot/player shoot 2H 48x48.png" +dest_files=["res://.godot/imported/player shoot 2H 48x48.png-9803739eaed87b62419b05b35dcbe01e.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 aa14200..84edab7 100644 --- a/project.godot +++ b/project.godot @@ -11,6 +11,7 @@ config_version=5 [application] config/name="September Game AB" +config/tags=PackedStringArray("2d", "lesson", "platformer") run/main_scene="uid://cueixogtk70go" config/features=PackedStringArray("4.5", "Forward Plus") config/icon="res://icon.svg" diff --git a/scenes/player.tscn b/scenes/player.tscn index e4132c4..d4480b6 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=27 format=3 uid="uid://d3y1iqmpknpyo"] +[gd_scene load_steps=47 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/player_idle/Player Idle 48x48.png" id="2_g2els"] [ext_resource type="Texture2D" uid="uid://uxdt2cgxicmt" path="res://graphics/player_jump/player jump 48x48.png" id="3_dqkch"] [ext_resource type="Texture2D" uid="uid://bgp8oow6hgh5o" path="res://graphics/player_run/player run 48x48.png" id="4_qlg0r"] +[ext_resource type="Texture2D" uid="uid://dadvc8tsvmkb6" path="res://graphics/player_shoot/Player Running Shooting 48x48.png" id="5_tuyoq"] +[ext_resource type="Texture2D" uid="uid://crll0t2wjtsly" path="res://graphics/player_shoot/player shoot 2H 48x48.png" id="6_fjrip"] [sub_resource type="CapsuleShape2D" id="CapsuleShape2D_3vyb7"] radius = 6.0 @@ -89,6 +91,78 @@ region = Rect2(288, 0, 48, 48) atlas = ExtResource("4_qlg0r") region = Rect2(336, 0, 48, 48) +[sub_resource type="AtlasTexture" id="AtlasTexture_f1ej7"] +atlas = ExtResource("5_tuyoq") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_l71n6"] +atlas = ExtResource("5_tuyoq") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ke2ow"] +atlas = ExtResource("5_tuyoq") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ujl30"] +atlas = ExtResource("5_tuyoq") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_31cv2"] +atlas = ExtResource("5_tuyoq") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_pf23h"] +atlas = ExtResource("5_tuyoq") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_dt7fs"] +atlas = ExtResource("5_tuyoq") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wqfne"] +atlas = ExtResource("5_tuyoq") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wnwbv"] +atlas = ExtResource("6_fjrip") +region = Rect2(0, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gl8cc"] +atlas = ExtResource("6_fjrip") +region = Rect2(48, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_487ah"] +atlas = ExtResource("6_fjrip") +region = Rect2(96, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_md1ol"] +atlas = ExtResource("6_fjrip") +region = Rect2(144, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_bj30b"] +atlas = ExtResource("6_fjrip") +region = Rect2(192, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_jc3p3"] +atlas = ExtResource("6_fjrip") +region = Rect2(240, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hax0n"] +atlas = ExtResource("6_fjrip") +region = Rect2(288, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_t4otl"] +atlas = ExtResource("6_fjrip") +region = Rect2(336, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_j2b1d"] +atlas = ExtResource("6_fjrip") +region = Rect2(384, 0, 48, 48) + +[sub_resource type="AtlasTexture" id="AtlasTexture_cs1tg"] +atlas = ExtResource("6_fjrip") +region = Rect2(432, 0, 48, 48) + [sub_resource type="SpriteFrames" id="SpriteFrames_3vyb7"] animations = [{ "frames": [{ @@ -170,6 +244,70 @@ animations = [{ "loop": true, "name": &"run", "speed": 15.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_f1ej7") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_l71n6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ke2ow") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ujl30") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_31cv2") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_pf23h") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_dt7fs") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wqfne") +}], +"loop": false, +"name": &"shoot_run", +"speed": 15.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_wnwbv") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gl8cc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_487ah") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_md1ol") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_bj30b") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_jc3p3") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_hax0n") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_t4otl") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_j2b1d") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_cs1tg") +}], +"loop": false, +"name": &"shoot_still", +"speed": 15.0 }] [node name="Player" type="CharacterBody2D"] @@ -188,14 +326,14 @@ target_position = Vector2(50, 0) target_position = Vector2(-50, 0) [node name="RightSpawn" type="Marker2D" parent="."] -position = Vector2(10, -4) +position = Vector2(16, -7) [node name="LeftSpawn" type="Marker2D" parent="."] -position = Vector2(-10, -4) +position = Vector2(-16, -7) [node name="PlayerSprite" type="AnimatedSprite2D" parent="."] sprite_frames = SubResource("SpriteFrames_3vyb7") -animation = &"jump" +animation = &"shoot_run" autoplay = "idle" [node name="Camera2D" type="Camera2D" parent="."] diff --git a/scripts/player.gd b/scripts/player.gd index effd5d7..fc29eec 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -1,10 +1,12 @@ -extends CharacterBody2D +class_name Player extends CharacterBody2D +## Character controller. +## TODO: fix bullet cooldown timer const SPEED = 300.0 const JUMP_VELOCITY = -600.0 enum FaceDirection{LEFT, RIGHT} -enum State{IDLE, WALK, JUMP, FALLING} +enum State{IDLE, WALK, JUMP, FALLING, SHOOT_STILL, SHOOT_RUN} @export var BUMP_POWER := 50 @export var SHOVE_POWER := 200 @@ -14,9 +16,10 @@ enum State{IDLE, WALK, JUMP, FALLING} var current_state: State = State.IDLE var facing : FaceDirection = FaceDirection.RIGHT var direction : float = 0.0 -var jump_buffer_timer : Timer var push_target : RigidBody2D var push_enabled : bool = false +var jump_buffer_timer : Timer +var shoot_cooldown_timer : Timer @onready var right_cast: RayCast2D = $RightCast @onready var left_cast: RayCast2D = $LeftCast @@ -27,6 +30,9 @@ var push_enabled : bool = false func _ready() -> void: jump_buffer_timer = Timer.new() add_child(jump_buffer_timer) + shoot_cooldown_timer = Timer.new() + shoot_cooldown_timer.one_shot = true + add_child(shoot_cooldown_timer) func _physics_process(delta: float) -> void: handle_input() @@ -65,14 +71,22 @@ func handle_input() -> void: # Handle shooting if Input.is_action_just_pressed("shoot"): - print("pew-pew") - match facing: - FaceDirection.RIGHT: - %SceneManager.make_bullet(right_spawn.global_transform, 700) - print("shoot right") - FaceDirection.LEFT: - %SceneManager.make_bullet(left_spawn.global_transform, -700) - print("shoot left") + if shoot_cooldown_timer.time_left == 0: + if velocity.x: + current_state = State.SHOOT_RUN + else: + current_state = State.SHOOT_STILL + print("pew-pew") + match facing: + FaceDirection.RIGHT: + %SceneManager.make_bullet(right_spawn.global_transform, 700) + print("shoot right") + FaceDirection.LEFT: + %SceneManager.make_bullet(left_spawn.global_transform, -700) + print("shoot left") + shoot_cooldown_timer.start(0.2) + else: + print("can't shoot right now because there are %s seconds left in the cooldown timer" % shoot_cooldown_timer.time_left) # Handle throwing grenades if Input.is_action_just_pressed("throw"): @@ -152,6 +166,16 @@ func update_state() -> void: current_state = State.IDLE else: current_state = State.WALK + + # Player shooting + State.SHOOT_STILL: + await player_sprite.animation_finished + current_state = State.IDLE + + # Player shooting while moving + State.SHOOT_RUN: + await player_sprite.animation_finished + current_state = State.WALK func update_animation() -> void: match facing: @@ -168,3 +192,7 @@ func update_animation() -> void: player_sprite.play("jump") State.FALLING: player_sprite.play("fall") + State.SHOOT_STILL: + player_sprite.play("shoot_still") + State.SHOOT_RUN: + player_sprite.play("shoot_run")