Skip to content

Commit

Permalink
The ludovyc (#120)
Browse files Browse the repository at this point in the history
* Wip

* [wip] autotile works !

* [wip] start read a json to load map

* [wip] load map from json

* [wip] EntityStatic and deposit clay

* [wip] check constructible deposit clay

* add and load map singularity_40

* [wip] add a warehouse and start spawn trees

* [wip] add warehouse.png, spawn trees

* [wip] select a building

* [wip] made a script to import tile-based entities, update warehouse png

* [fix] add new line at the end of the file

---------

Co-authored-by: theludovyc <theludovyc@gmail.com>
  • Loading branch information
LinuxDonald and theludovyc committed May 21, 2024
1 parent 844ace7 commit dd90513
Show file tree
Hide file tree
Showing 20 changed files with 917 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Assets/World/Buildings/Warehouse/Warehouse.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[ext_resource type="Script" path="res://Assets/World/Buildings/Warehouse/Warehouse.gd" id="3"]
[ext_resource type="Shape3D" uid="uid://b0tf8160mv311" path="res://Assets/World/Shapes/BoxShape3x3.tres" id="4"]

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_n6neb"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_xttng"]
transparency = 2
alpha_scissor_threshold = 0.05
alpha_antialiasing_mode = 0
Expand All @@ -27,7 +27,7 @@ region_enabled = true
region_rect = Rect2(0, 0, 384, 256)

[node name="Outline" parent="Billboard" index="0"]
material_overlay = SubResource("StandardMaterial3D_n6neb")
material_overlay = SubResource("StandardMaterial3D_xttng")
offset = Vector2(0, 10)
texture = ExtResource("1")
region_enabled = true
Expand Down
12 changes: 12 additions & 0 deletions Assets/World/Terrain2D/Building/Building.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@tool

extends EntityStatic
class_name Building2D

signal selected(type)

@export var entity_type:Entities.types

func _on_Area2d_input_event(viewport, event, shape_idx):
if event.is_action_pressed("alt_command"):
selected.emit(entity_type)
28 changes: 28 additions & 0 deletions Assets/World/Terrain2D/Building/Warehouse.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[gd_scene load_steps=4 format=3 uid="uid://rw2lkwx0ovwe"]

[ext_resource type="Texture2D" uid="uid://642b17aathmd" path="res://Assets/World/Terrain2D/Building/warehouse.png" id="1_8w56y"]
[ext_resource type="Script" path="res://Assets/World/Terrain2D/Building/Building.gd" id="2_0x2ov"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_d0aee"]
size = Vector2(170, 88)

[node name="Warehouse" type="Sprite2D"]
texture = ExtResource("1_8w56y")
centered = false
offset = Vector2(-96, -64)
hframes = 4
frame = 1
region_rect = Rect2(0, 128, 192, 128)
script = ExtResource("2_0x2ov")
width = 3
height = 3

[node name="Area2D" type="Area2D" parent="."]
collision_mask = 0
monitorable = false

[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2(13, -12)
shape = SubResource("RectangleShape2D_d0aee")

[connection signal="input_event" from="Area2D" to="." method="_on_Area2d_input_event"]
Binary file added Assets/World/Terrain2D/Building/warehouse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions Assets/World/Terrain2D/Camera2D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Camera2D

const SPEED = 500

# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var dir = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")

position += dir * SPEED * delta

pass
6 changes: 6 additions & 0 deletions Assets/World/Terrain2D/Entities.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends Node

enum types{
Warehouse,
Spruce
}
32 changes: 32 additions & 0 deletions Assets/World/Terrain2D/EntityStatic.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@tool

extends Sprite2D
class_name EntityStatic

@export var width = 1:
set(p_width):
if p_width != width:
width = p_width
update_offset()

@export var height = 1:
set(p_height):
if p_height != height:
height = p_height
update_offset()

func _ready():
if Engine.is_editor_hint():
texture_changed.connect(_on_texture_changed)

func update_offset():
if texture == null:
return

if centered:
centered = false

offset = Vector2(0, -texture.get_height()) + Vector2(-width * 32, height * 16)

func _on_texture_changed():
update_offset()
54 changes: 54 additions & 0 deletions Assets/World/Terrain2D/Game2D.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
extends Node
class_name Game2D

@onready var rtl = $CanvasLayer/RichTextLabel

@onready var tm = $TileMap

@onready var cam = $Camera2D

@onready var node_entities = $Entities

const Entities_Scene = {
Entities.types.Warehouse:preload("res://Assets/World/Terrain2D/Building/Warehouse.tscn"),
Entities.types.Spruce:preload("res://Assets/World/Terrain2D/Trees/Spruce.tscn")
}

# Called when the node enters the scene tree for the first time.
func _ready():
tm.create_island("res://Assets/World/Terrain2D/singularity_40.json")
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var mousePos = get_viewport().get_mouse_position() + cam.position

rtl.text = ""

rtl.text += str(mousePos) + "\n"

var tile_pos = tm.local_to_map(mousePos)

rtl.text += str(tile_pos) + "\n"

var tile_data = tm.get_cell_tile_data(0, tile_pos)

if tile_data != null:
rtl.text += str(tile_data.terrain_set) + " / " + str(tile_data.terrain) + "\n"

rtl.text += str(tm.get_cell_atlas_coords(0, tile_pos))

func instantiate_Entity(entity_type:Entities.types) -> Node2D:
var entity_instance = Entities_Scene[entity_type].instantiate()

node_entities.add_child(entity_instance)

if entity_instance is Building2D:
entity_instance.selected.connect(_on_building_selected)

return entity_instance

func _on_building_selected(entity_type:Entities.types):
prints(name, entity_type)
pass
Loading

0 comments on commit dd90513

Please sign in to comment.