source: trunk/monsterz/thumbs.cpp @ 792

Last change on this file since 792 was 792, checked in by sam, 9 years ago

tiler: ensure AddTile() and BlitTile() accept vec3i arguments.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
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"
20
21using namespace lol;
22
23#include "thumbs.h"
24#include "monsterz.h"
25
26/*
27 * Thumbs implementation class
28 */
29
30class ThumbsData
31{
32    friend class Thumbs;
33
34private:
35    TileSet *icons;
36    int npieces;
37
38    Text *text[MAX_PIECES];
39    int count[MAX_PIECES];
40};
41
42/*
43 * Public Thumbs class
44 */
45
46Thumbs::Thumbs(int npieces)
47  : data(new ThumbsData())
48{
49    data->icons = Tiler::Register(PNG_ICONS, 24, 0, 1.0f);
50
51    data->npieces = 0;
52    SetMax(npieces);
53
54#if 0
55    position = vec3i(24, 72, 1);
56    bbox[0] = position;
57    bbox[1] = bbox[0] + vec3i(384, 384, 0);
58#endif
59}
60
61void 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
69void Thumbs::TickDraw(float deltams)
70{
71    Entity::TickDraw(deltams);
72
73    for (int n = 0; n < data->npieces; n++)
74    {
75        vec3i p = vec3i(459, 372 - 27 * n, 11);
76        Scene::GetDefault()->AddTile(data->icons, n, p, 0);
77    }
78}
79
80void 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]);
90        vec3i p = vec3i(492, 374 - 27 * n, 20);
91        data->text[n]->SetPos(p);
92    }
93
94    data->npieces = npieces;
95}
96
97void Thumbs::AddCount(int id, int count)
98{
99    if (id > 0 && id <= data->npieces)
100        data->count[id - 1] += count;
101}
102
103int 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
111Thumbs::~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
Note: See TracBrowser for help on using the repository browser.