Added Field
This commit is contained in:
@@ -0,0 +1,52 @@
|
|||||||
|
extends StaticBody2D
|
||||||
|
|
||||||
|
|
||||||
|
enum FieldType {
|
||||||
|
MIDDLE, CORNER, TOP, LEFT,
|
||||||
|
}
|
||||||
|
@export var field_type: FieldType
|
||||||
|
|
||||||
|
|
||||||
|
var POSITIONS_BY_TYPE : Dictionary = {
|
||||||
|
FieldType.MIDDLE: [
|
||||||
|
Vector2(0, 0),
|
||||||
|
Vector2(16, 0),
|
||||||
|
Vector2(32, 0),
|
||||||
|
Vector2(0, 16),
|
||||||
|
Vector2(16, 16),
|
||||||
|
Vector2(32, 16),
|
||||||
|
],
|
||||||
|
FieldType.CORNER: [
|
||||||
|
Vector2(64, 32),
|
||||||
|
Vector2(64, 48),
|
||||||
|
],
|
||||||
|
FieldType.TOP: [
|
||||||
|
Vector2(0, 32),
|
||||||
|
Vector2(16, 32),
|
||||||
|
Vector2(32, 32),
|
||||||
|
Vector2(0, 48),
|
||||||
|
Vector2(16, 48),
|
||||||
|
Vector2(32, 48),
|
||||||
|
],
|
||||||
|
FieldType.LEFT: [
|
||||||
|
Vector2(48, 0),
|
||||||
|
Vector2(48, 16),
|
||||||
|
Vector2(48, 32),
|
||||||
|
Vector2(48, 48),
|
||||||
|
Vector2(64, 0),
|
||||||
|
Vector2(64, 16),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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]
|
||||||
|
$Sprite2D.texture.region.position = positions[randi() % positions.size()]
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
[gd_scene load_steps=5 format=3 uid="uid://bo3w0sj364gql"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://cueeywtu6xdbv" path="res://data/images/Fierd.png" id="1_84wqk"]
|
||||||
|
[ext_resource type="Script" path="res://field.gd" id="1_hih70"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_moxxr"]
|
||||||
|
atlas = ExtResource("1_84wqk")
|
||||||
|
region = Rect2(0, 0, 16, 16)
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_17j0p"]
|
||||||
|
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
|
||||||
|
texture = SubResource("AtlasTexture_moxxr")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
shape = SubResource("RectangleShape2D_17j0p")
|
||||||
@@ -23,5 +23,6 @@ window/stretch/scale=8.0
|
|||||||
|
|
||||||
[rendering]
|
[rendering]
|
||||||
|
|
||||||
|
textures/canvas_textures/default_texture_filter=0
|
||||||
renderer/rendering_method="gl_compatibility"
|
renderer/rendering_method="gl_compatibility"
|
||||||
renderer/rendering_method.mobile="gl_compatibility"
|
renderer/rendering_method.mobile="gl_compatibility"
|
||||||
|
|||||||
Reference in New Issue
Block a user