Jump to content

C - a character moving in a matrix


Recommended Posts

Hi guys, could someone help me make ca caracter move in a matrix.

Code: 

 

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>


#define MAX_X 60
#define MAX_Y 20


using namespace std;
char base[MAX_Y][MAX_X]; // Base


// Prototypes




void init();
void display();
char player = 189;


void init()
{
int y, x;


/*           Base              */
for (y = 0; y < MAX_Y; y++) {
for (x = 0; x < MAX_X; x++) {
base[y][x] = ' ';
}
}
/* --------------------------- */


/*           Frame            */
for (y = 1; y < MAX_Y - 1; y++) {
base[y][0] = 186;
base[y][MAX_X - 1] = 186;
}


for (x = 1; x < MAX_X - 1; x++) {
base[0][x] = 205;
base[MAX_Y - 1][x] = 205;
}


base[0][0] = 201;
base[0][MAX_X - 1] = 187;
base[MAX_Y - 1][0] = 200;
base[MAX_Y - 1][MAX_X - 1] = 188;
/* --------------------------- */


base[18][30] = player;
}


void display()
{


int y, x;


for (y = 0; y < MAX_Y; y++) {
printf("t");
for (x = 0; x < MAX_X; x++) {
printf("%c", base[y][x]);
}
printf("n");
}


}






void main()
{ 
init();
display();
getch();


}

I want to point out that I'm a beginer so don't be hard on me :)

 

After that could someone explaine how double buffering works? :)

 

 

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.