summary refs log tree commit diff stats
path: root/util.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-11-02 09:17:25 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-11-02 09:17:25 -0400
commit45d6e635c880a7fae8711fba366519dd314d9faf (patch)
treea7c5e254938161727c8ba191ad68f801f1f0f2bb /util.cpp
parent4e8f554286593ec8aca6c61fa0fb9c4934bd640c (diff)
downloadmazeoflife-45d6e635c880a7fae8711fba366519dd314d9faf.tar.gz
mazeoflife-45d6e635c880a7fae8711fba366519dd314d9faf.tar.bz2
mazeoflife-45d6e635c880a7fae8711fba366519dd314d9faf.zip
Formatted source code
Diffstat (limited to 'util.cpp')
-rw-r--r--util.cpp89
1 files changed, 40 insertions, 49 deletions
diff --git a/util.cpp b/util.cpp index 9fcdbbd..693d0ad 100644 --- a/util.cpp +++ b/util.cpp
@@ -1,71 +1,62 @@
1#include "util.h" 1#include "util.h"
2#include "mazeoflife.h" 2
3#include <iostream> 3#include <iostream>
4 4
5void wrap(int& x, int& y) 5#include "mazeoflife.h"
6{
7 if (x < 0)
8 {
9 x = WIDTH+x;
10 } else if (x >= WIDTH)
11 {
12 x = x-WIDTH;
13 }
14 6
15 if (y < 0) 7void wrap(int& x, int& y) {
16 { 8 if (x < 0) {
17 y = HEIGHT+y; 9 x = WIDTH + x;
18 } else if (y >= HEIGHT) 10 } else if (x >= WIDTH) {
19 { 11 x = x - WIDTH;
20 y = y-HEIGHT; 12 }
21 } 13
14 if (y < 0) {
15 y = HEIGHT + y;
16 } else if (y >= HEIGHT) {
17 y = y - HEIGHT;
18 }
22} 19}
23 20
24TTF_Font* loadFont(int size) 21TTF_Font* loadFont(int size) {
25{ 22 TTF_Font* tmpfont = TTF_OpenFont("resources/mono.ttf", size);
26 TTF_Font* tmpfont = TTF_OpenFont("resources/mono.ttf", size);
27 23
28 if (tmpfont == NULL) 24 if (tmpfont == NULL) {
29 { 25 printf("Unable to load font: %s\n", TTF_GetError());
30 printf("Unable to load font: %s\n", TTF_GetError()); 26 exit(1);
31 exit(1); 27 }
32 }
33 28
34 return tmpfont; 29 return tmpfont;
35} 30}
36 31
37const char* getDataFile() 32const char* getDataFile() {
38{
39#ifdef WINDOWS 33#ifdef WINDOWS
40 char* dir = getenv("USERPROFILE"); 34 char* dir = getenv("USERPROFILE");
41#else 35#else
42 char* dir = getenv("HOME"); 36 char* dir = getenv("HOME");
43#endif 37#endif
44 38
45 return (std::string(dir) + "/.molhslist").c_str(); 39 return (std::string(dir) + "/.molhslist").c_str();
46} 40}
47 41
48SDL_Texture* loadImage(SDL_Renderer* renderer, std::string file) 42SDL_Texture* loadImage(SDL_Renderer* renderer, std::string file) {
49{ 43 SDL_Surface* surface = SDL_LoadBMP(file.c_str());
50 SDL_Surface* surface = SDL_LoadBMP(file.c_str()); 44 if (surface == NULL) {
51 if (surface == NULL) 45 std::cout << SDL_GetError() << std::endl;
52 { 46 return NULL;
53 std::cout << SDL_GetError() << std::endl; 47 }
54 return NULL;
55 }
56 48
57 SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); 49 SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
58 SDL_FreeSurface(surface); 50 SDL_FreeSurface(surface);
59 51
60 return texture; 52 return texture;
61} 53}
62 54
63void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y) 55void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y) {
64{ 56 SDL_Rect pos;
65 SDL_Rect pos; 57 pos.x = x;
66 pos.x = x; 58 pos.y = y;
67 pos.y = y; 59 SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h);
68 SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h);
69 60
70 SDL_RenderCopy(renderer, tex, NULL, &pos); 61 SDL_RenderCopy(renderer, tex, NULL, &pos);
71} \ No newline at end of file 62} \ No newline at end of file