start work on placing tiles

This commit is contained in:
zoe 2022-05-19 19:50:00 +02:00
parent 13ae90769b
commit 2a47a75b91
5 changed files with 20 additions and 5 deletions

Binary file not shown.

3
godot/world/Tools.gd Normal file
View file

@ -0,0 +1,3 @@
extends Node2D
enum ACTIVE {PLACE}

View file

@ -1,7 +1,8 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://world/StateApi.gd" type="Script" id=1]
[ext_resource path="res://world/Cam.tscn" type="PackedScene" id=2]
[ext_resource path="res://world/Tools.gd" type="Script" id=3]
[ext_resource path="res://world/Tilemaps.gd" type="Script" id=4]
[node name="World" type="Node"]
@ -11,3 +12,6 @@ script = ExtResource( 1 )
[node name="Tilemaps" type="Node" parent="."]
script = ExtResource( 4 )
[node name="Tools" type="Node2D" parent="."]
script = ExtResource( 3 )

View file

@ -59,8 +59,9 @@ impl StateServer {
}
#[export]
fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize){
self.world.put_tile_at(x, y, z, id);
fn put_tile_at(&mut self, _owner: &Node, x: usize, y: usize, z: usize, id: usize) -> bool{
let success = self.world.put_tile_at(x, y, z, id);
success
}
}

View file

@ -90,11 +90,18 @@ impl World {
positions
}
pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize){
pub fn put_tile_at(&mut self, x: usize, y: usize, z: usize, id: usize) -> bool{
if !self.can_put_tile_at(x, y, z, id){
return false;
}
self.tiles[x][y][z] = tiles::Tiletypes::from_repr(id as u8).unwrap();
true
}
pub fn can_put_tile_at(&self, x: usize, y: usize, z: usize, id: usize) -> bool{
if self.tiles[x][y][z] == tiles::Tiletypes::Air{
return true;
}
false
}