summary refs log tree commit diff stats
path: root/data/maps/the_entry/rooms/Red Blue Halls.txtpb
blob: d5fb8d4a16ec1d29320f4afac7f2a28305c3a1f6 (plain) (blame)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: "Red Blue Halls"
display_name: "Red Blue Area"
panels {
  name: "CENTER"
  path: "Panels/Back Right/br_1"
  clue: "center"
  answer: "middle"
  symbols: "sun"
}
panels {
  name: "DAY"
  path: "Panels/Back Right/br_2"
  clue: "day"
  answer: "night"
  symbols: "sun"
}
panels {
  name: "CENTER DAY"
  path: "Panels/Back Right/br_3"
  clue: ""
  answer: "noon"
  symbols: "sun"
  symbols: "sparkles"
  symbols: "lingo"
}
panels {
  name: "WANDER"
  path: "Panels/Pilgrimage/cream_2"
  clue: "wander"
  answer: "meander"
  symbols: "sun"
}
panels {
  name: "RAIN"
  path: "Panels/Back Right/br_7"
  clue: "rain"
  answer: "snow"
  symbols: "cross"
}
panels {
  name: "WOMAN"
  path: "Panels/Back Right/br_8"
  clue: "woman"
  answer: "man"
  symbols: "gender"
}
panels {
  name: "RAIN WOMAN"
  path: "Panels/Back Right/br_9"
  clue: ""
  answer: "scarf"
  symbols: "boxes"
  symbols: "lingo"
}
paintings {
  name: "BLARE"
  path: "Components/Paintings/blare"
  orientation: "east"
  display_name: "Brown Wall Painting"
}
paintings {
  name: "EYE"
  path: "Components/Paintings/eyes3"
  orientation: "west"
  display_name: "Beige Wall Painting"
}
background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "includes.h"

GameState::GameState()
{
	player_color = getColor(255, 255, 0);
	event_color = getColor(0, 0, 255);

	newGame = false;

	info.playerx = 1;
	info.playery = 1;
	info.level = Level();
	info.doneMaking = false;
	board = Board(&info);

	SDL_WM_SetCaption("Maze Of Life - Level 1", NULL);
}

void GameState::input(SDLKey key)
{
	if (info.doneMaking)
	{
		switch (key)
		{
			case SDLK_LEFT:
				move(info.playerx-1, info.playery);

				break;
			case SDLK_RIGHT:
				move(info.playerx+1, info.playery);

				break;
			case SDLK_UP:
				move(info.playerx, info.playery-1);

				break;
			case SDLK_DOWN:
				move(info.playerx, info.playery+1);

				break;
			case SDLK_ESCAPE:
				changeState(new TitleState());

				break;
		}
	}
}

void GameState::tick()
{
	if (newGame)
	{
		switch (rand()%4)
		{
			case 0: info.playerx = 1; info.playery = 1; break;
			case 1: info.playerx = 1; info.playery = HEIGHT-2; break;
			case 2: info.playerx = WIDTH-2; info.playery = HEIGHT-2; break;
			case 3: info.playerx = WIDTH-2; info.playery = 1; break;
		}

		info.level.incrementLevel();
		info.doneMaking = false;
		board = Board(&info);
		newGame = false;

		char title[32];
		sprintf(title, "Maze Of Life - Level %d", info.level.getLevel());
		SDL_WM_SetCaption(title, NULL);
	}

	board.tick();
}

void GameState::move(int x, int y)
{
	wrap(&x, &y);

	if (board.isObstructed(x,y)) return;
	if ((x==15)&&(y==15)) newGame = true;

	info.playerx = x;
	info.playery = y;
}

void GameState::render(SDL_Surface* screen)
{
	// Paint maze
	board.render(screen);

	// Paint player
	SDL_Rect block;
	block.x = info.playerx*16;
	block.y = info.playery*16;
	block.w = 16;
	block.h = 16;

	SDL_FillRect(screen, &block, player_color);

	// Paint event
	block.x = 15*16;
	block.y = 15*16;

	SDL_FillRect(screen, &block, event_color);
}

GameState::Level::Level()
{
	level = 1;

	alive[0] = getColor(0, 0, 0); // Black
	alive[1] = getColor(255, 0, 0); // Red
	alive[2] = getColor(0, 255, 0); // Green
	alive[3] = getColor(85, 85, 85); // Dark Gray
	alive[4] = getColor(255, 0, 255); // Magenta

	dead[0] = getColor(255, 255, 255); // White
	dead[1] = getColor(255, 192, 203); // Pink
	dead[2] = getColor(0, 255, 255); // Cyan
	dead[3] = getColor(170, 170, 170); // Light Gray
	dead[4] = getColor(255, 128, 0); // Orange
}

int GameState::Level::getLevel()
{
	return level;
}

bool GameState::Level::checkSquare(int x, int y)
{
	switch (level/10+1)
	{
		case 1:
	                return ((x>13)&&(x<16)&&(y>13)&&(y<16));
		case 2:
	                return ((x>13)&&(x<17)&&(y>13)&&(y<17));
		case 3:
		case 4:
	                return ((x>12)&&(x<18)&&(y>12)&&(y<18));
		case 5:
		case 6:
			return ((x>11)&&(x<19)&&(y>11)&&(y<19));
		default:
			return true;
	}
}

Uint32 GameState::Level::getAliveColor()
{
	return alive[(level/10)%5];
}

Uint32 GameState::Level::getDeadColor()
{
	return dead[(level/10)%5];
}

void GameState::Level::incrementLevel()
{
	level++;
}

GameState::Board::Board()
{
	GameState::Board::Board(new GameState::Info());
}

GameState::Board::Board(GameState::Info* info)
{
	this->info = info;

	int x,y;
	for (y=0;y<HEIGHT;y++)
	{
		for (x=0;x<WIDTH;x++)
		{
			if (info->level.checkSquare(x, y))
			{
				blocks[x][y] = rand() % 2;
			} else {
				blocks[x][y] = false;
			}
		}
	}

	blocks[15][15] = false;
}

bool GameState::Board::isObstructed(int x, int y)
{
	return blocks[x][y];
}

void GameState::Board::render(SDL_Surface* screen)
{
	SDL_Rect block;
	block.w = 16;
	block.h = 16;

	int x,y;

	for (y=0;y<HEIGHT;y++)
	{
		for (x=0;x<WIDTH;x++)
		{
			block.x = x*16;
			block.y = y*16;

			SDL_FillRect(screen, &block, (blocks[x][y] ? info->level.getAliveColor() : info->level.getDeadColor()));
		}
	}
}

void GameState::Board::tick()
{
	bool temp[WIDTH][HEIGHT];
	int x,y;
	for (x=0;x<WIDTH;x++)
	{
		for (y=0;y<HEIGHT;y++)
		{
			temp[x][y] = blocks[x][y];
		}
	}

	for (x=0;x<WIDTH;x++)
	{
		for (y=0;y<HEIGHT;y++)
		{
			if ((x==15)&&(y==15))
			{
				continue;
			}

			int neighbors = 0;

			incrementIfNeighbor(x-1,y-1,temp,&neighbors);
			incrementIfNeighbor(x-1,y,temp,&neighbors);
			incrementIfNeighbor(x-1,y+1,temp,&neighbors);
			incrementIfNeighbor(x,y-1,temp,&neighbors);
			incrementIfNeighbor(x,y+1,temp,&neighbors);
			incrementIfNeighbor(x+1,y-1,temp,&neighbors);
			incrementIfNeighbor(x+1,y,temp,&neighbors);
			incrementIfNeighbor(x+1,y+1,temp,&neighbors);

			if (temp[x][y])
			{
				blocks[x][y] = ((neighbors >= 1) && (neighbors <= 4));
			} else {
				blocks[x][y] = (neighbors == 3);
			}
		}
	}

	if (!info->doneMaking && ++gens > 100) info->doneMaking = true;
}

void GameState::Board::incrementIfNeighbor(int x, int y, bool temp[WIDTH][HEIGHT], int* tick)
{
	int nx = x;
	int ny = y;

	wrap(&x, &y);

	if (!((nx!=x)&&(ny!=y)))
	{
		if ((temp[x][y])||((info->playerx==x)&&(info->playery==y))||((x==15)&&(y==15)))
		{
			++*tick;
		}
	}
}