Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

GameAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "GameAgent.h"
00010 
00011 #include "StateManager.h"
00012 
00013 #include "Log.h"
00014 #include "WorldMap.h"
00015 #include "InputAgent.h"
00016 #include "KeyStroke.h"
00017 #include "KeyBinder.h"
00018 #include "SimpleMsg.h"
00019 #include "IntMsg.h"
00020 #include "Path.h"
00021 #include "OptionAgent.h"
00022 
00023 #include "SDL.h"
00024 
00025 //-----------------------------------------------------------------
00026     void
00027 GameAgent::own_init()
00028 {
00029     m_manager = new StateManager();
00030     Path pathMap = Path::dataReadPath(OptionAgent::agent()->getParam(
00031                 "worldmap", "script/worldmap.lua"));
00032     WorldMap *worldmap = new WorldMap();
00033     worldmap->initMap(pathMap);
00034     m_manager->pushState(NULL, worldmap);
00035 
00036     keyBinding();
00037 }
00038 //-----------------------------------------------------------------
00039 /**
00040  * Update game.
00041  * Play level or show menu.
00042  */
00043     void
00044 GameAgent::own_update()
00045 {
00046     m_manager->updateGame();
00047 }
00048 //-----------------------------------------------------------------
00049 /**
00050  * Remember playtime.
00051  */
00052     void
00053 GameAgent::own_shutdown()
00054 {
00055     OptionAgent *options = OptionAgent::agent();
00056     int playtime = options->getAsInt("playtime");
00057     playtime += SDL_GetTicks() / 1000;
00058     options->setPersistent("playtime", playtime);
00059 
00060     delete m_manager;
00061 }
00062 
00063 //-----------------------------------------------------------------
00064 /**
00065  * Global keystrokes.
00066  */
00067     void
00068 GameAgent::keyBinding()
00069 {
00070     BaseMsg *msg;
00071     KeyBinder *keyBinder = InputAgent::agent()->keyBinder();
00072 
00073     // fullscreen
00074     KeyStroke fs(SDLK_F11, KMOD_NONE);
00075     msg = new SimpleMsg(Name::VIDEO_NAME, "fullscreen");
00076     keyBinder->addStroke(fs, msg);
00077 
00078     // log
00079     KeyStroke log_plus(SDLK_KP_PLUS, KMOD_RALT);
00080     msg = new SimpleMsg(Name::APP_NAME, "inc_loglevel");
00081     keyBinder->addStroke(log_plus, msg);
00082     KeyStroke log_minus(SDLK_KP_MINUS, KMOD_RALT);
00083     msg = new SimpleMsg(Name::APP_NAME, "dec_loglevel");
00084     keyBinder->addStroke(log_minus, msg);
00085 }
00086 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2