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