Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Capt Ruby example help
- - By jeremywoertink Date 2012-07-23 18:13
I'm still trying to get used to how Gosu works, and the API. I'm using the captin ruby example (https://github.com/jlnr/gosu/blob/master/examples/CptnRuby.rb) for a little game. I'm trying to implement levels. So when you collect all the gems it kicks you into level 2 by loading a new map with a new file. The second map loads fine, with all the gems in the correct spots, but the character's collision detection is off. He walks through walls, and gets stuck in mid air areas. If I load the second level first, then everything works fine. I've even tried creating a loading screen inbetween the levels incase there was a file read issue, but I get the same result. Is there something I should be looking for in particular? Has anyone else came across this? Maybe the logic in how the Map#solid? works needs to change. The second level isn't any larger than the first level. Same width, and maybe 1 extra row.

Any direction would be awesome.

Thanks,
~Jeremy
Parent - - By Spooner Date 2012-07-23 19:35
It is hard to guess where the issue is without seeing your code. If you just create a new map using another file it should be fine, but are you sure that you don't check for collisions on the old map while displaying the new map? Remember that CptnRuby has a reference to the map which he uses for collisions, which is separate, potentially, to the map used by the Window to display. Either create a new CptnRuby on each new level or add an attr_accessor :map on him that allows you to update the value.
Parent - By jeremywoertink Date 2012-07-23 21:20
interesting. You know, I actually didn't even think about it using the collision from the first map. That might make a little more sense now. I'm in middle of formatting my machine, so I have no code on it right now :( I'll try that out, and then let you know how it goes, or post some code :)

thanks!

~Jeremy

p.s. loving this forum.
Parent - - By jeremywoertink Date 2012-07-24 03:44
ok, so here is my code. https://gist.github.com/3167856

This version is giving me the same issue, but to solve this, I have to create a @cptn = CptnRuby.new during the load_new_level, and it works fine. After a little digging, I realized the CptnRuby was setting an instance variable for the map inside of it, but that variable never got reset, so it wasn't the map's solid? giving me the issue, but the cptn's try_to_jump and would_fit that were giving me the issue.

Glad to report it's all working now! Thanks so much for the suggestions :)

~Jeremy
Parent - By Spooner Date 2012-07-24 08:41
Aye, that is what I thought it was. It is odd that it works like that; you could change cptnruby so that it kept a reference to window and called window.map every time, which would also alleviate this issue, but there isn't a lot wrong with creating a new captain every level.

Good luck with your game dev :)
Up Topic Gosu / Gosu Exchange / Capt Ruby example help

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill