Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local defaultMaxHealth = 100
- local defaultObjectDamage = 2
- local keys = {space = 32, left = 37, right = 39, a = 65, d = 68, e = 69, q = 81}
- local players = {}
- local objects = {}
- local settings = {
- throwKeys = {[keys.e] = true},
- leftKeys = {[keys.left] = true, [keys.a] = true, [keys.q] = true},
- rightKeys = {[keys.right] = true, [keys.d] = true},
- }
- function main()
- for n in pairs(tfm.get.room.playerList) do
- eventNewPlayer(n)
- end
- end
- function pythag(x1, y1, x2, y2, r)
- local x = x2 - x1
- local y = y2 - y1
- local r = r + r
- return x * x + y * y < r * r
- end
- function setKeys(n)
- for i, key in pairs(keys) do
- tfm.exec.bindKeyboard(n, key, true, true)
- end
- end
- function showHealthBar(n)
- local player = players[n]
- local healthLen = math.floor(tonumber(player.health) * (250 / defaultMaxHealth))
- if healthLen < 80 then healthLen = 80 elseif healthLen > 250 then healthLen = 250 end
- ui.addTextArea(0, "", n, 10, 25, 250, 20, 0x324650, 0x89a7f5, 0.7, true)
- ui.addTextArea(1, "<p align='center'>"..player.health.." Health", n, 10, 25, healthLen, 20, 0x171918, 0x171918, 0.5, true)
- end
- function eventNewGame()
- for n in pairs(tfm.get.room.playerList) do
- eventPlayerRespawn(n)
- end
- ui.setShamanName("Get ready..")
- ui.setMapName("pow's wars")
- end
- function eventLoop()
- for i, object in pairs(tfm.get.room.objectList) do
- local id = object.id
- if objects[id] and not objects[id].didDamage then
- for n, data in pairs(tfm.get.room.playerList) do
- if objects[id].spawner ~= n and pythag(object.x, object.y, data.x, data.y, 50) and (math.abs(object.vx) > 2 or math.abs(object.vy) > 2) then
- local player = players[n]
- if player then
- player.health = player.health - defaultObjectDamage
- -- player.health = player.health - math.abs(object.vx) - math.abs(object.vy) - defaultObjectDamage
- if player.health <= 0 then tfm.exec.killPlayer(n) end
- showHealthBar(n)
- objects[id].didDamage = true
- end
- end
- end
- end
- end
- end
- function eventKeyboard(n, key, down, x, y)
- local data = tfm.get.room.playerList[n]
- local player = players[n]
- if not data.isDead then
- if settings.rightKeys[key] then
- player.direction = 1
- elseif settings.leftKeys[key] then
- player.direction = -1
- elseif settings.throwKeys[key] then
- local id = tfm.exec.addShamanObject(34, x + (20 * player.direction), y - 10, 0, math.random(8, 12) * player.direction, 0, false)
- objects[id] = {spawner = n, didDamage = false}
- end
- end
- end
- function eventNewPlayer(n)
- if not players[n] then
- players[n] = {health = defaultMaxHealth, direction = 1}
- end
- setKeys(n)
- showHealthBar(n)
- end
- function eventPlayerDied(n)
- players[n].health = 0
- showHealthBar(n)
- local num, pn = 0, ""
- for n, data in pairs(tfm.get.room.playerList) do
- if not data.isDead then
- pn = n
- num = num + 1
- end
- end
- if num == 1 then
- tfm.exec.setGameTime(5)
- tfm.exec.giveCheese(pn)
- tfm.exec.playerVictory(pn)
- elseif num == 0 then
- tfm.exec.newGame(maps[math.random(#maps)])
- end
- end
- function eventPlayerRespawn(n)
- players[n].health = defaultMaxHealth
- showHealthBar(n)
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment