Added Level. Removed params from _init()

This commit is contained in:
2024-09-09 02:15:39 +03:00
parent f4758551cb
commit e7cbf0a6a1
11 changed files with 78 additions and 49 deletions
+15 -18
View File
@@ -1,11 +1,13 @@
class_name Door
extends StaticBody2D
enum DoorType {BOTTOM_DOOR, TOP_DOOR}
@export var door_type: DoorType
@export var type: DoorType
enum DoorState {OPENED, CLOSED, OPENING, CLOSING}
@export var door_state: DoorState
@export var state: DoorState
var ANIMATIONS_BY_TYPE : Dictionary = {
@@ -25,50 +27,45 @@ signal opened()
signal closed()
func _init(type: DoorType = DoorType.BOTTOM_DOOR, state: DoorState = DoorState.OPENED) -> void:
door_type = type
door_state = state
func _ready() -> void:
play_animation()
func play_animation() -> void:
var animation : String = "%s_%s" % [
ANIMATIONS_BY_TYPE[door_type],
ANIMATIONS_BY_STATE[door_state]
ANIMATIONS_BY_TYPE[type],
ANIMATIONS_BY_STATE[state]
]
$AnimatedSprite2D.play(animation)
func open() -> void:
if door_state != DoorState.CLOSED:
print("Door in state '%s' can't be opened" % DoorState.find_key(door_state))
if state != DoorState.CLOSED:
print("Door in state '%s' can't be opened" % DoorState.find_key(state))
return
door_state = DoorState.OPENING
state = DoorState.OPENING
play_animation()
func close():
if door_state != DoorState.OPENED:
print("Door in state '%s' can't be closed" % DoorState.find_key(door_state))
if state != DoorState.OPENED:
print("Door in state '%s' can't be closed" % DoorState.find_key(state))
return
door_state = DoorState.CLOSING
state = DoorState.CLOSING
play_animation()
func _on_animated_sprite_2d_animation_finished() -> void:
match door_state:
match state:
DoorState.CLOSING:
door_state = DoorState.CLOSED
state = DoorState.CLOSED
$CollisionShape2D.disabled = false
play_animation()
DoorState.OPENING:
door_state = DoorState.OPENED
state = DoorState.OPENED
$CollisionShape2D.disabled = true
play_animation()
DoorState.CLOSED:
+2
View File
@@ -250,8 +250,10 @@ script = ExtResource("1_7rkx7")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
position = Vector2(8, 8)
sprite_frames = SubResource("SpriteFrames_uucy3")
animation = &"bottom_door_opened"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(8, 8)
shape = SubResource("RectangleShape2D_notjl")
+4 -6
View File
@@ -1,10 +1,12 @@
class_name Field
extends StaticBody2D
enum FieldType {
MIDDLE, CORNER, TOP, LEFT,
}
@export var field_type: FieldType
@export var type: FieldType
var POSITIONS_BY_TYPE : Dictionary = {
@@ -39,14 +41,10 @@ var POSITIONS_BY_TYPE : Dictionary = {
}
func _init(type : FieldType = FieldType.MIDDLE) -> void:
field_type = type
func _ready() -> void:
update_atlas_position()
func update_atlas_position() -> void:
var positions = POSITIONS_BY_TYPE[field_type]
var positions = POSITIONS_BY_TYPE[type]
$Sprite2D.texture.region.position = positions[randi() % positions.size()]
+2 -1
View File
@@ -12,11 +12,12 @@ size = Vector2(16, 16)
[node name="Field" type="StaticBody2D"]
script = ExtResource("1_hih70")
field_type = 1
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
position = Vector2(8, 8)
texture = SubResource("AtlasTexture_moxxr")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(8, 8)
shape = SubResource("RectangleShape2D_17j0p")
+4 -6
View File
@@ -1,3 +1,5 @@
class_name Forest
extends StaticBody2D
@@ -8,7 +10,7 @@ enum ForestType {
FRAME_TOP_LEFT, FRAME_TOP_RIGHT,
FRAME_BOTTOM_LEFT, FRAME_BOTTOM_RIGHT,
}
@export var forest_type: ForestType
@export var type: ForestType
var POSITIONS_BY_TYPE : Dictionary = {
@@ -59,14 +61,10 @@ var POSITIONS_BY_TYPE : Dictionary = {
}
func _init(type : ForestType = ForestType.TOP) -> void:
forest_type = type
func _ready() -> void:
update_atlas_position()
func update_atlas_position() -> void:
var positions = POSITIONS_BY_TYPE[forest_type]
var positions = POSITIONS_BY_TYPE[type]
$Sprite2D.texture.region.position = positions[randi() % positions.size()]
+2
View File
@@ -15,7 +15,9 @@ script = ExtResource("1_2dsrk")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture_filter = 1
position = Vector2(8, 8)
texture = SubResource("AtlasTexture_dddgb")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(8, 8)
shape = SubResource("RectangleShape2D_7s50m")
+27
View File
@@ -0,0 +1,27 @@
extends Node2D
const FOREST = preload("res://forest.tscn")
func _ready() -> void:
create_level()
func create_level() -> void:
var corners : Array
for i in range(4):
corners.append(FOREST.instantiate())
corners[0].type = Forest.ForestType.CORNER_TOP_LEFT
corners[1].type = Forest.ForestType.CORNER_TOP_RIGHT
corners[2].type = Forest.ForestType.CORNER_BOTTOM_LEFT
corners[3].type = Forest.ForestType.CORNER_BOTTOM_RIGHT
corners[0].position = Vector2(0, 0) * 16
corners[1].position = Vector2(19, 0) * 16
corners[2].position = Vector2(0, 10) * 16
corners[3].position = Vector2(19, 10) * 16
for corner in corners:
add_child(corner)
+6
View File
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://c1h0h1viac0gy"]
[ext_resource type="Script" path="res://level.gd" id="1_t0agp"]
[node name="Level" type="Node2D"]
script = ExtResource("1_t0agp")
+13 -16
View File
@@ -1,11 +1,13 @@
class_name Pickup
extends StaticBody2D
enum PickupType {CHERRY, FLY_AGARIC, GREEN_APPLE, RED_APPLE}
@export var pickup_type: PickupType
@export var type: PickupType
enum PickupState {PREPARING, SHOWING_UP, IDLING, HIGHLIGHTING}
@export var pickup_state: PickupState = PickupState.PREPARING
@export var state: PickupState = PickupState.PREPARING
var ANIMATIONS_BY_TYPE : Dictionary = {
@@ -23,40 +25,35 @@ var ANIMATIONS_BY_STATE : Dictionary = {
}
func _init(type : PickupType = PickupType.RED_APPLE) -> void:
pickup_type = type
func _ready() -> void:
play_animation()
func highlight() -> void:
pickup_state = PickupState.HIGHLIGHTING
state = PickupState.HIGHLIGHTING
play_animation()
func play_animation() -> void:
var animation : String
if pickup_state == PickupState.PREPARING:
animation = ANIMATIONS_BY_STATE[pickup_state]
if state == PickupState.PREPARING:
animation = ANIMATIONS_BY_STATE[state]
else:
animation = "%s_%s" % [
ANIMATIONS_BY_TYPE[pickup_type],
ANIMATIONS_BY_STATE[pickup_state]
ANIMATIONS_BY_TYPE[type],
ANIMATIONS_BY_STATE[state]
]
$AnimatedSprite2D.play(animation)
func _on_animated_sprite_2d_animation_finished() -> void:
match pickup_state:
match state:
PickupState.PREPARING:
pickup_state = PickupState.SHOWING_UP
state = PickupState.SHOWING_UP
play_animation()
PickupState.SHOWING_UP:
pickup_state = PickupState.IDLING
state = PickupState.IDLING
play_animation()
PickupState.HIGHLIGHTING:
pickup_state = PickupState.IDLING
state = PickupState.IDLING
play_animation()
+2 -2
View File
@@ -303,12 +303,12 @@ script = ExtResource("2_rayse")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture_filter = 1
position = Vector2(13, 9)
position = Vector2(8, 8)
sprite_frames = SubResource("SpriteFrames_00ngh")
animation = &"red_apple_showing_up"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
visible = false
position = Vector2(8, 8)
shape = SubResource("RectangleShape2D_jph8c")
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
+1
View File
@@ -11,6 +11,7 @@ config_version=5
[application]
config/name="Vegeconda"
run/main_scene="res://level.tscn"
config/features=PackedStringArray("4.3", "GL Compatibility")
config/icon="res://icon.svg"