Changeset 352
- Timestamp:
- Feb 4, 2011, 1:20:53 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/monsterz/Makefile.am
r340 r352 4 4 monsterz_SOURCES = \ 5 5 monsterz.cpp monsterz.h title.cpp title.h interface.cpp interface.h \ 6 fusion.cpp fusion.h board.cpp board.h piece.cpp piece.h mash.cpp mash.h \ 7 thumbs.cpp thumbs.h 6 board.cpp board.h piece.cpp piece.h mash.cpp mash.h thumbs.cpp thumbs.h 8 7 monsterz_CXXFLAGS = @LOL_CFLAGS@ @PIPI_CFLAGS@ 9 8 monsterz_LDADD = $(top_builddir)/src/liblol.a -
trunk/monsterz/board.cpp
r348 r352 17 17 #include <cstdlib> 18 18 #include <ctime> 19 #include <cstring> 19 20 20 21 #include "core.h" … … 34 35 35 36 private: 37 Board::game_t game; 38 36 39 int2 dim; 37 int npieces; 38 int board, tiles; 40 int minnpieces, npieces, maxnpieces; 41 42 int board, tiles, icons; 39 43 int click, whip; 40 44 … … 44 48 Piece *piece; 45 49 } 46 pairs[MAX_WIDTH][MAX_HEIGHT], grabbed; 50 pairs[MAX_WIDTH][MAX_HEIGHT]; 51 52 /* Hunt */ 53 struct Pair grabbed; 47 54 int nmoves; 55 int2 src_cell, dst_cell; 56 57 /* Fusion */ 58 struct Pair current[2]; 59 int next[2], rotation; 48 60 49 61 Text *scoretext; … … 53 65 Emitter *emitter; 54 66 Thumbs *thumbs; 55 int2 src_cell, dst_cell;56 67 57 68 int2 oldmouse; … … 61 72 enum 62 73 { 63 IDLE, 64 BADCLICK, 65 GRAB, 74 HUNT_IDLE, 75 HUNT_BADCLICK, 76 HUNT_GRAB, 77 FUSION_IDLE, 66 78 } 67 79 state; … … 72 84 */ 73 85 74 Board::Board( int2 dim, intnpieces)86 Board::Board(game_t game, int2 dim, int minnpieces, int maxnpieces) 75 87 : data(new BoardData()) 76 88 { 89 data->game = game; 90 77 91 data->dim = dim; 78 data->npieces = npieces; 92 data->minnpieces = minnpieces; 93 data->npieces = minnpieces; 94 data->maxnpieces = maxnpieces; 79 95 data->board = Tiler::Register(PNG_BOARD, 384, 384, 1.0f); 80 96 data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f); 97 data->icons = Tiler::Register(PNG_ICONS, 24, 24, 1.0f); 81 98 data->click = Sampler::Register(WAV_CLICK); 82 99 data->whip = Sampler::Register(WAV_WHIP); … … 85 102 Ticker::Ref(data->emitter); 86 103 87 Fill(); 104 data->thumbs = new Thumbs(0); 105 Ticker::Ref(data->thumbs); 106 107 switch (data->game) 108 { 109 case GAME_HUNT: 110 Fill(); 111 data->thumbs->SetMax(data->npieces); 112 data->state = BoardData::HUNT_IDLE; 113 break; 114 115 case GAME_FUSION: 116 for (int j = 0; j < data->dim.j; j++) 117 for (int i = 0; i < data->dim.i; i++) 118 data->pairs[i][j].id = 0; 119 120 data->current[0].id = GetRandomId(); 121 data->current[1].id = GetRandomId(); 122 data->current[0].piece = new Piece(data->emitter, int2(3, 8), 123 80 + 20 * data->current[0].id); 124 data->current[1].piece = new Piece(data->emitter, int2(4, 8), 125 80 + 20 * data->current[1].id); 126 Ticker::Ref(data->current[0].piece); 127 Ticker::Ref(data->current[1].piece); 128 data->current[0].piece->SetPos(int2(3, 7) * 48); 129 data->current[1].piece->SetPos(int2(4, 7) * 48); 130 131 data->next[0] = GetRandomId(); 132 data->next[1] = GetRandomId(); 133 data->rotation = 0; 134 135 data->thumbs->SetMax(data->npieces + 1); 136 data->state = BoardData::FUSION_IDLE; 137 break; 138 } 88 139 89 140 data->mashes = NULL; 90 141 data->nextblink = 0.0f; 91 142 data->whipdelay = 0.0f; 92 data->state = BoardData::IDLE;93 94 data->thumbs = new Thumbs(MAX_PIECES);95 Ticker::Ref(data->thumbs);96 143 97 144 data->scoretext = new Text(NULL, "monsterz/gfx/font2.png"); … … 115 162 116 163 /* If possible, make a random monster blink */ 117 if ( (data->nextblink -= deltams) < 0.0f)164 if (data->game == Board::GAME_HUNT && (data->nextblink -= deltams) < 0.0f) 118 165 { 119 166 data->pairs[rand() % data->dim.i] … … 142 189 switch (data->state) 143 190 { 144 case BoardData:: IDLE:191 case BoardData::HUNT_IDLE: 145 192 /* Should we start dragging something? */ 146 193 if (buttons[0] && !data->oldbuttons[0] && mousepos.x != -1) … … 153 200 data->src_cell = mousepos / 48; 154 201 data->dst_cell = int2(-1); 155 data->state = BoardData:: GRAB;202 data->state = BoardData::HUNT_GRAB; 156 203 } 157 204 else 158 data->state = BoardData::BADCLICK; 159 } 160 break; 161 case BoardData::GRAB: 205 data->state = BoardData::HUNT_BADCLICK; 206 } 207 break; 208 209 case BoardData::HUNT_GRAB: 162 210 if (mousepos.x != -1) 163 211 { … … 196 244 if (data->dst_cell != int2(-1)) 197 245 Switch(data->src_cell, data->dst_cell); 198 data->state = BoardData::IDLE; 199 } 200 break; 201 case BoardData::BADCLICK: 246 data->state = BoardData::HUNT_IDLE; 247 } 248 break; 249 250 case BoardData::HUNT_BADCLICK: 202 251 if (!buttons[0]) 203 data->state = BoardData::IDLE; 204 break; 252 data->state = BoardData::HUNT_IDLE; 253 break; 254 255 case BoardData::FUSION_IDLE: 256 { 257 int column = -1; 258 259 if (clicked[2]) 260 { 261 column = data->current[0].piece->GetCell().x; 262 data->rotation = (data->rotation + 1) % 2; 263 if (column - data->rotation > data->dim.i - 1) 264 column = data->dim.i - 1 - data->rotation; 265 if (!data->rotation) 266 { 267 BoardData::Pair tmp = data->current[0]; 268 data->current[0] = data->current[1]; 269 data->current[1] = tmp; 270 if (column == data->dim.i - 1) 271 column = 6; 272 } 273 } 274 275 if (mousepos.x != -1 276 && mousepos.x / 48 != data->current[0].piece->GetCell().x) 277 { 278 column = mousepos.x / 48; 279 column = column < 0 ? 0 : column > data->dim.i - 2 + data->rotation ? data->dim.i - 2 + data->rotation : column; 280 } 281 282 if (column != -1) 283 { 284 if (data->rotation) 285 { 286 data->current[0].piece->SetCell(int2(column, 6)); 287 data->current[1].piece->SetCell(int2(column, 7)); 288 } 289 else 290 { 291 data->current[0].piece->SetCell(int2(column, 7)); 292 data->current[1].piece->SetCell(int2(column + 1, 7)); 293 } 294 295 data->current[0].piece->Move(data->current[0].piece->GetCell() * 48); 296 data->current[1].piece->Move(data->current[1].piece->GetCell() * 48); 297 } 298 299 if (clicked[0]) 300 { 301 for (int t = 0; t < 2; t++) 302 { 303 int i = data->current[t].piece->GetCell().i; 304 for (int j = 0; j < 7; j++) 305 if (data->pairs[i][j].id == 0) 306 { 307 data->current[t].piece->SetCell(int2(i, j)); 308 data->current[t].piece->Move(int2(i, j) * 48); 309 data->pairs[i][j] = data->current[t]; 310 data->thumbs->AddCount(data->current[t].id, 1); 311 break; 312 } 313 } 314 315 data->current[0].id = data->next[0]; 316 data->current[1].id = data->next[1]; 317 data->current[0].piece = new Piece(data->emitter, int2(3, 7), 318 80 + 20 * data->current[0].id); 319 data->current[1].piece = new Piece(data->emitter, int2(4, 7), 320 80 + 20 * data->current[1].id); 321 Ticker::Ref(data->current[0].piece); 322 Ticker::Ref(data->current[1].piece); 323 data->current[0].piece->SetPos(int2(3, 8) * 48); 324 data->current[1].piece->SetPos(int2(4, 8) * 48); 325 data->current[0].piece->Move(data->current[0].piece->GetCell() * 48); 326 data->current[1].piece->Move(data->current[1].piece->GetCell() * 48); 327 data->next[0] = GetRandomId(); 328 data->next[1] = GetRandomId(); 329 data->rotation = 0; 330 331 Resolve(); 332 } 333 break; 334 } 205 335 } 206 336 … … 215 345 Scene::GetDefault()->AddTile((data->board << 16) | 0, 216 346 position.x, position.y, 1, 0); 347 348 switch (data->game) 349 { 350 case GAME_HUNT: 351 break; 352 case GAME_FUSION: 353 Scene::GetDefault()->AddTile((data->icons << 16) | (data->next[0] - 1), 354 350, 400, 11, 0); 355 Scene::GetDefault()->AddTile((data->icons << 16) | (data->next[1] - 1), 356 380, 400, 11, 0); 357 break; 358 } 217 359 } 218 360 … … 502 644 } 503 645 504 Board::~Board() 505 { 506 Input::UntrackMouse(this); 646 int Board::GetRandomId() const 647 { 648 int max = data->npieces; 649 650 if (max > data->minnpieces) 651 max--; 652 653 return 1 + rand() % max; 654 } 655 656 void Board::Resolve() 657 { 658 int list[MAX_PIECES][MAX_PIECES]; 659 int count[MAX_PIECES * MAX_PIECES]; 507 660 508 661 for (int j = 0; j < data->dim.j; j++) 509 662 for (int i = 0; i < data->dim.i; i++) 510 { 511 data->pairs[i][j].piece->SetBelow(NULL); 512 Ticker::Unref(data->pairs[i][j].piece); 513 } 663 list[i][j] = -1; 664 memset(count, 0, sizeof(count)); 665 666 int seq = 0, effect = 0; 667 668 /* Count connected tiles */ 669 for (int j = 0; j < data->dim.j; j++) for (int i = 0; i < data->dim.i; i++) 670 { 671 if (!data->pairs[i][j].id) 672 continue; 673 674 if (data->pairs[i][j].id >= data->maxnpieces) 675 continue; 676 677 if (list[i][j] != -1) 678 continue; 679 680 list[i][j] = seq; 681 count[seq] = TagNeighbours(list, i, j); 682 if (count[seq] >= 3) 683 effect = 1; 684 seq++; 685 } 686 687 /* Only continue if there is an effect */ 688 if (!effect) 689 return; 690 691 /* Add tiles to a mash; add mash to our list */ 692 Mash *mash = new Mash(data->emitter); 693 Ticker::Ref(mash); 694 695 for (int j = 0; j < data->dim.j; j++) for (int i = 0; i < data->dim.i; i++) 696 { 697 if (list[i][j] == -1) 698 continue; 699 if (count[list[i][j]] < 3) 700 continue; 701 702 mash->AddPiece(data->pairs[i][j].piece); 703 data->pairs[i][j].piece = NULL; 704 } 705 706 mash->nextmash = data->mashes; 707 data->mashes = mash; 708 709 /* Create new pieces where necessary */ 710 for (int j = 0; j < data->dim.j; j++) for (int i = 0; i < data->dim.i; i++) 711 { 712 if (list[i][j] == -1) 713 continue; 714 if (count[list[i][j]] < 3) 715 { 716 if (!data->pairs[i][j].piece) 717 data->pairs[i][j].id = 0; 718 continue; 719 } 720 721 data->pairs[i][j].id++; 722 if (data->pairs[i][j].id > data->npieces 723 && data->pairs[i][j].id <= data->maxnpieces) 724 { 725 data->npieces++; 726 data->thumbs->SetMax(data->npieces); 727 } 728 data->pairs[i][j].piece = new Piece(data->emitter, int2(i, j), 80 + 20 * data->pairs[i][j].id); 729 Ticker::Ref(data->pairs[i][j].piece); 730 data->pairs[i][j].piece->SetPos(int2(i, j) * 48); 731 data->thumbs->AddCount(data->pairs[i][j].id, 1); 732 count[list[i][j]] = 0; 733 list[i][j] = -1; 734 } 735 736 /* Move everything down */ 737 for (int j = data->dim.j; j--;) for (int i = 0; i < data->dim.i; i++) 738 { 739 if (list[i][j] == -1 || data->pairs[i][j].piece) 740 continue; 741 742 for (int j2 = j + 1; j2 < data->dim.j; j2++) 743 { 744 data->pairs[i][j2 - 1] = data->pairs[i][j2]; 745 if (data->pairs[i][j2 - 1].id) 746 { 747 data->pairs[i][j2 - 1].piece->SetCell(int2(i, j2 - 1)); 748 data->pairs[i][j2 - 1].piece->Move(int2(i, j2 - 1) * 48); 749 } 750 list[i][j2 - 1] = list[i][j2]; 751 } 752 753 data->pairs[i][data->dim.j - 1].id = 0; 754 list[i][data->dim.j - 1] = -1; 755 } 756 757 /* Start again (FIXME: make this a while() loop) */ 758 Resolve(); 759 } 760 761 int Board::TagNeighbours(int list[MAX_PIECES][MAX_PIECES], int i, int j) 762 { 763 int2 const off[] = { int2(-1, 0), int2(1, 0), int2(0, -1), int2(0, 1) }; 764 765 int count = 1; 766 767 for (int n = 0; n < 4; n++) 768 { 769 int i2 = i + off[n].i; 770 int j2 = j + off[n].j; 771 772 if (i2 >= 0 && i2 < data->dim.i && j2 >= 0 && j2 < data->dim.j 773 && data->pairs[i2][j2].id == data->pairs[i][j].id 774 && list[i2][j2] == -1) 775 { 776 list[i2][j2] = list[i][j]; 777 count += TagNeighbours(list, i2, j2); 778 } 779 } 780 return count; 781 } 782 783 Board::~Board() 784 { 785 Input::UntrackMouse(this); 786 787 switch (data->game) 788 { 789 case GAME_HUNT: 790 for (int j = 0; j < data->dim.j; j++) 791 for (int i = 0; i < data->dim.i; i++) 792 { 793 data->pairs[i][j].piece->SetBelow(NULL); 794 Ticker::Unref(data->pairs[i][j].piece); 795 } 796 break; 797 case GAME_FUSION: 798 for (int j = 0; j < data->dim.j; j++) 799 for (int i = 0; i < data->dim.i; i++) 800 if (data->pairs[i][j].id) 801 Ticker::Unref(data->pairs[i][j].piece); 802 Ticker::Unref(data->current[0].piece); 803 Ticker::Unref(data->current[1].piece); 804 break; 805 } 514 806 Ticker::Unref(data->thumbs); 515 807 Ticker::Unref(data->scoretext); … … 525 817 Tiler::Deregister(data->board); 526 818 Tiler::Deregister(data->tiles); 819 Tiler::Deregister(data->icons); 527 820 Sampler::Deregister(data->click); 528 821 Sampler::Deregister(data->whip); -
trunk/monsterz/board.h
r314 r352 24 24 { 25 25 public: 26 Board(int2 dim, int npieces); 26 typedef enum 27 { 28 GAME_HUNT, 29 GAME_FUSION, 30 } 31 game_t; 32 33 Board(game_t, int2 dim, int minnpieces, int maxnpieces); 27 34 virtual ~Board(); 28 35 … … 31 38 virtual void TickDraw(float deltams); 32 39 40 /* Hunt mode */ 33 41 void Fill(); 34 42 void Switch(int2 cell_a, int2 cell_b); 35 43 int ListMashes(int list[MAX_WIDTH][MAX_HEIGHT]); 36 44 int ListMoves(int list[MAX_WIDTH][MAX_HEIGHT]); 45 46 /* Fusion mode */ 47 int GetRandomId() const; 48 void Resolve(); 49 int TagNeighbours(int list[MAX_PIECES][MAX_PIECES], int i, int j); 37 50 38 51 private: -
trunk/monsterz/interface.cpp
r350 r352 22 22 #include "title.h" 23 23 #include "board.h" 24 #include "fusion.h"25 24 #include "monsterz.h" 26 25 … … 36 35 Title *title; 37 36 Board *board; 38 Fusion *fusion;39 37 int screen, tiles; 40 38 … … 57 55 data->title = NULL; 58 56 data->board = NULL; 59 data->fusion = NULL;60 57 data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f); 61 58 data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f); … … 83 80 Ticker::Unref(data->title); 84 81 data->title = NULL; 85 data->fusion = new Fusion(int2(6, 8), 3, 12); 86 Ticker::Ref(data->fusion); 87 #if 0 88 data->board = new Board(int2(8, 8), 8); 82 data->board = new Board(Board::GAME_FUSION, int2(6, 8), 3, 12); 83 //data->board = new Board(Board::GAME_HUNT, int2(8, 8), 8, 8); 89 84 Ticker::Ref(data->board); 90 #endif91 85 data->state = InterfaceData::GAME; 92 86 } … … 118 112 if (data->board) 119 113 Ticker::Unref(data->board); 120 if (data->fusion)121 Ticker::Unref(data->fusion);122 114 Tiler::Deregister(data->tiles); 123 115 Tiler::Deregister(data->screen); -
trunk/win32/monsterz.vcxproj
r340 r352 13 13 <ItemGroup> 14 14 <ClInclude Include="..\monsterz\board.h" /> 15 <ClInclude Include="..\monsterz\fusion.h" />16 15 <ClInclude Include="..\monsterz\interface.h" /> 17 16 <ClInclude Include="..\monsterz\mash.h" /> … … 53 52 <ItemGroup> 54 53 <ClCompile Include="..\monsterz\board.cpp" /> 55 <ClCompile Include="..\monsterz\fusion.cpp" />56 54 <ClCompile Include="..\monsterz\interface.cpp" /> 57 55 <ClCompile Include="..\monsterz\mash.cpp" /> -
trunk/win32/monsterz.vcxproj.filters
r340 r352 89 89 </ClInclude> 90 90 <ClInclude Include="..\monsterz\board.h" /> 91 <ClInclude Include="..\monsterz\fusion.h" />92 91 <ClInclude Include="..\monsterz\interface.h" /> 93 92 <ClInclude Include="..\monsterz\piece.h" /> … … 177 176 </ClCompile> 178 177 <ClCompile Include="..\monsterz\board.cpp" /> 179 <ClCompile Include="..\monsterz\fusion.cpp" />180 178 <ClCompile Include="..\monsterz\interface.cpp" /> 181 179 <ClCompile Include="..\monsterz\monsterz.cpp" />
Note: See TracChangeset
for help on using the changeset viewer.