First Prototype

This commit is contained in:
Exobyt 2024-09-08 23:03:55 +02:00
parent c321b70bb0
commit eb11047456
35 changed files with 779 additions and 4 deletions

View file

@ -0,0 +1,78 @@
extends "res://scenes/game/entities/entity.gd"
@onready var rollTimer = $RollTimer
@onready var rollCooldownTimer = $RollCooldownTimer
@onready var animatedSprite = $AnimatedSprite2D
var rollSpeed = maxSpeed * 5
const rollCooldown = 5.0
const rollTime = 0.4
var rolling = false
var canRoll = true
var lastDirection : Vector2
var lastdirectionVector : Vector2
func _physics_process(delta: float) -> void:
var direction : Vector2 = Input.get_vector("MOVE_LEFT", "MOVE_RIGHT", "MOVE_UP", "MOVE_DOWN").normalized()
#var direction : Vector2 = Vector2(
#Input.get_action_strength("MOVE_RIGHT") - Input.get_action_strength("MOVE_LEFT"),
#Input.get_action_strength("MOVE_DOWN") - Input.get_action_strength("MOVE_UP")
#)
var directionVector : Vector2 = position.direction_to(position + direction)
if direction != Vector2.ZERO and not rolling:
lastDirection = direction
lastdirectionVector = directionVector
if Input.is_action_just_pressed("ROLL") and lastDirection != Vector2.ZERO:
roll()
if rolling:
move(lastdirectionVector * speed, acceleration)
else:
move(directionVector * speed, acceleration)
setAnimation()
move_and_slide()
func move(newVelocity : Vector2, acc):
velocity.x = move_toward(velocity.x,
newVelocity.x,
acc)
velocity.y = move_toward(velocity.y,
newVelocity.y,
acc)
func roll():
if not rolling and canRoll:
canRoll = false
setSpeed(rollSpeed)
invincible = true
rolling = true
rollTimer.start(rollTime)
func _on_roll_timeout() -> void:
resetSpeed()
invincible = false
rolling = false
rollCooldownTimer.start(rollCooldown)
func _on_roll_cooldown_timer_timeout() -> void:
canRoll = true
func setAnimation():
if not rolling:
if Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT") and animatedSprite.animation != "LEFT":
animatedSprite.play("LEFT")
elif Input.is_action_pressed("MOVE_RIGHT") and not Input.is_action_pressed("MOVE_LEFT") and animatedSprite.animation != "RIGHT":
animatedSprite.play("RIGHT")
elif Input.is_action_pressed("MOVE_UP") and animatedSprite.animation != "UP" and not Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT"):
animatedSprite.play("UP")
elif Input.is_action_pressed("MOVE_DOWN") and animatedSprite.animation != "DOWN" and not Input.is_action_pressed("MOVE_LEFT") and not Input.is_action_pressed("MOVE_RIGHT"):
animatedSprite.play("DOWN")
elif not (Input.is_action_pressed("MOVE_UP") or Input.is_action_pressed("MOVE_RIGHT") or Input.is_action_pressed("MOVE_DOWN") or Input.is_action_pressed("MOVE_LEFT")):
animatedSprite.play("IDLE")

View file

@ -0,0 +1,101 @@
[gd_resource type="SpriteFrames" load_steps=12 format=3 uid="uid://dv18sf3aj0n1h"]
[ext_resource type="Texture2D" uid="uid://b2xbgtcyxvi73" path="res://Assets/Player/Player.png" id="1_21ptg"]
[sub_resource type="AtlasTexture" id="AtlasTexture_m3bgq"]
atlas = ExtResource("1_21ptg")
region = Rect2(0, 64, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_6rhbk"]
atlas = ExtResource("1_21ptg")
region = Rect2(16, 64, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_51ijx"]
atlas = ExtResource("1_21ptg")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_ydp1x"]
atlas = ExtResource("1_21ptg")
region = Rect2(16, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_l7ggo"]
atlas = ExtResource("1_21ptg")
region = Rect2(0, 128, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_404j7"]
atlas = ExtResource("1_21ptg")
region = Rect2(16, 128, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_csdks"]
atlas = ExtResource("1_21ptg")
region = Rect2(0, 96, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_yahsm"]
atlas = ExtResource("1_21ptg")
region = Rect2(16, 96, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_8pkt3"]
atlas = ExtResource("1_21ptg")
region = Rect2(0, 32, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_rq2en"]
atlas = ExtResource("1_21ptg")
region = Rect2(16, 32, 16, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_m3bgq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_6rhbk")
}],
"loop": true,
"name": &"DOWN",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_51ijx")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ydp1x")
}],
"loop": true,
"name": &"IDLE",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_l7ggo")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_404j7")
}],
"loop": true,
"name": &"LEFT",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_csdks")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_yahsm")
}],
"loop": true,
"name": &"RIGHT",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_8pkt3")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_rq2en")
}],
"loop": true,
"name": &"UP",
"speed": 5.0
}]

View file

@ -0,0 +1,56 @@
[gd_scene load_steps=6 format=3 uid="uid://0duodsosmfpq"]
[ext_resource type="PackedScene" uid="uid://b18cf4i8v6a1" path="res://scenes/game/entities/entity.tscn" id="1_kmfws"]
[ext_resource type="Script" path="res://scenes/game/entities/player/player.gd" id="2_s0pfn"]
[ext_resource type="SpriteFrames" uid="uid://dv18sf3aj0n1h" path="res://scenes/game/entities/player/player.tres" id="3_mlsai"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_gk017"]
size = Vector2(16, 16)
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_upmug"]
radius = 8.0
height = 16.0
[node name="Player" groups=["Player"] instance=ExtResource("1_kmfws")]
script = ExtResource("2_s0pfn")
[node name="Area2D" parent="." index="0" groups=["Player"]]
[node name="CollisionShape2D" parent="Area2D" index="0"]
position = Vector2(0, 8)
shape = SubResource("RectangleShape2D_gk017")
[node name="CollisionShape2D" parent="." index="1"]
position = Vector2(0, 8)
shape = SubResource("CapsuleShape2D_upmug")
[node name="AnimatedSprite2D" parent="." index="2"]
sprite_frames = ExtResource("3_mlsai")
animation = &"DOWN"
metadata/_aseprite_wizard_config_ = {
"layer": "",
"o_ex_p": "",
"o_folder": "",
"o_name": "",
"only_visible": false,
"slice": "",
"source": "res://Assets/Player/Player.ase"
}
metadata/_aseprite_wizard_interface_config_ = {
"layer_section": false,
"slice_section": false
}
[node name="Camera2D" type="Camera2D" parent="." index="3"]
zoom = Vector2(3, 3)
limit_smoothed = true
position_smoothing_enabled = true
[node name="RollTimer" type="Timer" parent="." index="4"]
one_shot = true
[node name="RollCooldownTimer" type="Timer" parent="." index="5"]
one_shot = true
[connection signal="timeout" from="RollTimer" to="." method="_on_roll_timeout"]
[connection signal="timeout" from="RollCooldownTimer" to="." method="_on_roll_cooldown_timer_timeout"]