1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00
This commit is contained in:
MewMew 2019-08-26 02:00:00 +02:00
parent d0244e4139
commit fea21bb776
3 changed files with 134 additions and 60 deletions

View File

@ -19,7 +19,7 @@ require "player_list"
require "poll"
require "score"
require "modules.floaty_chat"
require "modules.autohotbar"
--require "modules.autohotbar"
--require "on_tick_schedule"
---- enable modules here ----
@ -63,6 +63,7 @@ require "modules.autohotbar"
--require "maps.wave_of_death.WoD"
--require "maps.stone_maze.main"
--require "maps.overgrowth"
require "maps.tetris"
--require "maps.maze_challenge"
--require "maps.cave_miner"
--require "maps.rocky_waste"
@ -89,6 +90,7 @@ require "modules.autohotbar"
--require "maps.blue_beach"
--require "maps.lost_desert"
--require "maps.cube"
--require "maps.forest_circle"
--require "maps.empty_map"
--require "maps.custom_start"
-----------------------------

View File

@ -88,26 +88,37 @@ local function is_position_inside_playfield(position)
return true
end
local function has_position_free_space(surface, position)
--local entities = surface.find_entities_filtered({area = {{position.x + 0.1, position.y + 0.1},{position.x + 0.9, position.y + 0.9}}})
local entities = surface.find_entities_filtered({position = {position.x + 0.5, position.y + 0.5}})
if not entities then game.print(1) return true end
if not global.active_brick.entities then game.print(2) return true end
for _, e in pairs(global.active_brick.entities) do
if e == entities[1] then game.print(3) return true end
end
return false
end
local function draw_active_bricks(surface)
if not global.active_brick then return end
if not global.active_brick.entities then global.active_brick.entities = {} end
for k, e in pairs(global.active_brick.entities) do
e.destroy()
for k, e in pairs(global.active_brick.entities) do
if e.valid then global.tetris_active_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y))] = false end
global.active_brick.entities[k] = nil
e.destroy()
end
for _, p in pairs(global.active_brick.positions) do
global.active_brick.entities[#global.active_brick.entities + 1] = surface.create_entity({name = global.active_brick.entity_name, position = p})
local e = surface.create_entity({name = global.active_brick.entity_name, position = p})
global.tetris_active_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y))] = true
global.active_brick.entities[#global.active_brick.entities + 1] = e
end
end
local function set_collision_grid(surface)
for x = 0, playfield_width - 1, 1 do
for y = 0, playfield_height - 1, 1 do
local position = {x = playfield_area.left_top.x + x, y = playfield_area.left_top.y + y}
global.tetris_grid[coord_string(math.floor(position.x), math.floor(position.y))] = true
end
end
--local entities = surface.find_entities_filtered({area = {{playfield_area.left_top.x, playfield_area.left_top.y},{playfield_area.right_bottom.x, playfield_area.right_bottom.y}}, force = "enemy"})
local entities = surface.find_entities_filtered({area = playfield_area, force = "enemy"})
for _, e in pairs(entities) do
if not global.tetris_active_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y))] then
global.tetris_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y))] = false
else
game.print(e.position)
end
end
end
@ -127,27 +138,6 @@ local function rotate_brick(surface)
global.active_brick.direction = new_direction
end
local function new_brick(surface)
if global.active_brick then return end
if game.tick < 60 then return end
global.active_brick = {}
local spawn_position = {x = playfield_area.left_top.x + playfield_width * 0.5, y = playfield_area.left_top.y + 3}
local r = math.random(1, #bricks)
--local r = 6
local brick = bricks[r]
global.active_brick.direction = 1
global.active_brick.type = r
global.active_brick.positions = {}
global.active_brick.entity_name = brick.entity_name
for k, v in pairs(brick.vectors[1]) do
global.active_brick.positions[k] = {x = spawn_position.x + v[1], y = spawn_position.y + v[2]}
end
end
local function set_hotbar()
for _, player in pairs(game.connected_players) do
player.set_quick_bar_slot(1, "iron-plate")
@ -157,10 +147,8 @@ local function set_hotbar()
end
local function set_inventory()
for _, player in pairs(game.connected_players) do
for _, item in pairs({"iron-plate", "copper-plate", "iron-gear-wheel"}) do
for _, player in pairs(game.connected_players) do
for _, item in pairs({"iron-plate", "copper-plate", "iron-gear-wheel"}) do
if player.get_main_inventory().get_item_count(item) == 0 then
player.insert({name = item, count = 1})
end
@ -183,14 +171,103 @@ local function move(surface, item)
end
end
local function draw_playfield(surface)
for x = 0, playfield_width - 1, 1 do
for y = 0, playfield_height - 1, 1 do
local position = {x = playfield_area.left_top.x + x, y = playfield_area.left_top.y + y}
global.tetris_grid[coord_string(math.floor(position.x), math.floor(position.y))] = true
surface.set_tiles({{name = "tutorial-grid", position = position}})
end
end
end
local function kill_line(entities)
for _, e in pairs(entities) do
e.surface.create_entity({name = "explosion", position = e.position, force = "neutral"})
--global.tetris_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y))] = true
e.die()
end
end
local function move_lines_down(surface, y)
local entities = surface.find_entities_filtered({area = {{playfield_area.left_top.x, playfield_area.left_top.y},{playfield_area.left_top.x + playfield_width + 1, playfield_area.left_top.y + y + 1}}, force = "enemy"})
for _, e in pairs(entities) do
-- if not is_entity_active(e) then
if e.valid then
--global.tetris_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y))] = true
e.clone{position={e.position.x, e.position.y + 1}, surface=surface, force="enemy"}
--global.tetris_grid[coord_string(math.floor(e.position.x), math.floor(e.position.y + 1))] = false
e.destroy()
end
end
end
local function tetris(surface)
local c = 0
for y = 0, playfield_height, 1 do
local entities = surface.find_entities_filtered({area = {{playfield_area.left_top.x, playfield_area.left_top.y + y},{playfield_area.left_top.x + playfield_width + 1, playfield_area.left_top.y + y + 1}}, force = "enemy"})
if #entities == playfield_width then
kill_line(entities)
move_lines_down(surface, y)
set_collision_grid(surface)
c = c + 1
end
end
if c < 1 then return end
game.print(c .. " lines cleared!")
end
local function reset_play_area(surface)
local entities = surface.find_entities_filtered({area = playfield_area, force = "enemy"})
for _, e in pairs(entities) do
if math.random(1,3) == 1 then e.surface.create_entity({name = "big-explosion", position = e.position, force = "neutral"}) end
e.destroy()
end
set_collision_grid(surface)
global.last_reset = game.tick + 300
end
local function new_brick(surface)
if global.active_brick then return end
local spawn_position = {x = playfield_area.left_top.x + playfield_width * 0.5, y = playfield_area.left_top.y + 3}
if not global.tetris_grid[coord_string(math.floor(spawn_position.x), math.floor(spawn_position.y))] then
reset_play_area(surface)
end
if game.tick < global.last_reset then
game.print("Round begins in.. " .. math.abs(math.floor((game.tick - global.last_reset) / 60)))
return
end
local r = math.random(1, #bricks)
--local r = 6
local brick = bricks[r]
global.active_brick = {}
global.active_brick.direction = 1
global.active_brick.type = r
global.active_brick.positions = {}
global.active_brick.entity_name = brick.entity_name
for k, v in pairs(brick.vectors[1]) do
global.active_brick.positions[k] = {x = spawn_position.x + v[1], y = spawn_position.y + v[2]}
end
end
local function move_down(surface)
if not global.active_brick then return end
for k, p in pairs(global.active_brick.positions) do
if not global.tetris_grid[coord_string(math.floor(global.active_brick.positions[k].x), math.floor(global.active_brick.positions[k].y + 1))] then
for k, p in pairs(global.active_brick.positions) do
global.tetris_grid[coord_string(math.floor(p.x), math.floor(p.y))] = false
global.tetris_active_grid[coord_string(math.floor(p.x), math.floor(p.y))] = false
end
global.active_brick = nil
tetris(surface)
new_brick(surface)
return
end
end
@ -199,16 +276,6 @@ local function move_down(surface)
end
end
local function draw_playfield(surface)
for x = 1, playfield_width, 1 do
for y = 1, playfield_height, 1 do
local position = {x = playfield_area.left_top.x + x, y = playfield_area.left_top.y + y}
surface.set_tiles({{name = "tutorial-grid", position = position}})
global.tetris_grid[coord_string(math.floor(position.x), math.floor(position.y))] = true
end
end
end
local function on_player_cursor_stack_changed(event)
local player = game.players[event.player_index]
--game.print(game.tick)
@ -249,20 +316,21 @@ end
local function on_init(event)
global.tetris_grid = {}
global.tetris_active_grid = {}
global.last_reset = 120
end
local function tick()
--set_inventory()
local surface = game.surfaces[1]
if game.tick % 30 == 0 then
new_brick(surface)
end
if game.tick % 30 == 0 then
move_down(surface)
end
if game.tick % 8 == 0 then
if game.tick % 4 == 0 then
draw_active_bricks(surface)
end
if game.tick % 16 == 0 then
move_down(surface)
end
if game.tick % 60 == 0 then
new_brick(surface)
end
end
event.on_nth_tick(2, tick)

View File

@ -11,9 +11,13 @@ local valid_entities = {
local function mining_speed_cooldown(p)
if not global.manual_mining_booster[p.index] then return end
if game.tick - global.manual_mining_booster[p.index] < 180 then return end
if not p.character then p.character.character_mining_speed_modifier = 0 return end
--if not p.character then p.character.character_mining_speed_modifier = 0 return end
if not p.character then return end
p.character.character_mining_speed_modifier = p.character.character_mining_speed_modifier - 1
if p.character.character_mining_speed_modifier <= 0 then p.character.character_mining_speed_modifier = 0 end
if p.character.character_mining_speed_modifier <= 0 then
p.character.character_mining_speed_modifier = 0
global.manual_mining_booster[p.index] = nil
end
end
local function on_player_mined_entity(event)