Implementing a matrix into my game

Monkey Forums/Monkey Beginners/Implementing a matrix into my game

elite_dtn(Posted 2017) [#1]
I'm creating a platform game which uses tiles and a txt file to create my map with, i was just wondering what is the easiest way of having a camera following my player and only displaying a small bit of my map. How would it move the tiles and load the next bit of my level? I'm new to monkey-x so any help would be greatly received:)


Gerry Quinn(Posted 2017) [#2]
Usually for platform games we don't think in terms of matrices. If your tiles are a 2D array, and the player is at (px,py), and your screen is 11 x 11 tiles, you might draw something like:



Here xCentre and yCentre are screen coordinates of the centre of your viewing area, and wTile and hTile are the width and height of a tile.

This would draw an 11 x 11 block of tiles centred on the player.

Later on you might want to tweak this, with smooth scrolling, and perhaps showing more of the level in the direction the player is currently pointing.


elite_dtn(Posted 2017) [#3]
Thank you for the help!, okay that makes sense. Would this go in my on render method of my main game class or in my level class?


Gerry Quinn(Posted 2017) [#4]
The rendering method of the app ultimately calls everything that gets drawn. That applies whether it's drawing everything in detail, or just calling gameWindow.Render() which in turn draws things in detail, or itself calls rendering methods of other classes (sprites, animated score values, maps, whatever). It all depends on how you want to organise things, which depends on personal preferences and the size of your project.

Obviously things can draw only what they have access to, and you will want to have a happy medium between keeping things nicely encapsulated, and getting at information easily Practice is the only way to lear this. Always start with small, simple projects, then when you move on to bigger projects, think about the simpler ones and how they could have been structured to make programming easier.


elite_dtn(Posted 2017) [#5]
Was thrown in at the deep end because its a school project, game will ideally have 10 levels with menu systems and player movements, enemies and power-ups - it is a 2d platform game but due to very limited programming knowledge i am struggling with even the easier parts.


Gerry Quinn(Posted 2017) [#6]
Well, in the simplest terms, it's down to whether you prefer dealing with multiple small classes, or with loads of methods and fields in one class. The computer doesn't really care!

By the way, does your game have to scroll? That adds a fair amount of complexity, but the classic platform games often had everything on one screen, meaning no need to scroll at all!


elite_dtn(Posted 2017) [#7]
I have smaller classes with my big main game class, i would prefer it to scroll but understand it is a complicated feature. I'm basing it upon new super mario bros in terms of features and look and feel.


Gerry Quinn(Posted 2017) [#8]
I usually have a Game class and a separate GameWindow class that does all the drawing. But you might find that to be overkill.

As for scrolling, it is easy enough in itself when you know how, but you have to add certain tweaks to make it look good and smooth, and they are the greater cause of complications...


elite_dtn(Posted 2017) [#9]
How in your example would DrawTile know which tile to draw, i have around 7.This is my current method for drawing the tiles

                 Method draw()
				Local tile:String
				For Local y:Int = 0 To 14
				For Local x:Int = 0 To 49
					tile = tiles[x][y]
					If tile = BrownTile Then DrawImage tileset, x*32, y*32, BrownTile
					If tile = SlopeDown Then DrawImage tileset, x*32, y*32, SlopeDown
					If tile = SlopeUp Then DrawImage tileset, x*32, y*32, SlopeUp
					If tile = BPlatform Then DrawImage tileset, x*32, y*32, BPlatform
					If tile = Sky Then DrawImage tileset, x*32, y*32, Sky
					If tile = FPlatform Then DrawImage tileset, x*32, y*32, FPlatform
					If tile = Lava Then DrawImage tileset, x*32, y*32, Lava
				Next
				Next
			End 



Gerry Quinn(Posted 2017) [#10]
That's what the GetTile( x:Int, y:Int ) method or function is supposed to be telling it. Of course accessing the array directly is fine if you prefer it that way.


elite_dtn(Posted 2017) [#11]
Sorry i'm not sure i understand.


Gerry Quinn(Posted 2017) [#12]
Method GetTile:Int( x:Int, y:Int )
Return tiles[ x ][ y ]
End


Obviously you don't need it if tiles is simply an array of ints in the same class like above, but that might not always be the case.


elite_dtn(Posted 2017) [#13]
I've decided to put on hold having the camera system follow the character until later on in development. I am having difficulties finding the easiest way for my player to jump, i have movement left and right working but i'm finding it hard to find the code to make the player jump.


Gerry Quinn(Posted 2017) [#14]
If you google, you'll usually be able find tips for doing this kind of thing. The language may be different but the methods are the same regardless of language.


elite_dtn(Posted 2017) [#15]
Couldn't find anything, or didn't really understand the code. I have moving left and right working but still stuck on how to get the character jumping. Especially how the graphical side will work with powerups.


Gerry Quinn(Posted 2017) [#16]
Don't mix up the graphical size with the 'physics' side (by saying physics, I'm not implying that your game objects and characters have to care about Newton's laws). The physics understands what's going on, the graphics just draws it.

For example, what happens when you jump? Your character moves up, slows down, and then falls until he hits a platform below him. Depending on the game, he might be able to change direction or even jump again while in mid-air - or he might not. Usually he can go through platforms when moving up.

Try googling stuff like "platform game code examples" etc.

Platform games are relatively difficult for a starting project Tetris has some aspects in common (Tetris pieces don't jump, but they fall and land, and change direction mid-flight) and might be a starting point for consideration.