view controler.cc.orig @ 122:5219bf3d5e71

title_draw
author e085768
date Mon, 27 Jun 2011 19:44:46 +0900
parents 411ba68e9cf8
children
line wrap: on
line source

/* controler.c */

#include "libps2.h"
#include "ps2util.h"
#include "controler.h"
#include <stdbool.h>
#include <SDL.h>

#include "matrix_calc.h"
#include "TaskManager.h"
#include "SceneGraph.h"
#include "Application.h"

#include "sjoy.h" // ps2関連ファイルから


//キー入力変数
struct SGO_PAD pad;

/*
  SgoexCerium をみながら、改変。
  引数を追加して、変数名以外の書き方を似せた
*/
bool padCheck(SDL_Joystick *joy) {

  SDL_JoystickUpdate();

  if (SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED) {
    pad.st += (pad.st < 2) ? 1 : 0;
  } else {
    pad.st = 0;
  }

  if (SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) {
    pad.se += (pad.se < 2) ? 1 : 0;
  } else {
    pad.se = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_LEFT)==SDL_PRESSED) { 
    pad.left += (pad.left < 2) ? 1 : 0;
  } else {
    pad.left = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_RIGHT)==SDL_PRESSED) {  
    pad.right += (pad.right < 2) ? 1 : 0;
  } else {
    pad.right = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_UP)==SDL_PRESSED) {  
    pad.up += (pad.up < 2) ? 1 : 0;
  } else {
    pad.up = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_DOWN)==SDL_PRESSED) {
    pad.down += (pad.down < 2) ? 1 : 0;
  } else {
    pad.down = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED) { 
    pad.r1 += (pad.r1 < 2) ? 1 : 0;
  } else {
    pad.r1 = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED) {  
    pad.r2 += (pad.r2 < 2) ? 1 : 0;
  } else {
    pad.r2 = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED) {
    pad.l1 += (pad.l1 < 2) ? 1 : 0;
  } else {
    pad.l1 = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED) { 
    pad.l2 += (pad.l2 < 2) ? 1 : 0;
  } else {
    pad.l2 = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_CROSS)==SDL_PRESSED) {  
    pad.cross += (pad.cross < 2) ? 1 : 0;
  } else {
    pad.cross = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_CIRCLE)==SDL_PRESSED) {
    pad.circle += (pad.circle < 2) ? 1 : 0;
  } else {
    pad.circle = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_TRIANGLE)==SDL_PRESSED) {
    pad.triangle += (pad.triangle < 2) ? 1 : 0;
  } else {
    pad.triangle = 0;
  }
  if (SDL_JoystickGetButton(joy,PS2_SQUARE)==SDL_PRESSED) {
    pad.square += (pad.square < 2) ? 1 : 0;
  } else {
    pad.square = 0;
  }

  if ( (SDL_JoystickGetButton(joy,PS2_SELECT)==SDL_PRESSED) 
       && (SDL_JoystickGetButton(joy,PS2_START)==SDL_PRESSED)
       && (SDL_JoystickGetButton(joy,PS2_L1)==SDL_PRESSED)
       && (SDL_JoystickGetButton(joy,PS2_R1)==SDL_PRESSED)
       && (SDL_JoystickGetButton(joy,PS2_L2)==SDL_PRESSED)
       && (SDL_JoystickGetButton(joy,PS2_R2)==SDL_PRESSED)
  ){
    return false;
  }


  return true;
}


bool keybord()
{
  SDL_PumpEvents();
  Uint8 *keys = SDL_GetKeyState(NULL);

  printf("key--\n");

  if (keys[SDLK_UP]) {
    pad.up += (pad.up < 2) ? 1 : 0;
  } else {
    pad.up = 0;
  }
  if (keys[SDLK_DOWN]) {
    pad.down += (pad.down < 2) ? 1 : 0;
  } else {
    pad.down = 0;
  }

  if (keys[SDLK_RIGHT]) {
    pad.right += (pad.right < 2) ? 1 : 0;
  } else {
    pad.right = 0;
  }

  if (keys[SDLK_LEFT]) {
    pad.left += (pad.left < 2) ? 1 : 0;
  } else {
    pad.left = 0;
  }

  if (keys[SDLK_a]) {
    pad.cross += (pad.cross < 2) ? 1 : 0;
  } else {
    pad.cross = 0;
  }

  if (keys[SDLK_z]) {
    pad.circle += (pad.circle < 2) ? 1 : 0;
  } else {
    pad.circle = 0;
  }

  if (keys[SDLK_s]) {
    pad.square += (pad.square < 2) ? 1 : 0;
  } else {
    pad.square = 0;
  }
    
  if (keys[SDLK_x]) {
    pad.triangle += (pad.triangle < 2) ? 1 : 0;
  } else {
    pad.triangle = 0;
  }

  if (keys[SDLK_r]) {
    pad.r2 += (pad.r2 < 2) ? 1 : 0;
  } else {
    pad.r2 = 0;
  }

  if (keys[SDLK_e]) {
    pad.r1 += (pad.r1 < 2) ? 1 : 0;
  } else {
    pad.r1 = 0;
  }

  if (keys[SDLK_w]) {
    pad.l1 += (pad.l1 < 2) ? 1 : 0;
  } else {
    pad.l1 = 0;
  }

  if (keys[SDLK_q]) {
    pad.l1 += (pad.l2 < 2) ? 1 : 0;
  } else {
    pad.l2 = 0;
  }

  // START ボタンは Return が似合う気がする
  //if(keys[SDLK_1])
  if (keys[SDLK_RETURN]) {
    pad.st += (pad.st < 2) ? 1 : 0;
  } else {
    pad.st = 0;
  }

  if (keys[SDLK_2]) {
    pad.se += (pad.se < 2) ? 1 : 0;
  } else {
    pad.se = 0;
  }

  if (keys[SDLK_ESCAPE]) {
    SDL_Quit();
    exit(1);
    //pad[0].st = 1;
    //pad[0].se = 1;
  }

  //SELECT, START, L1, R1, L2, R2
  if ( (keys[SDLK_2])
       && (keys[SDLK_RETURN]) 
       && (keys[SDLK_w])
       && (keys[SDLK_e])
       && (keys[SDLK_q])
       && (keys[SDLK_r])
       ){
    return false;
  }
    
  return true;
}