1
0

Worked on dIntDesJam #1

This commit is contained in:
Jon Michael Aanes 2016-02-05 13:01:11 +01:00
commit d3abf21352

147
1/main.lua Normal file
View File

@ -0,0 +1,147 @@
local WIDTH = 800
local HEIGHT = 600
local MAX_LIVES = 15
local SPEED = 5
local TIME_BETWEEN_REQS = 3
local player = {x = 400, y = 300, dx = 0, dy = 0, lives = MAX_LIVES}
local requirements = {}
requirements[1] = {
check = function ()
local speed = (player.dx*player.dx + player.dy*player.dy)
return speed < 0.7 * SPEED and speed > 0.1 * SPEED
end,
str = "Du bevæger dig for langsomt!"
}
requirements[2] = {
check = function ()
return (player.dx*player.dx + player.dy*player.dy) > 0.7 * SPEED
end,
str = "Du bevæger dig for hurtigt!"
}
requirements[3] = {
check = function ()
return (player.dx*player.dx + player.dy*player.dy) < 0.1 * SPEED
end,
str = "Du står stille!"
}
requirements[4] = {
check = function ()
return player.dx*player.dx > 0.7 * SPEED and player.dy*player.dy < 0.1 * SPEED
end,
str = "Du bevæger dig for meget på X aksen!"
}
requirements[5] = {
check = function ()
return player.dx*player.dx < 0.1 * SPEED and player.dy*player.dy > 0.7 * SPEED
end,
str = "Du bevæger dig for meget på Y aksen!"
}
requirements[6] = {
check = function ()
return player.dx*player.dx > 0.5 * SPEED and player.dy*player.dy > 0.5 * SPEED
end,
str = "Du bevæger dig for meget på skråt!"
}
requirements[7] = {
check = function ()
return player.lives > MAX_LIVES/2 and math.random() < 0.2
end,
str = "Du er for synlig!"
}
requirements[8] = {
check = function ()
return math.random() < 0.1
end,
str = "Du forstår jo ikke hvad du laver!"
}
requirements[9] = {
check = function ()
return player.x < 100 or player.x > WIDTH - 100 or player.y < 100 or player.y > WIDTH - 100
end,
str = "Du er for tæt på kanten!"
}
requirements[10] = {
check = function ()
return ((player.x-WIDTH/2)^2 + (player.y-HEIGHT/2)^2) < 70
end,
str = "Du er for tæt på midten!"
}
requirements[11] = {
check = function ()
return math.random() < 0.03
end,
str = "Fuck dig!"
}
local req_time = TIME_BETWEEN_REQS
local last_req = nil
local current_req = nil
local function select_next_req ()
current_req = nil
while not current_req do
local req = requirements[math.random(#requirements)]
if req.check() and last_req ~= req then
current_req = req
end
end
last_req = current_req
end
function love.load ()
love.window.setTitle("dIntDesJam #1 (JMAA)")
end
local req_x, req_y = 0, 0
function love.update (dt)
player.x = (player.x + player.dx + WIDTH) % WIDTH
player.y = (player.y + player.dy + HEIGHT) % HEIGHT
player.dx, player.dy = player.dx*(1-dt), player.dy*(1-dt)
if love.keyboard.isDown("w") then
player.dy = player.dy - dt * SPEED
elseif love.keyboard.isDown("s") then
player.dy = player.dy + dt * SPEED
end
if love.keyboard.isDown("a") then
player.dx = player.dx - dt * SPEED
elseif love.keyboard.isDown("d") then
player.dx = player.dx + dt * SPEED
end
req_time = req_time - dt
if req_time <= 0 then
req_x, req_y = math.random(WIDTH-300)+50, math.random(HEIGHT-300)+50
req_time = TIME_BETWEEN_REQS
player.lives = player.lives - 1
select_next_req()
end
end
function love.draw ()
love.graphics.setColor(255,255,255)
if current_req then
love.graphics.print(current_req.str, req_x, req_y)
end
love.graphics.setColor(255,255,255, 255 * player.lives/MAX_LIVES)
love.graphics.circle("fill", player.x, player.y, 10)
end