Changeset 332


Ignore:
Timestamp:
Feb 2, 2011, 1:56:53 AM (10 years ago)
Author:
sam
Message:

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

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/interface.cpp

    r331 r332  
    2020#include "core.h"
    2121#include "interface.h"
     22#include "title.h"
     23#include "board.h"
    2224#include "monsterz.h"
    2325
     
    3133
    3234private:
     35    Title *title;
     36    Board *board;
    3337    int screen, tiles;
     38
     39    enum
     40    {
     41        INIT,
     42        TITLE,
     43        GAME,
     44    }
     45    state;
    3446};
    3547
     
    4153  : data(new InterfaceData())
    4254{
     55    data->title = NULL;
     56    data->board = NULL;
    4357    data->screen = Tiler::Register(PNG_BACKGROUND, 640, 480, 1.0f);
    4458    data->tiles = Tiler::Register(PNG_TILES, 48, 48, 1.0f);
     59    data->state = InterfaceData::INIT;
    4560
    4661    position = int3(0, 0, 1);
    4762    bbox[0] = position;
    4863    bbox[1] = bbox[0] + int3(640, 480, 0);
    49 
    50     Input::TrackMouse(this);
    5164}
    5265
     
    5467{
    5568    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    }
    5690}
    5791
     
    73107Interface::~Interface()
    74108{
     109    if (data->title)
     110        Ticker::Unref(data->title);
     111    if (data->board)
     112        Ticker::Unref(data->board);
    75113    Tiler::Deregister(data->tiles);
    76114    Tiler::Deregister(data->screen);
  • trunk/monsterz/monsterz.cpp

    r331 r332  
    2323#include "core.h"
    2424#include "sdlinput.h"
    25 #include "title.h"
    26 #include "board.h"
    2725#include "interface.h"
    2826
     
    6462    /* Register an input driver and some debug stuff */
    6563    new SdlInput();
    66     new Board(int2(8, 8), 9);
    67     //new Title();
    6864    new Interface();
    6965    new DebugFps(460, 20);
  • trunk/monsterz/title.cpp

    r331 r332  
    7575    data->nextperiod = TitleData::DAY;
    7676    data->timer = RandF(2000.0f, 3000.0f);
     77
     78    position = int3(24, 72, 1);
     79    bbox[0] = position;
     80    bbox[1] = bbox[0] + int3(384, 384, 0);
     81
     82    Input::TrackMouse(this);
    7783}
    7884
     
    207213}
    208214
     215int Title::IsClicked() const
     216{
     217    return clicked[0];
     218}
     219
    209220Title::~Title()
    210221{
     222    Input::UntrackMouse(this);
    211223    Tiler::Deregister(data->logo);
    212224    Tiler::Deregister(data->title);
  • trunk/monsterz/title.h

    r321 r332  
    1717#define __MONSTERZ_TITLE_H__
    1818
     19#include "interface.h"
    1920#include "monsterz.h"
    2021
     
    2627    Title();
    2728    virtual ~Title();
     29
     30    int IsClicked() const;
    2831
    2932protected:
  • trunk/src/input.cpp

    r330 r332  
    3131public:
    3232    InputData()
    33       : mouse(-1, -1),
    34         buttons(0, 0, 0),
    35         nentities(0)
     33      : mouse(-1),
     34        buttons(0),
     35        nentities(0),
     36        lastfocus(0)
    3637    { }
    3738
     
    4344    WorldEntity *entities[MAX_ENTITIES];
    4445    int nentities;
     46    WorldEntity *lastfocus;
    4547}
    4648inputdata;
     
    121123    {
    122124        if (data->entities[n] == best)
     125        {
    123126            data->entities[n]->mousepos = (int2)((int3)coord - best->bbox[0]);
     127            if (best != data->lastfocus)
     128                data->entities[n]->pressed = data->buttons;
     129        }
    124130        else
     131        {
    125132            data->entities[n]->mousepos = int2(-1);
     133            /* FIXME */
     134            data->entities[n]->released = 0;
     135            data->entities[n]->pressed = 0;
     136            data->entities[n]->clicked = 0;
     137        }
    126138    }
     139
     140    data->lastfocus = best;
    127141}
    128142
     
    131145    data->buttons[index] = 1;
    132146
    133     /* FIXME: parse all subscribed entities and update them */
     147    if (data->lastfocus)
     148    {
     149        if (!data->lastfocus->pressed[index])
     150            data->lastfocus->clicked[index] = 1;
     151        data->lastfocus->pressed[index] = 1;
     152        data->lastfocus->released[index] = 0;
     153    }
    134154}
    135155
     
    138158    data->buttons[index] = 0;
    139159
    140     /* FIXME: parse all subscribed entities and update them */
     160    if (data->lastfocus)
     161    {
     162        if (data->lastfocus->pressed[index])
     163            data->lastfocus->released[index] = 1;
     164        data->lastfocus->pressed[index] = 0;
     165        data->lastfocus->clicked[index] = 0;
     166    }
    141167}
    142168
  • trunk/src/worldentity.h

    r329 r332  
    2929    int2 mousepos;
    3030    int3 mousebuttons;
     31    int3 pressed, clicked, released;
    3132
    3233protected:
Note: See TracChangeset for help on using the changeset viewer.