[340] | 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 | |
---|
[340] | 23 | #include "thumbs.h" |
---|
| 24 | #include "monsterz.h" |
---|
| 25 | |
---|
| 26 | /* |
---|
| 27 | * Thumbs implementation class |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | class ThumbsData |
---|
| 31 | { |
---|
| 32 | friend class Thumbs; |
---|
| 33 | |
---|
| 34 | private: |
---|
[790] | 35 | TileSet *icons; |
---|
[340] | 36 | int npieces; |
---|
| 37 | |
---|
| 38 | Text *text[MAX_PIECES]; |
---|
| 39 | int count[MAX_PIECES]; |
---|
| 40 | }; |
---|
| 41 | |
---|
| 42 | /* |
---|
| 43 | * Public Thumbs class |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | Thumbs::Thumbs(int npieces) |
---|
| 47 | : data(new ThumbsData()) |
---|
| 48 | { |
---|
[633] | 49 | data->icons = Tiler::Register(PNG_ICONS, 24, 0, 1.0f); |
---|
[340] | 50 | |
---|
[345] | 51 | data->npieces = 0; |
---|
| 52 | SetMax(npieces); |
---|
[340] | 53 | |
---|
| 54 | #if 0 |
---|
[866] | 55 | position = ivec3(24, 72, 1); |
---|
[340] | 56 | bbox[0] = position; |
---|
[866] | 57 | bbox[1] = bbox[0] + ivec3(384, 384, 0); |
---|
[340] | 58 | #endif |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void Thumbs::TickGame(float deltams) |
---|
| 62 | { |
---|
| 63 | Entity::TickGame(deltams); |
---|
| 64 | |
---|
| 65 | for (int n = 0; n < data->npieces; n++) |
---|
| 66 | data->text[n]->SetInt(data->count[n]); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | void Thumbs::TickDraw(float deltams) |
---|
| 70 | { |
---|
| 71 | Entity::TickDraw(deltams); |
---|
| 72 | |
---|
| 73 | for (int n = 0; n < data->npieces; n++) |
---|
| 74 | { |
---|
[866] | 75 | ivec3 p = ivec3(459, 372 - 27 * n, 11); |
---|
[792] | 76 | Scene::GetDefault()->AddTile(data->icons, n, p, 0); |
---|
[340] | 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
[345] | 80 | void Thumbs::SetMax(int npieces) |
---|
| 81 | { |
---|
| 82 | for (int n = npieces; n < data->npieces; n++) |
---|
| 83 | Ticker::Unref(data->text[n]); |
---|
| 84 | |
---|
| 85 | for (int n = data->npieces; n < npieces; n++) |
---|
| 86 | { |
---|
| 87 | data->count[n] = 0; |
---|
| 88 | data->text[n] = new Text(NULL, "monsterz/gfx/font1.png"); |
---|
| 89 | Ticker::Ref(data->text[n]); |
---|
[866] | 90 | ivec3 p = ivec3(492, 374 - 27 * n, 20); |
---|
[345] | 91 | data->text[n]->SetPos(p); |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | data->npieces = npieces; |
---|
| 95 | } |
---|
| 96 | |
---|
[340] | 97 | void Thumbs::AddCount(int id, int count) |
---|
| 98 | { |
---|
[348] | 99 | if (id > 0 && id <= data->npieces) |
---|
| 100 | data->count[id - 1] += count; |
---|
[340] | 101 | } |
---|
| 102 | |
---|
[348] | 103 | int Thumbs::GetCount(int id) |
---|
| 104 | { |
---|
| 105 | if (id > 0 && id <= data->npieces) |
---|
| 106 | return data->count[id - 1]; |
---|
| 107 | else |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
[340] | 111 | Thumbs::~Thumbs() |
---|
| 112 | { |
---|
| 113 | for (int n = 0; n < data->npieces; n++) |
---|
| 114 | Ticker::Unref(data->text[n]); |
---|
| 115 | Tiler::Deregister(data->icons); |
---|
| 116 | delete data; |
---|
| 117 | } |
---|
| 118 | |
---|