[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 <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 | |
---|
| 28 | class InterfaceData |
---|
| 29 | { |
---|
| 30 | friend class Interface; |
---|
| 31 | |
---|
| 32 | private: |
---|
| 33 | int screen, tiles; |
---|
| 34 | }; |
---|
| 35 | |
---|
| 36 | /* |
---|
| 37 | * Public Interface class |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | Interface::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 | |
---|
| 53 | void Interface::TickGame(float deltams) |
---|
| 54 | { |
---|
| 55 | WorldEntity::TickGame(deltams); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void 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 | |
---|
| 73 | Interface::~Interface() |
---|
| 74 | { |
---|
| 75 | Tiler::Deregister(data->tiles); |
---|
| 76 | Tiler::Deregister(data->screen); |
---|
| 77 | delete data; |
---|
| 78 | } |
---|
| 79 | |
---|