Added Objects
This commit is contained in:
parent
eb11047456
commit
78dcaac886
11 changed files with 148 additions and 35 deletions
|
|
@ -3,15 +3,17 @@
|
|||
[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
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
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="."]
|
||||
light_mask = 4
|
||||
visibility_layer = 5
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ extends "res://scenes/game/entities/entity.gd"
|
|||
|
||||
@onready var animatedSprite = $AnimatedSprite2D
|
||||
|
||||
@onready var pickupArea = $PickupArea
|
||||
|
||||
var rollSpeed = maxSpeed * 5
|
||||
|
||||
const rollCooldown = 5.0
|
||||
|
|
@ -14,6 +16,9 @@ var rolling = false
|
|||
|
||||
var canRoll = true
|
||||
|
||||
var carrying = false
|
||||
var object = null
|
||||
|
||||
var lastDirection : Vector2
|
||||
var lastdirectionVector : Vector2
|
||||
|
||||
|
|
@ -31,6 +36,17 @@ 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"):
|
||||
match carrying:
|
||||
false:
|
||||
if pickupArea.get_overlapping_areas() != []:
|
||||
pickup(pickupArea.get_overlapping_areas()[0])
|
||||
true:
|
||||
dropObject()
|
||||
#pickupArea.get_overlapping_areas()[0].pickup(self)
|
||||
#print(pickupArea.get_overlapping_areas())
|
||||
|
||||
|
||||
if rolling:
|
||||
move(lastdirectionVector * speed, acceleration)
|
||||
else:
|
||||
|
|
@ -48,21 +64,12 @@ func move(newVelocity : Vector2, acc):
|
|||
|
||||
func roll():
|
||||
if not rolling and canRoll:
|
||||
dropObject()
|
||||
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:
|
||||
|
|
@ -76,3 +83,28 @@ func setAnimation():
|
|||
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")
|
||||
|
||||
|
||||
func _on_roll_timeout() -> void:
|
||||
resetSpeed()
|
||||
invincible = false
|
||||
rolling = false
|
||||
rollCooldownTimer.start(rollCooldown)
|
||||
|
||||
|
||||
func _on_roll_cooldown_timer_timeout() -> void:
|
||||
canRoll = true
|
||||
|
||||
func pickup(newObject):
|
||||
if newObject.player == null and not rolling:
|
||||
carrying = true
|
||||
object = newObject
|
||||
speed -= object.getWeight()
|
||||
object.pickup(self)
|
||||
|
||||
func dropObject():
|
||||
if carrying:
|
||||
carrying = false
|
||||
object.drop()
|
||||
object = null
|
||||
resetSpeed()
|
||||
|
|
|
|||
|
|
@ -4,27 +4,21 @@
|
|||
[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
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_8u3aq"]
|
||||
radius = 8.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"]
|
||||
[node name="CollisionShape2D" parent="." index="0"]
|
||||
position = Vector2(0, 8)
|
||||
shape = SubResource("CapsuleShape2D_upmug")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="2"]
|
||||
[node name="AnimatedSprite2D" parent="." index="1"]
|
||||
sprite_frames = ExtResource("3_mlsai")
|
||||
animation = &"DOWN"
|
||||
metadata/_aseprite_wizard_config_ = {
|
||||
|
|
@ -41,16 +35,24 @@ metadata/_aseprite_wizard_interface_config_ = {
|
|||
"slice_section": false
|
||||
}
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="." index="3"]
|
||||
[node name="Camera2D" type="Camera2D" parent="." index="2"]
|
||||
zoom = Vector2(3, 3)
|
||||
limit_smoothed = true
|
||||
position_smoothing_enabled = true
|
||||
|
||||
[node name="RollTimer" type="Timer" parent="." index="4"]
|
||||
[node name="RollTimer" type="Timer" parent="." index="3"]
|
||||
one_shot = true
|
||||
|
||||
[node name="RollCooldownTimer" type="Timer" parent="." index="5"]
|
||||
[node name="RollCooldownTimer" type="Timer" parent="." index="4"]
|
||||
one_shot = true
|
||||
|
||||
[node name="PickupArea" type="Area2D" parent="." index="5" groups=["Player"]]
|
||||
position = Vector2(0, 8)
|
||||
collision_layer = 8
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="PickupArea" index="0"]
|
||||
shape = SubResource("CircleShape2D_8u3aq")
|
||||
|
||||
[connection signal="timeout" from="RollTimer" to="." method="_on_roll_timeout"]
|
||||
[connection signal="timeout" from="RollCooldownTimer" to="." method="_on_roll_cooldown_timer_timeout"]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dgxw2n4ei2ahe"]
|
||||
[gd_scene load_steps=5 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"]
|
||||
[ext_resource type="PackedScene" uid="uid://41ksceqosqq2" path="res://scenes/game/objects/Vase/vase.tscn" id="4_mot7l"]
|
||||
|
||||
[node name="mainGame" type="Node2D"]
|
||||
script = ExtResource("1_napbe")
|
||||
|
|
@ -10,3 +11,11 @@ script = ExtResource("1_napbe")
|
|||
[node name="Map" parent="." instance=ExtResource("3_vpriv")]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("3_sjgkj")]
|
||||
light_mask = 1
|
||||
visibility_layer = 1
|
||||
z_index = 0
|
||||
y_sort_enabled = false
|
||||
|
||||
[node name="Vase" parent="." instance=ExtResource("4_mot7l")]
|
||||
position = Vector2(32, 24)
|
||||
value = 985
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
[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_map_data = PackedByteArray("AAD///7/AAAAAAAAAAAAAP7/AAAAAAAAAAD+////AAAAAAAAAAD+/wAAAAAAAAAAAAD+//7/AAAAAAAAAAABAP7/AAAAAAAAAAACAP7/AAAAAAAAAAD+/wEAAAAAAAAAAAD+/wIAAAAAAAAAAAD+/wMAAAAAAAAAAAADAP7/AAAAAAAAAAAEAP7/AAAAAAAAAAD//wMAAAAAAAAAAAACAAMAAAAAAAAAAAADAAMAAAAAAAAAAAAEAAMAAAAAAAAAAAAEAAQAAAAAAAAAAAADAAYAAAAAAAAAAAACAAYAAAAAAAAAAAABAAYAAAAAAAAAAAAAAAYAAAAAAAAAAAD//wYAAAAAAAAAAAD+/wYAAAAAAAAAAAADAAUAAAAAAAAAAAAEAAUAAAAAAAAAAAAEAAYAAAAAAAAAAAAFAAMAAAAAAAAAAAAFAAIAAAAAAAAAAAAFAAEAAAAAAAAAAAA=")
|
||||
tile_set = ExtResource("1_gju0a")
|
||||
|
|
|
|||
15
scenes/game/objects/Vase/vase.tscn
Normal file
15
scenes/game/objects/Vase/vase.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://41ksceqosqq2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dxpd1pq7v6ing" path="res://scenes/game/objects/object.tscn" id="1_fkdlr"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_pmiic"]
|
||||
radius = 12.0
|
||||
|
||||
[node name="Vase" instance=ExtResource("1_fkdlr")]
|
||||
y_sort_enabled = true
|
||||
|
||||
[node name="CollisionShape2D" parent="." index="0"]
|
||||
shape = SubResource("CircleShape2D_pmiic")
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="1"]
|
||||
animation = &""
|
||||
30
scenes/game/objects/object.gd
Normal file
30
scenes/game/objects/object.gd
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
extends Area2D
|
||||
|
||||
@export_range(10,1000) var value = 10
|
||||
@export_range(1,70) var weight = 1
|
||||
|
||||
const heavy = 50
|
||||
|
||||
var player = null
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
#if player != null and weight >= heavy :
|
||||
#global_position.y = move_toward(global_position.y, player.global_position.y, 5)
|
||||
#global_position.x = move_toward(global_position.x, player.global_position.x, 5)
|
||||
|
||||
#if player != null and weight <= heavy :
|
||||
if player != null:
|
||||
global_position.y = move_toward(global_position.y, player.global_position.y, 3)
|
||||
global_position.x = move_toward(global_position.x, player.global_position.x, 3)
|
||||
|
||||
func pickup(newPlayer):
|
||||
z_index = 2
|
||||
player = newPlayer
|
||||
|
||||
func drop():
|
||||
global_position.y += 10
|
||||
player = null
|
||||
z_index = 0
|
||||
|
||||
func getWeight():
|
||||
return weight
|
||||
12
scenes/game/objects/object.tscn
Normal file
12
scenes/game/objects/object.tscn
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://dxpd1pq7v6ing"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/game/objects/object.gd" id="1_3y27f"]
|
||||
|
||||
[node name="Object" type="Area2D" groups=["Object"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 8
|
||||
script = ExtResource("1_3y27f")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
Loading…
Add table
Add a link
Reference in a new issue