Hey,
I am new to Lua and Love. I read through the basics and wanted to build my first game. You have to catch the Snow. But i cant get the Collisions System to work. It works in a way but sometimes it doesn´t. Please Help me.
Hopefully sombody can help me
Falling Snow Collision Fail
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Falling Snow Collision Fail
- Attachments
-
- Falling Snow.love
- (2.18 KiB) Downloaded 171 times
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Falling Snow Collision Fail
You packaged your .love the wrong way. Make sure to zip the contents of your game folder, not the folder itself.
- Attachments
-
- Falling Snow.love
- (1.03 KiB) Downloaded 176 times
Help us help you: attach a .love.
Re: Falling Snow Collision Fail
oh sorry...
normaly i am starting the game through the terminal...
normaly i am starting the game through the terminal...
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Falling Snow Collision Fail
Don't worry about it. Just remember to zip the contents in the future.
Also, I've looked at your code, but couldn't find the problem.
Also, I've looked at your code, but couldn't find the problem.
Help us help you: attach a .love.
Re: Falling Snow Collision Fail
Me too, it doesn't seem to have anything wrong
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Falling Snow Collision Fail
But why does the collision system fail ?
I cant understand it ...
I cant understand it ...
Re: Falling Snow Collision Fail
Serakus, all of us are a bit confused. Where you think the collision system is failling? What it should be happen? At least I can't see any problem. With the box I managed to score some points so the collision is working. You need to explain what then was supposed then to happen please.serakus wrote:But why does the collision system fail ?
I cant understand it ...
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Falling Snow Collision Fail
Your problem was that you were drawing the player from the top left, but doing the collision from the center. It took me a little fiddling to find it though, it's a sneaky bug.
Also, your code can be far simpler if you make the gamestate a string, rather than a table of booleans. You also don't need else return in there, Lua is very forgiving like that.
Also, your code can be far simpler if you make the gamestate a string, rather than a table of booleans. You also don't need else return in there, Lua is very forgiving like that.
Code: Select all
function love.load()
love.graphics.setCaption("Falling Snow")
love.graphics.setMode( 400, 320, false, false, 0)
init()
end
function love.update(dt)
changestate()
_counter = _counter + dt
if gamestate == "game" then
timeout(dt)
enemymove(dt)
playermove(dt)
if _counter >= 1 then
_enemy()
_counter = 0
end
end
end
function love.draw()
if gamestate == "over" then
love.graphics.print(" Press Enter to try Again!", 10, 160)
elseif gamestate == "pause" then
love.graphics.print(" Press Enter to continue!", 10 , 160)
elseif gamestate == "menu" then
love.graphics.print(" Catch the Snow!", 10, 148)
love.graphics.print(" Press Enter to start the Game!", 10, 160 )
elseif gamestate == "game" then
-- Drawing the Player
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
-- Drawing the Score/FPS/Time
love.graphics.print("Time: " .. time, 10, 10)
love.graphics.print("Score: " .. score, 10, 30)
-- Drawing Enemys
love.graphics.setPoint(3, "smooth")
for i, v in ipairs(enemy) do
love.graphics.point(v.x, v.y)
end
end
end
function playermove(dt)
if love.keyboard.isDown("left") then
if (player.x - dt * player.speed) > 0 then
player.x = player.x - dt * player.speed
end
elseif love.keyboard.isDown("right") then
if (player.x + dt * player.speed) + 10 < 400 then
player.x = player.x + dt * player.speed
end
end
--[[
if love.keyboard.isDown("up") then
player.y = player.y - dt * player.speed
elseif love.keyboard.isDown("down") then
player.y = player.y + dt * player.speed
end
]]--
end
function _enemy()
if enemycount <= 6 then
local en = {}
en.speed = math.random(70,100)
en.x = math.random(0,390)
en.y = 0
table.insert(enemy, en)
enemycount = enemycount + 1
end
end
function enemymove(dt)
for i,v in ipairs(enemy) do
v.y = v.y + dt * v.speed
if v.y >= 320 then
table.remove(enemy, i)
enemycount = enemycount - 1
elseif v.x >= player.x and v.x <= (player.x + 10) and v.y >= player.y and v.y <= (player.y + 10) then
table.remove(enemy, i)
enemycount = enemycount - 1
score = score + 1
end
end
end
function init()
player = {}
player.x = 10
player.y = 308
player.speed = 150
player.height = 10
player.width = 10
gamestate = "menu"
time = 20
score = 0
enemy = {}
enemycount = 0
_counter = 0
end
function changestate()
if gamestate == "game" and love.keyboard.isDown("p") then
gamestate = "pause"
end
if love.keyboard.isDown("return") then
if gamestate == "over" then
newGame()
gamestate = "game"
elseif gamestate == "pause" or gamestate == "menu" then
gamestate = "game"
end
end
end
function timeout(dt)
time = time - dt
if time <= 0 then
gamestate = "over"
end
end
function newGame()
init()
end
Kurosuke needs beta testers
Re: Falling Snow Collision Fail
Thank You very much
Who is online
Users browsing this forum: Google [Bot] and 7 guests