Going down the wrong path?

Started by
2 comments, last by Torch306 21 years, 4 months ago
Hey there everybody. I just finished making my first attempt at a tetris-clone. It runs really slow and needs lots of improvement, but that''ll be next week, after finals are over. My question is that i''ve found my way of thinking to be kinda stuck and I''m afraid i''m going down the wrong path. I made a matrix for the board and would have 1''s instead of 0''s for the blocks. My problem is I can only picture making a game with a matrix, am I way off? This includes sidescrollers, breakout, old RPG''s(Fantasy Star). Can someone set me straight if I''m heading for disaster? Thanks a lot!
Advertisement
Well... Tetris makes sense to have a 2d-array ("matrix") to store previously-played pieces.

In fact, 2d arrays are really nice when dealing with all sorts of things (SNES games like Super Metroid work the best using 2d arrays for collision detection and graphic tiling).

I mean... you *could* have made tetris without a matrix by making your pieces be instances of "Piece" class with a specific polygon shape (L-shaped, Right-S, etc), then drop them down the screen until collision detection determines that two shapes overlap... but that''s too much of a headache.


So, using arrays to store the "map" of games isn''t a "bad" thing... unless there is a better way to do it.
The main thing is when you need to display or modify or do whatever to the matrix

for(int x; x <= xvalue ; x++) {
for( int y; y <= yvalue; y++) {
// do whatever to matrix[xvalue][yvalue]
} // end for
} // end for

When the matrix gets really big (say for metroid) that slows things down quite a bit. What''s the best way of dealing with this?
You would have to allow random access rather than sequential. That way instead of iterating through the entire matrix, you would only access a single variable. Sorry I can''t be more specific or give an example. I can''t think of one that wouldn''t be specific to something.
-------------------------GBGames' Blog: An Indie Game Developer's Somewhat Interesting ThoughtsStaff Reviewer for Game Tunnel

This topic is closed to new replies.

Advertisement