-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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 <[email protected]>
- Loading branch information
1 parent
844ace7
commit dd90513
Showing
20 changed files
with
917 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
extends Node | ||
|
||
enum types{ | ||
Warehouse, | ||
Spruce | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.