source: trunk/monsterz/thumbs.cpp @ 686

Last change on this file since 686 was 686, checked in by sam, 10 years ago

Put everything in the "lol" namespace. Better late than never.

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