source: trunk/monsterz/interface.cpp @ 331

Last change on this file since 331 was 331, checked in by sam, 11 years ago

Add an Interface class that displays the general interface.

  • Property svn:keywords set to Id
File size: 1.5 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 "monsterz.h"
23
24/*
25 * Interface implementation class
26 */
27
28class InterfaceData
29{
30    friend class Interface;
31
32private:
33    int screen, tiles;
34};
35
36/*
37 * Public Interface class
38 */
39
40Interface::Interface()
41  : data(new InterfaceData())
42{
43    data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f);
44    data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
45
46    position = int3(0, 0, 1);
47    bbox[0] = position;
48    bbox[1] = bbox[0] + int3(640, 480, 0);
49
50    Input::TrackMouse(this);
51}
52
53void Interface::TickGame(float deltams)
54{
55    WorldEntity::TickGame(deltams);
56}
57
58void Interface::TickDraw(float deltams)
59{
60    WorldEntity::TickDraw(deltams);
61
62    int2 mouse = Input::GetMousePos();
63
64    Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 10, 0);
65
66    if (mouse.x >= 0 && mouse.y >= 0)
67    {
68        int2 m = mouse + int2(-6, 6 - 48);
69        Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 20, 0);
70    }
71}
72
73Interface::~Interface()
74{
75    Tiler::Deregister(data->tiles);
76    Tiler::Deregister(data->screen);
77    delete data;
78}
79
Note: See TracBrowser for help on using the repository browser.