This commit is contained in:
mrbesen 2019-07-21 10:32:16 +02:00
commit 193e2ecb65
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
5 changed files with 108 additions and 0 deletions

12
README.md Normal file
View File

@ -0,0 +1,12 @@
# Superhot - Factorio mod
Time runs as fast as you run.
This mod is inspired by the game [Superhot](http://superhot.jp)
If you have problems you can reset the timing in you wold with:
```
/c game.speed = 1
```
Download the Mod [here](https://mods.factorio.com/mod/Superhot)

83
control.lua Normal file
View File

@ -0,0 +1,83 @@
--local movingActive = 673 -- this value is actually not random, but carefully calculated , src value: 0,1484375
local miningActive = 100
function init()
if not global.Superhot then
global.Superhot = {}
end
if not global.Superhot.playermovement then
global.Superhot.playermovement = {}
end
end
function getDist(mov)
return math.sqrt((mov[1] * mov[1]) + (mov[2] * mov[2]))
end
-- caps the speed using a logarithmic function, is undefined for x <= 0!
function movementcap(x)
return (75.88 * math.log(x)) + 244
end
script.on_event({defines.events.on_tick},
function (e)
init() -- init variables TODO: do somewhere else!
local activeMax = 0
local lastplayer -- just for DEBUG
for index,player in pairs(game.connected_players) do --loop through all online players on the server
lastplayer = player
if player.valid and player.connected and player.character then
local active = 0
-- is mining?
if player.mining_state.mining then
active = miningActive
end
--is moving
local newpos = player.position
local oldpos = global.Superhot.playermovement[player.index]
local mov = {0,0}
if oldpos ~= nil then
mov = {oldpos.x - newpos.x, oldpos.y - newpos.y}
local dist = getDist(mov)
if dist > 0 then
active = active + movementcap(dist)
end
end
--update movement
global.Superhot.playermovement[player.index] = newpos
--update max
if active > activeMax then
activeMax = active
end
end
end
local goal = activeMax/100.0
local diff = goal - game.speed
-- make acceleration smoother
if diff > 0.2 or diff < -0.2 then
diff = diff / 2.0
end
goal = game.speed + diff
--clip to upper and lower bound
if goal < 0.1 then
goal = 0.1
elseif goal > 10 then
goal = 10
end
--actually set it
game.speed = goal
end
)
-- spped modifyer: game.speed=1
-- freeze time: game.player.surface.freeze_daytime=true
-- defines.events.on_pre_player_mined_item

11
info.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "Superhot",
"version": "0.1.0",
"title": "SuperHot",
"author": "MrBesen",
"contact": "https://git.mrbesen.de/mrbesen/superhot/issues",
"homepage": "https://git.mrbesen.de/mrbesen/superhot",
"factorio_version": "0.17",
"dependencies": ["base >= 0.17"],
"description": "Time runs as fast as you run."
}

2
install.sh Normal file
View File

@ -0,0 +1,2 @@
#!/bin/bash
cd ../ && zip Superhot/Superhot_0.1.0.zip -r Superhot/*.lua Superhot/info.json && cp -f Superhot_0.1.0.zip ~/.factorio/mods/ && echo "Done."

BIN
movementcap.ods Normal file

Binary file not shown.