Hi all!
I'm brand new to Lua, Love2D, and bump, and have what may be a very dumb question.
I followed
this tutorial (the parts that are posted anyway), and everything was going smoothly, but then I went off and tried to build on what I'd learned, and now I'm running into a stumbling block.
Basically I've got a little cube dude that you can move around a couple platforms and jump. That's it. This worked great for platforms (ground), but as soon as I tried to make walls, it didn't work right anymore. Basically when you sidle up against a wall and then try to jump, the player just sort of jitters up and down.
Here's the code for the Ground class (using hump for that):
Code: Select all
local Class = require 'libs.hump.class'
local Entity = require 'entities.Entity'
local Ground = Class{
__includes = Entity -- Ground class inherits our Entity class
}
function Ground:init(world, x, y, w, h)
Entity.init(self, world, x, y, w, h)
self.world:add(self, self:getRect())
self.isGround = true
end
function Ground:draw()
love.graphics.rectangle('fill', self:getRect())
end
return Ground
Here's the code for the stage, where it creates a bunch of grounds (and a player) and adds them to the world:
Code: Select all
function gameLevel1:enter()
-- Game Levels do need collisions.
world = bump.newWorld(16) -- Create a world for bump to function in.
-- Initialize our Entity System
Entities:enter()
player = Player(world, 100, 50)
ground_0 = Ground(world, 200, love.graphics.getHeight()-250, 640, 50)
ground_1 = Ground(world, 0, love.graphics.getHeight()-50, love.graphics.getWidth(), 50)
ground_2 = Ground(world, 400, 150, 640, 50)
wall_0 = Ground(world, 0,0,50,love.graphics.getHeight())
wall_1 = Ground(world, love.graphics.getWidth()-50 ,0,50,love.graphics.getHeight())
-- Add instances of our entities to the Entity List
Entities:addMany({player, ground_0, ground_1, wall_0, ground_2, wall_1})
-- Camera?
-- camera = Camera(player)
end
and here's the code for jumping, and checking for collisions, which is in the update function of my player:
Code: Select all
if love.keyboard.isDown("up", "w") then
if -self.yVelocity < self.jumpMaxSpeed and not self.hasReachedMax then
self.yVelocity = self.yVelocity - self.jumpAcc * dt
elseif math.abs(self.yVelocity) > self.jumpMaxSpeed then
self.hasReachedMax = true
end
self.isGrounded = false -- we are no longer in contact with the ground
end
-- these store the location the player should arrive at
local goalX = self.x + self.xVelocity
local goalY = self.y + self.yVelocity
-- Move the player while testing for collisions
self.x, self.y, collisions, len = self.world:move(self, goalX, goalY)
and then this is in the player's draw:
Code: Select all
function player:draw()
love.graphics.draw(self.img, self.x, self.y)
self.rc:draw(self.x, self.y)
end
I can provide any more information you need, and am excited to dig in and sort this out! Thanks!