Archived

This topic is now archived and is closed to further replies.

Joppe

Desperate, help me.

Recommended Posts

Joppe    122
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...

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
chris1234    122
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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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))

Share this post


Link to post
Share on other sites