1) The player isn't moving correctly on the Y axis
2) The player isn't colliding properly
I have a few questions as well, but I'll address them later on.
I've been trying for about a day to get this problem fixed, but fixed a different problem whist doing so! Now I'm down to 2 issues! Here are my problems in more detail:
Problem 1
-------------
I'll be playing my game, and I'll hit a wall. The player goes about half way into the wall, then his X get's reset. This keeps happening, but he clips into the wall. What am I doing wrong?
Problem 2
------------
The character moves fine along the X axis, but when I try to move him down he does REALLY SLOW. How can I fix this?
I've put almost 2 weeks of effort into this, and have had so many issues with it. But thanks to the people on this forum helping me(and a thread ages ago encouraging me(it was the jumping thread)), I haven't lost faith and have had the motivation to march on!
Now, I have some other questions:
If you've ever looked into the code of Mr. BallGuy, you'll know that I had lots of different ball classes and a few different coin classes. I think I would know how to prevent it, but I'm not sure if it would work and there might be a better way of doing it. What I was thinking of doing was having the Lua class system with metatables and having the path to the coin image as an argument to the constructor. That way, I can make new instances of the coin class and have it use different coin images. I could probably also setup a for loop to generate different ball objects, since the ball image would have been the same. This is a question that I was going to ask when I started my other project as it won't be used in this one.
This game that I will have attached is going to have different level packs. Each level pack is going to introduce a new concept. Say I wanted to add a new object that if you walk over you die, would I just have to check the tiles the same way I did for the wall? Here's the code for it:
Code: Select all
function player:isColliding(map, x, y)
local layer = map.tl["Collision"]
local tileX, tileY = math.floor(object.x / map.tileWidth), math.floor(object.y / map.tileHeight)
local wall = layer.tileData(tileX, tileY)
return not(wall == nil)
local deadlyObj = map.tl["deadlyObj"]
local doX, doY = math.floor(object.x / map.tileWidth), math.floor(object.y / map.tileHeight)
local deadlyObj = layer.tileData(tileX, tileY)
return not(deadlyObj == nil)
end
Finally, I didn't know how to use the Tiled map editor and ATL together in LÖVE, so I watched Goatures tutorials on it. He did the following piece of code, but he didn't explain it. Maybe someone could explain it? I kind of half understand it, but I'd like someone to assure me
code:
Code: Select all
function player:update(dt)
local halfX = object.w / 2
local halfY = object.h / 2
object.x_vel = math.clamp(object.x_vel, -object.speed, object.speed)
object.y_vel = math.clamp(object.y_vel, -object.flySpeed, object.flySpeed)
local nextY = object.y + (object.y_vel*dt)
if object.y_vel < 0 then
if not (object:isColliding(lvl1, object.x - halfX, nextY - halfY))
and not (object:isColliding(lvl1, object.x + halfX - 1, nextY - halfY)) then
object.y = nextY
else
object.y = nextY + lvl1.tileHeight - ((nextY - halfY) % lvl1.tileHeight)
--object:collide("collideX")
end
end
if object.y_vel > 0 then
if not (object:isColliding(lvl1, object.x-halfX, nextY + halfY))
and not(object:isColliding(lvl1, object.x + halfX - 1, nextY + halfY)) then
object.y = nextY
else
object.y = nextY - ((nextY + halfY) % lvl1.tileHeight)
--object:collide("collideY")
end
end
local nextX = object.x + (object.x_vel * dt)
if object.x_vel > 0 then
if not(object:isColliding(lvl1, nextX + halfX, object.y - halfY))
and not(object:isColliding(lvl1, nextX + halfX, object.y + halfY - 1)) then
object.x = nextX
else
object.x = nextX - ((nextX + halfX) % lvl1.tileWidth)
end
elseif object.x_vel < 0 then
if not(object:isColliding(lvl1, nextX - halfX, object.y - halfY)) and not(object:isColliding(lvl1, nextX - halfX, object.y + halfY - 1)) then
object.x = nextX
else
object.x = nextX + lvl1.tileWidth - ((nextX - halfX) % lvl1.tileWidth)
end
end
object.state = object:getState()
end
-- The object is the player metatable, so in theroy it is the ACTUAL player!
After spending about 3 months or so with LÖVE, I feel like I'm not learning as much as I should have. People have said that Mr. BallGuy was a good first project, but I've seen some other peoples first projects and they're incredible! I know for a fact some have only spent a week with LÖVE. But I don't know. I'm learning and that's why I'm making games: So I have something to do, because I can't find a good game I enjoy, to learn and the odd time show off to some people in my class. I remember showing some people in my class my game and they didn't believe me when I told them I made it
So yeah, any help is appreciated! Thanks!
Game: https://www.dropbox.com/s/06j0eh4mnwonbb7/NOM.love
P.S. This is a version that I've released for HELP. This isn't what the game is going to look like, there will be changes as I'm sure you've guessed. I've gotten so frustrated with this game at times, but I will finish it. I expect it to take me until the end of the summer to get a working copy of it out(with a level pack, some better looking maps and a more creative background). If you think the game is a bad idea I don't mind because it isn't a release, you don't know the concept and it's really only for me to learn(that's what MBG was, a learning experience!).
EDIT: After writing this I noticed that sometimes there's a weird no-cliping issue that traps you in the wall. Maybe some help with that too please?