pick up CXXFLAGS passed on commandline
[rofl0r-df-libgraphics.git] / g_src / tetris.cpp
blob69c11a963b1475b4b8fbdf5bdfb9f753b9365c4f
1 #include <cstring>
2 #include <list>
4 #include "graphics.h"
5 #include "init.h"
6 #include "interface.h"
7 #include "random.h"
8 #include "texture_handler.h"
9 #include "KeybindingScreen.h"
11 using namespace std;
13 initst init;
14 interfacest gview;
15 texture_handlerst texture;
16 GameMode gamemode;
17 long movie_version = 10001;
19 long basic_seed;
20 int mt_index[MT_BUFFER_NUM];
21 short mt_cur_buffer;
22 short mt_virtual_buffer;
23 unsigned long mt_buffer[MT_BUFFER_NUM][MT_LEN];
25 char filecomp_buffer2_aux[80000];
26 char filecomp_buffer_aux[20000];
28 string errorlog_prefix;
31 bool tetriminoes[7][2][4] =
32 {{{0,0,0,0},{1,1,1,1}},
33 {{1,0,0,0},{1,1,1,0}},
34 {{0,0,0,1},{0,1,1,1}},
35 {{0,1,1,0},{0,1,1,0}},
36 {{0,0,1,1},{0,1,1,0}},
37 {{0,0,1,0},{0,1,1,1}},
38 {{1,1,0,0},{0,1,1,0}}};
40 struct line {
41 int x, y; // Location of the topmost character. y may be negative.
42 string s;
43 int color;
46 class Matrix : public viewscreenst {
47 list<line> lines;
48 typedef list<line>::iterator lit;
49 int frame;
51 string random_string(int len) {
52 string s(len, 0);
53 for (int i=0; i<len; i++)
54 s[i] = basic_random(256);
55 return s;
57 public:
58 Matrix() {
59 frame = 0;
61 virtual void feed(set<InterfaceKey> &events) {
62 if (events.count(INTERFACEKEY_D_PAUSE))
63 breakdownlevel = INTERFACE_BREAKDOWN_STOPSCREEN;
65 virtual void render() {
66 drawborder("Matrix", 1, 0);
67 for (lit i = lines.begin(); i != lines.end(); ++i) {
68 for (int j = 0; j < i->s.size(); ++j) {
69 int x = i->x;
70 int y = i->y + j;
71 if (x < gps.dimx && y > 0 && y < gps.dimy)
72 gps.addchar(i->x, i->y + j, i->s[j], i->color, 0, 0);
76 virtual void logic() {
77 if ((frame++) % 2) return;
78 // if (enabler.tracking_on)
79 // cout << gps.mouse_x << " " << gps.mouse_y << endl;
80 enabler.flag |= ENABLERFLAG_RENDER;
81 // Advance each line one step
82 for (lit i = lines.begin(); i != lines.end();) {
83 if ((++(i->y)) >= gps.dimy)
84 lines.erase(i++);
85 else
86 ++i;
88 // Maybe add a new line
89 if (basic_random(100) < 30) {
90 line l;
91 l.x = basic_random(gps.dimx);
92 int len = basic_random(gps.dimy);
93 l.y = -len;
94 l.s = random_string(len);
95 l.color = basic_random(7) + 1;
96 lines.push_back(l);
98 // Pretend this takes a while
99 // SDL_Delay(2);
100 // Uint32 start = SDL_GetTicks();
101 // while (SDL_GetTicks() - start < 3);
103 virtual void resize(int w, int h) {
104 // Clear out lines that are now off-screen
105 for (lit i = lines.begin(); i != lines.end();) {
106 if (i->x >= w || i->y >= h)
107 lines.erase(i++);
108 else
109 ++i;
114 char beginroutine() {
115 mt_init();
116 gview.addscreen(new Matrix, INTERFACE_PUSH_AT_BACK, NULL);
117 // viewscreen_movieplayerst *m = viewscreen_movieplayerst::create(INTERFACE_PUSH_AT_BACK);
118 // m->force_play("data/initial_movies/test.cmv");
119 return 1;
122 char mainloop() {
123 return gview.loop();
126 void endroutine() {
129 void dwarf_help_routine() {
132 void dwarf_end_announcements() {
135 void dwarf_option_screen() {
136 new KeybindingScreen();
139 void dwarf_remove_screen() {
142 void texture_handlerst::clean() {
145 void finishscrolling(int32_t &selection,int32_t min,int32_t max,int32_t jump,uint32_t flag,char littlekey) {}
146 char standardscrolling(std::set<InterfaceKey> &events,short &selection,int32_t min,int32_t max,int32_t jump,uint32_t flag) {}
147 char standardscrolling(std::set<InterfaceKey> &events,int32_t &selection,int32_t min,int32_t max,int32_t jump,uint32_t flag) {}
148 char secondaryscrolling(std::set<InterfaceKey> &events,short &scroll,int32_t min,int32_t max,int32_t jump,uint32_t flag) {}
149 char secondaryscrolling(std::set<InterfaceKey> &events,int32_t &scroll,int32_t min,int32_t max,int32_t jump,uint32_t flag) {}
151 void process_object_lines(textlinesst &lines, string &chktype, string &graphics_dir) {
154 void drawborder(const char *str, char style, const char *color) {
155 gps.erasescreen();
156 if (style) {
157 gps.changecolor(7,7,0);
158 for (int x=0; x < gps.dimx; x++) {
159 gps.locate(0, x);
160 gps.addchar(' ');
161 gps.locate(gps.dimy-1, x);
162 gps.addchar(' ');
164 for (int y=1; y < gps.dimy-1; y++) {
165 gps.locate(y, 0);
166 gps.addchar(' ');
167 gps.locate(y, gps.dimx-1);
168 gps.addchar(' ');
171 if (!str) return;
172 // gps.locate(0, MAX((gps.dimx - strlen(str)) / 2,0));
173 gps.locate(0, gps.dimx/2);
174 if (color)
175 gps.addcoloredst(str, color);
176 else {
177 gps.changecolor(7,0,1);
178 // Uint32 now = SDL_GetTicks() % 3000;
179 // gps.addst(str, now < 1000 ? justify_left : now < 2000 ? justify_center : justify_right);
180 gps.addst(str, justify_center);
184 void viewscreenst::help() { }
186 bool viewscreenst::key_conflict(InterfaceKey k) { return false; }