Love Platformer

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Love Platformer

Post by ddabrahim »

Hi.

I just would like to showcase what I’ve been working on in the past few weeks.
It is nothing out of ordinary, not even a game really, just a very basic platformer engine at this point.

This is how it currently looks (gif):
LovePlatformer.gif
LovePlatformer.gif (6.53 MiB) Viewed 10450 times

Basically what you see is 8 type of content:

  • Single Sprite
    Tiled Sprite
    Animated Sprite
    Platformer Player
    Platformer Solid
    Platformer Platform
    Platformer Ladder
    Platformer Movable


The Player character is animated and can:
  • Walk
    Jump
    Push obstacles
    Pull obstacles
    Grab the edge of platforms
    Climb ladders
    Jump off ladders
    Collide
Movable obstacles can:
  • Fall to the ground
    Stack on top of each other
    Move/Slide on the ground and also on top of each other
    Movement can be disabled so the player can not move it.
    Collide
Platforms can:
  • Move and carry the player character with them
    Movement can be disabled.
    Player can jump through but can be disabled.
    Player can grab the edge but can be disabled.
    Can also behave like a solid with everything disabled.
Of course it does not look much, but I am really happy about it because this is the very first time ever I have coded everything from scratch. I did not used any 3rd party libraries for physics, collision, animations or platformer parts, I coded everything from scratch and to be honest I am surprised it works :D

It is also pretty easy to code, I have implemented methods and properties so it is easy to work with.
To get an idea, the high level code for what you see is looks like this:

Code: Select all

local AnimatedSprite = require 'AnimatedSprite'
local Sprite = require 'Sprite'
local TiledSprite = require 'TiledSprite'
local Platformer = require 'Platformer'

local ground
local player
local pfe
local ladder
local platform

function love.load(arg)  

  ground = TiledSprite:new('Images/grassMid.png',20,1)
  ground:setPosition(0,700)

  player = AnimatedSprite:new()
  player:addFrameToAnimation('stand', 'Images/Player/p1_stand.png')
  player:addFrameToAnimation('jump', 'Images/Player/p1_jump.png')
  player:addFrameToAnimation('fall', 'Images/Player/p1_jump.png')
  for i = 1, 11, 1 do
    player:addFrameToAnimation('walkR', 'Images/Player/walk/p1_walk'..i..'.png')
  end
  for i = 11, 1, -1 do
    player:addFrameToAnimation('walkL', 'Images/Player/walk/p1_walk'..i..'.png')
  end
  player:setPosition(200,500)
  player:setScale(0.8,0.8)
  
  ladder = TiledSprite:new('Images/ladder_mid.png',1,4)
  ladder:setPosition(600,420)
  
  platform = TiledSprite:new('Images/bridge.png',2,1)
  platform:setPosition(700,550)

  pfe = Platformer:new()
  pfe:setPlayer(player)
  pfe:setSolid(ground)
  pfe:setMovable(createBox(600,630))
  pfe:setMovable(createBox(400,630))
  pfe:setMovable(createBox(250,500))
  pfe:setLadder(ladder)
  pfe:setPlatform(platform)
  
  platform.canJumpThrough = true
  
end


function love.update(dt)
   
  pfe:update(dt)

  if player.isMoveRight and player.isJump == false and player.isFall == false then
    player:setAnimationByName('walkR')
  end
  if player.isMoveLeft and player.isJump == false and player.isFall == false then
    player:setAnimationByName('walkL')
  end
  if player.isJump and player.isMove == false then player:setAnimationByName('jump') end
  if player.isMove == false and player.isJump == false and player:getAnimationName() ~= 'stand' then player:setAnimationByName('stand') end
  if player.isFall and player:getAnimationName() ~= 'fall' then player:setAnimationByName('fall') end
  player:updateAnimation(dt)
    
  if love.keyboard.isDown('i') then platform:moveUp(dt) end
  if love.keyboard.isDown('k') then platform:moveDown(dt) end
  if love.keyboard.isDown('j') then platform:moveLeft(dt) end
  if love.keyboard.isDown('l') then platform:moveRight(dt) end
  if love.keyboard.isDown('p') then platform.isPaused = true end
  if love.keyboard.isDown('g') then platform.isPaused = false end
    
end

function love.draw()
  
  pfe:draw()

end

function createBox(_x, _y)
  local box = Sprite:new('Images/box.png')
  box:setPosition(_x,_y)
  box:setScale(1,1)
  
  return box
end
I guess it is pretty short and easy to understand, most of the things handled by the Platformer Engine in the background and I have exposed many of the properties so you can manipulate any aspect of it.

I don’t know at the moment what direction to go with this. I am kind of stuck. I don’t actually have any idea for a game. I have done this only to get my feet wet with LÖVE and wanted to try something I have never done before and code as much on my own as I can without using any 3rd party lib.
Guess I could add some enemies, weapons, tons of other features but I am lack inspiration at the moment.

I am also considering to release this as some sort of open-source “Platformer Framework” but I'm not so sure if it would be any useful to anyone, after all the entire point of frameworks like LÖVE is to do it your own.

So any feedback and idea what to do with this would be appretiated :)

Thanks.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Love Platformer

Post by Gunroar:Cannon() »

Looks pretty neat. Nice work doing it without any other libs (not even box2d? :huh:) You could add enemy ai(smart or basic) and decide what game it would be if you want to expand it. Open world metroid style or linear super mario bros. style.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: Love Platformer

Post by pgimeno »

I wouldn't call box2d a third party lib, given that it's integrated in Löve. Otherwise calling e.g. love.image.newImageData could also be considered calling a third party lib.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: Love Platformer

Post by Gunroar:Cannon() »

Ha! That's what I thought. I was like "doesn't that mean drawing in love2d is also third party?". Though still wonder if it was used for collisions.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Love Platformer

Post by ddabrahim »

Thanks for the comments guys.

Indeed Love2D and everything built-in can be considered 3rd party. What I meant was, I did not used any libs that offer TiledSprites, AnimatedSprite, collision detection, movement or any platformer mechanics and I don't plan using any. I did not used Box2D or love.physics and love.math for this or any other libs for collision detection but love.graphics, love.image, love.window and love.keyboard to manage the game window, keyboard input and draw staff on the screen. Everything else is coded in Lua by me. I don't plan using any libraries for any gameplay mechanics.

Of course people probably think so what is the point lot of people do more complicated things than this. For me it was just an attempt to learn new things, fill gaps in my knowledge and showcase to the community where I am right now with LOVE and maybe get some ideas where to go from here.
You could add enemy ai(smart or basic) and decide what game it would be if you want to expand it.
Yes I was considering to add enemies that move left-right, move in a path and damage the player on collision, then also enemies that shoot "something" at the player or in a set of direction and many other things too.
But I am not too sure what direction to go with this really.

There is two paths that I find interesting, one is a more minimalistic vertical scroller like IcyTower and the other path is a more advanced open-world game like Starbound and Terraria with procedural generation because it is something I have never done before and it would offer some interesting challenges.

For now, before anything I would like to implement scene management, camera and some basic UI items like button, check boxed, sliders first and make sure performance is good and things are optimised on a large level and then I can consider what direction to go with this.

Thank you all.
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Love Platformer

Post by ddabrahim »

Hi all!

Just would like to post an update.
I haven't done a lot visually, mostly bug fixes and improvements but I managed to implement a basic camera that also support parallax scrolling that I can show you.

This is how it looks.
platformer.gif
platformer.gif (10.17 MiB) Viewed 5074 times
The most challenging part was to make sure collision continue to work with things drawn from a different translation than the player and to work with canvases / tiled sprites. But I got it working.
Like before, I did not used any 3rd party Camera library, I did implement the camera myself and I think I did find an intuitive way to use it.

To create a camera, all I have to do is

Code: Select all

local Camera = require "Camera2D"

cam1 = Camera:new()
cam2 = Camera:new()
and then in order to draw objects from the perspective of the camera all I have to do is pass the camera to the draw methods of the platformer objects

Code: Select all

background:draw(cam2)
platform:draw(cam1)
player:draw(cam1)
...etc
Also include methods to work with love's draw methods, for example

Code: Select all

cam1:start()
  love.graphics.draw....etc
cam1:stop()
To create the parallax effect and follow the player, I can update the position of each camera in love.update

Code: Select all

cam1:setPositionX(player:getPositionX())
cam1:setPositionY(player:getPositionY())
cam2:setPositionX(cam2:getPositionX() + player.speedX * dt)
cam2:setPositionY(cam2:getPositionY() + player.speedY * dt)
Also able to detect what is outside a camera and the platformer engine does take it in to account and does not check collision with things and don't draw them if outside.

What is missing and I would like to implement it at some point is Shake, Zoom and Rotation. But at the moment I am scared to think about how am I going to handle collision when things are rotated :D
It works for a traditional platformer game I guess and I try to appreciate that before I continue to punish myself :)
User avatar
ddabrahim
Party member
Posts: 182
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Love Platformer

Post by ddabrahim »

Hi all!

Just would like to post an update on this little platformer project.
I haven't done a lot in terms of new features and gameplay. One of the most significant progress I made is the ability to render 3D objects within 2D space.

This is what the result looks like:
3d-platformer.gif
3d-platformer.gif (22.1 MiB) Viewed 3229 times
I've been using groverburger's G3D library for this.
https://github.com/groverburger/g3d

I have implemented some custom methods to translate 3D coordinates in to 2D and make it easier to work with it in a 2D environment and to work with my camera system such as:

Code: Select all

.draw(camera) --so I can pass my camera to it similar to 2D objects
.setLocalPosition(x,y,z) --so I can change position of the object within the 3D space
.setGlobalPosition(x,y,z) --so I can change position of the object within the 2D space
.setLocalRotation(x,y,z) --so I can change rotation within 3D space
.setGlobalRotation(x,y,z) --so I can change rotation within the 2D space
One of the biggest advantages of this is that my brain does not have to melt when for example I set a 3d object to be at the same position as a 2D sprite and just works with my camera system so I can generate the above parallax scrolling effect easily.

Rendering 3D object in 2D is something I wanted to do for a very long time but every single engine lack this feature for some reason and most 2D frameworks I tried was way too complex to attempt to add any 3D functionality.
So I am extremely happy about this achievement. I could not have done it without the simplicity of LŐVE and G3D. Love this framework each day more and more and I am really grateful for all the awesome libraries this community has shared.

One thing I would like to implement next is a collider so I can also check collision between 3D and 2D objects. Not too sure at the moment how to go about creating a collider because no idea how to figure out the size of the 3D object from 2D perspective since the size also depends on the zoom, scale and local position of the object. One thing I am considering to do is just create 2D colliders manually and set their position to be the same as the 3D objects with some trial and error but then when I change the position of a 3D object, I also need to make sure to change the position of the collider. I need to think of a practical way to do this.

And then of course I also would like to add some enemies, projectile and melee weapons, collectables.
User avatar
Hugues Ross
Citizen
Posts: 85
Joined: Fri Oct 22, 2021 9:18 pm
Location: Quebec
Contact:

Re: Love Platformer

Post by Hugues Ross »

That's a pretty neat effect! I'll have to keep an eye on how this progresses.
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: Love Platformer

Post by ReFreezed »

Yeah, I like that mix of 2D and 3D.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
togFox
Party member
Posts: 764
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Love Platformer

Post by togFox »

well done. Very unique!
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: dusoft and 15 guests