Desperate, help me.

Started by
3 comments, last by Joppe 22 years, 4 months ago
Could someone give me some source code or examples of array functions for a tetris game in C++? I can´t get the collisions to work... I can´t get the pieces to stop where I want them to. They just slide right thru the other ones. Please help me...
Got gum?
Advertisement
Well can''t give you my code as I don''t use the usual 4x4 array for a shape...but I this should work:

int Field[20][10];
int shape[4][4];
int row, column;
int curRow, curCol;

Field contains is your playing field in which all the previous shapes that stopped falling will be copied, shape contains the current shape that is falling down.
row and column are just two variable and curRow and curCol tell you the current row and column of you shapes location.
so every turn or once every so many turns curRow is increased by 1 so that the shape falls down...so the you check if it hit an other shape in your field:

for(row = 0; row < 4; row++)
for(column = 0; column < 4; column++)
if(shape[row][column] != 0)
if(Field[row + curRow + 1][curCol + column)] != 0)
// We have hit something so stop moving.

now obviously this isn''t optimized at all and we still don''t check if the shape hit the bottom (row 19) of the Field. but that shouldn''t be to hard to implement.
I hope this helps u (a little)...

Chris

Thanks Chris.

Keep the answers coming.
Got gum?
Got your collision detection working already joppe?
or still not clear to you?

Chris

if you want to get in touch of me try:

Christiaanprins@hotmail.com
or icq (40328570)
Check this out
www.c-coding.net
There on the downloads section you will find a Tetris like game me and a friend have written. Its full source code is free so you can find...i think everything you need about a tetris game))

This topic is closed to new replies.

Advertisement