Skip to content
Snippets Groups Projects
Commit b3ddda47 authored by Taha Belkhiri's avatar Taha Belkhiri
Browse files

ajout MAPSIZE variable

parent ff3ea329
No related branches found
No related tags found
No related merge requests found
0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0
0 0 0 1 0 0 1 0 0 0 0 1 1 1 0 0 0 0 0 0
0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 1 0 1 0
0 0 0 0 0
0 0 0 0 0
File added
......@@ -10,15 +10,24 @@ void gestMenu(){
running = 0;
break;
case SDL_KEYUP:
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_x:
running = 0;
continue;
case SDLK_UP:
MAPSIZE++;
continue;
case SDLK_DOWN:
MAPSIZE--;
continue;
default:
game_state = GAME;
initMap();
continue;
}
break;
......@@ -51,7 +60,7 @@ void gestGame(){
continue;
case SDLK_s:
writeMap(map, "map.txt");
writeMap("map.txt");
printf("Saved map to map.txt\n");
default:
......
......@@ -7,7 +7,6 @@ int game_state;
int main(){
running = 1;
game_state = MENU;
initMap(map);
MainLoop();
......
#include "map.h"
int MAPSIZE = 20;
int map[MAPSIZE][MAPSIZE];
int ** map;
void allocateMap(){
map = malloc(MAPSIZE * sizeof(int*));
for(int i = 0; i < MAPSIZE; i++){
map[i] = malloc(MAPSIZE * sizeof(int));
}
}
void initMap(int map[MAPSIZE][MAPSIZE]) {
void initMap() {
allocateMap();
for(int i = 0; i < MAPSIZE; i++){
for(int j = 0; j < MAPSIZE; j++){
map[i][j] = 0;
......@@ -13,7 +22,7 @@ void initMap(int map[MAPSIZE][MAPSIZE]) {
}
void printMap(int map[MAPSIZE][MAPSIZE]){
void printMap(){
for(int i = 0; i < MAPSIZE; i++){
for(int j = 0; j < MAPSIZE; j++){
printf("%d ", map[i][j]);
......@@ -23,7 +32,7 @@ void printMap(int map[MAPSIZE][MAPSIZE]){
}
void writeMap(int map[MAPSIZE][MAPSIZE], char* filename){
void writeMap(char* filename){
FILE* f = fopen(filename, "w");
for(int i = 0; i < MAPSIZE; i++){
for(int j = 0; j < MAPSIZE; j++){
......
......@@ -3,11 +3,11 @@
#include "main.h"
#define MAPSIZE 20
extern int map[MAPSIZE][MAPSIZE];
extern int MAPSIZE;
extern int ** map;
void printMap(int map[MAPSIZE][MAPSIZE]);
void initMap(int map[MAPSIZE][MAPSIZE]);
void writeMap(int map[MAPSIZE][MAPSIZE], char* filename);
void printMap();
void initMap();
void writeMap(char* filename);
#endif
\ No newline at end of file
......@@ -18,6 +18,7 @@ SDL_Surface * columnSurface = NULL;
SDL_Texture * backgroundTexture = NULL;
SDL_Surface * backgroundSurface = NULL;
void CreateWindow(){
if (SDL_Init(SDL_INIT_VIDEO) != 0){
......@@ -78,16 +79,31 @@ void drawPlayButton(){
SDL_RenderCopy(renderer, playButtonTexture, NULL, &playButtonRect);
}
void drawMAPSIZE(){
char str[10];
sprintf(str, "%d", MAPSIZE);
SDL_Color textColor = {0, 0, 0};
SDL_Surface * surface = TTF_RenderText_Solid(RobotoFont, str, textColor);
SDL_Texture * texture = SDL_CreateTextureFromSurface(renderer, surface);
int titleWidth, titleHeight;
SDL_QueryTexture(texture, NULL, NULL, &titleWidth, &titleHeight);
SDL_Rect titleRect = {ScreenDimension.w/2 - titleWidth/2, ScreenDimension.h/1.2 - titleHeight, titleWidth, titleHeight};
SDL_RenderCopy(renderer, texture, NULL, &titleRect);
}
void drawMenu(){
SDL_RenderClear(renderer);
drawBackground();
drawTitle();
drawPlayButton();
drawMAPSIZE();
SDL_RenderPresent(renderer);
}
void drawMap(int map[MAPSIZE][MAPSIZE]){
void drawMap(){
int x_offset = ScreenDimension.w/2 - MAPSIZE*CELLSIZE/2;
for(int i = 0; i < MAPSIZE; i++){
for(int j = 0; j < MAPSIZE; j++){
......@@ -114,7 +130,7 @@ void drawGame(){
SDL_RenderClear(renderer);
drawBackground();
drawBackground2();
drawMap(map);
drawMap();
drawColumns();
SDL_RenderPresent(renderer);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment