diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-12-26 11:29:04 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-12-26 11:29:04 +0100 |
commit | d572bc0a27b05c6632ba76bd630c7c4fd8f0ae5d (patch) | |
tree | 8bffeb9f025dc1c77bc53b65caf10d9b1fab5f2c /character |
initial commit
Diffstat (limited to 'character')
-rw-r--r-- | character/assets/boss_ko_2.wav | bin | 0 -> 200050 bytes | |||
-rw-r--r-- | character/assets/boss_ko_2.wav.import | 24 | ||||
-rw-r--r-- | character/assets/boss_ko_2_speed_up.wav | bin | 0 -> 55986 bytes | |||
-rw-r--r-- | character/assets/boss_ko_2_speed_up.wav.import | 24 | ||||
-rw-r--r-- | character/assets/character_spritesheet.png | bin | 0 -> 4629 bytes | |||
-rw-r--r-- | character/assets/character_spritesheet.png.import | 34 | ||||
-rw-r--r-- | character/assets/character_spritesheet.png~ | bin | 0 -> 4764 bytes | |||
-rw-r--r-- | character/character.gd | 223 | ||||
-rw-r--r-- | character/character.tscn | 52 | ||||
-rw-r--r-- | character/character_sprite_frames.tres | 265 |
10 files changed, 622 insertions, 0 deletions
diff --git a/character/assets/boss_ko_2.wav b/character/assets/boss_ko_2.wav Binary files differnew file mode 100644 index 0000000..0eed22b --- /dev/null +++ b/character/assets/boss_ko_2.wav diff --git a/character/assets/boss_ko_2.wav.import b/character/assets/boss_ko_2.wav.import new file mode 100644 index 0000000..d462c6a --- /dev/null +++ b/character/assets/boss_ko_2.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://c5fphxg1torik" +path="res://.godot/imported/boss_ko_2.wav-82c65adb3b984cb2964503f8b8f2e1a5.sample" + +[deps] + +source_file="res://character/assets/boss_ko_2.wav" +dest_files=["res://.godot/imported/boss_ko_2.wav-82c65adb3b984cb2964503f8b8f2e1a5.sample"] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/character/assets/boss_ko_2_speed_up.wav b/character/assets/boss_ko_2_speed_up.wav Binary files differnew file mode 100644 index 0000000..b1d9139 --- /dev/null +++ b/character/assets/boss_ko_2_speed_up.wav diff --git a/character/assets/boss_ko_2_speed_up.wav.import b/character/assets/boss_ko_2_speed_up.wav.import new file mode 100644 index 0000000..cc5b88a --- /dev/null +++ b/character/assets/boss_ko_2_speed_up.wav.import @@ -0,0 +1,24 @@ +[remap] + +importer="wav" +type="AudioStreamWAV" +uid="uid://1tatxmb1yho1" +path="res://.godot/imported/boss_ko_2_speed_up.wav-755e37e7a7926935cf77cd90f2568d2d.sample" + +[deps] + +source_file="res://character/assets/boss_ko_2_speed_up.wav" +dest_files=["res://.godot/imported/boss_ko_2_speed_up.wav-755e37e7a7926935cf77cd90f2568d2d.sample"] + +[params] + +force/8_bit=false +force/mono=false +force/max_rate=false +force/max_rate_hz=44100 +edit/trim=false +edit/normalize=false +edit/loop_mode=0 +edit/loop_begin=0 +edit/loop_end=-1 +compress/mode=0 diff --git a/character/assets/character_spritesheet.png b/character/assets/character_spritesheet.png Binary files differnew file mode 100644 index 0000000..9c1b844 --- /dev/null +++ b/character/assets/character_spritesheet.png diff --git a/character/assets/character_spritesheet.png.import b/character/assets/character_spritesheet.png.import new file mode 100644 index 0000000..3009953 --- /dev/null +++ b/character/assets/character_spritesheet.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d3cp58o1j55au" +path="res://.godot/imported/character_spritesheet.png-2d80c8875136c51fbbec17d53bbcb841.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://character/assets/character_spritesheet.png" +dest_files=["res://.godot/imported/character_spritesheet.png-2d80c8875136c51fbbec17d53bbcb841.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +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/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/assets/character_spritesheet.png~ b/character/assets/character_spritesheet.png~ Binary files differnew file mode 100644 index 0000000..2136c69 --- /dev/null +++ b/character/assets/character_spritesheet.png~ diff --git a/character/character.gd b/character/character.gd new file mode 100644 index 0000000..ef18bbc --- /dev/null +++ b/character/character.gd @@ -0,0 +1,223 @@ +class_name Character +extends Node2D + + +const BASE_SPEED := 50.0 +const VERTICAL_DISTANCE := 24 + +signal speed_changed +var speed_modifier := 1.0: + set(value): + speed_modifier = value + speed_changed.emit() + +enum Type { + Rock, + Paper, + Scissors, +} + +signal type_change_finished +signal type_changed +@export var current_type: Type = Type.Rock: + set(value): + current_type = value + type_changed.emit() + +enum Direction { + None, + Left, + Right, +} + +enum State { + Idle, + Walk, + Jump, + Fall, + Transform, +} + +var current_state: State = State.Idle + +var vertical_tween: Tween + +@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D + + +func _ready() -> void: + speed_changed.connect(func(): + $AnimatedSprite2D.speed_scale = speed_modifier + ) + + type_changed.connect(func(): + if current_state == State.Jump: + $AnimatedSprite2D.play("%s_jump" % get_type_name()) + elif current_state == State.Fall: + $AnimatedSprite2D.play("%s_fall" % get_type_name()) + ) + + +func get_type_name(type: Type = current_type): + match type: + Type.Rock: + return "rock" + Type.Paper: + return "paper" + Type.Scissors: + return "scissors" + + +func idle(): + current_state = State.Idle + + $AnimatedSprite2D.play("%s_idle" % get_type_name()) + + +func walk(direction: Direction): + current_state = State.Walk + + $AnimatedSprite2D.flip_h = direction == Direction.Left + $AnimatedSprite2D.play("%s_walk" % get_type_name()) + + if is_on_wall(direction): + return + + var direction_vector: Vector2 + match direction: + Direction.Left: + direction_vector = Vector2.LEFT + + Direction.Right: + direction_vector = Vector2.RIGHT + + position.x = lerp( + position.x, + position.x + (BASE_SPEED * speed_modifier * direction_vector.x), + get_process_delta_time() + ) + + +func jump(): + if is_below_ceiling(): + return + + current_state = State.Jump + + $AnimatedSprite2D.play("%s_jump" % get_type_name()) + + vertical_tween = get_tree().create_tween() + vertical_tween.tween_property( + self, + "position", + position - Vector2(0, VERTICAL_DISTANCE), + min(1.0 / speed_modifier, 1.0) + ) + + await vertical_tween.finished + + if not is_on_floor(): + fall() + else: + current_state = State.Idle + + +func fall(): + current_state = State.Fall + + $AnimatedSprite2D.play("%s_fall" % get_type_name()) + + vertical_tween = get_tree().create_tween() + vertical_tween.tween_property( + self, + "position", + position + Vector2(0, VERTICAL_DISTANCE), + min(1.0 / speed_modifier, 1.0) + ) + + await vertical_tween.finished + + if not is_on_floor(): + fall() + else: + current_state = State.Idle + + +func is_on_floor() -> bool: + $RayDownLeft.force_raycast_update() + $RayDownRight.force_raycast_update() + + return $RayDownLeft.is_colliding() or $RayDownRight.is_colliding() + + +func is_on_ledge() -> bool: + return true + pass + # TODO: add two more down Rays + # and up rays for is_below wall and is_below_ledge + # to fix falling through wall + # funktion im base-game aber auch gar nicht vorhanden:) + + +func is_on_bottom_floor() -> bool: + var stage: Stage = get_tree().current_scene + var map: TileMapLayer = get_tree().get_first_node_in_group("tilemap") + var bottom = position.y + (get_sprite_size().y / 2) + map.tile_set.tile_size.y + + return bottom >= stage.get_world_boundaries()[Vector2.DOWN] + + +func is_below_ceiling() -> bool: + return $RayUpLeft.is_colliding() or $RayUpRight.is_colliding() + + +func is_on_wall(direction: Direction) -> bool: + var stage: Stage = get_tree().current_scene + + match direction: + Direction.None: + return $RayLeft.is_colliding() or $RayRight.is_colliding() + + Direction.Left: + var left = position.x - (get_sprite_size().x / 2) + return $RayLeft.is_colliding() or left <= stage.get_world_boundaries()[Vector2.LEFT] + + Direction.Right: + var right = position.x + (get_sprite_size().x / 2) + return $RayRight.is_colliding() or right >= stage.get_world_boundaries()[Vector2.RIGHT] + + return false + + +func change_type_random(): + var types = Type.values() + types.erase(current_type) + + current_type = types.pick_random() + + +func animate_type_change(): + var previous_state := current_state + current_state = State.Transform + + var tween_was_running := false + if vertical_tween and vertical_tween.is_running(): + vertical_tween.pause() + tween_was_running = true + + $AnimatedSprite2D.play("transform") + await $AnimatedSprite2D.animation_finished + + current_state = previous_state + + type_change_finished.emit() + + if tween_was_running: + vertical_tween.play() + + +func get_sprite_size() -> Vector2: + var sprite_frames: SpriteFrames = $AnimatedSprite2D.sprite_frames + var texture := sprite_frames.get_frame_texture($AnimatedSprite2D.animation, $AnimatedSprite2D.frame) + + return texture.get_size() - Vector2(4, 0) diff --git a/character/character.tscn b/character/character.tscn new file mode 100644 index 0000000..3a1b0e8 --- /dev/null +++ b/character/character.tscn @@ -0,0 +1,52 @@ +[gd_scene load_steps=4 format=3 uid="uid://d21spw8y5yiuu"] + +[ext_resource type="Script" path="res://character/character.gd" id="1_wqxem"] +[ext_resource type="SpriteFrames" uid="uid://cvbw222po7psr" path="res://character/character_sprite_frames.tres" id="2_xbkcg"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_wfm33"] +size = Vector2(12, 12) + +[node name="Character" type="Node2D"] +script = ExtResource("1_wqxem") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +texture_filter = 1 +position = Vector2(-10, -10) +sprite_frames = ExtResource("2_xbkcg") +animation = &"scissors_idle" +centered = false + +[node name="Collision" type="Area2D" parent="."] +collision_layer = 0 +collision_mask = 256 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Collision"] +shape = SubResource("RectangleShape2D_wfm33") + +[node name="RayLeft" type="RayCast2D" parent="."] +target_position = Vector2(-8, 0) +collision_mask = 256 + +[node name="RayRight" type="RayCast2D" parent="."] +target_position = Vector2(8, 0) +collision_mask = 256 + +[node name="RayUpLeft" type="RayCast2D" parent="."] +position = Vector2(-6, 0) +target_position = Vector2(0, -10) +collision_mask = 256 + +[node name="RayUpRight" type="RayCast2D" parent="."] +position = Vector2(6, 0) +target_position = Vector2(0, -10) +collision_mask = 256 + +[node name="RayDownLeft" type="RayCast2D" parent="."] +position = Vector2(-6, 0) +target_position = Vector2(0, 9) +collision_mask = 768 + +[node name="RayDownRight" type="RayCast2D" parent="."] +position = Vector2(6, 0) +target_position = Vector2(0, 9) +collision_mask = 768 diff --git a/character/character_sprite_frames.tres b/character/character_sprite_frames.tres new file mode 100644 index 0000000..6aa4352 --- /dev/null +++ b/character/character_sprite_frames.tres @@ -0,0 +1,265 @@ +[gd_resource type="SpriteFrames" load_steps=29 format=3 uid="uid://cvbw222po7psr"] + +[ext_resource type="Texture2D" uid="uid://d3cp58o1j55au" path="res://character/assets/character_spritesheet.png" id="1_0ukqc"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_q8pdk"] +atlas = ExtResource("1_0ukqc") +region = Rect2(0, 60, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_k21bg"] +atlas = ExtResource("1_0ukqc") +region = Rect2(20, 60, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_a33vs"] +atlas = ExtResource("1_0ukqc") +region = Rect2(40, 60, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ad1cw"] +atlas = ExtResource("1_0ukqc") +region = Rect2(100, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_khl7x"] +atlas = ExtResource("1_0ukqc") +region = Rect2(0, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_yqka7"] +atlas = ExtResource("1_0ukqc") +region = Rect2(20, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_6o2jd"] +atlas = ExtResource("1_0ukqc") +region = Rect2(80, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fi3xw"] +atlas = ExtResource("1_0ukqc") +region = Rect2(40, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_8aswo"] +atlas = ExtResource("1_0ukqc") +region = Rect2(60, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_0x2b7"] +atlas = ExtResource("1_0ukqc") +region = Rect2(100, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_luqcw"] +atlas = ExtResource("1_0ukqc") +region = Rect2(0, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_er4mc"] +atlas = ExtResource("1_0ukqc") +region = Rect2(20, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_h68fd"] +atlas = ExtResource("1_0ukqc") +region = Rect2(80, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2uumw"] +atlas = ExtResource("1_0ukqc") +region = Rect2(40, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_isrrp"] +atlas = ExtResource("1_0ukqc") +region = Rect2(60, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_1xa27"] +atlas = ExtResource("1_0ukqc") +region = Rect2(100, 60, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_qhn6i"] +atlas = ExtResource("1_0ukqc") +region = Rect2(0, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_wsjy3"] +atlas = ExtResource("1_0ukqc") +region = Rect2(20, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_g2iar"] +atlas = ExtResource("1_0ukqc") +region = Rect2(80, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_btwgo"] +atlas = ExtResource("1_0ukqc") +region = Rect2(40, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_g5iao"] +atlas = ExtResource("1_0ukqc") +region = Rect2(60, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_i0gr8"] +atlas = ExtResource("1_0ukqc") +region = Rect2(120, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_uf1gj"] +atlas = ExtResource("1_0ukqc") +region = Rect2(140, 0, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_06q0h"] +atlas = ExtResource("1_0ukqc") +region = Rect2(120, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_k4wtj"] +atlas = ExtResource("1_0ukqc") +region = Rect2(140, 20, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_064a1"] +atlas = ExtResource("1_0ukqc") +region = Rect2(120, 40, 20, 20) + +[sub_resource type="AtlasTexture" id="AtlasTexture_komno"] +atlas = ExtResource("1_0ukqc") +region = Rect2(140, 40, 20, 20) + +[resource] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_q8pdk") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_k21bg") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_a33vs") +}], +"loop": false, +"name": &"ko", +"speed": 6.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_ad1cw") +}], +"loop": true, +"name": &"paper_fall", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_khl7x") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_yqka7") +}], +"loop": true, +"name": &"paper_idle", +"speed": 4.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_6o2jd") +}], +"loop": true, +"name": &"paper_jump", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_fi3xw") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_8aswo") +}], +"loop": true, +"name": &"paper_walk", +"speed": 4.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_0x2b7") +}], +"loop": false, +"name": &"rock_fall", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_luqcw") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_er4mc") +}], +"loop": true, +"name": &"rock_idle", +"speed": 4.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_h68fd") +}], +"loop": false, +"name": &"rock_jump", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_2uumw") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_isrrp") +}], +"loop": true, +"name": &"rock_walk", +"speed": 4.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_1xa27") +}], +"loop": false, +"name": &"scissors_fall", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_qhn6i") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_wsjy3") +}], +"loop": true, +"name": &"scissors_idle", +"speed": 4.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_g2iar") +}], +"loop": false, +"name": &"scissors_jump", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_btwgo") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_g5iao") +}], +"loop": true, +"name": &"scissors_walk", +"speed": 4.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_i0gr8") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_uf1gj") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_06q0h") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_k4wtj") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_064a1") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_komno") +}], +"loop": false, +"name": &"transform", +"speed": 4.0 +}] |