source: trunk/monsterz/interface.cpp @ 735

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

core: get rid of now useless <cstdio> includes.

  • Property svn:keywords set to Id
File size: 2.6 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;
[331]39    int screen, 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;
[664]59    data->screen = Tiler::Register(PNG_BACKGROUND, vec2i(640, 480), 0, 1.0f);
[633]60    data->tiles = Tiler::Register(PNG_TILES, 48, 0, 1.0f);
[332]61    data->state = InterfaceData::INIT;
[331]62
[664]63    position = vec3i(0, 0, 1);
[331]64    bbox[0] = position;
[664]65    bbox[1] = bbox[0] + vec3i(640, 480, 0);
[331]66}
67
68void Interface::TickGame(float deltams)
69{
70    WorldEntity::TickGame(deltams);
[332]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;
[353]84            if (rand() & 1)
[664]85                data->board = new Board(Board::GAME_FUSION, vec2i(6, 8), 3, 12);
[353]86            else
[664]87                data->board = new Board(Board::GAME_HUNT, vec2i(8, 8), 8, 8);
[332]88            Ticker::Ref(data->board);
89            data->state = InterfaceData::GAME;
90        }
91        break;
92    case InterfaceData::GAME:
93        break;
94    }
[331]95}
96
97void Interface::TickDraw(float deltams)
98{
99    WorldEntity::TickDraw(deltams);
100
[664]101    vec2i mouse = Input::GetMousePos();
[331]102
103    Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 10, 0);
104
105    if (mouse.x >= 0 && mouse.y >= 0)
106    {
[664]107        vec2i m = mouse + vec2i(-6, 6 - 48);
[639]108        Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 30, 0);
[331]109    }
110}
111
112Interface::~Interface()
113{
[332]114    if (data->title)
115        Ticker::Unref(data->title);
116    if (data->board)
117        Ticker::Unref(data->board);
[331]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.