source: trunk/monsterz/interface.cpp @ 352

Last change on this file since 352 was 352, checked in by sam, 12 years ago

Merge the Fusion class back into Board.

  • Property svn:keywords set to Id
File size: 2.5 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, 640, 480, 1.0f);
58    data->tiles = Tiler::Register(PNG_TILES, 48, 48, 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            data->board = new Board(Board::GAME_FUSION, int2(6, 8), 3, 12);
83            //data->board = new Board(Board::GAME_HUNT, int2(8, 8), 8, 8);
84            Ticker::Ref(data->board);
85            data->state = InterfaceData::GAME;
86        }
87        break;
88    case InterfaceData::GAME:
89        break;
90    }
91}
92
93void Interface::TickDraw(float deltams)
94{
95    WorldEntity::TickDraw(deltams);
96
97    int2 mouse = Input::GetMousePos();
98
99    Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 10, 0);
100
101    if (mouse.x >= 0 && mouse.y >= 0)
102    {
103        int2 m = mouse + int2(-6, 6 - 48);
104        Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 20, 0);
105    }
106}
107
108Interface::~Interface()
109{
110    if (data->title)
111        Ticker::Unref(data->title);
112    if (data->board)
113        Ticker::Unref(data->board);
114    Tiler::Deregister(data->tiles);
115    Tiler::Deregister(data->screen);
116    delete data;
117}
118
Note: See TracBrowser for help on using the repository browser.