Made particles emit from resource
This commit is contained in:
@@ -1,20 +1,19 @@
|
|||||||
extends Building
|
extends Building
|
||||||
|
|
||||||
|
var nearest_res
|
||||||
|
var _distance
|
||||||
|
var _direction
|
||||||
|
|
||||||
const CARBON_RESOURCE = preload("res://data/game_resources/carbon/carbon_resource.tres")
|
const CARBON_RESOURCE = preload("res://data/game_resources/carbon/carbon_resource.tres")
|
||||||
|
const HARVESTER_PARTICLES = preload("res://data/buildings/basic/harvester/harvester_particles.tscn")
|
||||||
|
|
||||||
|
func initialize(building: BuildingBase) -> void:
|
||||||
|
nearest_res = Grid.get_nearest_resource(building.position, CARBON_RESOURCE)
|
||||||
|
_distance = building.position.distance_to(nearest_res)
|
||||||
|
_direction = nearest_res.direction_to(building.position)
|
||||||
|
|
||||||
func ready(building: BuildingBase) -> void:
|
func ready(building: BuildingBase) -> void:
|
||||||
var nearest_res := Grid.get_nearest_resource(building.position, CARBON_RESOURCE)
|
var particles = HARVESTER_PARTICLES.instantiate()
|
||||||
var _distance = building.position.distance_to(nearest_res)
|
particles.init(_distance, _direction, CARBON_RESOURCE)
|
||||||
|
particles.position = nearest_res
|
||||||
var particles = CPUParticles2D.new()
|
building.add_sibling(particles)
|
||||||
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)
|
|
||||||
|
|||||||
37
data/buildings/basic/harvester/harvester_particles.gd
Normal file
37
data/buildings/basic/harvester/harvester_particles.gd
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
extends Node2D
|
||||||
|
|
||||||
|
var _pickup
|
||||||
|
|
||||||
|
var _distance
|
||||||
|
var _direction
|
||||||
|
var _emitters: Array[CPUParticles2D] = []
|
||||||
|
|
||||||
|
func init(distance: float, direction: Vector2, res: GameResource) -> void:
|
||||||
|
_distance = distance
|
||||||
|
_direction = direction
|
||||||
|
_pickup = res
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
if _emitters.size() < 10:
|
||||||
|
var particles = CPUParticles2D.new()
|
||||||
|
particles.amount = 8
|
||||||
|
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 = _direction
|
||||||
|
particles.initial_velocity_max = _distance * 2.25
|
||||||
|
particles.initial_velocity_min = _distance * 2.2
|
||||||
|
particles.lifetime = 1.65
|
||||||
|
add_child(particles)
|
||||||
|
_emitters.append(particles)
|
||||||
|
else:
|
||||||
|
for i in range(1, _emitters.size()):
|
||||||
|
_emitters[i].queue_free()
|
||||||
|
_emitters.resize(1)
|
||||||
|
ResourceManager.pickup(_pickup)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_particles_timer_timeout() -> void:
|
||||||
|
_ready()
|
||||||
12
data/buildings/basic/harvester/harvester_particles.tscn
Normal file
12
data/buildings/basic/harvester/harvester_particles.tscn
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[gd_scene load_steps=2 format=3 uid="uid://73dsjfc4imfo"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://data/buildings/basic/harvester/harvester_particles.gd" id="1_td5fv"]
|
||||||
|
|
||||||
|
[node name="HarvesterParticles" type="Node2D"]
|
||||||
|
script = ExtResource("1_td5fv")
|
||||||
|
|
||||||
|
[node name="ParticlesTimer" type="Timer" parent="."]
|
||||||
|
wait_time = 0.5
|
||||||
|
autostart = true
|
||||||
|
|
||||||
|
[connection signal="timeout" from="ParticlesTimer" to="." method="_on_particles_timer_timeout"]
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
[gd_resource type="Resource" script_class="Building" load_steps=6 format=3 uid="uid://cta6ngelbwo8b"]
|
[gd_resource type="Resource" script_class="Building" load_steps=5 format=3 uid="uid://cta6ngelbwo8b"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_24f36"]
|
[ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="1_24f36"]
|
||||||
[ext_resource type="Script" path="res://data/buildings/building.gd" id="1_aylgh"]
|
[ext_resource type="Script" path="res://data/buildings/building.gd" id="1_aylgh"]
|
||||||
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="2_s5ve8"]
|
[ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="2_s5ve8"]
|
||||||
[ext_resource type="Resource" uid="uid://dr00rd4f42jqe" path="res://data/game_resources/gem/gem_resource.tres" id="3_y57vu"]
|
|
||||||
|
|
||||||
[sub_resource type="AtlasTexture" id="AtlasTexture_pbx2g"]
|
[sub_resource type="AtlasTexture" id="AtlasTexture_pbx2g"]
|
||||||
atlas = ExtResource("1_24f36")
|
atlas = ExtResource("1_24f36")
|
||||||
@@ -15,6 +14,5 @@ atlas_texture = SubResource("AtlasTexture_pbx2g")
|
|||||||
name = "Warehouse"
|
name = "Warehouse"
|
||||||
description = "Allows storage of more materials"
|
description = "Allows storage of more materials"
|
||||||
cost = {
|
cost = {
|
||||||
ExtResource("2_s5ve8"): 500,
|
ExtResource("2_s5ve8"): 500
|
||||||
ExtResource("3_y57vu"): 200
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,7 @@ extends Resource
|
|||||||
@export var description: String
|
@export var description: String
|
||||||
@export var cost: Dictionary
|
@export var cost: Dictionary
|
||||||
|
|
||||||
|
func initialize(building: BuildingBase) -> void:
|
||||||
|
pass
|
||||||
func ready(building: BuildingBase) -> void:
|
func ready(building: BuildingBase) -> void:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ 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)
|
_building_data.initialize(self)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
sprite_2d.texture = _building_data.atlas_texture
|
sprite_2d.texture = _building_data.atlas_texture
|
||||||
|
_building_data.ready(self)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ func change_building(data: BuildingBase) -> void:
|
|||||||
layer_info[Constants.TilemapLayers.BUILDINGS] = data
|
layer_info[Constants.TilemapLayers.BUILDINGS] = data
|
||||||
|
|
||||||
func get_resource() -> GameResource:
|
func get_resource() -> GameResource:
|
||||||
return layer_info[Constants.TilemapLayers.ENVIRONMENT] as GameResource
|
return layer_info[Constants.TilemapLayerss.ENVIRONMENT] as GameResource
|
||||||
|
|
||||||
func has_resource() -> bool:
|
func has_resource() -> bool:
|
||||||
return has_layer(Constants.TilemapLayers.ENVIRONMENT)
|
return has_layer(Constants.TilemapLayers.ENVIRONMENT)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ func _ready() -> void:
|
|||||||
|
|
||||||
func _cleanup_gather() -> void:
|
func _cleanup_gather() -> void:
|
||||||
interaction_finished.emit()
|
interaction_finished.emit()
|
||||||
|
#TODO add the interaction for buildings
|
||||||
var res: GameResource = Grid.get_location_data(grid_position).get_resource()
|
var res: GameResource = Grid.get_location_data(grid_position).get_resource()
|
||||||
ResourceManager.pickup(res)
|
ResourceManager.pickup(res)
|
||||||
self.queue_free()
|
self.queue_free()
|
||||||
|
|||||||
Reference in New Issue
Block a user