Minor code cleanup.
This commit is contained in:
-37
@@ -22,31 +22,16 @@ typedef struct {
|
|||||||
int right;
|
int right;
|
||||||
} App;
|
} App;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
SDL_Texture *texture;
|
|
||||||
} Entity;
|
|
||||||
|
|
||||||
App app;
|
App app;
|
||||||
|
|
||||||
Entity player;
|
|
||||||
|
|
||||||
void handleInput(void);
|
void handleInput(void);
|
||||||
void cleanup(void);
|
void cleanup(void);
|
||||||
void prepareScene(void);
|
void prepareScene(void);
|
||||||
void presentScene(void);
|
void presentScene(void);
|
||||||
SDL_Texture *loadTexture(char *);
|
|
||||||
void blit(SDL_Texture *, int, int);
|
|
||||||
int getIndex(int, int, int);
|
int getIndex(int, int, int);
|
||||||
|
|
||||||
int main(int argc, char* args[]) {
|
int main(int argc, char* args[]) {
|
||||||
memset(&app, 0, sizeof(app));
|
memset(&app, 0, sizeof(app));
|
||||||
memset(&player, 0, sizeof(player));
|
|
||||||
|
|
||||||
player.x = 100;
|
|
||||||
player.y = 100;
|
|
||||||
player.texture = loadTexture("text.jpg");
|
|
||||||
|
|
||||||
IMG_Init(IMG_INIT_JPG);
|
IMG_Init(IMG_INIT_JPG);
|
||||||
|
|
||||||
@@ -86,25 +71,6 @@ int main(int argc, char* args[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void blit(SDL_Texture *texture, int x, int y)
|
|
||||||
{
|
|
||||||
SDL_Rect dest;
|
|
||||||
|
|
||||||
dest.x = x;
|
|
||||||
dest.y = y;
|
|
||||||
SDL_QueryTexture(texture, NULL, NULL, &dest.w, &dest.h);
|
|
||||||
|
|
||||||
SDL_RenderCopy(app.renderer, texture, NULL, &dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* loadTexture(char *filePath) {
|
|
||||||
SDL_Texture *texture;
|
|
||||||
|
|
||||||
texture = IMG_LoadTexture(app.renderer, filePath);
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanup(void) {
|
void cleanup(void) {
|
||||||
SDL_DestroyWindow(app.window);
|
SDL_DestroyWindow(app.window);
|
||||||
SDL_DestroyRenderer(app.renderer);
|
SDL_DestroyRenderer(app.renderer);
|
||||||
@@ -120,9 +86,6 @@ void handleInput(void) {
|
|||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
player.x += 1;
|
|
||||||
player.y += 1;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user