Added Forest
This commit is contained in:
@@ -0,0 +1,72 @@
|
|||||||
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
|
enum ForestType {
|
||||||
|
TOP, BOTTOM, LEFT, RIGHT,
|
||||||
|
CORNER_TOP_LEFT, CORNER_TOP_RIGHT,
|
||||||
|
CORNER_BOTTOM_LEFT, CORNER_BOTTOM_RIGHT,
|
||||||
|
FRAME_TOP_LEFT, FRAME_TOP_RIGHT,
|
||||||
|
FRAME_BOTTOM_LEFT, FRAME_BOTTOM_RIGHT,
|
||||||
|
}
|
||||||
|
@export var forest_type: ForestType
|
||||||
|
|
||||||
|
|
||||||
|
var POSITIONS_BY_TYPE : Dictionary = {
|
||||||
|
ForestType.TOP: [
|
||||||
|
Vector2(16, 0),
|
||||||
|
Vector2(32, 0),
|
||||||
|
Vector2(16, 16),
|
||||||
|
Vector2(32, 16),
|
||||||
|
],
|
||||||
|
ForestType.BOTTOM: [
|
||||||
|
Vector2(16, 32),
|
||||||
|
Vector2(32, 32),
|
||||||
|
Vector2(16, 48),
|
||||||
|
Vector2(32, 48),
|
||||||
|
],
|
||||||
|
ForestType.LEFT: [
|
||||||
|
Vector2(0, 16),
|
||||||
|
Vector2(0, 32),
|
||||||
|
],
|
||||||
|
ForestType.RIGHT: [
|
||||||
|
Vector2(48, 16),
|
||||||
|
Vector2(48, 32),
|
||||||
|
],
|
||||||
|
ForestType.CORNER_TOP_LEFT: [
|
||||||
|
Vector2(0, 0),
|
||||||
|
],
|
||||||
|
ForestType.CORNER_TOP_RIGHT: [
|
||||||
|
Vector2(48, 0),
|
||||||
|
],
|
||||||
|
ForestType.CORNER_BOTTOM_LEFT: [
|
||||||
|
Vector2(0, 48),
|
||||||
|
],
|
||||||
|
ForestType.CORNER_BOTTOM_RIGHT: [
|
||||||
|
Vector2(48, 48),
|
||||||
|
],
|
||||||
|
ForestType.FRAME_TOP_LEFT: [
|
||||||
|
Vector2(64, 32),
|
||||||
|
],
|
||||||
|
ForestType.FRAME_TOP_RIGHT: [
|
||||||
|
Vector2(64, 48),
|
||||||
|
],
|
||||||
|
ForestType.FRAME_BOTTOM_LEFT: [
|
||||||
|
Vector2(64, 0),
|
||||||
|
],
|
||||||
|
ForestType.FRAME_BOTTOM_RIGHT: [
|
||||||
|
Vector2(64, 16),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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]
|
||||||
|
$Sprite2D.texture.region.position = positions[randi() % positions.size()]
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://cu2ub0e6tk0a0"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://forest.gd" id="1_2dsrk"]
|
||||||
|
[ext_resource type="Texture2D" uid="uid://b6wbb26dayco1" path="res://data/images/Forest.png" id="1_jq2nb"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_dddgb"]
|
||||||
|
atlas = ExtResource("1_jq2nb")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_7s50m"]
|
||||||
|
size = Vector2(16, 16)
|
||||||
|
|
||||||
|
[node name="Forest" type="StaticBody2D"]
|
||||||
|
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="."]
|
||||||
|
visible = false
|
||||||
|
shape = SubResource("RectangleShape2D_7s50m")
|
||||||
Reference in New Issue
Block a user