[331] | 1 | // |
---|
| 2 | // Monsterz |
---|
| 3 | // |
---|
| 4 | // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|
| 5 | // This program is free software; you can redistribute it and/or |
---|
| 6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
| 7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
| 8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
| 9 | // |
---|
| 10 | |
---|
| 11 | #if defined HAVE_CONFIG_H |
---|
| 12 | # include "config.h" |
---|
| 13 | #endif |
---|
| 14 | |
---|
| 15 | #include <cmath> |
---|
| 16 | #include <cstdlib> |
---|
| 17 | #include <ctime> |
---|
| 18 | |
---|
| 19 | #include "core.h" |
---|
[686] | 20 | |
---|
| 21 | using namespace lol; |
---|
| 22 | |
---|
[331] | 23 | #include "interface.h" |
---|
[332] | 24 | #include "title.h" |
---|
| 25 | #include "board.h" |
---|
[331] | 26 | #include "monsterz.h" |
---|
| 27 | |
---|
| 28 | /* |
---|
| 29 | * Interface implementation class |
---|
| 30 | */ |
---|
| 31 | |
---|
| 32 | class InterfaceData |
---|
| 33 | { |
---|
| 34 | friend class Interface; |
---|
| 35 | |
---|
| 36 | private: |
---|
[332] | 37 | Title *title; |
---|
| 38 | Board *board; |
---|
[790] | 39 | TileSet *tiles; |
---|
[332] | 40 | |
---|
| 41 | enum |
---|
| 42 | { |
---|
| 43 | INIT, |
---|
| 44 | TITLE, |
---|
| 45 | GAME, |
---|
| 46 | } |
---|
| 47 | state; |
---|
[331] | 48 | }; |
---|
| 49 | |
---|
| 50 | /* |
---|
| 51 | * Public Interface class |
---|
| 52 | */ |
---|
| 53 | |
---|
| 54 | Interface::Interface() |
---|
| 55 | : data(new InterfaceData()) |
---|
| 56 | { |
---|
[332] | 57 | data->title = NULL; |
---|
| 58 | data->board = NULL; |
---|
[633] | 59 | data->tiles = Tiler::Register(PNG_TILES, 48, 0, 1.0f); |
---|
[332] | 60 | data->state = InterfaceData::INIT; |
---|
[331] | 61 | |
---|
[866] | 62 | position = ivec3(0, 0, 1); |
---|
[331] | 63 | bbox[0] = position; |
---|
[866] | 64 | bbox[1] = bbox[0] + ivec3(640, 480, 0); |
---|
[331] | 65 | } |
---|
| 66 | |
---|
| 67 | void Interface::TickGame(float deltams) |
---|
| 68 | { |
---|
| 69 | WorldEntity::TickGame(deltams); |
---|
[332] | 70 | |
---|
| 71 | switch (data->state) |
---|
| 72 | { |
---|
| 73 | case InterfaceData::INIT: |
---|
| 74 | data->title = new Title(); |
---|
| 75 | Ticker::Ref(data->title); |
---|
| 76 | data->state = InterfaceData::TITLE; |
---|
| 77 | break; |
---|
| 78 | case InterfaceData::TITLE: |
---|
| 79 | if (data->title->IsClicked()) |
---|
| 80 | { |
---|
| 81 | Ticker::Unref(data->title); |
---|
| 82 | data->title = NULL; |
---|
[863] | 83 | data->board = new Board(Board::GAME_HUNT, ivec2(8, 8), 7, 8); |
---|
[332] | 84 | Ticker::Ref(data->board); |
---|
| 85 | data->state = InterfaceData::GAME; |
---|
| 86 | } |
---|
| 87 | break; |
---|
| 88 | case InterfaceData::GAME: |
---|
| 89 | break; |
---|
| 90 | } |
---|
[331] | 91 | } |
---|
| 92 | |
---|
| 93 | void Interface::TickDraw(float deltams) |
---|
| 94 | { |
---|
| 95 | WorldEntity::TickDraw(deltams); |
---|
| 96 | |
---|
[866] | 97 | ivec3 mouse(Input::GetMousePos()); |
---|
[331] | 98 | |
---|
[750] | 99 | if (Platform::GetMouseCount() && mouse.x >= 0 && mouse.y >= 0) |
---|
[331] | 100 | { |
---|
[866] | 101 | mouse += ivec3(-6, 6 - 48, 30); |
---|
[816] | 102 | Scene::GetDefault()->AddTile(data->tiles, 22, mouse, 0); |
---|
[331] | 103 | } |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | Interface::~Interface() |
---|
| 107 | { |
---|
[332] | 108 | if (data->title) |
---|
| 109 | Ticker::Unref(data->title); |
---|
| 110 | if (data->board) |
---|
| 111 | Ticker::Unref(data->board); |
---|
[331] | 112 | Tiler::Deregister(data->tiles); |
---|
| 113 | delete data; |
---|
| 114 | } |
---|
| 115 | |
---|