Just rename "midnight.love.zip" in midnight.app/Contents/Resources/ to "midnight.love".CaptainMaelstrom wrote:I tried following the "Creating a Mac OS X App" section here: http://www.love2d.org/wiki/Game_Distribution . But my friend said when he tried to run it, he gets the "no game" screen. Ideas?
Code Doodles!
- slime
- Solid Snayke
- Posts: 3161
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Code Doodles!
- CaptainMaelstrom
- Party member
- Posts: 161
- Joined: Sat Jan 05, 2013 10:38 pm
Re: Code Doodles!
Doh. Thanks slime. Everything works great now.
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Re: Code Doodles!
Here's my second one:
Galaxies!
Press spacebar to change galaxies.
Code messy and mostly uncommented due to laziness.
Edit: Modified code to make it more realistic.
Also, we should do something akin to JS1k (say, LOVE1k) that makes you create main.lua files less than 1k with boilerplate code. That would be pretty fun
Galaxies!
Press spacebar to change galaxies.
Code messy and mostly uncommented due to laziness.
Code: Select all
-- code doodle: galaxies
-- by phoenix enero
local screen = {}
math.randomseed(os.time())math.random()math.random()
local NOISESEED = math.random()*60000
function love.load()
screen.width = love.window.getWidth()
screen.height = love.window.getHeight()
-- changeable constants
num_arms = 4
spiral_pitch = math.rad(12)
angle_scale = 5
perturb_dist = 5
-- galaxy itself
galaxyPoints = generateGalaxy(4000)
end
function love.keypressed(key, isrepeat)
if key == " " then
num_arms = math.floor(math.random()*3+2)
spiral_pitch = math.rad(math.random()*5+10)
NOISESEED = math.random()*60000
galaxyPoints = generateGalaxy(2500)
end
end
function generateGalaxy(num_points)
-- lets generate multiple arms
local points = {}
local a = 50
local b = spiral_pitch
local e = 2.7182818284
for arm=1, num_arms do
local rho = (arm-1)/num_arms*2*math.pi
for i=1, num_points/num_arms do
local point = {}
local factor = ((i-num_points/5)/num_points)*4
local theta = 2*math.pi*angle_scale*factor-math.random()*1+0.5
local r = a*e^(b*theta)
local perturb = e^(r/(math.deg(b)*5)) * perturb_dist-perturb_dist/2
point.x, point.y = parametric(r+math.random()*perturb,
theta+rho)
local d = math.sqrt(point.x*point.x+point.y*point.y)
local noiseVal = love.math.noise(d/350+NOISESEED)--,
--(theta%(2*math.pi)/100)+NOISESEED-10)
local factor2 = (1/(math.max(r, 10)/150+1))
local r, g, b = HSL(noiseVal*255, 64,
factor2*factor2*255, 128)
point.color = {r, g, b}
points[#points+1] = point
end
end
return points
end
function parametric(r, theta)
return math.cos(theta)*r, math.sin(theta)*r
end
function polar(x, y, px, py)
local dx = px-x
local dy = py-y
local r = math.sqrt(dx*dx+dy*dy)
local theta = math.atan2(dy, dx)
return r, theta
end
function love.update(dt)
end
function love.draw()
love.graphics.setBlendMode("additive")
love.graphics.setColor(255, 255, 255)
for _, v in pairs(galaxyPoints) do
love.graphics.setColor(v.color)
love.graphics.circle("fill",
v.x+screen.width/2,
v.y+screen.height/2,
NOISESEED%2+0.5)
end
end
-- Converts HSL to RGB. (input and output range: 0 - 255)
function HSL(h, s, l, a)
if s<=0 then return l,l,l,a end
h, s, l = h/256*6, s/255, l/255
local c = (1-math.abs(2*l-1))*s
local x = (1-math.abs(h%2-1))*c
local m,r,g,b = (l-.5*c), 0,0,0
if h < 1 then r,g,b = c,x,0
elseif h < 2 then r,g,b = x,c,0
elseif h < 3 then r,g,b = 0,c,x
elseif h < 4 then r,g,b = 0,x,c
elseif h < 5 then r,g,b = x,0,c
else r,g,b = c,0,x
end return (r+m)*255,(g+m)*255,(b+m)*255,a
end
Also, we should do something akin to JS1k (say, LOVE1k) that makes you create main.lua files less than 1k with boilerplate code. That would be pretty fun
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
Re: Code Doodles!
Another do nothing doodle.
- Attachments
-
- sprong.love
- Simple spring
- (869 Bytes) Downloaded 233 times
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: Code Doodles!
I made a polygon transforming thing that slowly adds sides to itself. Instead of using the default Löve polygons, I had to make my owns. Here are the controls:
SPACE or "R": Randomizes colors
ENTER: Toggles inner lines
Middle click: Toggles auto-running polygon changes
Mouse wheel: Increases/Decreases the polygon's sides
And the code:
It also includes unneeded things and my screenshots/in-game recording systems because I was lazy to remove them and there is no need to not publish them...
EDIT: Made another one as a test. Here comes the warning:
DO NOT TRY IT IF YOU HAVE PROBLEMS WITH FLASHING IMAGES!!!
This one was a small test. When you enter it (or reload by pressing Ctrl+L), it'll ask you the file name. Just throw a few images in the game folder, type them in and hit enter. Use the mouse wheel to increase/decrease the amount of frames per image. What it does is take your image, divide it in 3 (red-only, green-only, blue-only) and show them on the screen one at a time. If you set a low amount of frames per image (1 is the best one), it looks just like if your image was normal colored. If you set it to a high amount (30 is the best one), it'll show slowly each color map of your picture.
Since it maps the pixels of your image to make this, this may take a while to load, but not much...
SPACE or "R": Randomizes colors
ENTER: Toggles inner lines
Middle click: Toggles auto-running polygon changes
Mouse wheel: Increases/Decreases the polygon's sides
And the code:
Code: Select all
-- LÖVE Code Doodle #5
-- by HugoBDesigner
function love.load()
shapet = 0
shapetb = 0
shapemaxt = 10
shaped = "f"
shapemin = 3
shapemax = 15
recordingdata = {}
isRecording = false
timerecorded = 0 --Just so users can see how long they've been recording
framesrecorded = 0 --Just so users can see how long they've been recording
recordingtimer = 0
recordingmaxtimer = .025
canrun = true
inlines = true
rcol = {}
rcol[1] = {0, 0, 0, 255}
rcol[2] = {255, 255, 255, 255}
rcol[3] = {155, 155, 155, 255}
love.graphics.setBackgroundColor(unpack(rcol[1]))
end
function love.update(dt)
local dt = math.min(dt, 1/60)
if canrun then
if shaped == "f" then
shapet = shapet + dt
if shapet >= shapemaxt then
shaped = "b"
end
else
shapet = shapet - dt
if shapet <= 0 then
shaped = "f"
end
end
shapetb = shapet
end
if isRecording then
if recordingtimer >= recordingmaxtimer then
local a = love.graphics.newScreenshot()
recordingdata[#recordingdata+1] = a
framesrecorded = framesrecorded + dt
timerecorded = round(framesrecorded)
love.graphics.setCaption( "Spacing Out [RECORDING] - " .. tostring(timerecorded) .. " seconds - " .. tostring(#recordingdata) .. "frames")
recordingtimer = 0
else
recordingtimer = recordingtimer + dt
end
end
end
function love.draw()
local rd = 100
local sides = (shapet/shapemaxt)*(shapemax-shapemin)+shapemin
local points = love.graphics.shape("line", 400, 300, rd, math.limit(sides, shapemin, shapemax))
love.graphics.clear()
love.graphics.print("sides = " .. round(sides), 5, 15)
love.graphics.setLineWidth(2)
love.graphics.setColor(unpack(rcol[3]))
if inlines then
for i = 1, #points, 2 do
local px = points[i]
local py = points[i+1]
for a = 1, #points, 2 do
if a ~= i then
local npx = points[a]
local npy = points[a+1]
love.graphics.line(px, py, npx, npy)
end
end
end
end
love.graphics.setLineWidth(4)
love.graphics.setColor(unpack(rcol[2]))
local points = love.graphics.shape("line", 400, 300, rd, math.limit(sides, shapemin, shapemax))
end
function love.graphics.shape(mode, x, y, rd, sides)
local points = {}
for i = 1, math.ceil(sides) do
local px = x
local py = y
local a = math.pi*2/sides*i
px = px + math.cos(a)*rd
py = py + math.sin(a)*rd
table.insert(points, px)
table.insert(points, py)
end
love.graphics.polygon(mode, points)
return points
end
function love.keypressed(key, unicode)
if key == "escape" then
love.event.quit()
end
if key == "f12" then
love.mouse.setGrab(not love.mouse.isGrabbed())
end
if key == "f3" then
-- PART 1: Get the screenshot itself and make it as an image
local number = 1
local lnumber = "0001"
if not love.filesystem.exists("screenshots") then --make one
love.filesystem.mkdir("screenshots")
end
local screenshot = love.graphics.newScreenshot()
while love.filesystem.exists("screenshots/screenshot_" .. lnumber .. ".png") do
number = number + 1
if number >= 1 and number < 10 then
lnumber = "000" .. tostring(number)
elseif number >= 10 and number < 100 then
lnumber = "00" .. tostring(number)
elseif number >= 100 and number < 1000 then
lnumber = "0" .. tostring(number)
else
lnumber = tostring(number)
end
end
--screenshot:encode("screenshots/screenshot_" .. lnumber .. ".png")
--PART 2: Remove transparecy from screenshots. I noticed that they make transparent pixels
local image = screenshot
local imagewidth = image:getWidth()
local imageheight = image:getHeight()
for y = 0, imageheight-1 do
for x = 0, imagewidth-1 do
local r, g, b, a = image:getPixel( x, y )
if a < 255 then
image:setPixel( x, y, r, g, b, 255)
end
end
end
image:encode("screenshots/screenshot_" .. lnumber .. ".png")
end
if key == "f9" then
if isRecording then
stoprecording()
else
startrecording()
end
end
if key == "f10" then
if isRecording then
stoprecording(true)
end
end
if key == "f11" then
if isRecording then
isRecording = false
recordingdata = {}
framesrecorded = 0
timerecorded = 0
end
end
if key == "enter" or key == "return" or key == "kpenter" then
inlines = not inlines
end
if key == " " or key == "r" then
rcol[1] = {math.random(55), math.random(55), math.random(55), rcol[1][4]}
rcol[2] = {math.random(155, 255), math.random(155, 255), math.random(155, 255), rcol[2][4]}
rcol[3] = {math.random(55, 205), math.random(55, 205), math.random(55, 205), rcol[3][4]}
love.graphics.setBackgroundColor(unpack(rcol[1]))
end
end
function love.keyreleased(key, unicode)
end
function love.mousepressed(x, y, button)
local mult = 50
local add = shapemaxt/(mult*(shapemax-shapemin))
if button == "m" then
canrun = not canrun
shapet = math.floor(shapet*mult/2)/mult*2
end
if canrun == false then
if button == "wu" then
shapet = math.limit(shapet + add, 0, shapemaxt)
elseif button == "wd" then
shapet = math.limit(shapet - add, 0, shapemaxt)
end
end
end
function love.mousereleased(x, y, button)
end
function dist(x1, y1, x2, y2, ab)
local ab = ab or true
local w, h = x1-x2, y1-y2
if ab then
w = math.abs(w)
h = math.abs(h)
end
return math.sqrt(w^2+h^2)
end
function speedX(angle, speed)
return -math.sin(angle)*speed
end
function speedY(angle, speed)
return math.cos(angle)*speed
end
function math.limit(n, mn, mx)
return math.max(mn, math.min(mx, n))
end
function math.offset(n, mn, mx, f)
local n = n
local f = f or mx
if math.abs(mn-mx) > f then f = mx end
while n >= mx do
n = n - f
end
while n < mn do
n = n + f
end
return n
end
function round(n, d)
local d = d or 2
return math.floor(10^d*n)/(10^d)
end
function fade(currenttime, maxtime, c1, c2)
local tp = currenttime/maxtime
local ret = {} --return color
for i = 1, #c1 do
ret[i] = c1[i]+(c2[i]-c1[i])*tp
ret[i] = math.max(ret[i], 0)
ret[i] = math.min(ret[i], 255)
end
return unpack(ret)
end
function startrecording()
recordingdata = {}
isRecording = true
end
function stoprecording(transparency)
local transparency = transparency or false
isRecording = false
recordingtimer = 0
if not love.filesystem.exists( "records" ) then
love.filesystem.mkdir( "records" )
end
local a = "0001"
local n = 1
if love.filesystem.exists("records/record_" .. a) then
while love.filesystem.exists("records/record_" .. a) do
local zeros = ""
n = n + 1
if n >= 1 and n < 10 then
zeros = "000"
elseif n >= 10 and n < 100 then
zeros = "00"
elseif n >= 100 and n < 1000 then
zeros = "0"
end
a = zeros .. tostring(n)
end
end
n = 0
love.filesystem.mkdir("records/record_" .. a)
------------------
for i = 1, #recordingdata do
print("Recording saving at " .. tostring(round(100/#recordingdata*i, 2)) .. "%")
local b = "0001"
if love.filesystem.exists("records/record_" .. a .. "/" .. b .. ".png") then
while love.filesystem.exists("records/record_" .. a .. "/" .. b .. ".png") do
local zeros = ""
n = n + 1
if n >= 1 and n < 10 then
zeros = "000"
elseif n >= 10 and n < 100 then
zeros = "00"
elseif n >= 100 and n < 1000 then
zeros = "0"
end
b = zeros .. tostring(n)
end
end
if transparency then
for x = 0, recordingdata[i]:getWidth()-1 do
for y = 0, recordingdata[i]:getHeight()-1 do
local r, g, b, a = recordingdata[i]:getPixel(x, y)
a = 255
recordingdata[i]:setPixel(x, y, r, g, b, a)
end
end
end
recordingdata[i]:encode("records/record_" .. a .. "/" .. b .. ".png")
end
recordingdata = {}
framesrecorded = 0
timerecorded = 0
end
function table.contains(t, e)
for i, v in pairs(t) do
if v == e then
return i
end
end
return false
end
EDIT: Made another one as a test. Here comes the warning:
DO NOT TRY IT IF YOU HAVE PROBLEMS WITH FLASHING IMAGES!!!
This one was a small test. When you enter it (or reload by pressing Ctrl+L), it'll ask you the file name. Just throw a few images in the game folder, type them in and hit enter. Use the mouse wheel to increase/decrease the amount of frames per image. What it does is take your image, divide it in 3 (red-only, green-only, blue-only) and show them on the screen one at a time. If you set a low amount of frames per image (1 is the best one), it looks just like if your image was normal colored. If you set it to a high amount (30 is the best one), it'll show slowly each color map of your picture.
Since it maps the pixels of your image to make this, this may take a while to load, but not much...
Code: Select all
-- LÖVE Code Doodle #6
-- by HugoBDesigner
function love.load()
imgs = {}
imgname = ""
state = "type"
currentimg = 0
frames = 3
exists = true
end
function loadimage(name)
imgdt = love.image.newImageData(name .. ".png")
for i = 1, 3 do
local newdt = love.image.newImageData(name .. ".png")
newdt:mapPixel(function(x, y, r, g, b, a)
local newr, newg, newb = r, g, b
if i == 2 or i == 3 then
newr = 0
end
if i == 1 or i == 3 then
newg = 0
end
if i == 1 or i == 2 then
newb = 0
end
return newr, newg, newb, a
end)
table.insert(imgs, love.graphics.newImage(newdt))
end
end
function love.update(dt)
currentimg = currentimg + 1
if currentimg > 3*frames then currentimg = 1 end
end
function love.draw()
if state == "draw" then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.draw(imgs[math.ceil(currentimg/frames)], 0, 0)
love.graphics.setColor(0, 0, 0, 255)
local txt, x, y = "Frames per image: " .. frames, 5, 15
love.graphics.print(txt, x-1, y-1)
love.graphics.print(txt, x, y-1)
love.graphics.print(txt, x+1, y-1)
love.graphics.print(txt, x-1, y)
love.graphics.print(txt, x+1, y)
love.graphics.print(txt, x-1, y+1)
love.graphics.print(txt, x, y+1)
love.graphics.print(txt, x+1, y+1)
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print(txt, x, y)
else
love.graphics.setColor(255, 255, 255, 255)
local font = love.graphics.newFont(12)
local txt1 = "Type your image name:"
love.graphics.print(txt1, 400-font:getWidth(txt1)/2, 50)
love.graphics.print(imgname, 400-font:getWidth(imgname)/2, 80)
if exists == false then
love.graphics.setColor(255, 155, 155, 255)
local txt2 = "Type a name that DOES exists as a .png"
love.graphics.print(txt2, 400-font:getWidth(txt2)/2, 110)
end
end
end
function love.mousepressed(x, y, button)
if button == "wu" then
frames = math.min(frames+1, 30)
elseif button == "wd" then
frames = math.max(frames-1, 1)
end
end
function love.keypressed(key, unicode)
if key == "escape" then
love.event.quit()
end
if state == "type" then
forget = {"rshift", "lshift", "lalt", "ralt", "rctrl", "lctrl"}
if key == "enter" or key == "return" or key == "kpenter" then
if love.filesystem.exists(imgname .. ".png") then
loadimage(imgname)
state = "draw"
else
exists = false
end
elseif key == "backspace" then
if string.len(imgname) <= 1 then
imgname = ""
else
imgname = string.sub(imgname, 1, -2)
end
elseif table.contains(forget, key) == false then
imgname = imgname .. key
end
end
if key == "l" and (love.keyboard.isDown("lctrl") or love.keyboard.isDown("rctrl")) then
love.load()
end
end
function table.contains(t, e)
for i, v in pairs(t) do
if v == e then
return i
end
end
return false
end
Re: Code Doodles!
I found a blog has has tons of Processing sketches similar to the doodles in this thread. They are non-interactive gifs but are still generated with code and may serve as inspiration.
http://beesandbombs.tumblr.com/
Anyway, here's a doodle I came up with.
http://beesandbombs.tumblr.com/
Anyway, here's a doodle I came up with.
Code: Select all
local width = love.graphics.getWidth()
local height = love.graphics.getHeight()
local dots = {}
local timer = 0
local RADIUS = 25
local function distanceBetweenPoints(x1, y1, x2, y2)
local xdiff = x2 - x1
local ydiff = y2 - y1
local distance = math.sqrt(xdiff*xdiff + ydiff*ydiff)
return distance
end
function love.load()
love.graphics.setBackgroundColor(75, 75, 75)
for i = 0, height / (RADIUS * 2) do
for j = 0, width / (RADIUS * 2) do
dot = {
x = j * (RADIUS * 2),
y = i * (RADIUS * 2),
r = RADIUS,
color = {255, 255, 255}
}
table.insert(dots, dot)
end
end
end
function love.update(dt)
local mX = love.mouse.getX()
local mY = love.mouse.getY()
local centerX, centerY = width/2, height/2
for i = 1, #dots do
local d = dots[i]
local normDiffX = (mX - centerX) / distanceBetweenPoints(mX, mY, centerX, centerY)
local normDiffY = (mY - centerY) / distanceBetweenPoints(mX, mY, centerX, centerY)
-- move
d.x = d.x - normDiffX*200 * dt
d.y = d.y - normDiffY*200 * dt
-- wrap-around
if d.x > width + d.r then -- right edge
d.x = 0 - d.r
end
if d.y > height + d.r then -- bottom edge
d.y = 0 - d.r
end
if d.x < 0 - d.r then -- left edge
d.x = width + d.r
end
if d.y < 0 - d.r then -- top edge
d.y = height + d.r
end
-- avoid mouse
if distanceBetweenPoints(mX, mY, d.x, d.y) < d.r*2 then
d.color = {
love.math.random(100, 200),
love.math.random(100, 200),
love.math.random(100, 200)
}
d.r = d.r - 20 * dt
if mX < d.x then
d.x = d.x + 100 * dt
elseif mX > d.x then
d.x = d.x - 100 * dt
end
if mY < d.y then
d.y = d.y + 100 * dt
elseif mY > d.y then
d.y = d.y - 100 * dt
end
end
end
end
function love.draw()
for i = 1, #dots do
love.graphics.setColor(dots[i].color)
love.graphics.circle('fill', dots[i].x, dots[i].y, dots[i].r)
love.graphics.setColor(255, 255, 255)
end
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
if key == 'r' then
dots = {}
love.load()
end
end
- Attachments
-
- doodle1.love
- (929 Bytes) Downloaded 167 times
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Code Doodles!
An inefficient way to read the time. But was fun trying to make all the images procedurally in love.load.
Code: Select all
--[[ CODE DOODLE #4 by DaedalusYoung ]]--
--[[ Dials ]]--
local img = {}
local rn = love.math.random(1000)
local dials = { 0, 0, 0 }
local timer = 0
local ss = os.date("%S")
local function pixf(x, y, r, g, b, a)
local d = math.min((((x - 128) ^ 2)+((y - 128) ^ 2)) ^ 0.54, 255)
a = 255 - math.min(math.max(0, (d - 168) * 255), 255)
d = (255 - d)
local n = love.math.noise(x / 40, y / 40, rn) + (love.math.noise(x / 20, y / 20, rn) * 0.5) + (love.math.noise(x / 10, y / 10, rn) * 0.25)
n = (n / 1.75) * 255
if d < n then d = math.max(d - (n - d), 0) end
return d, d, d, a
end
function love.load()
love.graphics.setBackgroundColor(0, 0, 0)
love.window.setTitle("Dials")
local temp = love.image.newImageData(256, 256)
img.face = {}
for i = 1, 3 do
rn = love.math.random(1000)
temp:mapPixel(pixf)
img.face[i] = love.graphics.newImage(temp)
end
temp = love.image.newImageData(16, 128)
for x = 0, 15 do
for y = 0, 127 do
local a = 0
local xoff = math.abs(x - 7.5) * 16
a = math.min(255, math.max(0, (y - (xoff)) * 16))
temp:setPixel(x, y, 255, 255, 255, a)
end
end
img.dial = love.graphics.newImage(temp)
temp = love.image.newImageData(20, 600)
temp:mapPixel(function(x, y, r, g, b, a) local c = love.math.random(192, 255) - (y / 4) return c, c, c, 255 end)
img.bg = love.graphics.newImage(temp)
end
function love.update(dt)
timer = timer + dt
if ss ~= os.date("%S") then
timer = 0
ss = os.date("%S")
end
dials[1] = (os.date("%I") / 6) * math.pi
dials[2] = (os.date("%M") / 30) * math.pi
dials[3] = ((timer + os.date("%S")) / 30) * math.pi
dials[2] = dials[2] + (dials[3] / 60)
dials[1] = dials[1] + (dials[2] / 12)
end
function love.draw()
love.graphics.setColor(220, 212, 204)
love.graphics.draw(img.bg, 0, 0, 0, 40, 1)
for i = 1, 3 do
love.graphics.setColor(0, 0, 0, 127)
love.graphics.circle('fill', 147 + (i-1) * 256, 203, 115, 128)
love.graphics.setColor(237, 226, 194)
love.graphics.draw(img.face[i], 16 + (i-1) * 256, 72)
love.graphics.circle('line', 143.5 + (i-1) * 256, 199.5, 115, 128)
love.graphics.setColor(0, 0, 0, 127)
love.graphics.draw(img.dial, 143 + (i-1) * 256, 204, dials[i], 1, 1, 8, 120)
love.graphics.setColor(201, 69, 47)
love.graphics.draw(img.dial, 143 + (i-1) * 256, 200, dials[i], 1, 1, 8, 120)
end
end
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Code Doodles!
And after that, I was inspired to play some more with love.math.noise, so I created Doodle #5:
"Rolling Hills"
aka "Ain't No Creeper Gon' Blow Me Up Now"
"Rolling Hills"
aka "Ain't No Creeper Gon' Blow Me Up Now"
Code: Select all
--[[ CODE DOODLE #5 by DaedalusYoung ]]--
--[[ Rolling Hills ]]--
local map = {}
local width = 16
local height = 16
local timer = 0
local waveheight = 50
local wavesize = 5
local blockmode = false
local keytimer = 0
local keyinput = true
function love.load()
love.window.setTitle("Rolling Hills")
for y = 1, height do
map[y] = {}
for x = 1, width do
map[y][x] = 0
end
end
end
function love.update(dt)
timer = timer + dt
if not keyinput then
keytimer = keytimer + dt
if keytimer >= 0.04 then
keytimer = 0
keyinput = true
end
else
if love.keyboard.isDown("a", "d", "q", "e") then
keyinput = false
end
if love.keyboard.isDown("a") then
waveheight = math.floor(waveheight - 0.5)
end
if love.keyboard.isDown("d") then
waveheight = math.ceil(waveheight + 0.5)
end
waveheight = math.min(100, math.max(1, waveheight))
if love.keyboard.isDown("q") then
wavesize = math.floor((wavesize * 10) - 0.5) / 10
end
if love.keyboard.isDown("e") then
wavesize = math.ceil((wavesize * 10) + 0.5) / 10
end
wavesize = math.min(15, math.max(1, wavesize))
end
for y = 1, height do
map[y] = {}
for x = 1, width do
map[y][x] = love.math.noise(x / wavesize, y / wavesize, timer / 4)
end
end
end
function love.draw()
for y = 1, height do
for x = 1, width do
local x1 = (x * 24) - (y * 24) + 400
local x2 = x1 + 22
local x3 = x1
local x4 = x1 - 22
local val = map[y][x] * waveheight
if blockmode then
val = val - ((val + 10) % 20)
end
local y1 = (((y * 24) + (x * 24)) / 2) + (100 - val)
local y2 = y1 + 11
local y3 = y1 + 22
local y4 = y1 + 11
--left side
love.graphics.setColor(32, 147, 32)
love.graphics.polygon('fill', x3, y3, x4, y4, x4, y4 + 4, x3, y3 + 4)
love.graphics.setColor(104, 68, 33)
love.graphics.polygon('fill', x3, y3 + 4, x4, y4 + 4, x4, y4 + 20, x3, y3 + 20)
love.graphics.setColor(33, 33, 33)
love.graphics.polygon('fill', x3, y3 + 20, x4, y4 + 20, x4, y4 + 80, x3, y3 + 80)
love.graphics.setColor(68, 68, 68)
love.graphics.polygon('fill', x3, y3 + 21, x4, y4 + 21, x4, y4 + 40, x3, y3 + 40)
love.graphics.polygon('fill', x3, y3 + 41, x4, y4 + 41, x4, y4 + 60, x3, y3 + 60)
--right side
love.graphics.setColor(25, 116, 25)
love.graphics.polygon('fill', x2, y2, x3, y3, x3, y3 + 4, x2, y2 + 4)
love.graphics.setColor(76, 50, 25)
love.graphics.polygon('fill', x2, y2 + 4, x3, y3 + 4, x3, y3 + 20, x2, y2 + 20)
love.graphics.setColor(25, 25, 25)
love.graphics.polygon('fill', x2, y2 + 20, x3, y3 + 20, x3, y3 + 80, x2, y2 + 80)
love.graphics.setColor(50, 50, 50)
love.graphics.polygon('fill', x2, y2 + 21, x3, y3 + 21, x3, y3 + 40, x2, y2 + 40)
love.graphics.polygon('fill', x2, y2 + 41, x3, y3 + 41, x3, y3 + 60, x2, y2 + 60)
--top side
love.graphics.setColor(43, 198, 43)
love.graphics.polygon('fill', x1, y1, x2, y2, x3, y3, x4, y4)
love.graphics.setColor(25, 116, 25)
love.graphics.polygon('line', x1, y1, x2, y2, x3, y3, x4, y4)
end
end
love.graphics.setColor(255, 255, 255)
love.graphics.print("Wave size: " .. wavesize .. " [Q] and [E] to change\nWave height: " .. waveheight .. " [A] and [D] to change\n[B] to toggle Block Mode", 16, 16)
end
function love.keypressed(k)
if k == "b" then
blockmode = not blockmode
end
end
-
- Party member
- Posts: 712
- Joined: Fri Jun 22, 2012 4:54 pm
- Contact:
Re: Code Doodles!
... it's ... so ... beautiful!
And with just 100 lines of code and no graphic assets... well done!
And with just 100 lines of code and no graphic assets... well done!
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
Re: Code Doodles!
Dwarf Fortress game in LÖVE... my body is ready.DaedalusYoung wrote:And after that, I was inspired to play some more with love.math.noise, so I created Doodle #5:
"Rolling Hills"
aka "Ain't No Creeper Gon' Blow Me Up Now"
Who is online
Users browsing this forum: No registered users and 0 guests