Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Platformer example [using bump] — Gideros Forum

Platformer example [using bump]

rrraptorrrraptor Member
edited December 2019 in Game & application design
Just want to share a simple platformer example :smile:
Code is not very well commented, because my english is not good enough :neutral:

https://github.com/MultiPain/gideros-platformer
+1 -1 (+9 / -0 )Share on Facebook

Comments

  • Nice example.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • piepie Member
    Cool, does it use bump? I see there is bump.lua in the file list but I am on mobile right now. Bump is native since some gideros release ago :smile: I think you can remove that file and use the plugin. also, adding bump word in this topic will make it easier to find it later :smiley:

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • rrraptorrrraptor Member
    edited January 2018

    Nice example.

    Thanks.
    pie said:

    Cool, does it use bump?

    Yeah, it is.
    pie said:

    Bump is native since some gideros release ago

    Hmm...i missed that...
    pie said:

    adding bump word in this topic will make it easier to find it later

    Done o:)

    Edit: have some problems with native bump. I need custom response function for one-way platforms, and it looks like this:
    local slide, cross = bump.responses.slide, bump.responses.cross
    local oneWay = function(world, col, x, y, w, h, goalX, goalY, filter)
    	if col.normal.y < 0 and not col.overlaps then
    		col.didTouch = true
    		return slide(world, col, x, y, w, h, goalX, goalY, filter)
    	else
    		return cross(world, col, x, y, w, h, goalX, goalY, filter)
    	end
    end
     
    self.world:addResponse("oneWay", oneWay)
    But with native bump, i cant get access to cross and slide function.

    Likes: antix, pie

    +1 -1 (+2 / -0 )Share on Facebook
  • Thanks, I was thinking about to develop a platform game and I need to create some prototype first. You save me some time.
  • antixantix Member
    edited January 2018
    Nice one @rrraptor, I really like your solution to the one way platform issue :)

    Maybe @hgy29 can build this one into cBump :)

    Likes: hgy29

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    Yes, I certainly can add your custom response to native bump, One way platforms are so common with platformers that even original bump should have included it at first. i would call it platform instead of oneway though.
  • Just to say, love the way you've coded the movement. So easy. May use the good bits in my next game. :)
    My Gideros games: www.totebo.com
  • @hgy29 well, this is not my implementation) I found the solution on love2d forum. But kikito (bump dev) says:
    for moving one-way platforms, you will need a bit more (platforms will need to "push up" whatever is touching them when they are moving up)
    So the solution is a bit more complicated.
  • totebototebo Member
    edited January 2018
    I downloaded the demo from Github and tried to run it with the latest Gideros 2018.1.1. Got an error:
    ./Stuff/bump.lua:43: x must be a number, but was nil(a nil)
    stack traceback:
    	./Stuff/bump.lua:43: in function 'assertType'
    	./Stuff/bump.lua:54: in function 'assertIsRect'
    	./Stuff/bump.lua:617: in function 'add'
    	Stuff/Platformer.lua:10: in function 'init'
    	[string "property.lua"]:52: in function '__new'
    	[string "property.lua"]:46: in function '__new'
    	[string "property.lua"]:59: in function 'new'
    	Scenes/GameScene.lua:68: in function 'loadLevel'
    	Scenes/GameScene.lua:15: in function 'init'
    	[string "property.lua"]:52: in function '__new'
    	[string "property.lua"]:59: in function 'new'
    	main.lua:8: in main chunk
    I tried to require "cbump" instead of the Lua Bump, and then I get this error:
    Scenes/GameScene.lua:43: attempt to index field 'responses' (a nil value)
    stack traceback:
    	Scenes/GameScene.lua:43: in function 'setupWorld'
    	Scenes/GameScene.lua:12: in function 'init'
    	[string "property.lua"]:52: in function '__new'
    	[string "property.lua"]:59: in function 'new'
    	main.lua:8: in main chunk
    Would be great to get it working out of the box, to show people new to Gideros.
    My Gideros games: www.totebo.com
  • rrraptorrrraptor Member
    edited January 2018
    @totebo i fixed that already )) Order matters...
    See the commit
    https://github.com/MultiPain/gideros-platformer/commit/bf41948f59196a8f5790614cbeb4d0342cee2511
    or screenshot:


    It doesn't work with native bump, for some reason. I removed custom response function, fixed "Item ray must be added to the world before getting its rect" error, and now player just crushing...
    1.png
    720 x 108 - 11K
    1.png 11.4K
  • totebototebo Member
    edited January 2018
    Ok cool, halfway there! I also got that "item needs to be added" with Bump in my own game. Maybe it's a bug in the Gideros c version of Bump?
    My Gideros games: www.totebo.com
  • @rrraptor The reason I wanted to download the demo was to see if jump height can be controlled. As in, the longer you hold jump the higher you jump.
    My Gideros games: www.totebo.com
  • totebo said:

    jMaybe it's a bug in the Gideros c version of Bump?

    Yeah, in my case world:project(...) works in lua version without adding item to the world, but cbump requiring to do so.
    totebo said:

    jump height can be controlled

    Nope, it doesnt.

    Btw, this example will not work with native verion, becouse of custom response function.

    Likes: totebo

    +1 -1 (+1 / -0 )Share on Facebook
  • hgy29hgy29 Maintainer
    rrraptor said:


    So the solution is a bit more complicated.

    Sure, I used a custom filter instead for Arthur and additional game logic for moving platforms. But collision response would be a start anyway.
  • I didn't use any custom response for one way platforms, I just processed it in the collision filter.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited November 1
    rrraptor said:

    totebo said:

    jMaybe it's a bug in the Gideros c version of Bump?

    Yeah, in my case world:project(...) works in lua version without adding item to the world, but cbump requiring to do so.
    Btw, this example will not work with native verion, because of custom response function.
    I think I would need this "custom response function" ability :p I implemented moving platforms, that works great on horizontal moving platforms but not if they move vertically :s
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLux said:

    I think I would need this "custom response function" ability :p I implemented moving platforms, that works great on horizontal moving platforms but not if they move vertically :s

    Technically it is possible (using luaL_ref/luaL_unref), but requires alot of changes.
  • MoKaLuxMoKaLux Member
    edited November 2
    (at) rrraptor bump.lua you are using (which I have included in my test platformer) and gideros cbump are not behaving the same at all :s
    I have two sample cases:
    - bump.lua, when I am on a vertical moving platform I can jump when the platform is either going up or down which is super cool :)
    - gideros cbump, when I am on a vertical moving platform I can only jump when the platform is going down :/

    - bump.lua collisionfilter doesn't work as expected, that is the last elseif statement is always executed even if it doesn't collide at all :o
    - gideros cbump collisionfilter works as expected :)

    It is a shame because I would need a mix of bump.lua and cbump :p
    I am investigating and trying to find where guderos cbump and bump.lua differ. I will also try to make a sample project to show exactly what I mean.

    Here is my collisionfilter function (pass through platforms work out of the box without custom collisions)
    self.collisionfilter = function(item, other)
    	-- "touch", "cross", "slide", "bounce"
    	if item.isplayer1 then
    		if other.isnme then return "bounce" -- NOT TESTED
    		elseif other.isground then return "slide" -- TESTS OK
    		elseif other.isladder then return "cross" -- TESTS OK
    		elseif other.isptpf then -- TESTS OK
    			if item.isdown then return "cross" end -- go down on key down pressed
    			if item.body.vy > 0 then -- going down
    				local itembottom = item.y + item.h
    				local otherbottom = other.y + 8 -- treshold magik XXX +2
    				if itembottom <= otherbottom then return "slide" end
    			end
    		elseif other.ismvpf then  -- TEST OK WITH BUMP.LUA
    			if item.body.vy > 0 then -- going down
    				local itembottom = item.y + item.h
    				local otherbottom = other.y + 8 -- treshold magik XXX
    				if itembottom <= otherbottom then return "slide" end
    			else
    				return "cross"
    			end
    		elseif other.isspring then -- TESTS OK WITH GIDEROS CBUMP
    			if item.body.vy >= 0 then -- going down
    				print("xxx", item.body.vy) -- IN BUMP.LUA THIS CODE IS ALWAYS EXECUTED!!!
    				return "bounce"
    			end
    		end
    	end
    end
    PEACE
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    edited November 2
    I thought I found it :# !
    bump.lua
    function World:check(item, goalX, goalY, filter)
    	filter = filter or defaultFilter
     
    	local visited = {[item] = true}
    --	local visitedFilter = function(itm, other) -- TYPO itm?
    	local visitedFilter = function(item, other)
    		if visited[other] then return false end
    --		return filter(itm, other) -- TYPO itm?
    		return filter(item, other)
    	end
    ...
    end
    but no :* to be continued :D
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • cbump Gideros is not the same as bump.lua :| I don't know how to fix :( but with Gideros there is always a way :p
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.