source: trunk/monsterz/interface.cpp @ 332

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

Implement the title screen. Click on it to start a game.

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