Added building structure
Created harvester building added harvester particles added nearest resource func
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_p1crr"]
|
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_p1crr"]
|
||||||
[ext_resource type="Script" path="res://data/buildings/building_group.gd" id="1_xphre"]
|
[ext_resource type="Script" path="res://data/buildings/building_group.gd" id="1_xphre"]
|
||||||
[ext_resource type="Resource" uid="uid://d38xgwstvtcm4" path="res://data/buildings/basic/harvester_building.tres" id="2_7d7fa"]
|
[ext_resource type="Resource" uid="uid://d38xgwstvtcm4" path="res://data/buildings/basic/harvester/harvester_building.tres" id="2_5rd2r"]
|
||||||
[ext_resource type="Resource" uid="uid://cta6ngelbwo8b" path="res://data/buildings/basic/warehouse_building.tres" id="3_vxs34"]
|
[ext_resource type="Resource" uid="uid://cta6ngelbwo8b" path="res://data/buildings/basic/warehouse_building.tres" id="3_vxs34"]
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_nleix"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_nleix"]
|
||||||
@@ -13,4 +13,4 @@ region = Rect2(1024, 576, 64, 64)
|
|||||||
script = ExtResource("1_xphre")
|
script = ExtResource("1_xphre")
|
||||||
name = "Basic"
|
name = "Basic"
|
||||||
atlas_texture = SubResource("AtlasTexture_nleix")
|
atlas_texture = SubResource("AtlasTexture_nleix")
|
||||||
buildings = Array[Resource("res://data/buildings/building.gd")]([ExtResource("2_7d7fa"), ExtResource("3_vxs34")])
|
buildings = Array[Resource("res://data/buildings/building.gd")]([ExtResource("2_5rd2r"), ExtResource("3_vxs34")])
|
||||||
|
|||||||
20
data/buildings/basic/harvester/harvester.gd
Normal file
20
data/buildings/basic/harvester/harvester.gd
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
extends Building
|
||||||
|
|
||||||
|
const CARBON_RESOURCE = preload("res://data/game_resources/carbon/carbon_resource.tres")
|
||||||
|
|
||||||
|
func ready(building: BuildingBase) -> void:
|
||||||
|
var nearest_res := Grid.get_nearest_resource(building.position, CARBON_RESOURCE)
|
||||||
|
var _distance = building.position.distance_to(nearest_res)
|
||||||
|
|
||||||
|
var particles = CPUParticles2D.new()
|
||||||
|
particles.amount = 60
|
||||||
|
particles.spread = 8
|
||||||
|
particles.material = ParticleProcessMaterial.new()
|
||||||
|
particles.radial_accel_max = _distance * -2.5
|
||||||
|
particles.radial_accel_min = _distance * -2.55
|
||||||
|
particles.gravity = Vector2.ZERO
|
||||||
|
particles.direction = building.position.direction_to(nearest_res)
|
||||||
|
particles.initial_velocity_max = _distance * 2.25
|
||||||
|
particles.initial_velocity_min = _distance * 2.2
|
||||||
|
particles.lifetime = 1.65
|
||||||
|
building.add_child(particles)
|
||||||
18
data/buildings/basic/harvester/harvester_building.tres
Normal file
18
data/buildings/basic/harvester/harvester_building.tres
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[gd_resource type="Resource" load_steps=5 format=3 uid="uid://d38xgwstvtcm4"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_m1sbx"]
|
||||||
|
[ext_resource type="Script" path="res://data/buildings/basic/harvester/harvester.gd" id="3_fy2m4"]
|
||||||
|
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="3_xlnq5"]
|
||||||
|
|
||||||
|
[sub_resource type="AtlasTexture" id="AtlasTexture_mgt0w"]
|
||||||
|
atlas = ExtResource("1_m1sbx")
|
||||||
|
region = Rect2(1088, 128, 64, 64)
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("3_fy2m4")
|
||||||
|
atlas_texture = SubResource("AtlasTexture_mgt0w")
|
||||||
|
name = "Harvester"
|
||||||
|
description = "Harvests nearby resources"
|
||||||
|
cost = {
|
||||||
|
ExtResource("3_xlnq5"): 100
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
[gd_resource type="Resource" script_class="Building" load_steps=5 format=3 uid="uid://d38xgwstvtcm4"]
|
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_8uuv4"]
|
|
||||||
[ext_resource type="Script" path="res://data/buildings/building.gd" id="1_s0c8c"]
|
|
||||||
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="2_ppxqc"]
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5nxx0"]
|
|
||||||
atlas = ExtResource("1_8uuv4")
|
|
||||||
region = Rect2(1088, 128, 64, 64)
|
|
||||||
|
|
||||||
[resource]
|
|
||||||
script = ExtResource("1_s0c8c")
|
|
||||||
atlas_texture = SubResource("AtlasTexture_5nxx0")
|
|
||||||
name = "Harvester"
|
|
||||||
description = "Harvests nearby"
|
|
||||||
cost = {
|
|
||||||
ExtResource("2_ppxqc"): 100
|
|
||||||
}
|
|
||||||
@@ -5,3 +5,6 @@ extends Resource
|
|||||||
@export var name: String
|
@export var name: String
|
||||||
@export var description: String
|
@export var description: String
|
||||||
@export var cost: Dictionary
|
@export var cost: Dictionary
|
||||||
|
|
||||||
|
func ready(building: BuildingBase) -> void:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ var _building_data: Building
|
|||||||
func initialize(data: Building, grid_location: Vector2i) -> void:
|
func initialize(data: Building, grid_location: Vector2i) -> void:
|
||||||
_building_data = data
|
_building_data = data
|
||||||
position = Grid.grid_to_world_center(grid_location)
|
position = Grid.grid_to_world_center(grid_location)
|
||||||
|
_building_data.ready(self)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
sprite_2d.texture = _building_data.atlas_texture
|
sprite_2d.texture = _building_data.atlas_texture
|
||||||
|
|||||||
5
data/buildings/building_methods.gd
Normal file
5
data/buildings/building_methods.gd
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
extends Resource
|
||||||
|
class_name BuildingMethods
|
||||||
|
|
||||||
|
func ready(building: BuildingBase) -> void:
|
||||||
|
pass
|
||||||
6
data/buildings/building_methods.tscn
Normal file
6
data/buildings/building_methods.tscn
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://7threw5x5tw6"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://data/buildings/building_methods.gd" id="1_ll4rt"]
|
||||||
|
|
||||||
|
[node name="BuildingMethods" type="Node2D"]
|
||||||
|
script = ExtResource("1_ll4rt")
|
||||||
@@ -4,6 +4,8 @@ const GRID_SIZE := 64
|
|||||||
var world_grid: TileMap
|
var world_grid: TileMap
|
||||||
var world_data: Dictionary = {}
|
var world_data: Dictionary = {}
|
||||||
|
|
||||||
|
var res_locations := {}
|
||||||
|
|
||||||
func init(grid: TileMap) -> void:
|
func init(grid: TileMap) -> void:
|
||||||
world_grid = grid
|
world_grid = grid
|
||||||
|
|
||||||
@@ -37,6 +39,19 @@ func get_location_data(pos: Vector2i) -> CellData:
|
|||||||
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
|
func change_location_resource(pos: Vector2i, data: GameResource) -> void:
|
||||||
world_data[pos].change_resource(data)
|
world_data[pos].change_resource(data)
|
||||||
world_grid.set_cell(Constants.TilemapLayers.ENVIRONMENT, pos, 0, data.atlas_location)
|
world_grid.set_cell(Constants.TilemapLayers.ENVIRONMENT, pos, 0, data.atlas_location)
|
||||||
|
if not res_locations.has(data):
|
||||||
|
res_locations[data] = []
|
||||||
|
res_locations[data].append(Grid.grid_to_world_center(pos))
|
||||||
|
|
||||||
|
func get_nearest_resource(pos: Vector2, data: GameResource) -> Vector2:
|
||||||
|
var distance: float = 9999
|
||||||
|
var nearest: Vector2
|
||||||
|
for location: Vector2 in res_locations[data]:
|
||||||
|
var _dist = pos.distance_to(location)
|
||||||
|
if _dist < distance:
|
||||||
|
distance = _dist
|
||||||
|
nearest = location
|
||||||
|
return nearest
|
||||||
|
|
||||||
func change_location_building(pos: Vector2i, data: BuildingBase) -> void:
|
func change_location_building(pos: Vector2i, data: BuildingBase) -> void:
|
||||||
world_data[pos].change_building(data)
|
world_data[pos].change_building(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user