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

4
scenes/GLOBAL.gd Normal file
View file

@ -0,0 +1,4 @@
extends Node
func resetValues():
pass

View file

@ -0,0 +1,47 @@
extends CharacterBody2D
## Signal for when the entity dies
signal death
## Signal for when the entity gets damaged
signal damaged
## Signal for when the entity gets healed
signal healed
## The maximal possible amount of Health for the Entity
@export_range(1,100) var maxHealth = 10
## The maximal possible Speed of the Entity
@export_range(100,500) var maxSpeed = 200
## The normal Speed between Min and Max
@export_range(100,500) var normalSpeed = 100
## The lowest possible Speed of the Entity
@export_range(100,500) var minSpeed = 50
## Acceleration of the Entity
@export_range(100,500) var acceleration = 10
@onready var health = maxHealth
@onready var speed = normalSpeed
var invincible = false
func hit(damage : int) -> void:
health -= damage
damaged.emit()
if health <= 0:
health = 0
death.emit()
func heal(heal : int) -> void:
health += heal
healed.emit()
if health >= maxHealth:
health = maxHealth
func resetSpeed():
speed = normalSpeed
func resetHealth():
health = health
func setSpeed(n):
speed = n

View file

@ -0,0 +1,17 @@
[gd_scene load_steps=2 format=3 uid="uid://b18cf4i8v6a1"]
[ext_resource type="Script" path="res://scenes/game/entities/entity.gd" id="1_s7hj7"]
[node name="Entity" type="CharacterBody2D" groups=["Entity"]]
collision_layer = 2
script = ExtResource("1_s7hj7")
[node name="Area2D" type="Area2D" parent="." groups=["Entity"]]
collision_layer = 8
collision_mask = 16
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]

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"]

View file

@ -4,7 +4,6 @@ extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
print()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:

View file

@ -1,6 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://dgxw2n4ei2ahe"]
[gd_scene load_steps=4 format=3 uid="uid://dgxw2n4ei2ahe"]
[ext_resource type="Script" path="res://scenes/game/mainGame/main_game.gd" id="1_napbe"]
[ext_resource type="PackedScene" uid="uid://0duodsosmfpq" path="res://scenes/game/entities/player/player.tscn" id="3_sjgkj"]
[ext_resource type="PackedScene" uid="uid://br7eqr6jomsg4" path="res://scenes/game/map/map.tscn" id="3_vpriv"]
[node name="mainGame" type="Node2D"]
script = ExtResource("1_napbe")
[node name="Map" parent="." instance=ExtResource("3_vpriv")]
[node name="Player" parent="." instance=ExtResource("3_sjgkj")]

View file

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=4 uid="uid://4bbmk4wy0a1b"]
[ext_resource type="TileSet" path="res://Assets/Tilemaps/Floor.tres" id="1_557um"]
[node name="Floor" type="TileMapLayer"]
position = Vector2(16, 32)
tile_map_data = PackedByteArray("AAD+//3/AAAAAAAAAAD+//7/AAAAAAAAAAD9//7/AAAAAAAAAAD///3/AAAAAAAAAAAAAP7/AAAAAAAAAAD///7/AAAAAAAAAAD9////AAAAAAAAAAD8////AAAAAAAAAAD/////AAAAAAAAAAD9/wAAAAAAAAAAAAD+////AAAAAAAAAAA=")
tile_set = ExtResource("1_557um")

9
scenes/game/map/map.tscn Normal file
View file

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=4 uid="uid://br7eqr6jomsg4"]
[ext_resource type="TileSet" uid="uid://64vn4umcy2ke" path="res://Assets/Tilemaps/Walls.tres" id="1_gju0a"]
[node name="Map" type="Node2D"]
[node name="Walls" type="TileMapLayer" parent="."]
tile_map_data = PackedByteArray("AAD///7/AAAAAAAAAAAAAP7/AAAAAAAAAAD+////AAAAAAAAAAD+/wAAAAAAAAAAAAD+//7/AAAAAAAAAAABAP7/AAAAAAAAAAACAP7/AAAAAAAAAAD+/wEAAAAAAAAAAAD+/wIAAAAAAAAAAAD+/wMAAAAAAAAAAAADAP7/AAAAAAAAAAAEAP7/AAAAAAAAAAA=")
tile_set = ExtResource("1_gju0a")

View file

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=4 uid="uid://m3sgr6auims"]
[ext_resource type="TileSet" path="res://Assets/Tilemaps/Wall.tres" id="1_8k7fq"]
[node name="Walls" type="TileMapLayer"]
position = Vector2(16, 32)
tile_map_data = PackedByteArray("AAD8//v/AAAAAAEAAAD8//z/AAABAAAAAAD7//3/AAABAAEAAAD7//v/AAABAAEAAAD8//r/AAADAAEAAAD9//z/AAADAAEAAAD8//7/AAABAAAAAAD7////AAABAAEAAAD8////AAAAAAEAAAD8/wAAAAAAAAAAAAD9//3/AAAAAAEAAAD9//7/AAACAAEAAAD8//3/AAABAAAAAAA=")
tile_set = ExtResource("1_8k7fq")

11
scenes/main/main.gd Normal file
View file

@ -0,0 +1,11 @@
extends Node
func _ready() -> void:
loadGame()
func loadGame():
G.resetValues()
for i in get_children():
i.queue_free()
add_child(load("res://scenes/game/mainGame/main_game.tscn").instantiate())

View file

@ -1,3 +1,6 @@
[gd_scene format=3 uid="uid://bwsbkfnkncfhp"]
[gd_scene load_steps=2 format=3 uid="uid://bwsbkfnkncfhp"]
[ext_resource type="Script" path="res://scenes/main/main.gd" id="1_1blp2"]
[node name="Main" type="Node"]
script = ExtResource("1_1blp2")