1 // Hyperbolic Rogue -- fake mobile target
2 // Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
3 
4 #define ISFAKEMOBILE 1
5 #define MOBPAR_FORMAL int
6 #define MOBPAR_ACTUAL 0
7 #define MIX_MAX_VOLUME 128
8 #define NOMAIN
9 #include <string>
10 
11 namespace hr {
12   const char *scorefile = "fakemobile_score.txt";
13   }
14 
15 #include <SDL/SDL.h>
16 
17 #include "hyper.cpp"
18 
19 #include <SDL/SDL_ttf.h>
20 #include <SDL/SDL_gfxPrimitives.h>
21 
22 #undef main
23 
24 namespace hr {
25 
26 transmatrix Orient = Id;
27 
28 int lasttick = 0;
29 
getOrientation()30 transmatrix getOrientation() {
31   int curtick = SDL_GetTicks();
32   ld t = (curtick - lasttick) / 1000.0;
33   lasttick = curtick;
34   Uint8 *keystate = SDL_GetKeyState(NULL);
35   if(keystate[SDLK_LCTRL]) {
36     if(keystate['s']) Orient = Orient * cspin(2, 1, t);
37     if(keystate['w']) Orient = Orient * cspin(1, 2, t);
38     if(keystate['a']) Orient = Orient * cspin(2, 0, t);
39     if(keystate['d']) Orient = Orient * cspin(0, 2, t);
40     }
41   return Orient;
42   }
43 
resetmusic()44 void resetmusic() { printf("resetmusic\n"); }
45 
playSound(cell * c,const string & fname,int vol)46 void playSound(cell *c, const string& fname, int vol) {
47   printf("Play sound: %s\n", fname.c_str());
48   }
49 
50 SDL_Surface *s;
51 
52 int gdpos = 0;
53 
gdpop()54 int gdpop() { return graphdata[gdpos++]; }
55 
56 TTF_Font *font[256];
57 
rawdisplaystr(int x,int y,int shift,int size,const char * str,int color,int align)58 bool rawdisplaystr(int x, int y, int shift, int size, const char *str, int color, int align) {
59 
60   if(strlen(str) == 0) return false;
61 
62   if(size <= 0 || size > 255) {
63     return false;
64     }
65   SDL_Color col;
66   col.r = (color >> 16) & 255;
67   col.g = (color >> 8 ) & 255;
68   col.b = (color >> 0 ) & 255;
69 
70   col.r >>= darken; col.g >>= darken; col.b >>= darken;
71 
72   if(!font[size])
73     font[size] = TTF_OpenFont("VeraBd.ttf", size);
74 
75   SDL_Surface *txt = TTF_RenderText_Solid(font[size], str, col);
76 
77   if(txt == NULL) return false;
78 
79   SDL_Rect rect;
80 
81   rect.w = txt->w;
82   rect.h = txt->h;
83 
84   rect.x = x - rect.w * align / 16;
85   rect.y = y - rect.h/2;
86 
87   bool clicked = (mousex >= rect.x && mousey >= rect.y && mousex <= rect.x+rect.w && mousey <= rect.y+rect.h);
88 
89   SDL_BlitSurface(txt, NULL, s,&rect);
90   SDL_FreeSurface(txt);
91 
92   return clicked;
93   }
94 
textwidth(int siz,const string & str)95 int textwidth(int siz, const string &str) {
96   if(isize(str) == 0) return 0;
97 
98   if(!font[siz]) font[siz] = TTF_OpenFont("VeraBd.ttf", siz);
99 
100   int w, h;
101   TTF_SizeUTF8(font[siz], str.c_str(), &w, &h);
102   // printf("width = %d [%d]\n", w, isize(str));
103   return w;
104   }
105 
106 char action;
107 
currentlyConnecting()108 bool currentlyConnecting() { return false; }
currentlyConnected()109 bool currentlyConnected() { return false; }
viewAchievements()110 void viewAchievements() { printf("view Achievements\n"); }
viewLeaderboard(string id)111 void viewLeaderboard(string id) { printf("view Leaderboard :: %s\n", id.c_str()); }
switchGoogleConnection()112 void switchGoogleConnection() { printf("sgc\n"); }
113 
shareScore(int)114 void shareScore(int) {
115   printf("share\n");
116   }
117 
openURL()118 void openURL() {
119   printf("< openURL > \n");
120   }
121 
122 }
123 
124 using namespace hr;
125 
main(int argc,char ** argv)126 int main(int argc, char **argv) {
127 
128   initAll();
129   glhr::init();
130 
131   vid.xres = 800; vid.yres = 450;
132   vid.usingGL = false;
133   // 450; vid.yres = 600;
134 
135   s= SDL_SetVideoMode(vid.xres, vid.yres, 32, 0);
136 
137   if(TTF_Init() != 0) {
138     printf("Failed to initialize TTF.\n");
139     exit(2);
140     }
141 
142   int mx = 0; int my = 0; bool _clicked = false;
143 
144   inv::on = true;
145   // firstland = laMinefield;
146   // activateSafety(laWhirlwind);
147 
148   items[itGreenStone] = 100;
149   // items[itDiamond] = 50;
150   // for(int i=1; i<10; i++) kills[i] = 5;
151 
152   while(true) {
153 
154     SDL_LockSurface(s);
155     memset(s->pixels, 0, vid.xres * vid.yres * 4);
156     SDL_UnlockSurface(s);
157 
158     mousex = mx;
159     mousey = my;
160     clicked = _clicked;
161 
162     mobile_draw(MOBPAR_ACTUAL);
163     action = 0;
164 
165     gdpos = 0;
166     while(gdpos < isize(graphdata)) {
167       switch(gdpop()) {
168         case 2: {
169           int x = gdpop(), y = gdpop(), al = gdpop();
170           int color = gdpop();
171           int size = gdpop();
172           gdpop();
173           int n = gdpop();
174           string s;
175           for(int i=0; i<n; i++) s += char(gdpop());
176           rawdisplaystr(x, y, 0, size, s.c_str(), color, al);
177           break;
178           }
179 
180         case 1: {
181           int col = gdpop();
182           int otl = gdpop();
183           int num = gdpop();
184 
185           Sint16 xpox[6000], xpoy[6000];
186 
187           // printf("%4d polygon %d\n", gdpos, num);
188           for(int i=0; i<num; i++) xpox[i] = gdpop(), xpoy[i] = gdpop();
189 
190           filledPolygonColor(s, xpox, xpoy, num, col);
191           aapolygonColor(s, xpox, xpoy, num, otl);
192           break;
193           }
194 
195         case 3: {
196           int col = gdpop();
197           int num = gdpop();
198 
199           for(int i=0; i<num; i++) polyx[i] = gdpop(), polyy[i] = gdpop();
200 
201           for(int i=0; i<num-1; i++)
202             aalineColor(s, polyx[i], polyy[i], polyx[i+1], polyy[i+1], col);
203           }
204 
205         case 4: {
206           int col = gdpop();
207           int out = gdpop();
208           int x = gdpop(), y = gdpop(), rad = gdpop();
209 
210           aacircleColor(s, x, y, rad, (col << 8) + 0xFF);
211           }
212 
213         case 5: {
214           int out = gdpop();
215           /* not implemented */
216           }
217 
218         }
219       }
220     SDL_UpdateRect(s, 0, 0, vid.xres, vid.yres);
221 
222     SDL_Event ev;
223     while(SDL_PollEvent(&ev)) {
224 
225       if(ev.type == SDL_MOUSEBUTTONDOWN) {
226         mx = ev.button.x;
227         my = ev.button.y;
228         _clicked = true;
229         }
230 
231       if(ev.type == SDL_MOUSEBUTTONUP) {
232         _clicked = false;
233         }
234 
235       if(ev.type == SDL_MOUSEMOTION) {
236         mx = ev.motion.x;
237         my = ev.motion.y;
238         }
239 
240       if(ev.type == SDL_KEYDOWN) {
241         int sym = ev.key.keysym.sym;
242 /*        if(sym == '1') {
243   printf("Number of cells explored, by distance from the player:\n");
244   for(int i=0; i<10; i++) printf(" %d", explore[i]); printf("\n");
245           return 0;
246           }
247         else if(sym == '2') {
248           items[rand() % ittypes] += 3;
249           kills[rand() % motypes] += 3;
250           }
251         else if(sym == '3') {
252           items[itHell] = 0;
253           items[itGreenStone] = 100;
254           }
255         action = sym; */
256         if(ev.key.keysym.mod & KMOD_LCTRL) continue;
257         mousing = false;
258         handlekey(sym, sym);
259         }
260 
261       if(ev.type == SDL_QUIT) {
262         SDL_Quit();
263         return 0;
264         }
265       }
266     }
267 
268   SDL_Quit();
269 
270   clearMemory();
271   }
272 
273