using std::cout;
using std::endl;
-int returnSet(int& value, int action2 = 0);
+
void Events::processEvents()
break;
}
case SDL_WINDOWEVENT:
- {
switch (sdl_event.window.event)
{
case SDL_WINDOWEVENT_FOCUS_GAINED:
- {
window_focus = true;
Graphix::catchMouse();
break;
- }
case SDL_WINDOWEVENT_FOCUS_LOST:
- {
window_focus = false;
Graphix::freeMouse();
break;
- }
case SDL_WINDOWEVENT_RESIZED:
- {
Graphix::setWindowSize(sdl_event.window.data1, sdl_event.window.data2);
break;
- }
default:
break;
}
break;
- }
- case SDL_KEYDOWN:{
+ case SDL_KEYDOWN:
if (sdl_event.key.keysym.sym == SDLK_ESCAPE)
{
- quit = true;
+ quit = true; //TODO nicht gleich alles beenden bei Escape
+ halt = true;
}
- key_held[sdl_event.key.keysym.sym]=true;
+ if (!isKHeld(sdl_event.key.keysym.sym))
+ KeyDown(sdl_event.key.keysym.sym);
+
+ key_held[sdl_event.key.keysym.sym] = true;
break;
- }
- case SDL_KEYUP:{
+ case SDL_KEYUP:
+ KeyUp(sdl_event.key.keysym.sym);
key_held[sdl_event.key.keysym.sym]=false;
- fKey(sdl_event.key.keysym.sym);
break;
- }
- case SDL_MOUSEMOTION:{
+ case SDL_MOUSEMOTION:
if (window_focus)
mousemotion(sdl_event.motion);
break;
- }
- case SDL_MOUSEBUTTONDOWN:{
- if (sdl_event.button.button == SDL_BUTTON_LEFT)
- {
- action1++;
- }
- if (sdl_event.button.button == SDL_BUTTON_RIGHT)
- {
- action2++;
- }
+ case SDL_MOUSEBUTTONDOWN:
+ MouseDown(sdl_event.button.button);
+ mouse_held[sdl_event.button.button] = true;
+ break;
+ case SDL_MOUSEBUTTONUP:
+ MouseUp(sdl_event.button.button);
+ mouse_held[sdl_event.button.button] = false;
break;
- }
default:
break;
}
//if (sdl_motion.x!=400 && sdl_motion.y!=200)
{
- mouse_x = sdl_motion.xrel;
- mouse_y = sdl_motion.yrel;
+ view_x = sdl_motion.xrel;
+ view_y = sdl_motion.yrel;
SDL_WarpMouseInWindow(NULL, Graphix::getWindowWidth() / 2, Graphix::getWindowHeight() / 2);
}
}
-void Events::fKey(int _key)
+void Events::KeyDown(int _key)
{
switch (_key)
{
case SDLK_F10:
//???
break;
+ case SDLK_SPACE:
+ jump++;
+ break;
+ case SDLK_LSHIFT:
+ timeshift = true;
+ break;
+ default:
+ break;
+ }
+}
+
+void Events::KeyUp(int _key)
+{
+ switch (_key)
+ {
+ case SDLK_LSHIFT:
+ timeshift = false;
+ break;
+ default:
+ break;
+ }
+}
+
+void Events::MouseDown(int _key)
+{
+ switch (_key)
+ {
+ case SDL_BUTTON_LEFT:
+ jump++;
+ break;
+ case SDL_BUTTON_RIGHT:
+ timeshift = true;
+ break;
+ default:
+ break;
+ }
+}
+
+void Events::MouseUp(int _key)
+{
+ switch (_key)
+ {
+ case SDL_BUTTON_RIGHT:
+ timeshift = false;
+ break;
default:
break;
}
void Events::keymotion()
{
- axis(view_x, SDLK_w, SDLK_s);
- axis(view_y, SDLK_a, SDLK_d);
- axis(view_z, SDLK_e, SDLK_q);
+ axis(move_x, SDLK_w, SDLK_s);
+ axis(move_y, SDLK_a, SDLK_d);
}
void Events::padmotion()
int Events::getViewX()
{
- return view_x;
+ return returnSet(view_x);
}
int Events::getViewY()
{
- return view_y;
+ return returnSet(view_y);
}
-int Events::getViewZ()
-{
- return view_z;
-}
-int Events::getMouseX()
+int Events::getMoveX()
{
- return returnSet(mouse_x);
+ return move_x;
}
-int Events::getMouseY()
+int Events::getMoveY()
{
- return returnSet(mouse_y);
+ return move_y;
}
-int Events::getAction1()
+int Events::getJump()
{
- return returnSet(action1);
+ return returnSet(jump);
}
-int Events::getAction2()
+bool Events::getTimeShift()
{
- return returnSet(action2);
+ return timeshift;
}
-bool Events::isHeld(int const _key)
+bool Events::isKHeld(int const _key)
{
return key_held[_key];
}
+bool Events::isMHeld(int const _key)
+{
+ return mouse_held[_key];
+}
+
-int returnSet(int& value, int action2)
+int Events::returnSet(int& value, int action2)
{
int tmp = value;
value = action2;
int Events::view_x = 0;
int Events::view_y = 0;
-int Events::view_z = 0;
-int Events::mouse_x = 0;
-int Events::mouse_y = 0;
+int Events::move_x = 0;
+int Events::move_y = 0;
-int Events::action1 = 0;
-int Events::action2 = 0;
+int Events::jump = 0;
+bool Events::timeshift = false;
bool Events::quit = false;
+bool Events::halt = false;
+
bool Events::window_focus = true;
//virtual void keydown(SDL_Keycode sdl_event);
bool static quit;
+ bool static halt;
bool static window_focus;
int static getViewX();
int static getViewY();
- int static getViewZ();
- int static getMouseX();
- int static getMouseY();
+ int static getMoveX();
+ int static getMoveY();
- int static getAction1();
- int static getAction2();
+ int static getJump();
+ bool static getTimeShift();
- bool static isHeld(int const);
+ bool static isKHeld(int const);
+ bool static isMHeld(int const);
private:
void static keymotion();
void static padmotion();
- void static fKey(int);
+ void static KeyDown(int);
+ void static KeyUp(int);
+
+ void static MouseDown(int);
+ void static MouseUp(int);
void static axis(int&, int, int);
+ int static returnSet(int& value, int action2 = 0);
+
//const Uint8* keymap;
map<int, bool> static key_held;
map<int, bool> static mouse_held;
int static view_x;
int static view_y;
- int static view_z;
- int static mouse_x;
- int static mouse_y;
+ int static move_x;
+ int static move_y;
- int static action1;
- int static action2;
+ int static jump;
+ bool static timeshift;
};
{
Message::error("GameOver");
}
- int move_x = Events::getMouseX();
- int move_y = Events::getMouseY();
- int shoot = Events::getAction1();
- int reset = Events::getAction2();
+ int move_x = Events::getMoveX();
+ int move_y = Events::getMoveY();
+ //int shoot = Events::getAction1();
+ //int reset = Events::getAction2();
//cout << move_x << " " << move_y << endl;
lookat->turn(0.3f *move_x, vec3(0.f, 1.f, 0.f));
if (move_y)
lookat->turn(0.3f *move_y, vec3(1.f, 0.f, 0.f));
- if (shoot)
- {
- vec3 direction = lookat->push(vec3(0.f, 0.f, shoot*0.1f));
- //SceneObjects->push_back(self->copy();)
- }
- if (reset)
- lookat->stop();
+ //if (shoot)
+ //{
+ // vec3 direction = lookat->push(vec3(0.f, 0.f, shoot*0.1f));
+ // //SceneObjects->push_back(self->copy();)
+ //}
+ //if (reset)
+ // lookat->stop();
// XYAchse um den Player
if (Events::getViewX() || Events::getViewY())
}
- // Zoom auf Player
- if (Events::getViewZ())
- {
- // float dist = 0;
- // if (lookat!=NULL)
- // dist = VektorAbs(getViewerPos() - lookat->getPosition());
- // if (true)
- view = translate( vec3(0.f,0.f,(float)(5*deltaT *sign(Events::getViewZ()))))*view;
- //view = view*scale(vec3((float)(1 + deltaT * sign(Events::getViewZ()))));
- }
+ //// Zoom auf Player
+ //if (Events::getViewZ())
+ //{
+ //// float dist = 0;
+ //// if (lookat!=NULL)
+ //// dist = VektorAbs(getViewerPos() - lookat->getPosition());
+ //// if (true)
+ // view = translate( vec3(0.f,0.f,(float)(5*deltaT *sign(Events::getViewZ()))))*view;
+ // //view = view*scale(vec3((float)(1 + deltaT * sign(Events::getViewZ()))));
+ //}
if (lookat != NULL)
pos = lookat->getPosition();