source: trunk/monsterz/interface.cpp @ 759

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

monsterz: get rid of the Fusion mode, it sucked.

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[331]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"
[686]20
21using namespace lol;
22
[331]23#include "interface.h"
[332]24#include "title.h"
25#include "board.h"
[331]26#include "monsterz.h"
27
28/*
29 * Interface implementation class
30 */
31
32class InterfaceData
33{
34    friend class Interface;
35
36private:
[332]37    Title *title;
38    Board *board;
[752]39    int tiles;
[332]40
41    enum
42    {
43        INIT,
44        TITLE,
45        GAME,
46    }
47    state;
[331]48};
49
50/*
51 * Public Interface class
52 */
53
54Interface::Interface()
55  : data(new InterfaceData())
56{
[332]57    data->title = NULL;
58    data->board = NULL;
[633]59    data->tiles = Tiler::Register(PNG_TILES, 48, 0, 1.0f);
[332]60    data->state = InterfaceData::INIT;
[331]61
[664]62    position = vec3i(0, 0, 1);
[331]63    bbox[0] = position;
[664]64    bbox[1] = bbox[0] + vec3i(640, 480, 0);
[331]65}
66
67void Interface::TickGame(float deltams)
68{
69    WorldEntity::TickGame(deltams);
[332]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;
[759]83            data->board = new Board(Board::GAME_HUNT, vec2i(8, 8), 8, 8);
[332]84            Ticker::Ref(data->board);
85            data->state = InterfaceData::GAME;
86        }
87        break;
88    case InterfaceData::GAME:
89        break;
90    }
[331]91}
92
93void Interface::TickDraw(float deltams)
94{
95    WorldEntity::TickDraw(deltams);
96
[664]97    vec2i mouse = Input::GetMousePos();
[331]98
[750]99    if (Platform::GetMouseCount() && mouse.x >= 0 && mouse.y >= 0)
[331]100    {
[664]101        vec2i m = mouse + vec2i(-6, 6 - 48);
[639]102        Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 30, 0);
[331]103    }
104}
105
106Interface::~Interface()
107{
[332]108    if (data->title)
109        Ticker::Unref(data->title);
110    if (data->board)
111        Ticker::Unref(data->board);
[331]112    Tiler::Deregister(data->tiles);
113    delete data;
114}
115
Note: See TracBrowser for help on using the repository browser.