source: trunk/monsterz/interface.cpp @ 686

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

Put everything in the "lol" namespace. Better late than never.

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