Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "game_map.h"
- #include<stdio.h>
- #include<conio.h>
- void GameMap::LoadMap(char* name)
- {
- FILE* fp = NULL;
- fp = fopen(name, "rb");
- //fopen_s(&fp, name, "rb");
- if ( fp == NULL)
- {
- return;
- }
- game_map.max_x = 0;
- game_map.max_y = 0;
- for (int i =0; i< MAX_MAP_Y; i++)
- {
- for ( int j = 0; j < MAX_MAP_X; j++)
- {
- fscanf(fp,"%d",&game_map.tile[i][j]);
- //fscanf_s( fp, "%d", &game_map.tile[i][j]);
- int val = game_map.tile[i][j];
- if ( val > 0)
- {
- if (j> game_map.max_x)
- game_map.max_x = j;
- if ( i> game_map.max_y ) game_map.max_y = i;
- }
- }
- }
- game_map.max_x = (game_map.max_x + 1) *TILE_SIZE;
- game_map.max_y = ( game_map.max_y + 1) * TILE_SIZE;
- game_map.start_y = 0;
- game_map.start_x = 0;
- game_map.file_name_ = name;
- fclose(fp);
- }
- void GameMap:: LoadTiles ( SDL_Renderer* screen)
- {
- char file_img[30];
- FILE* fp = NULL;
- for ( int i = 0; i< MAX_TILE; i++)
- {
- // sprintf_s(file_img,"map%d.png",i);
- sprintf(file_img,"map/map%d.png",i);
- //fopen_s( &fp, file_img, "rb");
- fp = fopen(file_img,"rb");
- if ( fp == NULL)
- {
- continue;
- }
- fclose(fp);
- tile_map[i].Load_Image(file_img, screen);
- }
- }
- void GameMap:: DrawMap ( SDL_Renderer* screen )
- {
- int x1 = 0, x2 = SCREEN_WIDTH;
- int y1 =0, y2 = SCREEN_HEIGHT;
- int max_x = game_map.start_x / TILE_SIZE;
- int max_y = game_map.start_y / TILE_SIZE;
- for ( int i = y1; i<= y2; i+= TILE_SIZE)
- {
- max_x = game_map.start_x / TILE_SIZE;
- for ( int j = x1; j<= x2; j += TILE_SIZE)
- {
- int val = game_map.tile[max_y][max_x];
- if ( val >0 && val < 20)
- {
- tile_map[val].SetRect(j,i);
- tile_map[val].Render(screen);
- }
- max_x ++;
- }
- max_y ++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement