// // Monsterz // // Copyright: (c) 2005-2011 Sam Hocevar // This program is free software; you can redistribute it and/or // modify it under the terms of the Do What The Fuck You Want To // Public License, Version 2, as published by Sam Hocevar. See // http://sam.zoy.org/projects/COPYING.WTFPL for more details. // #if defined HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include #include "core.h" #include "interface.h" #include "title.h" #include "board.h" #include "fusion.h" #include "monsterz.h" /* * Interface implementation class */ class InterfaceData { friend class Interface; private: Title *title; Board *board; Fusion *fusion; int screen, tiles; enum { INIT, TITLE, GAME, } state; }; /* * Public Interface class */ Interface::Interface() : data(new InterfaceData()) { data->title = NULL; data->board = NULL; data->fusion = NULL; data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f); data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f); data->state = InterfaceData::INIT; position = int3(0, 0, 1); bbox[0] = position; bbox[1] = bbox[0] + int3(640, 480, 0); } void Interface::TickGame(float deltams) { WorldEntity::TickGame(deltams); switch (data->state) { case InterfaceData::INIT: data->title = new Title(); Ticker::Ref(data->title); data->state = InterfaceData::TITLE; break; case InterfaceData::TITLE: if (data->title->IsClicked()) { Ticker::Unref(data->title); data->title = NULL; data->fusion = new Fusion(int2(6, 8), 3, 12); Ticker::Ref(data->fusion); #if 0 data->board = new Board(int2(8, 8), 8); Ticker::Ref(data->board); #endif data->state = InterfaceData::GAME; } break; case InterfaceData::GAME: break; } } void Interface::TickDraw(float deltams) { WorldEntity::TickDraw(deltams); int2 mouse = Input::GetMousePos(); Scene::GetDefault()->AddTile((data->screen << 16) | 0, 0, 0, 10, 0); if (mouse.x >= 0 && mouse.y >= 0) { int2 m = mouse + int2(-6, 6 - 48); Scene::GetDefault()->AddTile((data->tiles << 16) | 22, m.x, m.y, 20, 0); } } Interface::~Interface() { if (data->title) Ticker::Unref(data->title); if (data->board) Ticker::Unref(data->board); if (data->fusion) Ticker::Unref(data->fusion); Tiler::Deregister(data->tiles); Tiler::Deregister(data->screen); delete data; }