So how would I go about it. It's really puzzling
I am using bump for collisions
This one is the messed up one when i tried to add spikes i don't know what went wrong
Code: Select all
local bump = require "bump"
world = bump.newWorld()
font = love.graphics.setNewFont("Quicksand-Light.ttf")
enemy = {x = 0,
y = 0,
width = 32,
height = 64,
jump = -350,
gravity = 500,
runSpeed = 400,
xVelocity = 0,
yVelocity = 0,
terminalVelocity = 900
}
player = {
x = 0,
y = 0,
width = 32,
height = 64,
jump = -350,
gravity = 500,
runSpeed = 400,
xVelocity = 0,
yVelocity = 0,
terminalVelocity = 900
}
function player.setPosition(x, y)
player.x, player.y = x, 1100
end
function player.update(dt)
player.move(dt)
player.applyGravity(dt)
player.collied(dt)
end
function player.move(dt)
if love.keyboard.isDown("e") then
love.event.quit()
end
if love.keyboard.isDown("r") then
love.event.quit("restart")
end
if love.keyboard.isDown("q") then
love.window.setMode( 1800, 900)
end
if love.keyboard.isDown("d") then
player.xVelocity = player.runSpeed
elseif love.keyboard.isDown("a") then
player.xVelocity = -player.runSpeed
else
player.xVelocity = 0
end
if love.keyboard.isDown("w") then
if player.yVelocity == 0 then
player.yVelocity = player.jump
end
end
end
if player.yVelocity ~= 0 then
player.y = player.y + player.yVelocity
player.yVelocity = player.yVelocity - player.gravity
end
function player.applyGravity(dt)
if player.yVelocity < player.terminalVelocity then
player.yVelocity = player.yVelocity + player.gravity * dt
else
player.yVelocity = player.terminalVelocity
end
end
function player.collied(dt)
local futureX = player.x + player.xVelocity * dt
local futureY = player.y + player.yVelocity * dt
local nextX, nextY, cols, len = world:move(player, futureX, futureY )
for i = 1, len do
local col = cols[i]
if col.normal.y == -1 or col.normal.y == 1 then
player.yVelocity = 0
end
end
player.x = nextX
player.y = nextY
end
function player.draw()
love.graphics.setColor(255,255,255)
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
end
local level = require "level_1"
function loadObjects(level)
local objects = level.layers[1].objects
for i = 1, #objects do
local obj = objects[i]
world:add(obj, obj.x, obj.y, obj.width, obj.height)
end
end
function drawObjects(level)
local objects = level.layers[1].objects
love.graphics.setColor(0,20,200)
for i = 1, #objects do
local obj = objects[i]
love.graphics.rectangle("line", obj.x, obj.y, obj.width, obj.height, love.graphics.setColor(0, 20, 200))
love.graphics.setColor(255, 0, 0, 255)
love.graphics.print("A is for left, D is for right, W is for jump.", 10, 1230, 200, 2, 2, love.graphics.setColor(255, 0, 0))
love.graphics.print("E is to quit, Q is to change screen size.", 10, 1150, 200, 2, 2, love.graphics.setColor(255, 0, 0))
love.graphics.print("R is for reset.", 10, 1050, 200, 2, 2, love.graphics.setColor(255, 0, 0))
love.graphics.print("Hello Welcome to my game, I hope you enjoy.", 10, 1250, 0, 2, 2, love.graphics.setColor(0, 255, 0))
love.graphics.print("The Objective of the game is get to the end.", 1150, 1040, 0, 2, 2, love.graphics.setColor(150, 150, 150))
love.graphics.print("You can climb upside down if you hold Jump.", 1690, 840, 0, 1, 1, love.graphics.setColor(0, 150, 255))
love.graphics.print("Careful if the cube monser hits you then you'll have to restart.", 3584.00, 1790.00, 0, 2, 2, love.graphics.setColor(0, 150, 255))
end
end
--Main
function love.load()
player.img = love.graphics.newImage('purple.png')
player.setPosition(love.graphics.getWidth()/2, 0)
world:add(player, player.x, player.y, player.width, player.height)
loadObjects(level)
sound = love.audio.newSource("bensound-scifi.mp3")
love.audio.play(sound)
print(love.system.getPowerInfo())
end
function love.update(dt)
player.update(dt)
end
function love.draw()
scale = 0.8
dx = player.x - (love.graphics.getWidth() / 2) / scale
dy = player.y - (love.graphics.getHeight() / 2) / scale
love.graphics.scale(scale)
love.graphics.translate(-dx, -dy)
player.draw()
love.graphics.draw(player.img, player.x, player.y, 0, 1, 1, 20, 20, love.graphics.setColor(255,255,255))
drawObjects(level)
end
Code: Select all
function world.add(object)
world.objects[#world.objects+1] = object
return object
end
function world.update(dt)
for i=#world.objects, 1, -1 do
local object = world.objects[i]
if object.remove then table.remove(world.objects, i)
else object.update(dt) end
end
end
Code: Select all
function newEnemy(x, y)
local enemy = {}
enemy.x = x
enemy.y = y
enemy.remove = false
function enemy:update(dt)
-- movement, collision stuff, etc..
end
function enemy:draw()
-- draw the enemy
end
return enemy
end
local myEnemy = world.add(newEnemy(100, 200))
Code: Select all
if player.lives > 0 then player.lives = player.lives-1
else player.isDeadForEverEndTheDamnGameHere = true end
Yeah but im very new and don't really know how to do a .love I will when i learn how to. Thanks for the help ill try it out. haha i have trouble with life/health because i keep getting errorsMadByte wrote: ↑Sat Jan 13, 2018 5:59 pm Killing an actor
There are many ways to "kill" an actor in a game. One would be to set the x and y position outside the visible screen area and reuse the table (and reset x,y) if the actor is alive again. Another and imho better solution would be to add an instance of an actor to a separate "world" table, iterate through all objects and if an actor has been killed, remove the instance from the table. Something like:
Another advantage would be that you don't have to update every single actor alone. Just update and draw all via world.update and world.draw.Code: Select all
function world.add(object) world.objects[#world.objects+1] = object return object end function world.update(dt) for i=#world.objects, 1, -1 do local object = world.objects[i] if object.remove then table.remove(world.objects, i) else object.update(dt) end end end
Adding enemies
You could use the world approach I explained above to handle multiply enemies at once. just make sure that you add new instances to the world instead of the same one. Adding instances can also be done in different ways. If you're new to lua, the easiest one would be to do something like this:
An advantage of this approach is that it's quite easy to understand and apply. But it's not the cleanest and by far not the most efficient one.Code: Select all
function newEnemy(x, y) local enemy = {} enemy.x = x enemy.y = y enemy.remove = false function enemy:update(dt) -- movement, collision stuff, etc.. end function enemy:draw() -- draw the enemy end return enemy end local myEnemy = world.add(newEnemy(100, 200))
Obstacles / Power-ups
Mostly the same stuff done for the enemy can be used on those as well. Those things are just objects the player can collid with, which have different collision resolutions (power-up: collid, remove, add buffs to the player ; obstacles(spikes): collid, kill player).
Life and health
Don't know how to have problems with these. Life isn't more then a variable decreasing if the player get "removed" / killed or added by power-ups. Nothing more like (when killed):Same for health.. just a variable decreasing, and if it gets below 0, kill the player, remove a life and re-spawn the player after some time.Code: Select all
if player.lives > 0 then player.lives = player.lives-1 else player.isDeadForEverEndTheDamnGameHere = true end
I'm sure you get that done on your own.
btw. I think it's kinda rude to expect people to download every single dependency of your project and assemble them on their own.. Just upload a *.love and you'll receive lot more responses and maybe some changed/fixed code. Make sure it executes properly before uploading it.
Good luck.
It's not that difficult.ShadowPenguins wrote: ↑Sat Jan 13, 2018 6:59 pm Yeah but im very new and don't really know how to do a .love I will when i learn how to.
ShadowPenguins wrote: haha i have trouble with life/health because i keep getting errors
soo every time I do it, It just comes as an error would it be ok to just give a .zipMadByte wrote: ↑Sat Jan 13, 2018 7:05 pmIt's not that difficult.ShadowPenguins wrote: ↑Sat Jan 13, 2018 6:59 pm Yeah but im very new and don't really know how to do a .love I will when i learn how to.
The wiki in general is a great resource to learn all kinds of stuff about LÖVE.
ShadowPenguins wrote: haha i have trouble with life/health because i keep getting errors
I suppose you mean "main.lua" ? All you have to do is selecting the files and directories in your project folder (not the folder itself!) and zip them. When done, just rename the .zip to .love. If you're on Windows, you may need to un-hide file extensions.ShadowPenguins wrote: ↑Sat Jan 13, 2018 7:49 pm soo every time I do it, It just comes as an error would it be ok to just give a .zip
p.s. im doing everything right it just says make sure main.love is at the top it is at the top I swear
I got it working i just learned its very case sensitive . I added it up at the top. thank you for showing me how to make the love fileMadByte wrote: ↑Sat Jan 13, 2018 8:06 pmI suppose you mean "main.lua" ? All you have to do is selecting the files and directories in your project folder (not the folder itself!) and zip them. When done, just rename the .zip to .love. If you're on Windows, you may need to un-hide file extensions.ShadowPenguins wrote: ↑Sat Jan 13, 2018 7:49 pm soo every time I do it, It just comes as an error would it be ok to just give a .zip
p.s. im doing everything right it just says make sure main.love is at the top it is at the top I swear
Users browsing this forum: Google [Bot] and 4 guests