Added Level. Removed params from _init()
This commit is contained in:
+15
-18
@@ -1,11 +1,13 @@
|
|||||||
|
class_name Door
|
||||||
|
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
enum DoorType {BOTTOM_DOOR, TOP_DOOR}
|
enum DoorType {BOTTOM_DOOR, TOP_DOOR}
|
||||||
@export var door_type: DoorType
|
@export var type: DoorType
|
||||||
|
|
||||||
enum DoorState {OPENED, CLOSED, OPENING, CLOSING}
|
enum DoorState {OPENED, CLOSED, OPENING, CLOSING}
|
||||||
@export var door_state: DoorState
|
@export var state: DoorState
|
||||||
|
|
||||||
|
|
||||||
var ANIMATIONS_BY_TYPE : Dictionary = {
|
var ANIMATIONS_BY_TYPE : Dictionary = {
|
||||||
@@ -25,50 +27,45 @@ signal opened()
|
|||||||
signal closed()
|
signal closed()
|
||||||
|
|
||||||
|
|
||||||
func _init(type: DoorType = DoorType.BOTTOM_DOOR, state: DoorState = DoorState.OPENED) -> void:
|
|
||||||
door_type = type
|
|
||||||
door_state = state
|
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|
||||||
|
|
||||||
func play_animation() -> void:
|
func play_animation() -> void:
|
||||||
var animation : String = "%s_%s" % [
|
var animation : String = "%s_%s" % [
|
||||||
ANIMATIONS_BY_TYPE[door_type],
|
ANIMATIONS_BY_TYPE[type],
|
||||||
ANIMATIONS_BY_STATE[door_state]
|
ANIMATIONS_BY_STATE[state]
|
||||||
]
|
]
|
||||||
$AnimatedSprite2D.play(animation)
|
$AnimatedSprite2D.play(animation)
|
||||||
|
|
||||||
|
|
||||||
func open() -> void:
|
func open() -> void:
|
||||||
if door_state != DoorState.CLOSED:
|
if state != DoorState.CLOSED:
|
||||||
print("Door in state '%s' can't be opened" % DoorState.find_key(door_state))
|
print("Door in state '%s' can't be opened" % DoorState.find_key(state))
|
||||||
return
|
return
|
||||||
|
|
||||||
door_state = DoorState.OPENING
|
state = DoorState.OPENING
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func close():
|
func close():
|
||||||
if door_state != DoorState.OPENED:
|
if state != DoorState.OPENED:
|
||||||
print("Door in state '%s' can't be closed" % DoorState.find_key(door_state))
|
print("Door in state '%s' can't be closed" % DoorState.find_key(state))
|
||||||
return
|
return
|
||||||
|
|
||||||
door_state = DoorState.CLOSING
|
state = DoorState.CLOSING
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|
||||||
|
|
||||||
func _on_animated_sprite_2d_animation_finished() -> void:
|
func _on_animated_sprite_2d_animation_finished() -> void:
|
||||||
match door_state:
|
match state:
|
||||||
DoorState.CLOSING:
|
DoorState.CLOSING:
|
||||||
door_state = DoorState.CLOSED
|
state = DoorState.CLOSED
|
||||||
$CollisionShape2D.disabled = false
|
$CollisionShape2D.disabled = false
|
||||||
play_animation()
|
play_animation()
|
||||||
DoorState.OPENING:
|
DoorState.OPENING:
|
||||||
door_state = DoorState.OPENED
|
state = DoorState.OPENED
|
||||||
$CollisionShape2D.disabled = true
|
$CollisionShape2D.disabled = true
|
||||||
play_animation()
|
play_animation()
|
||||||
DoorState.CLOSED:
|
DoorState.CLOSED:
|
||||||
|
|||||||
@@ -250,8 +250,10 @@ script = ExtResource("1_7rkx7")
|
|||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
|
position = Vector2(8, 8)
|
||||||
sprite_frames = SubResource("SpriteFrames_uucy3")
|
sprite_frames = SubResource("SpriteFrames_uucy3")
|
||||||
animation = &"bottom_door_opened"
|
animation = &"bottom_door_opened"
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(8, 8)
|
||||||
shape = SubResource("RectangleShape2D_notjl")
|
shape = SubResource("RectangleShape2D_notjl")
|
||||||
|
|||||||
+4
-6
@@ -1,10 +1,12 @@
|
|||||||
|
class_name Field
|
||||||
|
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
enum FieldType {
|
enum FieldType {
|
||||||
MIDDLE, CORNER, TOP, LEFT,
|
MIDDLE, CORNER, TOP, LEFT,
|
||||||
}
|
}
|
||||||
@export var field_type: FieldType
|
@export var type: FieldType
|
||||||
|
|
||||||
|
|
||||||
var POSITIONS_BY_TYPE : Dictionary = {
|
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:
|
func _ready() -> void:
|
||||||
update_atlas_position()
|
update_atlas_position()
|
||||||
|
|
||||||
|
|
||||||
func update_atlas_position() -> 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()]
|
$Sprite2D.texture.region.position = positions[randi() % positions.size()]
|
||||||
|
|||||||
@@ -12,11 +12,12 @@ size = Vector2(16, 16)
|
|||||||
|
|
||||||
[node name="Field" type="StaticBody2D"]
|
[node name="Field" type="StaticBody2D"]
|
||||||
script = ExtResource("1_hih70")
|
script = ExtResource("1_hih70")
|
||||||
field_type = 1
|
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
|
position = Vector2(8, 8)
|
||||||
texture = SubResource("AtlasTexture_moxxr")
|
texture = SubResource("AtlasTexture_moxxr")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(8, 8)
|
||||||
shape = SubResource("RectangleShape2D_17j0p")
|
shape = SubResource("RectangleShape2D_17j0p")
|
||||||
|
|||||||
+4
-6
@@ -1,3 +1,5 @@
|
|||||||
|
class_name Forest
|
||||||
|
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
@@ -8,7 +10,7 @@ enum ForestType {
|
|||||||
FRAME_TOP_LEFT, FRAME_TOP_RIGHT,
|
FRAME_TOP_LEFT, FRAME_TOP_RIGHT,
|
||||||
FRAME_BOTTOM_LEFT, FRAME_BOTTOM_RIGHT,
|
FRAME_BOTTOM_LEFT, FRAME_BOTTOM_RIGHT,
|
||||||
}
|
}
|
||||||
@export var forest_type: ForestType
|
@export var type: ForestType
|
||||||
|
|
||||||
|
|
||||||
var POSITIONS_BY_TYPE : Dictionary = {
|
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:
|
func _ready() -> void:
|
||||||
update_atlas_position()
|
update_atlas_position()
|
||||||
|
|
||||||
|
|
||||||
func update_atlas_position() -> 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()]
|
$Sprite2D.texture.region.position = positions[randi() % positions.size()]
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ script = ExtResource("1_2dsrk")
|
|||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
|
position = Vector2(8, 8)
|
||||||
texture = SubResource("AtlasTexture_dddgb")
|
texture = SubResource("AtlasTexture_dddgb")
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(8, 8)
|
||||||
shape = SubResource("RectangleShape2D_7s50m")
|
shape = SubResource("RectangleShape2D_7s50m")
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -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
@@ -1,11 +1,13 @@
|
|||||||
|
class_name Pickup
|
||||||
|
|
||||||
extends StaticBody2D
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
enum PickupType {CHERRY, FLY_AGARIC, GREEN_APPLE, RED_APPLE}
|
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}
|
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 = {
|
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:
|
func _ready() -> void:
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|
||||||
|
|
||||||
func highlight() -> void:
|
func highlight() -> void:
|
||||||
pickup_state = PickupState.HIGHLIGHTING
|
state = PickupState.HIGHLIGHTING
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|
||||||
|
|
||||||
func play_animation() -> void:
|
func play_animation() -> void:
|
||||||
var animation : String
|
var animation : String
|
||||||
if pickup_state == PickupState.PREPARING:
|
if state == PickupState.PREPARING:
|
||||||
animation = ANIMATIONS_BY_STATE[pickup_state]
|
animation = ANIMATIONS_BY_STATE[state]
|
||||||
else:
|
else:
|
||||||
animation = "%s_%s" % [
|
animation = "%s_%s" % [
|
||||||
ANIMATIONS_BY_TYPE[pickup_type],
|
ANIMATIONS_BY_TYPE[type],
|
||||||
ANIMATIONS_BY_STATE[pickup_state]
|
ANIMATIONS_BY_STATE[state]
|
||||||
]
|
]
|
||||||
$AnimatedSprite2D.play(animation)
|
$AnimatedSprite2D.play(animation)
|
||||||
|
|
||||||
|
|
||||||
func _on_animated_sprite_2d_animation_finished() -> void:
|
func _on_animated_sprite_2d_animation_finished() -> void:
|
||||||
match pickup_state:
|
match state:
|
||||||
PickupState.PREPARING:
|
PickupState.PREPARING:
|
||||||
pickup_state = PickupState.SHOWING_UP
|
state = PickupState.SHOWING_UP
|
||||||
play_animation()
|
play_animation()
|
||||||
PickupState.SHOWING_UP:
|
PickupState.SHOWING_UP:
|
||||||
pickup_state = PickupState.IDLING
|
state = PickupState.IDLING
|
||||||
play_animation()
|
play_animation()
|
||||||
PickupState.HIGHLIGHTING:
|
PickupState.HIGHLIGHTING:
|
||||||
pickup_state = PickupState.IDLING
|
state = PickupState.IDLING
|
||||||
play_animation()
|
play_animation()
|
||||||
|
|||||||
@@ -303,12 +303,12 @@ script = ExtResource("2_rayse")
|
|||||||
|
|
||||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||||
texture_filter = 1
|
texture_filter = 1
|
||||||
position = Vector2(13, 9)
|
position = Vector2(8, 8)
|
||||||
sprite_frames = SubResource("SpriteFrames_00ngh")
|
sprite_frames = SubResource("SpriteFrames_00ngh")
|
||||||
animation = &"red_apple_showing_up"
|
animation = &"red_apple_showing_up"
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
visible = false
|
position = Vector2(8, 8)
|
||||||
shape = SubResource("RectangleShape2D_jph8c")
|
shape = SubResource("RectangleShape2D_jph8c")
|
||||||
|
|
||||||
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ config_version=5
|
|||||||
[application]
|
[application]
|
||||||
|
|
||||||
config/name="Vegeconda"
|
config/name="Vegeconda"
|
||||||
|
run/main_scene="res://level.tscn"
|
||||||
config/features=PackedStringArray("4.3", "GL Compatibility")
|
config/features=PackedStringArray("4.3", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user