Update render.c
This commit is contained in:
+19
-21
@@ -12,13 +12,12 @@ extern int spr_x[5][6];
|
||||
extern int grid[2][18][8];
|
||||
extern SDL_Renderer *sr;
|
||||
extern SDL_Texture * texture;
|
||||
int tile_c;
|
||||
extern int tile_pos;
|
||||
extern bool next_p; // next piece flag
|
||||
|
||||
int tile_shp, tilesrc_x, tilesrc_y, tiledst_x, tiledst_y;
|
||||
int row = 0, col = 0;
|
||||
|
||||
int tile_c;
|
||||
int last_time, current_time, deltatime, score;
|
||||
|
||||
///////////////// SPRITE SHEET TOP LEFT COORDINATES /////////////////
|
||||
@@ -42,6 +41,7 @@ SDL_Rect level_back = {231, 7, 76, 66};
|
||||
SDL_Rect level_trim = {230, 6, 78, 68};
|
||||
SDL_Rect next_back = {257, 86, 18, 37};
|
||||
SDL_Rect next_trim = {256, 85, 20, 39};
|
||||
SDL_Rect next_tile = {260, 88, 12, 11};
|
||||
SDL_Rect high_back = {13, 7, 76, 186};
|
||||
SDL_Rect high_trim = {12, 6, 78, 188};
|
||||
SDL_Rect tile_src = {72, 0, 12, 11};
|
||||
@@ -87,16 +87,24 @@ return 0;
|
||||
|
||||
///////////////// DISPLAY NEXT PIECE /////////////////
|
||||
int Ren_next(void) {
|
||||
tile_shp = 1; // tile shape
|
||||
if (next_p == 0) {
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(sr, 0xff , 0xff , 0xff, 0xff);
|
||||
SDL_SetRenderDrawColor(sr, 0x00 , 0x00 , 0x00, 0xff);
|
||||
SDL_RenderFillRect(sr, &next_back); // background
|
||||
SDL_SetRenderDrawColor (sr, 0x00, 0x00, 0x00, 255);
|
||||
SDL_RenderDrawRect(sr, &next_trim); // trim
|
||||
SDL_RenderDrawLine (sr, 259, 124, 276, 124); // next shadow
|
||||
SDL_RenderDrawLine (sr, 259, 125, 277, 125);
|
||||
SDL_RenderDrawLine (sr, 276, 124, 276, 89);
|
||||
SDL_RenderDrawLine (sr, 277, 125, 277, 89);
|
||||
SDL_SetRenderDrawColor (sr, 0xff, 0xff, 0xff, 0xff);
|
||||
SDL_RenderDrawRect(sr, &next_trim); // trim
|
||||
for (int i = 0; i < 3; i++) {
|
||||
tile_src.x = spr_x[tile_shp][tile_next[i] - 1]; // source x position in sprite map depends on tile shape and colour
|
||||
tile_src.y = 0; // source y position in sprite map = 0
|
||||
tile_dst.x = 260; // tile destination x position = 260
|
||||
tile_dst.y = 88 + (i * 11); // add 11 pixels to move to next tile destination y location
|
||||
SDL_RenderCopy(sr, texture, &tile_src, &tile_dst);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -205,11 +213,8 @@ int Ren_menu(void) {
|
||||
}
|
||||
|
||||
///////////////// DISPLAY GAME BOARD/////////////////
|
||||
int display_grid()
|
||||
{
|
||||
tiledst_y = 1;
|
||||
int display_grid() {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
tiledst_x = 112;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
int k = grid[0][i][j];
|
||||
tile_shp = 1; // tile shape
|
||||
@@ -219,28 +224,24 @@ int display_grid()
|
||||
tilesrc_x = spr_x[tile_shp][k];
|
||||
tile_src.x = tilesrc_x;
|
||||
tile_src.y = tilesrc_y;
|
||||
tile_dst.x = tiledst_x;
|
||||
tile_dst.y = tiledst_y;
|
||||
tile_dst.x = tiledst_x + 112 + (j * 12);
|
||||
tile_dst.y = tiledst_y + 1 + (i * 11);
|
||||
SDL_RenderCopy(sr, texture, &tile_src, &tile_dst); // draw colour tile
|
||||
} else {
|
||||
tile_dst.x = tiledst_x;
|
||||
tile_dst.y = tiledst_y;
|
||||
tile_dst.x = tiledst_x + 112 + (j * 12);
|
||||
tile_dst.y = tiledst_y + 1 + (i * 11);
|
||||
SDL_SetRenderDrawColor(sr, 0x0 , 0x0 , 0x0, 0xff);
|
||||
SDL_RenderFillRect(sr, &tile_dst); // draw empty tile
|
||||
}
|
||||
tiledst_x = tiledst_x + 12; // next column
|
||||
}
|
||||
tiledst_y = tiledst_y + 11; // next row
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
///////////////// UPDATE GAME /////////////////
|
||||
int Ren_game(void) {
|
||||
if (pause_f == true) {
|
||||
Ren_pause();
|
||||
SDL_Delay(40);
|
||||
return 0;
|
||||
}
|
||||
backdrop(colour);
|
||||
@@ -261,12 +262,9 @@ if (pause_f == true) {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1; i++) {
|
||||
|
||||
current_time = SDL_GetTicks();
|
||||
deltatime = current_time - last_time;
|
||||
|
||||
if (deltatime > 1000) { // deltatime > 500 - (score * 10)
|
||||
|
||||
if (deltatime > 500) { // deltatime > 500 - (score * 10)
|
||||
last_time = current_time;
|
||||
deltatime = 0;
|
||||
disp_column (row, col);
|
||||
|
||||
Reference in New Issue
Block a user