diff options
| author | Starla Insigna <starla4444@gmail.com> | 2013-08-27 11:39:37 -0400 |
|---|---|---|
| committer | Starla Insigna <starla4444@gmail.com> | 2013-08-27 11:39:37 -0400 |
| commit | ffd335aca284c286030e2b26f1a02a0441748f46 (patch) | |
| tree | bcc1c241621fe159ae7ef178122fb41c5f23eb00 /util.cpp | |
| parent | d47da18958b5214def5127e201f60668c566d9bb (diff) | |
| download | mazeoflife-ffd335aca284c286030e2b26f1a02a0441748f46.tar.gz mazeoflife-ffd335aca284c286030e2b26f1a02a0441748f46.tar.bz2 mazeoflife-ffd335aca284c286030e2b26f1a02a0441748f46.zip | |
Started rewriting game from scratch with SDL2
Only the title screen is currently implemented
Diffstat (limited to 'util.cpp')
| -rw-r--r-- | util.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
| diff --git a/util.cpp b/util.cpp new file mode 100644 index 0000000..b021146 --- /dev/null +++ b/util.cpp | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #include "util.h" | ||
| 2 | #include "mazeoflife.h" | ||
| 3 | #include <iostream> | ||
| 4 | |||
| 5 | void wrap(int* x, int* y) | ||
| 6 | { | ||
| 7 | if (*x < 0) | ||
| 8 | { | ||
| 9 | *x = WIDTH-(0-*x); | ||
| 10 | } else if (*y < 0) | ||
| 11 | { | ||
| 12 | *y = HEIGHT-(0-*y); | ||
| 13 | } else if (*x >= WIDTH) | ||
| 14 | { | ||
| 15 | *x = *x-WIDTH; | ||
| 16 | } else if (*y >= HEIGHT) | ||
| 17 | { | ||
| 18 | *y = *y-HEIGHT; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | TTF_Font* loadFont(int size) | ||
| 23 | { | ||
| 24 | TTF_Font* tmpfont = TTF_OpenFont("resources/mono.ttf", size); | ||
| 25 | |||
| 26 | if (tmpfont == NULL) | ||
| 27 | { | ||
| 28 | printf("Unable to load font: %s\n", TTF_GetError()); | ||
| 29 | exit(1); | ||
| 30 | } | ||
| 31 | |||
| 32 | return tmpfont; | ||
| 33 | } | ||
| 34 | |||
| 35 | const char* getDataFile() | ||
| 36 | { | ||
| 37 | #ifdef WINDOWS | ||
| 38 | char* dir = getenv("USERPROFILE"); | ||
| 39 | #else | ||
| 40 | char* dir = getenv("HOME"); | ||
| 41 | #endif | ||
| 42 | |||
| 43 | return (std::string(dir) + "/.molhslist").c_str(); | ||
| 44 | } | ||
| 45 | |||
| 46 | SDL_Texture* loadImage(SDL_Renderer* renderer, std::string file) | ||
| 47 | { | ||
| 48 | SDL_Surface* surface = SDL_LoadBMP(file.c_str()); | ||
| 49 | if (surface == NULL) | ||
| 50 | { | ||
| 51 | std::cout << SDL_GetError() << std::endl; | ||
| 52 | return NULL; | ||
| 53 | } | ||
| 54 | |||
| 55 | SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); | ||
| 56 | SDL_FreeSurface(surface); | ||
| 57 | |||
| 58 | return texture; | ||
| 59 | } | ||
| 60 | |||
| 61 | void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y) | ||
| 62 | { | ||
| 63 | SDL_Rect pos; | ||
| 64 | pos.x = x; | ||
| 65 | pos.y = y; | ||
| 66 | SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h); | ||
| 67 | |||
| 68 | SDL_RenderCopy(renderer, tex, NULL, &pos); | ||
| 69 | } \ No newline at end of file | ||
