mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-06 00:23:49 +02:00
progress
This commit is contained in:
parent
6a39f6ab62
commit
0aa0253d50
@ -52,18 +52,26 @@ function noise_vector_entity_path(surface, entity_name, position, base_vector, l
|
||||
return entities
|
||||
end
|
||||
|
||||
function noise_vector_tile_path(surface, tile_name, position, base_vector, length, brush_size)
|
||||
function noise_vector_tile_path(surface, tile_name, position, base_vector, length, brush_size, whitelist)
|
||||
local seed_1 = math.random(1, 10000000)
|
||||
local seed_2 = math.random(1, 10000000)
|
||||
local vector = {}
|
||||
local tiles = {}
|
||||
local minimal_movement = 0.75
|
||||
local minimal_movement = 0.65
|
||||
local brush_vectors = get_brush(brush_size)
|
||||
|
||||
for a = 1, length, 1 do
|
||||
tiles[#tiles + 1] = {name = tile_name, position = position}
|
||||
for _, v in pairs(brush_vectors) do
|
||||
surface.set_tiles({{name = tile_name, position = {position.x + v[1], position.y + v[2]}}}, true)
|
||||
local p = {x = position.x + v[1], y = position.y + v[2]}
|
||||
if whitelist then
|
||||
if whitelist[surface.get_tile(p).name] then
|
||||
surface.set_tiles({{name = tile_name, position = p}}, true)
|
||||
tiles[#tiles + 1] = {name = tile_name, position = p}
|
||||
end
|
||||
else
|
||||
surface.set_tiles({{name = tile_name, position = p}}, true)
|
||||
tiles[#tiles + 1] = {name = tile_name, position = p}
|
||||
end
|
||||
end
|
||||
|
||||
local noise = simplex_noise(position.x * 0.1, position.y * 0.1, seed_1)
|
||||
|
@ -1,5 +1,87 @@
|
||||
require "functions.noise_vector_path"
|
||||
require "functions.boss_unit"
|
||||
require "maps.island_troopers.terrain"
|
||||
|
||||
local function set_next_level()
|
||||
global.alive_enemies = 0
|
||||
global.current_stage = 1
|
||||
global.current_level = global.current_level + 1
|
||||
|
||||
global.path_tiles = nil
|
||||
global.stages = {}
|
||||
global.stages[1] = {
|
||||
path_length = 32 + global.current_level * 5,
|
||||
size = math.random(global.current_level * 2, global.current_level * 5),
|
||||
}
|
||||
for i = 1, global.current_level, 1 do
|
||||
global.stages[#global.stages + 1] = {
|
||||
path_length = 24 + global.current_level * 5,
|
||||
size = math.random(global.current_level * 2, global.current_level * 5),
|
||||
}
|
||||
end
|
||||
global.stages[#global.stages + 1] = {
|
||||
path_length = 128 + global.current_level * 5,
|
||||
size = false,
|
||||
}
|
||||
|
||||
game.print("Level " .. global.current_level .. " has begun!")
|
||||
|
||||
global.gamestate = 2
|
||||
end
|
||||
|
||||
--event.on_init(on_init)
|
||||
local function wait_until_stage_is_beaten()
|
||||
if global.alive_enemies > 0 then return end
|
||||
if global.stages[global.current_stage].size then
|
||||
global.current_stage = global.current_stage + 1
|
||||
global.gamestate = 2
|
||||
return
|
||||
end
|
||||
|
||||
game.print("Level " .. global.current_level .. " complete!!")
|
||||
global.gamestate = 5
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
player.insert({name = "pistol", count = 1})
|
||||
player.insert({name = "uranium-rounds-magazine", count = 128})
|
||||
player.insert({name = "firearm-magazine", count = 32})
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
local surface = game.surfaces[1]
|
||||
surface.request_to_generate_chunks({x = 0, y = 0}, 8)
|
||||
surface.force_generate_chunk_requests()
|
||||
|
||||
--global.level_tiles = {}
|
||||
global.level_vectors = {}
|
||||
global.current_level = 0
|
||||
global.gamestate = 1
|
||||
|
||||
game.forces.player.set_spawn_position({0, 2}, surface)
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
if not event.entity.valid then return end
|
||||
if event.entity.force.name == "enemy" then global.alive_enemies = global.alive_enemies - 1 end
|
||||
end
|
||||
|
||||
local gamestate_functions = {
|
||||
[1] = set_next_level,
|
||||
[2] = draw_path_to_next_stage,
|
||||
[3] = draw_the_island,
|
||||
[4] = wait_until_stage_is_beaten,
|
||||
[5] = kill_the_level,
|
||||
}
|
||||
|
||||
local function on_tick()
|
||||
if game.tick % 2 == 0 then
|
||||
gamestate_functions[global.gamestate]()
|
||||
end
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.on_init(on_init)
|
||||
event.add(defines.events.on_tick, on_tick)
|
||||
event.add(defines.events.on_entity_died, on_entity_died)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
@ -1,24 +1,80 @@
|
||||
local map_functions = require "tools.map_functions"
|
||||
local math_random = math.random
|
||||
|
||||
local function get_vector()
|
||||
local v = {}
|
||||
v[1] = (-100 + math.random(0, 200)) * 0.01
|
||||
v[2] = (-100 + math.random(0, 50)) * 0.01
|
||||
return v
|
||||
if global.current_stage == 1 then return {0, -1} end
|
||||
if global.current_stage == #global.stages then return {0, 1} end
|
||||
return {1, 0}
|
||||
end
|
||||
|
||||
local function draw_island(surface, position, size)
|
||||
map_functions.draw_noise_tile_circle(position, "grass-2", surface, size)
|
||||
local function add_enemies(surface, position)
|
||||
local radius = global.stages[global.current_stage].size
|
||||
local amount = math.ceil(((global.current_level * 10) / #global.stages) * global.current_stage)
|
||||
for a = 1, amount, 1 do
|
||||
local p = {x = position.x + (radius - math.random(0, radius * 2)), y = position.y + (radius - math.random(0, radius * 2))}
|
||||
if surface.can_place_entity({name = "small-biter", position = p, force = enemy}) then
|
||||
surface.create_entity({name = "small-biter", position = p, force = enemy})
|
||||
global.alive_enemies = global.alive_enemies + 1
|
||||
end
|
||||
end
|
||||
|
||||
if global.current_stage == #global.stages - 1 then
|
||||
local unit = surface.create_entity({name = "medium-spitter", position = position, force = enemy})
|
||||
add_boss_unit(unit, global.current_level * 2, 0.55)
|
||||
global.alive_enemies = global.alive_enemies + 1
|
||||
end
|
||||
end
|
||||
|
||||
local function draw_path(surface, position, length)
|
||||
local tiles = noise_vector_tile_path(surface, "grass-1", position, get_vector(), length, math.random(2, 5))
|
||||
return tiles
|
||||
function draw_the_island()
|
||||
if not global.stages[global.current_stage].size then global.gamestate = 4 return end
|
||||
local surface = game.surfaces[1]
|
||||
local position = global.path_tiles[#global.path_tiles].position
|
||||
map_functions.draw_noise_tile_circle(position, "grass-2", surface, global.stages[global.current_stage].size)
|
||||
add_enemies(surface, position)
|
||||
global.gamestate = 4
|
||||
end
|
||||
|
||||
function kill_level(surface)
|
||||
for _, t in pairs(surface.find_tiles_filtered({area = {{-256, -256}, {256, -32}}, name = {"grass-1", "grass-2"}})) do
|
||||
surface.set_tiles({{name = "water", position = t.position}}, true)
|
||||
local draw_path_tile_whitelist = {
|
||||
["water"] = true,
|
||||
}
|
||||
|
||||
function draw_path_to_next_stage()
|
||||
local surface = game.surfaces[1]
|
||||
|
||||
if global.current_stage ~= #global.stages then
|
||||
if global.current_stage == #global.stages - 1 then
|
||||
game.print("--Final Stage--")
|
||||
else
|
||||
game.print("--Stage " .. global.current_stage .. "--")
|
||||
end
|
||||
end
|
||||
|
||||
local position = {x = 0, y = 0}
|
||||
if global.path_tiles then position = global.path_tiles[#global.path_tiles].position end
|
||||
--game.print(get_vector()[1] .. " " .. get_vector()[2])
|
||||
global.path_tiles = noise_vector_tile_path(surface, "grass-1", position, get_vector(), global.stages[global.current_stage].path_length, math.random(2, 5), draw_path_tile_whitelist)
|
||||
|
||||
--for _, t in pairs(global.path_tiles) do
|
||||
-- global.level_tiles[#global.level_tiles + 1] = t
|
||||
--end
|
||||
|
||||
global.gamestate = 3
|
||||
end
|
||||
|
||||
local tile_whitelist = {"grass-1", "grass-2", "grass-3", "grass-4"}
|
||||
local function get_level_tiles(surface)
|
||||
global.level_tiles = {}
|
||||
for chunk in surface.get_chunks() do
|
||||
if chunk.y < 0 and game.forces.player.is_chunk_charted(surface, chunk) then
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = {{chunk.x * 32, chunk.y * 32}, {chunk.x * 32 + 32, chunk.y * 32 + 32}}, name = tile_whitelist})) do
|
||||
local index = math.abs(tile.position.y)
|
||||
if not global.level_tiles[index] then global.level_tiles[index] = {} end
|
||||
global.level_tiles[index][#global.level_tiles[index] + 1] = tile
|
||||
end
|
||||
end
|
||||
end
|
||||
for k, tile_row in pairs(global.level_tiles) do
|
||||
table.shuffle_table(global.level_tiles[k])
|
||||
end
|
||||
end
|
||||
|
||||
@ -28,27 +84,61 @@ local function wipe_vision(surface)
|
||||
end
|
||||
end
|
||||
|
||||
function draw_level(surface)
|
||||
kill_level(surface)
|
||||
wipe_vision(surface)
|
||||
local position = {x = 0, y = -32}
|
||||
for a = 1, 3, 1 do
|
||||
local size = math.random(20, 48)
|
||||
local length = size * 3
|
||||
local t = draw_path(surface, position, length)
|
||||
draw_island(surface, t[#t].position, size)
|
||||
position = t[#t].position
|
||||
local particles = {"coal-particle", "copper-ore-particle", "iron-ore-particle", "stone-particle"}
|
||||
local function create_particles(surface, position)
|
||||
local particle = particles[math_random(1, #particles)]
|
||||
local m = math_random(10, 30)
|
||||
local m2 = m * 0.005
|
||||
for i = 1, 25, 1 do
|
||||
surface.create_entity({
|
||||
name = particle,
|
||||
position = position,
|
||||
frame_speed = 0.1,
|
||||
vertical_speed = 0.1,
|
||||
height = 0.1,
|
||||
movement = {m2 - (math_random(0, m) * 0.01), m2 - (math_random(0, m) * 0.01)}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function kill_the_level()
|
||||
local surface = game.surfaces[1]
|
||||
if not global.level_tiles then get_level_tiles(surface) end
|
||||
|
||||
local amount = global.current_level
|
||||
for i = #global.level_tiles, 1, -1 do
|
||||
if global.level_tiles[i] then
|
||||
for k, tile in pairs(global.level_tiles[i]) do
|
||||
surface.set_tiles({{name = "water", position = tile.position}}, true)
|
||||
create_particles(surface, tile.position)
|
||||
global.level_tiles[i][k] = nil
|
||||
amount = amount - 1
|
||||
if amount <= 0 then return end
|
||||
end
|
||||
global.level_tiles[i] = nil
|
||||
end
|
||||
end
|
||||
|
||||
if #global.level_tiles == 0 then
|
||||
wipe_vision(surface)
|
||||
global.level_tiles = nil
|
||||
global.gamestate = 1
|
||||
end
|
||||
end
|
||||
|
||||
local function process_tile(surface, position)
|
||||
if position.y < 0 then surface.set_tiles({{name = "water", position = position}}, true) return end
|
||||
if position.y > 4 then surface.set_tiles({{name = "water-green", position = position}}, true) return end
|
||||
surface.set_tiles({{name = "sand-1", position = position}}, true)
|
||||
end
|
||||
|
||||
local function on_chunk_generated(event)
|
||||
local left_top = event.area.left_top
|
||||
local surface = event.surface
|
||||
for x = 0, 31, 1 do
|
||||
for y = 0, 31, 1 do
|
||||
local p = {x = left_top.x + x, y = left_top.y + y}
|
||||
if left_top.y < -32 then surface.set_tiles({{name = "water", position = p}}, true) end
|
||||
if left_top.y > 32 then surface.set_tiles({{name = "water-green", position = p}}, true) end
|
||||
local position = {x = left_top.x + x, y = left_top.y + y}
|
||||
process_tile(surface, position)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user