00001
00002
00003
00004
00005
00006
00007
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
00041
00042
00043 void
00044 GameAgent::own_update()
00045 {
00046 m_manager->updateGame();
00047 }
00048
00049
00050
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
00066
00067 void
00068 GameAgent::keyBinding()
00069 {
00070 BaseMsg *msg;
00071 KeyBinder *keyBinder = InputAgent::agent()->keyBinder();
00072
00073
00074 KeyStroke fs(SDLK_F11, KMOD_NONE);
00075 msg = new SimpleMsg(Name::VIDEO_NAME, "fullscreen");
00076 keyBinder->addStroke(fs, msg);
00077
00078
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