source: trunk/monsterz/title.cpp @ 321

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

Prepare the code architecture for the title screen animations.

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#include "monsterz.h"
22#include "title.h"
23
24/*
25 * Title implementation class
26 */
27
28class TitleData
29{
30    friend class Title;
31
32private:
33    int screen, title;
34    int anim[6];
35    int event[7];
36
37    enum
38    {
39        IDLE,
40        ANIM,
41        EVENT,
42    }
43    state;
44
45    enum
46    {
47        DAY,
48        NIGHT,
49        STEALTH,
50        RADIO,
51    }
52    period, nextperiod;
53
54    float timer;
55};
56
57/*
58 * Public Title class
59 */
60
61Title::Title()
62  : data(new TitleData())
63{
64    data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f);
65    data->title = Tiler::Register(PNG_TITLE, 384, 384, 1.0f);
66    for (int n = 0; n < 6; n++)
67        data->anim[n] = Tiler::Register(PNG_TITLEANIM[n], 384, 384, 1.0f);
68    for (int n = 0; n < 7; n++)
69        data->event[n] = Tiler::Register(PNG_TITLEEVENT[n], 384, 384, 1.0f);
70    data->state = TitleData::IDLE;
71    data->period = TitleData::DAY;
72    data->nextperiod = TitleData::DAY;
73    data->timer = 0.0f;
74}
75
76void Title::TickGame(float deltams)
77{
78    Entity::TickGame(deltams);
79
80    switch (data->state)
81    {
82    case TitleData::IDLE:
83    case TitleData::ANIM:
84    case TitleData::EVENT:
85        break;
86    }
87}
88
89void Title::TickDraw(float deltams)
90{
91    Entity::TickDraw(deltams);
92
93    int tiler = data->title;
94    int id = 0;
95
96    switch (data->state)
97    {
98    case TitleData::IDLE:
99        id = (int)data->period;
100        break;
101    case TitleData::ANIM:
102    case TitleData::EVENT:
103        break;
104    }
105
106    Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 0, 0);
107    Scene::GetDefault()->AddTile((tiler << 16) | id, 24, 72, 1, 0);
108}
109
110Title::~Title()
111{
112    Tiler::Deregister(data->screen);
113    Tiler::Deregister(data->title);
114    for (int n = 0; n < 6; n++)
115        Tiler::Deregister(data->anim[n]);
116    for (int n = 0; n < 7; n++)
117        Tiler::Deregister(data->event[n]);
118    delete data;
119}
120
Note: See TracBrowser for help on using the repository browser.