diff --git a/vegeconda/door.gd b/vegeconda/door.gd index fc96920..225363c 100644 --- a/vegeconda/door.gd +++ b/vegeconda/door.gd @@ -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: diff --git a/vegeconda/door.tscn b/vegeconda/door.tscn index 547f406..0d5998a 100644 --- a/vegeconda/door.tscn +++ b/vegeconda/door.tscn @@ -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") diff --git a/vegeconda/field.gd b/vegeconda/field.gd index e610be2..eafffac 100644 --- a/vegeconda/field.gd +++ b/vegeconda/field.gd @@ -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 = { @@ -37,10 +39,6 @@ var POSITIONS_BY_TYPE : Dictionary = { Vector2(64, 16), ], } - - -func _init(type : FieldType = FieldType.MIDDLE) -> void: - field_type = type func _ready() -> void: @@ -48,5 +46,5 @@ func _ready() -> void: 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()] diff --git a/vegeconda/field.tscn b/vegeconda/field.tscn index 96150a5..6f354af 100644 --- a/vegeconda/field.tscn +++ b/vegeconda/field.tscn @@ -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") diff --git a/vegeconda/forest.gd b/vegeconda/forest.gd index 30082ad..e63ee4d 100644 --- a/vegeconda/forest.gd +++ b/vegeconda/forest.gd @@ -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 = { @@ -57,10 +59,6 @@ var POSITIONS_BY_TYPE : Dictionary = { Vector2(64, 16), ], } - - -func _init(type : ForestType = ForestType.TOP) -> void: - forest_type = type func _ready() -> void: @@ -68,5 +66,5 @@ func _ready() -> void: 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()] diff --git a/vegeconda/forest.tscn b/vegeconda/forest.tscn index 9b3127e..14d8d75 100644 --- a/vegeconda/forest.tscn +++ b/vegeconda/forest.tscn @@ -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") diff --git a/vegeconda/level.gd b/vegeconda/level.gd new file mode 100644 index 0000000..b589f1e --- /dev/null +++ b/vegeconda/level.gd @@ -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) diff --git a/vegeconda/level.tscn b/vegeconda/level.tscn new file mode 100644 index 0000000..32e59dc --- /dev/null +++ b/vegeconda/level.tscn @@ -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") diff --git a/vegeconda/pickup.gd b/vegeconda/pickup.gd index 3254338..a331b3f 100644 --- a/vegeconda/pickup.gd +++ b/vegeconda/pickup.gd @@ -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() diff --git a/vegeconda/pickup.tscn b/vegeconda/pickup.tscn index ab49d95..5b1e94c 100644 --- a/vegeconda/pickup.tscn +++ b/vegeconda/pickup.tscn @@ -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"] diff --git a/vegeconda/project.godot b/vegeconda/project.godot index ed88a7c..2a5dcb6 100644 --- a/vegeconda/project.godot +++ b/vegeconda/project.godot @@ -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"