source: trunk/monsterz/interface.cpp @ 639

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

Make font objects use the TileSet system and fix the text objects' Z offset.
Fixes tickets #19 and #24.

  • Property svn:keywords set to Id
File size: 2.6 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 "interface.h"
22#include "title.h"
23#include "board.h"
24#include "monsterz.h"
25
26/*
27 * Interface implementation class
28 */
29
30class InterfaceData
31{
32    friend class Interface;
33
34private:
35    Title *title;
36    Board *board;
37    int screen, tiles;
38
39    enum
40    {
41        INIT,
42        TITLE,
43        GAME,
44    }
45    state;
46};
47
48/*
49 * Public Interface class
50 */
51
52Interface::Interface()
53  : data(new InterfaceData())
54{
55    data->title = NULL;
56    data->board = NULL;
57    data->screen = Tiler::Register(PNG_BACKGROUND, int2(640, 480), 0, 1.0f);
58    data->tiles = Tiler::Register(PNG_TILES, 48, 0, 1.0f);
59    data->state = InterfaceData::INIT;
60
61    position = int3(0, 0, 1);
62    bbox[0] = position;
63    bbox[1] = bbox[0] + int3(640, 480, 0);
64}
65
66void Interface::TickGame(float deltams)
67{
68    WorldEntity::TickGame(deltams);
69
70    switch (data->state)
71    {
72    case InterfaceData::INIT:
73        data->title = new Title();
74        Ticker::Ref(data->title);
75        data->state = InterfaceData::TITLE;
76        break;
77    case InterfaceData::TITLE:
78        if (data->title->IsClicked())
79        {
80            Ticker::Unref(data->title);
81            data->title = NULL;
82            if (rand() & 1)
83                data->board = new Board(Board::GAME_FUSION, int2(6, 8), 3, 12);
84            else
85                data->board = new Board(Board::GAME_HUNT, int2(8, 8), 8, 8);
86            Ticker::Ref(data->board);
87            data->state = InterfaceData::GAME;
88        }
89        break;
90    case InterfaceData::GAME:
91        break;
92    }
93}
94
95void Interface::TickDraw(float deltams)
96{
97    WorldEntity::TickDraw(deltams);
98
99    int2 mouse = Input::GetMousePos();
100
101    Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 10, 0);
102
103    if (mouse.x >= 0 && mouse.y >= 0)
104    {
105        int2 m = mouse + int2(-6, 6 - 48);
106        Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 30, 0);
107    }
108}
109
110Interface::~Interface()
111{
112    if (data->title)
113        Ticker::Unref(data->title);
114    if (data->board)
115        Ticker::Unref(data->board);
116    Tiler::Deregister(data->tiles);
117    Tiler::Deregister(data->screen);
118    delete data;
119}
120
Note: See TracBrowser for help on using the repository browser.