source: trunk/monsterz/interface.cpp @ 743

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

monsterz: disable the fusion mode for now.

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