Added AbstractPlatform
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
@tool
|
||||
class_name AbstractPlatform
|
||||
extends Node2D
|
||||
|
||||
|
||||
const TILE_SIZE = 8
|
||||
const MIN_WIDTH = TILE_SIZE * 2
|
||||
const MAX_WIDTH = TILE_SIZE * 32
|
||||
|
||||
|
||||
@export_range(MIN_WIDTH, MAX_WIDTH, TILE_SIZE) var platform_width: int = MIN_WIDTH:
|
||||
set(value):
|
||||
value = clampi(value, MIN_WIDTH, MAX_WIDTH)
|
||||
platform_width = value - (value % TILE_SIZE)
|
||||
if is_node_ready():
|
||||
rebuild_platform()
|
||||
|
||||
|
||||
@onready var collision: CollisionShape2D = $AnimatableBody2D/CollisionShape2D
|
||||
@onready var platform_sprite: Sprite2D = $PlatformSprite
|
||||
@onready var icon_sprite: AnimatedSprite2D = $IconSprite
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
platform_sprite.material.set_shader_parameter("tile_size", TILE_SIZE)
|
||||
rebuild_platform()
|
||||
|
||||
|
||||
func rebuild_platform() -> void:
|
||||
var shape := collision.shape as RectangleShape2D
|
||||
if not shape:
|
||||
shape = RectangleShape2D.new()
|
||||
collision.shape = shape
|
||||
shape.size = Vector2(platform_width, TILE_SIZE)
|
||||
|
||||
platform_sprite.material.set_shader_parameter("platform_width", platform_width)
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if Engine.is_editor_hint():
|
||||
return
|
||||
@@ -0,0 +1 @@
|
||||
uid://kjy0t56tgpxs
|
||||
@@ -0,0 +1,23 @@
|
||||
[gd_scene format=3 uid="uid://guvijso3k6eq"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://kjy0t56tgpxs" path="res://game/platform/abstract_platform.gd" id="1_426vp"]
|
||||
[ext_resource type="Texture2D" uid="uid://cpcuokqv8u2xa" path="res://images/level/platform.png" id="2_31xwx"]
|
||||
[ext_resource type="Shader" uid="uid://d4hm3vjx1rhsf" path="res://game/shaders/platform.gdshader" id="2_jsq8n"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_2ivtb"]
|
||||
shader = ExtResource("2_jsq8n")
|
||||
shader_parameter/tile_size = 16.0
|
||||
shader_parameter/platform_width = 16.0
|
||||
|
||||
[node name="AbstractPlatform" type="Node2D" unique_id=1226827206]
|
||||
script = ExtResource("1_426vp")
|
||||
|
||||
[node name="PlatformSprite" type="Sprite2D" parent="." unique_id=1901062470]
|
||||
material = SubResource("ShaderMaterial_2ivtb")
|
||||
texture = ExtResource("2_31xwx")
|
||||
|
||||
[node name="IconSprite" type="AnimatedSprite2D" parent="." unique_id=287774650]
|
||||
|
||||
[node name="AnimatableBody2D" type="AnimatableBody2D" parent="." unique_id=908936954]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="AnimatableBody2D" unique_id=175449124]
|
||||
Reference in New Issue
Block a user