Platformer code

Monkey Forums/Monkey Code/Platformer code

therevills(Posted 2011) [#1]
Here is a cut down version of the code used here:

http://www.monkeycoder.co.nz/Apps/app.php?id=47



There is a bug with this code, where the player can fall thru the tiles... can anyone see if they can fix it? Thanks!


dopeyrulz(Posted 2011) [#2]
therevills,

Nice work - working through all the 'game styles' are you! Good to certainly prove a number of different types of games working on the platform - well done!


dopeyrulz(Posted 2011) [#3]
therevills,

I've made one change in the jumping section as shown:
		If jumping
			dy += Level.GRAVITY * dt.delta
			Local tempY# = y + (dy * dt.delta)
			If dy <> 0
				If dy > 0
					If game.level.getCollisionTile(x - image.w2 + amount, tempY + image.h2 - amountY) > 0 Or 
						game.level.getCollisionTile(x + image.w2 - amount, tempY + image.h2 -amountY) > 0 Or
						game.level.getCollisionTile(x, tempY + image.h2 - amountY) > 0 Then
						
						dy = 0
						jumping = False
                                                'CHANGE HERE
						'y = round( (tempY + image.h2) / Level.TILE_SIZE ) * Level.TILE_SIZE - image.h2
						y = Floor( (tempY + image.h2) / Level.TILE_SIZE ) * Level.TILE_SIZE - image.h2

					Else
					    y = tempY
					Endif
				Else
					If game.level.getCollisionTile(x - image.w2 + amount, tempY - image.h2 ) > 0 Or 
						game.level.getCollisionTile(x + image.w2 - amount, tempY - image.h2) > 0 Or
						game.level.getCollisionTile(x, tempY - image.h2 ) > 0 Then
						
						dy = 0
						y = round((tempY - image.h2) / Level.TILE_SIZE) * Level.TILE_SIZE + image.h2
						
					Else
						y = tempY
					Endif
				Endif
			Endif
		Endif


It appears to fix the problem. The change should enforce the location to the block. The speed of the drop appears to be the main issue as the further you drop the more likely the chance of not landing properly as you move into the next block.


therevills(Posted 2011) [#4]
all the 'game styles


You noticed then :P

Still a couple to go... Tetris, Pacman - I was going to do break out but Midimaster beat me to it ;)

I thought since Monkey is new, it would be good to do the classic styles :)

It appears to fix the problem


I was sure I tried that.. D'oh! Yeah it looks good - Thanks Matt!

The speed of the drop


Yeah it does, I missed this check in the cut-down version on purpose to try to find the issue:

Class Player
	...
	Field maxDy# = 8
	...

	If jumping
		dy += Level.GRAVITY * dt.delta
		Local tempY# = y + (dy * dt.delta)

		if dy > maxDy then 
			dy = maxDy
		endif



dopeyrulz(Posted 2011) [#5]
No worries! Glad it's working!

Yeah - you beat me to Asteroids, but I'll keep working on it - not much more to go. I started Pacman in BlitzMax a while ago waiting for Monkey, but not sure I'll get that out any time soon.


therevills(Posted 2011) [#6]
Oh no :(

http://www.blitzbasic.com/Community/posts.php?topic=94270#1081127


therevills(Posted 2011) [#7]
Decided to try a different approach with the timing, now instead of using delta timing, Im using high fixed rate logic:

Please test:




Jesse(Posted 2011) [#8]
I have tried it for a while and everything seems to be working good now. Though, it might be better to try it with the actual demo since the actual graphics and sound would create a more accurate results.


therevills(Posted 2011) [#9]
Ive uploaded a new version - still in review... also the app keeps hiding for some reason?!


simonh(Posted 2011) [#10]
I've sent you an email therevills.


therevills(Posted 2011) [#11]
No worries - Ill update the app tonight :)


dopeyrulz(Posted 2011) [#12]
Above code working nicely!


amonite(Posted 2011) [#13]
Thank you for sharing this, helps me a lot to learn monkey.


Dabz(Posted 2011) [#14]
^Top forum nickname! :)

Off topic, sorry, but... Class! :D

Dabz