aboutsummaryrefslogtreecommitdiff
path: root/life.cc
blob: 7f0ace7be0811d6215ad50eee06e0c9e0b6e2102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <termbox.h>

#include "world.h"

int main(int, char*[]) {
	tb_init();

	tb_select_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE);	

	life::World<20,20> world;

	while ( true ) {
		struct tb_event ev;
		int t = tb_poll_event(&ev);

		if ( t == -1 ) {
			tb_shutdown();
			return -1;
		}

		switch (t) {
			case TB_EVENT_KEY:
				switch ( ev.key ) {
					case TB_KEY_ESC:
						tb_shutdown();
						return 0;
					case TB_KEY_SPACE:
						world.tick();
						break;
				}
				break;
			case TB_EVENT_MOUSE:
				if (ev.key == TB_KEY_MOUSE_LEFT) {
					world.summonLifeAt(ev.x, ev.y);
				}

				break;
			case TB_EVENT_RESIZE:
				break;
		}

		world.draw();
	}

	return 0;
}