source: trunk/monsterz/interface.cpp @ 1310

Last change on this file since 1310 was 1310, checked in by sam, 8 years ago

core: tick methods now use seconds, like any sane system.

  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1//
2// Monsterz
3//
4// Copyright: (c) 2005-2012 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    TileSet *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->tiles = Tiler::Register(PNG_TILES, ivec2(48), ivec2(0));
60    data->state = InterfaceData::INIT;
61
62    m_position = ivec3(0, 0, 1);
63    m_bbox[0] = m_position;
64    m_bbox[1] = m_bbox[0] + vec3(640, 480, 0);
65}
66
67void Interface::TickGame(float seconds)
68{
69    WorldEntity::TickGame(seconds);
70
71    switch (data->state)
72    {
73    case InterfaceData::INIT:
74        data->title = new Title();
75        Ticker::Ref(data->title);
76        data->state = InterfaceData::TITLE;
77        break;
78    case InterfaceData::TITLE:
79        if (data->title->IsClicked())
80        {
81            Ticker::Unref(data->title);
82            data->title = NULL;
83            data->board = new Board(Board::GAME_HUNT, ivec2(8, 8), 7, 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 seconds)
94{
95    WorldEntity::TickDraw(seconds);
96
97    ivec3 mouse(Input::GetMousePos(), 0);
98
99    if (Platform::GetMouseCount() && mouse.x >= 0 && mouse.y >= 0)
100    {
101        mouse += ivec3(-6, 6 - 48, 30);
102        Scene::GetDefault()->AddTile(data->tiles, 22, mouse, 0, vec2(1.0f));
103    }
104}
105
106Interface::~Interface()
107{
108    if (data->title)
109        Ticker::Unref(data->title);
110    if (data->board)
111        Ticker::Unref(data->board);
112    Tiler::Deregister(data->tiles);
113    delete data;
114}
115
Note: See TracBrowser for help on using the repository browser.