Added Map; Added Spawners; Changed Decorations; Cleaned up Code and some Settings; Added Enemy

This commit is contained in:
Exobyt 2024-09-14 19:34:17 +02:00
parent e82438139f
commit e18beb6c4c
160 changed files with 4674 additions and 182 deletions

View file

@ -0,0 +1,98 @@
extends "res://scenes/game/entities/entity.gd"
@export_range(1,10) var damage = 1
@export_range(0.1,1) var attackCooldown = 1
@onready var navigationAgent = $NavigationAgent
@onready var targetRaycast = $Radius/RayCast2D
@onready var attackCooldownTimer = $AttackCooldown
@onready var damageArea = $DamageArea
@onready var focusedPlayer = null
func focusPlayer(player):
focusedPlayer = player
func unfocusPlayer():
focusedPlayer = null
func _ready() -> void:
navigationAgent.velocity_computed.connect(Callable(_on_navigation_agent_velocity_computed))
func set_movement_target(movement_target: Vector2):
navigationAgent.set_target_position(movement_target)
func moveTowardsPlayer():
if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
navigationAgent.target_position = focusedPlayer.global_position
func _physics_process(delta: float) -> void:
if focusedPlayer != null:
#targetRaycast.target_position = focusedPlayer.global_position - global_position
if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
navigationAgent.target_position = focusedPlayer.global_position
if focusedPlayer != null:
targetRaycast.target_position = focusedPlayer.global_position - global_position
else:
targetRaycast.target_position = Vector2(global_position.x-1000,global_position.y-1000)
#if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
# navigationAgent.target_position = focusedPlayer.global_position
#if global_position.distance_squared_to(focusedPlayer.global_position) > speed *10:
#moveTowardsPlayer()
var currentAgentPosition = global_position
if NavigationServer2D.map_get_iteration_id(navigationAgent.get_navigation_map()) == 0:
return
if navigationAgent.is_navigation_finished():
return
var nextPathPosition = navigationAgent.get_next_path_position()
var newVelocity = currentAgentPosition.direction_to(nextPathPosition)
if navigationAgent.avoidance_enabled:
navigationAgent.set_velocity(newVelocity * speed)
else:
_on_navigation_agent_velocity_computed(newVelocity)
func _on_navigation_agent_velocity_computed(safe_velocity: Vector2) -> void:
velocity = safe_velocity
move_and_slide()
func _on_radius_body_entered(body: Node2D) -> void:
if body.is_in_group("Player"):
focusPlayer(body)
func _on_radius_body_exited(body: Node2D) -> void:
if body.is_in_group("Player"):
unfocusPlayer()
func attack():
damageArea.attack(damage)
func _on_damage_area_area_entered(area: Area2D) -> void:
attackCooldownTimer.start(attackCooldown)
func _on_attack_cooldown_timeout() -> void:
attack()
attackCooldownTimer.start(attackCooldown)
func _on_damage_area_area_exited(area: Area2D) -> void:
#attackCooldownTimer.time_left = attackCooldown
attackCooldownTimer.stop()
#func _on_ray_cast_2d_draw() -> void:
#if focusedPlayer != null:
##targetRaycast.target_position = focusedPlayer.global_position - global_position
#if $Radius.get_overlapping_bodies() != [] and not targetRaycast.is_colliding():
#navigationAgent.target_position = focusedPlayer.global_position

View file

@ -0,0 +1,91 @@
[gd_scene load_steps=11 format=3 uid="uid://bnxx7nnifjica"]
[ext_resource type="PackedScene" uid="uid://b18cf4i8v6a1" path="res://scenes/game/entities/entity.tscn" id="1_bf5v6"]
[ext_resource type="Script" path="res://scenes/game/entities/Enemy/enemy.gd" id="2_4vapd"]
[ext_resource type="Texture2D" uid="uid://dh14dje1066et" path="res://icon.svg" id="3_jenk6"]
[ext_resource type="PackedScene" uid="uid://cwirujaquehfc" path="res://scenes/game/Hitbox/damage_area.tscn" id="4_mr72k"]
[sub_resource type="CircleShape2D" id="CircleShape2D_xq7op"]
radius = 8.0
[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_c882v"]
light_mode = 2
[sub_resource type="AtlasTexture" id="AtlasTexture_rdbks"]
atlas = ExtResource("3_jenk6")
region = Rect2(0, 0, 128, 128)
[sub_resource type="SpriteFrames" id="SpriteFrames_i6h2x"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_rdbks")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_w20ih"]
radius = 128.0
height = 384.0
[sub_resource type="CircleShape2D" id="CircleShape2D_eto3a"]
radius = 16.0
[node name="Enemy" groups=["Enemy"] instance=ExtResource("1_bf5v6")]
collision_layer = 2560
script = ExtResource("2_4vapd")
damage = 1
attackCooldown = 1
normalSpeed = 80
[node name="CollisionShape2D" parent="." index="0"]
shape = SubResource("CircleShape2D_xq7op")
[node name="AnimatedSprite2D" parent="." index="1"]
material = SubResource("CanvasItemMaterial_c882v")
position = Vector2(2.38419e-07, 2.38419e-07)
scale = Vector2(0.125, 0.125)
sprite_frames = SubResource("SpriteFrames_i6h2x")
[node name="NavigationAgent" type="NavigationAgent2D" parent="." index="2"]
path_postprocessing = 1
simplify_path = true
avoidance_enabled = true
avoidance_layers = 2560
avoidance_mask = 3630
debug_enabled = true
debug_use_custom = true
debug_path_custom_color = Color(1, 0, 0, 1)
[node name="Radius" type="Area2D" parent="." index="3" groups=["Enemy"]]
collision_layer = 3687
collision_mask = 1024
[node name="CollisionShape2D" type="CollisionShape2D" parent="Radius" index="0"]
rotation = -1.57079
shape = SubResource("CapsuleShape2D_w20ih")
[node name="RayCast2D" type="RayCast2D" parent="Radius" index="1"]
target_position = Vector2(-12.48, 16)
collision_mask = 14
hit_from_inside = true
[node name="DamageArea" parent="." index="4" instance=ExtResource("4_mr72k")]
[node name="CollisionShape2D" parent="DamageArea" index="0"]
shape = SubResource("CircleShape2D_eto3a")
[node name="AttackCooldown" type="Timer" parent="." index="5"]
one_shot = true
[connection signal="velocity_computed" from="NavigationAgent" to="." method="_on_navigation_agent_velocity_computed"]
[connection signal="body_entered" from="Radius" to="." method="_on_radius_body_entered"]
[connection signal="body_exited" from="Radius" to="." method="_on_radius_body_exited"]
[connection signal="draw" from="Radius/RayCast2D" to="." method="_on_ray_cast_2d_draw"]
[connection signal="area_entered" from="DamageArea" to="." method="_on_damage_area_area_entered"]
[connection signal="area_exited" from="DamageArea" to="." method="_on_damage_area_area_exited"]
[connection signal="timeout" from="AttackCooldown" to="." method="_on_attack_cooldown_timeout"]
[editable path="DamageArea"]

View file

@ -1,5 +1,7 @@
extends CharacterBody2D
@onready var animatedSprite = $AnimatedSprite2D
## Signal for when the entity dies
signal death
## Signal for when the entity gets damaged
@ -11,11 +13,11 @@ signal healed
@export_range(1,100) var maxHealth = 10
## The maximal possible Speed of the Entity
@export_range(100,500) var maxSpeed = 200
@export_range(10,500) var maxSpeed = 200
## The normal Speed between Min and Max
@export_range(100,500) var normalSpeed = 100
@export_range(10,500) var normalSpeed = 100
## The lowest possible Speed of the Entity
@export_range(100,500) var minSpeed = 50
@export_range(10,500) var minSpeed = 50
## Acceleration of the Entity
@export_range(100,500) var acceleration = 10

View file

@ -3,11 +3,12 @@
[ext_resource type="Script" path="res://scenes/game/entities/entity.gd" id="1_s7hj7"]
[node name="Entity" type="CharacterBody2D" groups=["Entity"]]
light_mask = 4
visibility_layer = 4
light_mask = 512
visibility_layer = 512
z_index = 1
y_sort_enabled = true
collision_layer = 2
collision_layer = 512
collision_mask = 14
script = ExtResource("1_s7hj7")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

View file

@ -0,0 +1,26 @@
extends Camera2D
@export var INTENSITY = 2.0
@export var DURATION = 1000.0
@export var STARTTIME = 0
var currentStrength = 1
func _ready() -> void:
randomize()
func _process(delta: float) -> void:
var decreaser = (DURATION - (Time.get_ticks_msec() - STARTTIME)) / DURATION
var randX = randf_range(-1,1) * currentStrength * decreaser
var randY = randf_range(-1,1) * currentStrength * decreaser
offset = Vector2(randX, randY)
if decreaser < 0:
offset = Vector2.ZERO
func shake(strength : float = 1, duration : float = 1):
currentStrength = float(strength)
DURATION = float(duration*1000)
STARTTIME = Time.get_ticks_msec()

View file

@ -3,14 +3,16 @@ extends "res://scenes/game/entities/entity.gd"
@onready var rollTimer = $RollTimer
@onready var rollCooldownTimer = $RollCooldownTimer
@onready var animatedSprite = $AnimatedSprite2D
@onready var pickupArea = $PickupArea
@onready var interactionArea = $InteractionArea
@onready var healthBar = $Camera2D/CanvasLayer/Control/VBoxContainer/HealthBar
@onready var rollCooldownBar = $Camera2D/CanvasLayer/Control/VBoxContainer/RollCooldownBar
@onready var healthBar = $Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer/HealthBar
@onready var rollCooldownBar = $Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer2/RollCooldownBar
@onready var moneyValueLabel = $Camera2D/CanvasLayer/Control/HBoxContainer/MoneyValue
@onready var objectValue = $Camera2D/CanvasLayer/Control/ObjectValues/ObjectMoneyValue
@onready var objectValues = $Camera2D/CanvasLayer/Control/ObjectValues
@onready var camera = $Camera2D
var rollSpeed = maxSpeed * 5
@ -33,12 +35,18 @@ func _ready():
healthBar.min_value = 0
healthBar.max_value = health
func _physics_process(delta: float) -> void:
func setHudValues():
rollCooldownBar.value = rollCooldownTimer.time_left
healthBar.value = health
moneyValueLabel.text = str(G.money)
if object != null:
objectValues.show()
objectValue.text = str(object.getValue())
else:
objectValues.hide()
func _physics_process(delta: float) -> void:
setHudValues()
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"),
@ -51,12 +59,15 @@ func _physics_process(delta: float) -> void:
lastdirectionVector = directionVector
if Input.is_action_just_pressed("ROLL") and lastDirection != Vector2.ZERO:
roll()
if Input.is_action_just_pressed("INTERACT"):
if Input.is_action_just_pressed("ROLL") and lastDirection != Vector2.ZERO:
roll()
if Input.is_action_just_pressed("DOOR"):
openDoor()
if Input.is_action_just_pressed("Pickup"):
match carrying:
false:
pickup(getNearestObject(pickupArea.get_overlapping_areas()))
pickup(getNearestObject(interactionArea.get_overlapping_areas()))
true:
dropObject()
#pickupArea.get_overlapping_areas()[0].pickup(self)
@ -118,7 +129,7 @@ func _on_roll_cooldown_timer_timeout() -> void:
canRoll = true
func pickup(newObject):
if newObject != null:
if newObject != null and newObject.is_in_group("Object"):
if newObject.player == null and not rolling:
carrying = true
object = newObject
@ -137,10 +148,25 @@ func getNearestObject(list):
var shortestDistance = 0
if list != []:
for i in list:
if nearestObject == null:
shortestDistance = global_position.distance_to(i.global_position)
nearestObject = i
elif shortestDistance > global_position.distance_to(i.global_position):
shortestDistance = global_position.distance_to(i.global_position)
nearestObject = i
if i.is_in_group("Object"):
if nearestObject == null:
shortestDistance = global_position.distance_to(i.global_position)
nearestObject = i
elif shortestDistance > global_position.distance_to(i.global_position):
shortestDistance = global_position.distance_to(i.global_position)
nearestObject = i
return nearestObject
func openDoor():
for door in interactionArea.get_overlapping_areas():
if door.is_in_group("Door"):
door.get_parent().toggle()
func _on_hit_box_signal_hit(damage: Variant) -> void:
hit(damage)
camera.shake(2,0.5)
func _on_death() -> void:
print("HOHO")

View file

@ -1,30 +1,45 @@
[gd_scene load_steps=6 format=3 uid="uid://0duodsosmfpq"]
[gd_scene load_steps=17 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"]
[ext_resource type="Texture2D" uid="uid://drjv0kpcfubr0" path="res://Assets/Icons/Dollar.png" id="4_6t857"]
[ext_resource type="Theme" uid="uid://brft526ygjv2u" path="res://Theme/Hud.tres" id="4_pkh7x"]
[ext_resource type="Script" path="res://scenes/game/entities/player/camera.gd" id="4_pm6vd"]
[ext_resource type="Texture2D" uid="uid://doeb4tgupsuhn" path="res://Assets/LightRadius.png" id="4_rgjff"]
[ext_resource type="PackedScene" uid="uid://c2lwkqoigo128" path="res://scenes/game/Hitbox/hit_box.tscn" id="5_al0qa"]
[ext_resource type="Texture2D" uid="uid://b27g8eulkxvyr" path="res://Assets/Icons/Health.png" id="6_4smqb"]
[ext_resource type="StyleBox" uid="uid://cicm0nqh0g7fd" path="res://Theme/RollBar.tres" id="7_0w6mh"]
[ext_resource type="StyleBox" uid="uid://31r7sc1edews" path="res://Theme/Empty.tres" id="7_luccy"]
[ext_resource type="StyleBox" uid="uid://6x7dblrcglcl" path="res://Theme/HealthBar.tres" id="8_kgbvc"]
[ext_resource type="Texture2D" uid="uid://c2o4115sewunm" path="res://Assets/Icons/Roll.png" id="10_1rhoe"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_ihc0q"]
radius = 4.0
height = 16.0
[sub_resource type="CircleShape2D" id="CircleShape2D_7ukjs"]
radius = 8.94427
[sub_resource type="CircleShape2D" id="CircleShape2D_8u3aq"]
radius = 8.94427
[sub_resource type="CircleShape2D" id="CircleShape2D_bjveg"]
radius = 8.94427
[node name="Player" groups=["Player"] instance=ExtResource("1_kmfws")]
light_mask = 1536
visibility_layer = 1536
collision_layer = 1536
script = ExtResource("2_s0pfn")
[node name="CollisionShape2D" parent="." index="0"]
position = Vector2(0, 8)
position = Vector2(0, 4)
rotation = 1.57079
shape = SubResource("CapsuleShape2D_ihc0q")
shape = SubResource("CircleShape2D_7ukjs")
[node name="AnimatedSprite2D" parent="." index="1"]
visibility_layer = 4
light_mask = 1024
visibility_layer = 1024
scale = Vector2(1.5, 1.5)
sprite_frames = ExtResource("3_mlsai")
animation = &"IDLE"
frame_progress = 0.904526
animation = &"DOWN"
metadata/_aseprite_wizard_config_ = {
"layer": "",
"o_ex_p": "",
@ -43,6 +58,8 @@ metadata/_aseprite_wizard_interface_config_ = {
zoom = Vector2(4, 4)
limit_smoothed = true
position_smoothing_enabled = true
drag_horizontal_enabled = true
script = ExtResource("4_pm6vd")
[node name="CanvasLayer" type="CanvasLayer" parent="Camera2D" index="0"]
@ -55,54 +72,134 @@ grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource("4_pkh7x")
[node name="HBoxContainer" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control" index="0"]
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0
[node name="MoneyLabel" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer" index="0"]
[node name="TextureRect" type="TextureRect" parent="Camera2D/CanvasLayer/Control/HBoxContainer" index="0"]
layout_mode = 2
texture = ExtResource("4_6t857")
[node name="MoneyLabel" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer" index="1"]
visible = false
layout_mode = 2
text = "MONEY"
[node name="MoneyValue" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer" index="1"]
[node name="MoneyValue" type="Label" parent="Camera2D/CanvasLayer/Control/HBoxContainer" index="2"]
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="Camera2D/CanvasLayer/Control" index="1"]
modulate = Color(1, 1, 1, 0.901961)
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 16.0
offset_top = -63.9999
offset_right = 312.0
offset_bottom = -29.0
offset_top = -120.0
offset_right = 517.0
offset_bottom = -49.0
grow_vertical = 0
scale = Vector2(1.5, 1.5)
size_flags_horizontal = 3
alignment = 1
[node name="RollCooldownBar" type="ProgressBar" parent="Camera2D/CanvasLayer/Control/VBoxContainer" index="0"]
[node name="HBoxContainer2" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control/VBoxContainer" index="0"]
layout_mode = 2
size_flags_vertical = 3
[node name="TextureRect" type="TextureRect" parent="Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer2" index="0"]
layout_mode = 2
texture = ExtResource("10_1rhoe")
expand_mode = 2
[node name="RollCooldownBar" type="ProgressBar" parent="Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer2" index="1"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
theme_override_font_sizes/font_size = 16
theme_override_styles/background = ExtResource("7_0w6mh")
theme_override_styles/fill = ExtResource("7_luccy")
fill_mode = 1
show_percentage = false
[node name="HealthBar" type="ProgressBar" parent="Camera2D/CanvasLayer/Control/VBoxContainer" index="1"]
[node name="HBoxContainer" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control/VBoxContainer" index="1"]
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer" index="0"]
layout_mode = 2
texture = ExtResource("6_4smqb")
expand_mode = 2
[node name="HealthBar" type="ProgressBar" parent="Camera2D/CanvasLayer/Control/VBoxContainer/HBoxContainer" index="1"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 16
theme_override_styles/background = ExtResource("7_luccy")
theme_override_styles/fill = ExtResource("8_kgbvc")
rounded = true
[node name="ObjectValues" type="HBoxContainer" parent="Camera2D/CanvasLayer/Control" index="2"]
layout_mode = 1
anchors_preset = 3
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -288.0
offset_top = -112.0
offset_right = -22.0
offset_bottom = -12.0
grow_horizontal = 0
grow_vertical = 0
alignment = 2
[node name="MoneyLabel" type="Label" parent="Camera2D/CanvasLayer/Control/ObjectValues" index="0"]
layout_mode = 2
text = "+"
[node name="ObjectMoneyValue" type="Label" parent="Camera2D/CanvasLayer/Control/ObjectValues" index="1"]
layout_mode = 2
[node name="TextureRect" type="TextureRect" parent="Camera2D/CanvasLayer/Control/ObjectValues" index="2"]
layout_mode = 2
texture = ExtResource("4_6t857")
[node name="RollTimer" type="Timer" parent="." index="3"]
one_shot = true
[node name="RollCooldownTimer" type="Timer" parent="." index="4"]
one_shot = true
[node name="PickupArea" type="Area2D" parent="." index="5" groups=["Player"]]
collision_layer = 8
collision_mask = 4
[node name="InteractionArea" type="Area2D" parent="." index="5" groups=["Player"]]
collision_layer = 64
collision_mask = 24
[node name="CollisionShape2D" type="CollisionShape2D" parent="PickupArea" index="0"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractionArea" index="0"]
position = Vector2(0, 4)
shape = SubResource("CircleShape2D_8u3aq")
[node name="PointLight2D" type="PointLight2D" parent="." index="6"]
position = Vector2(0, 4)
color = Color(0.74978, 0.74978, 0.74978, 1)
energy = 0.5
range_item_cull_mask = 3647
shadow_enabled = true
shadow_item_cull_mask = 10
texture = ExtResource("4_rgjff")
texture_scale = 2.0
[node name="HitBox" parent="." index="7" instance=ExtResource("5_al0qa")]
[node name="CollisionShape2D" parent="HitBox" index="0"]
position = Vector2(0, 4)
shape = SubResource("CircleShape2D_bjveg")
[connection signal="death" from="." to="." method="_on_death"]
[connection signal="timeout" from="RollTimer" to="." method="_on_roll_timeout"]
[connection signal="timeout" from="RollCooldownTimer" to="." method="_on_roll_cooldown_timer_timeout"]
[connection signal="signalHit" from="HitBox" to="." method="_on_hit_box_signal_hit"]
[editable path="HitBox"]