Добавлен функционал передвижения NPC
This commit is contained in:
27
npc/npc.gd
Normal file
27
npc/npc.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
class_name NPC
|
||||
extends Node2D
|
||||
|
||||
var id_path: Array[Vector2i]
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
randomize()
|
||||
$Sprite2D.set_nation(randi()%$Sprite2D.Nations.max)
|
||||
set_spacesuit(false)
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _physics_process(delta: float) -> void:
|
||||
if id_path.is_empty(): return
|
||||
|
||||
var target_pos = Vector2(id_path.front()*World.tile_size)
|
||||
|
||||
global_position = global_position.move_toward(target_pos, 1)
|
||||
|
||||
if global_position == target_pos:
|
||||
id_path.pop_front()
|
||||
|
||||
func set_spacesuit(suit: bool) -> void:
|
||||
$Sprite2D.set_spacesuit(suit)
|
||||
|
||||
19
npc/npc.tscn
Normal file
19
npc/npc.tscn
Normal file
@@ -0,0 +1,19 @@
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cxueg5xm4buqk"]
|
||||
|
||||
[ext_resource type="Script" path="res://npc/npc.gd" id="1_m82ir"]
|
||||
[ext_resource type="Texture2D" uid="uid://bhpnk3olpquth" path="res://assets/moonnauts.png" id="1_vgeae"]
|
||||
[ext_resource type="Script" path="res://npc/sprite_2d.gd" id="2_jtl2q"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_2v0ml"]
|
||||
atlas = ExtResource("1_vgeae")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[node name="npc" type="Node2D"]
|
||||
z_index = 32
|
||||
z_as_relative = false
|
||||
script = ExtResource("1_m82ir")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_2v0ml")
|
||||
centered = false
|
||||
script = ExtResource("2_jtl2q")
|
||||
27
npc/sprite_2d.gd
Normal file
27
npc/sprite_2d.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
extends Sprite2D
|
||||
|
||||
enum Nations {
|
||||
ru = 0,
|
||||
arab = 1,
|
||||
chi = 2,
|
||||
max,
|
||||
}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func set_spacesuit(suit: bool) -> void:
|
||||
var atlas: AtlasTexture = texture
|
||||
if suit: atlas.region.position.y = 0
|
||||
else: atlas.region.position.y = 16
|
||||
|
||||
|
||||
func set_nation(nation: Nations) -> void:
|
||||
var atlas: AtlasTexture = texture
|
||||
atlas.region.position.x = 16*nation
|
||||
Reference in New Issue
Block a user