source: trunk/monsterz/thumbs.cpp @ 345

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

Change the length of the thumbs list according to the game progress.

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