source: trunk/monsterz/interface.cpp @ 339

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

Start working on a new gameplay, codenamed "Fusion".

  • 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#include "interface.h"
22#include "title.h"
23#include "board.h"
24#include "fusion.h"
25#include "monsterz.h"
26
27/*
28 * Interface implementation class
29 */
30
31class InterfaceData
32{
33    friend class Interface;
34
35private:
36    Title *title;
37    Board *board;
38    Fusion *fusion;
39    int screen, 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->fusion = NULL;
60    data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f);
61    data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
62    data->state = InterfaceData::INIT;
63
64    position = int3(0, 0, 1);
65    bbox[0] = position;
66    bbox[1] = bbox[0] + int3(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            data->fusion = new Fusion(int2(6, 8), 8);
86            Ticker::Ref(data->fusion);
87#if 0
88            data->board = new Board(int2(8, 8), 8);
89            Ticker::Ref(data->board);
90#endif
91            data->state = InterfaceData::GAME;
92        }
93        break;
94    case InterfaceData::GAME:
95        break;
96    }
97}
98
99void Interface::TickDraw(float deltams)
100{
101    WorldEntity::TickDraw(deltams);
102
103    int2 mouse = Input::GetMousePos();
104
105    Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 10, 0);
106
107    if (mouse.x >= 0 && mouse.y >= 0)
108    {
109        int2 m = mouse + int2(-6, 6 - 48);
110        Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 20, 0);
111    }
112}
113
114Interface::~Interface()
115{
116    if (data->title)
117        Ticker::Unref(data->title);
118    if (data->board)
119        Ticker::Unref(data->board);
120    if (data->fusion)
121        Ticker::Unref(data->fusion);
122    Tiler::Deregister(data->tiles);
123    Tiler::Deregister(data->screen);
124    delete data;
125}
126
Note: See TracBrowser for help on using the repository browser.