void Player::OnKeyPressed(sf::Keyboard::Key pressedKey)
{
	if(currentState == DyingState)
	{
		return;
	}

	switch(pressedKey)
	{
		case sf::Keyboard::Up:
			MovePlayer(MoveDirection::Up);
			break;
		case sf::Keyboard::Down:
			MovePlayer(MoveDirection::Down);
			break;
		case sf::Keyboard::Right:
			RotatePlayer(RotationAngle::Clock);
			break;
		case sf::Keyboard::Left:
			RotatePlayer(RotationAngle::Anti);
			break;
		case sf::Keyboard::A:
			RotatePlayer(RotationAngle::Clock);
			break;
		case sf::Keyboard::S:
			RotatePlayer(RotationAngle::Anti);
			break;
		case sf::Keyboard::Space:
			Fire();
			break;
	}
}
Esempio n. 2
0
void MultiSendMsgEnd ()
{
gameData.multigame.msg.nReceiver = 100;
if (!strnicmp (gameData.multigame.msg.szMsg, TXT_NAMES_OFF, 6)) {
	bNameReturning = 1-bNameReturning;
	HUDInitMessage (TXT_NAMERET, bNameReturning? TXT_NR_ACTIVE : TXT_NR_DISABLED);
	}
else if (!strnicmp (gameData.multigame.msg.szMsg, TXT_HANDICAP, 9)) {
	if (HandicapPlayer ())
		return;
	}
else if (!strnicmp (gameData.multigame.msg.szMsg, TXT_BOMBS_OFF, 7))
	netGame.DoSmartMine = 0;
else if (!(gameStates.render.cockpit.bShowPingStats || strnicmp (gameData.multigame.msg.szMsg, TXT_PING, 5))) {
	if (PingPlayer (-1))
		return;
	}
else if (!strnicmp (gameData.multigame.msg.szMsg, TXT_MOVE, 5)) {
	if (MovePlayer ())
		return;
	}
else if (!strnicmp (gameData.multigame.msg.szMsg, TXT_KICK, 5) && (gameData.app.nGameMode & GM_NETWORK)) {
	if (KickPlayer (0))
		return;
	}
else if (!strnicmp (gameData.multigame.msg.szMsg, TXT_BAN, 4) && (gameData.app.nGameMode & GM_NETWORK)) {
	if (KickPlayer (1))
		return;
	}
else
	HUDInitMessage ("%s '%s'", TXT_SENDING, gameData.multigame.msg.szMsg);
MultiSendMessage ();
MultiMessageFeedback ();
MultiSendMsgQuit ();
}
Esempio n. 3
0
int UpdatePlayer(SDL_Renderer *r, Player *p, double frameTime)//, Asteroid *ast)
{

  MovePlayer(r, p);

  p->prevBullet += frameTime;

  p->dest.x += sin(p->angle * PI / 180) * (p->speed * frameTime);

  p->dest.y -= cos(p->angle * PI / 180) * (p->speed * frameTime);

  WrapAround(p);

  for(int i = 0; i < p->bulletIndex; ++i) {
  
    if(UpdateBullet(r, p->b[i], frameTime)) {

      DestroyBullet(p->b[i]);
     
      ShiftBullets(p->b, i, p->bulletIndex);

      p->bulletIndex--;
 
    }

  }

  SDL_RenderCopyEx(r, p->t, NULL, &p->dest, p->angle, NULL, SDL_FLIP_NONE);

  return 0;

}
Esempio n. 4
0
	void PlayerJumpState::Execute(const shared_ptr<Player>& Obj) {
		//ジャンプ中も方向変更可能
		auto PtrBehavior = Obj->GetBehavior<PlayerBehavior>();
		PtrBehavior->MovePlayer();
		auto PtrGrav = Obj->GetBehavior<Gravity>();
		PtrGrav->Execute();
	}
Esempio n. 5
0
	void PlayerOnMoveboxState::Execute(const shared_ptr<Player>& Obj) {
		auto PtrBehavior = Obj->GetBehavior<PlayerBehavior>();
		PtrBehavior->MovePlayer();
		if (!PtrBehavior->OnMoveBox()) {
			Obj->GetStateMachine()->Push(PlayerJumpState::Instance());
		}
	}
Esempio n. 6
0
// This will handle the keyboard processing
void Soko::GameTick(ccTime dt)
{
	// So we don't move while "Level Complete" is on screen
	if (mGameRunning == false)
		return;

	if (mpPlayer->mIsMoving == false)
	{
		// Player moves in steps, so only change his move destination
		// if the key is still down while he is no longer moving
		int dx = 0;
		int dy = 0;
		if (GetAsyncKeyState(VK_UP) & 0x8000)
			dy++;
		else if (GetAsyncKeyState(VK_DOWN) & 0x8000)
			dy--;

		if (GetAsyncKeyState(VK_RIGHT) & 0x8000)
			++dx;
		else if (GetAsyncKeyState(VK_LEFT) & 0x8000)
			--dx;
		
		MovePlayer(dx, dy);
	}
}
Esempio n. 7
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_ESCAPE:
            PostQuitMessage(0);
            break;

        case VK_LEFT:
            TurnPlayer(-500);
            break;

        case VK_RIGHT:
            TurnPlayer(500);
            break;

        case VK_UP:
            MovePlayer(5);
            break;

        case VK_DOWN:
            MovePlayer(-5);
            break;

        case VK_TAB:
            ToggleDebug();
            break;
        }

        break;

    case WM_CLOSE:
        DestroyWindow(g_hwnd);
        break;

    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
}
Esempio n. 8
0
// 게임 로직 처리
void PlayGame() {
  while(!game_quit) {
    Input();
    UpdateGameQuit();
    UpdateTime();
    MovePlayer();
    UseItem();
    MoveEnemy();
    MoveEffect();
    MoveBomb();
    Draw();
  }
}
Esempio n. 9
0
int main()												// Here is our main().
{
    // This is our buffer that will hold all the maze data we wish to display to the screen.
    CHAR_INFO screenBuffer[SCREEN_WIDTH * SCREEN_HEIGHT] = {0};
    COORD bufferSize = {SCREEN_WIDTH , SCREEN_HEIGHT};	// This is a COORD that holds the width and height of our window that we will display
    COORD playerPos = {START_X, START_Y};				// This will hold our players position

    srand( GetTickCount() );							// This seeds our random numbers with time so it isn't always the same maze

    // Below we create our maze with a bunch of random # signs.
    // This just fills in our screen buffer with the data, but DOESN'T draw it yet.
    // It is faster to draw it all at once, rather than using WriteConsoleOutputCharacter().

    for(int y = 0; y < bufferSize.Y; y++)				// This fills in the columns (y value) of our buffer
    {
        // You will notice that we start at x = 2.  This is so we have some room to freely walk around in front of the maze.

        for(int x = 2; x < bufferSize.X; x++)			// This fills in the rows (x value) of our buffer.
        {
            // Below, we fill in the current index with a wall and color.
            if(!(rand() % 3))							// If our random number is 2, then draw a wall in our maze.  This mixes up the maze.
            {
                screenBuffer[x + y * SCREEN_WIDTH].Char.AsciiChar = WALL;
                screenBuffer[x + y * SCREEN_WIDTH].Attributes = FOREGROUND_GREEN;
            }
        }
    }

    // This will draw the player in it's current position, along with the maze.
    // It takes our screen buffer, and the players position to be drawn at.
    // This will draw the initial maze to the screen.
    DrawMaze(screenBuffer, playerPos.X, playerPos.Y);

    // Below is our main loop that check to see if we move the player, and if so, redraw the screen.

    while(1)
    {
        // We pass in our player position because we will change it if we move.
        // If we do move, then we return TRUE from MovePlayer() and we need to redraw the screen.

        if(MovePlayer(screenBuffer, playerPos))
        {
            // Draw the new updated player position within the maze
            DrawMaze(screenBuffer, playerPos.X, playerPos.Y);
        }
    }

    return 0;											// Return with zero problems
}														// End of the program
Esempio n. 10
0
enum ActionMenu StageMain(int *stageState, char *mapName)
{
    static int bgm = - 1;
    static char name[MAX_PATH];
    
    switch (*stageState) {
    case 0:
        map = ReadMap(mapName);
#if !MAP_EDIT_MODE
        GetBgmName(name, mapName);
        bgm = LoadSound(name);
#endif        
        *stageState = 1;
        break;

    case 1:
        {
            InitMap(map);
            CreateObject(map);
            DrawMain = StageDraw;
            LoopSound(bgm);
            *stageState = 2;
        }
        break;

    case 2:
            MoveMap(map);
            MoveEnemy(map);
            MoveItem(map);
            MoveBomb(map);
            MoveEnemy(map);
            MovePlayer(map);
            if (IsPlayerDie()) {
                SoundPlay(res.sound_die);
                life--;
                if (life < 0) {
                    FreeStage(map, stageState, bgm);
                    return MENU_GAMEOVER;
                }
                *stageState = 1;
            }
            if (IsPlayerClear()) {
                FreeStage(map, stageState, bgm);
                return MENU_CLEAR;
            }
            break;
    }
    return MENU_STAGE;
}
void otherPlayer::ContractDir(Edirection DIrr)
{
	int Xdir = 0;
	int Ydir = 0;
	switch (DIrr)
	{
	case E_up:Ydir = -1; break;
	case E_down:Ydir = 1; break;
	case E_left:Xdir = -1; break;
	case E_right:Xdir = 1; break;
	}

	while (!WCR.MapPtr->CheckCollision(BoundBox, x + Xdir, y + Ydir, 1) && !WCR.MapPtr->CheckCollision(BoundBox, x + Xdir, y + Ydir, 0))//only solid objects
		MovePlayer(Xdir, Ydir);
}
Esempio n. 12
0
bool ChatHandler::HandleMoveCommand(const char* args)
{
    char* px = strtok((char*)args, " ");
    char* py = strtok(NULL, " ");
    char* pz = strtok(NULL, " ");

    if (!px || !py || !pz)
        return false;

    float x = (float)atof(px);
    float y = (float)atof(py);
    float z = (float)atof(pz);

    MovePlayer(m_session, x, y, z);

    return true;
}
void ClientSideNetworkedGame::RunNetwork(int msec)
{
	static int time = 0;
	time += msec;

	// Framerate is too high
	if(time < (1000 / 60)) {
        MovePlayer();
		moveRemotePlayers();
		//do we need to move remote players here?? also..

		return;
	}

	frametime = time / 1000.0f;
	time = 0;

	// Read packets from server, and send new commands
	ReadPackets();
	SendCommand();

	int ack = networkClient->GetIncomingAcknowledged();
	int current = networkClient->GetOutgoingSequence();

//iam going to put the following in Game.cpp's game loop...

	// Check that we haven't gone too far
	if(current - ack > COMMAND_HISTORY_SIZE)
		return;

	// Predict the frames that we are waiting from the server
	for(int a = ack + 1; a < current; a++)
	{
		int prevframe = (a-1) & (COMMAND_HISTORY_SIZE-1);
		int frame = a & (COMMAND_HISTORY_SIZE-1);

		PredictMovement(prevframe, frame);
	}
	MoveObjects();
}
void MovementSystem::PlayerTransformations(Scene* scene)
{
	SetPivots(scene);

	glm::mat4 PlayerModel;
	PlayerModel = glm::scale(PlayerModel, glm::vec3(0.15f,0.15f, 0.15f));

	if(CheckCollision(scene))
	{
		PlayerModel = glm::translate(PlayerModel, glm::vec3(scene->getPlayer()->getHorizontalMotion(),scene->getPlayer()->getInitialYPosition(),scene->getPlayer()->getVerticalMotion()));
	}
	else
	{
		PlayerModel = glm::translate(PlayerModel, glm::vec3(scene->getPlayer()->getHorizontalMotion(),scene->getPlayer()->getInitialYPosition()+=scene->getPlayer()->getVelocity(),scene->getPlayer()->getVerticalMotion()));
		//PlayerModel = glm::translate(PlayerModel, glm::vec3(scene->getPlayer()->getHorizontalMotion(),scene->getPlayer()->getInitialYPosition(),scene->getPlayer()->getVerticalMotion()));
	}

	scene->getPlayer()->getModel()->setModelTransformations(PlayerModel);

	MovePlayer(scene->getPlayer()->getHorizontalMotion(),scene->getPlayer()->getInitialYPosition());

}
void otherPlayer::step()
{
//vspeed, hspeed, gravity, haccel, hspeedmax;

	AfterImage.emplace_back(PlayerAnimation.getCurrentSprite());

	//AfterImage[AfterImage.size() - 1].setPosition(x, y);
	//AfterImage[AfterImage.size() - 1].setColor(MyCol);
	//AfterImage[AfterImage.size() - 1].setFillColor(sf::Color::White);
	//after image step
	float frixUse = 0, HAUse = 0;
	if (WCR.MapPtr->CheckCollision(BoundBox, x, y + 1, 5) == 5)
	{
		frixUse = hfricSlip;
		HAUse = haccelSlip;
	}
	else
	{
		frixUse = hfric;
		HAUse = haccel;
	}
		
	int AlphaDec = 50;
	for (int i = 0; i < AfterImage.size(); i++)
	{
		if (AfterImage[i].getColor().a - AlphaDec <= 0)
			AfterImage.erase(AfterImage.begin() + i);
		AfterImage[i].setColor(sf::Color(AfterImage[i].getColor().r, AfterImage[i].getColor().g, AfterImage[i].getColor().b, AfterImage[i].getColor().a - AlphaDec));
	}

	if (xdir_ == -1)
	{
		if (PlayerAnimation.getCurrentAnimationID() != 0)//Not going left.
			PlayerAnimation.setAnimation(0);
		if (!PlayerAnimation.getIsPlaying())
			PlayerAnimation.setPlaying(true);
		if (hspeed - HAUse >= -hspeedmax)
			hspeed -= HAUse;
		else
			hspeed = -hspeedmax;
	}
	else if (xdir_ == 1)
	{
		if (PlayerAnimation.getCurrentAnimationID() != 1)//Not going right.
			PlayerAnimation.setAnimation(1);
		if (!PlayerAnimation.getIsPlaying())
			PlayerAnimation.setPlaying(true);
		if (hspeed + HAUse <= hspeedmax)
			hspeed += HAUse;
		else
			hspeed = hspeedmax;
	}
	else if (hspeed != 0)
	{
		if (PlayerAnimation.getIsPlaying())
		{
			PlayerAnimation.setPlaying(false);
			PlayerAnimation.resetAnimation();
		}
		if (hspeed > 0)
		{
			if (hspeed - frixUse >= 0)
				hspeed -= frixUse;
			else
				hspeed = 0;
		}
		else
		{
			if (hspeed + frixUse <= 0)
				hspeed += frixUse;
			else
				hspeed = 0;
		}

	}
	if (hspeed != 0)
	{
		if (WCR.MapPtr->CheckCollision(BoundBox, x + hspeed, y, 1) || WCR.MapPtr->CheckCollision(BoundBox, x + hspeed, y, 0))
		{
			bool fixed = false;
			if (WCR.MapPtr->CheckCollision(BoundBox, x + hspeed, y, 0) != 1)
			{
				for (int i = 1; i <= 17; i++)//17 because there seems to be a rounding bug?
					if (!WCR.MapPtr->CheckCollision(BoundBox, x + hspeed, y - i, 1))
					{
						fixed = true;
						MovePlayer(hspeed, -i);
						break;
					}
			}
			if (!fixed)
			{
				if (hspeed > 0)
					ContractDir(E_right);//Error?
				else if (hspeed < 0)
					ContractDir(E_left);
				hspeed = 0;
			}
		}
		else
			MovePlayer(hspeed, 0);
	}
	if (falling)
	{
		if (vspeed < 0)
		{
			//WCR.MapPtr->CheckCollision(BoundBox, x + hspeed, y)
			if (WCR.MapPtr->CheckCollision(BoundBox, x, y + vspeed, 1) || WCR.MapPtr->CheckCollision(BoundBox, x, y + vspeed, 0) == 1)
			{
				ContractDir(E_up);
				vspeed = 0;
			}
			else
				MovePlayer(0, vspeed);
		}
		else
		{
			if (WCR.MapPtr->CheckCollision(BoundBox, x, y + vspeed, 1) || WCR.MapPtr->CheckCollision(BoundBox, x, y + vspeed, 0) == 1)
			{
				falling = false;
				vspeed = 0;
				//Contract to ground.
				ContractDir(E_down);
			}
			else
				MovePlayer(0, vspeed);
		}
		if (vspeed + gravity > vspeedMax)
			vspeed = vspeedMax;
		else
			vspeed += gravity;
	}
	else
	{
		if (!WCR.MapPtr->CheckCollision(BoundBox, x, y + 1, 1))//not a solid
			falling = true;
	}
	if (WCR.MapPtr->CheckCollision(BoundBox, x, y, 2) == 2)//Bouncy Block
	{
		vspeed = -15;
		falling = true;
	}

	int STR=20;//How many subdivides of distance.

	if (xAct > 0)//Have to move right
	{
		xAct -= xAct / STR + 1;
		if (xAct < 0)
			xAct = 0;
	}
	if (xAct < 0)//Have to move left
	{
		xAct -= xAct / STR - 1;
		if (xAct > 0)
			xAct = 0;
	}
	if (yAct > 0)//Have to move down
	{
		yAct -= yAct / STR + 1;
		if (yAct < 0)
			yAct = 0;
	}
	if (yAct < 0)//Have to move up
	{
		yAct -= yAct / STR - 1;
		if (yAct > 0)
			yAct = 0;
	}

	for (int i = 0; i < 100; i++)
	{
		if (WCR.MapPtr->CheckCollision(BoundBox, x, y, 1))
			y -= 1;
		else
			break;
	}

	PlayerImage.setPosition(x - xAct, y - yAct);	
	PlayerAnimation.step();
}
Esempio n. 16
0
int main(int argc, char **argv)
{
	const SDL_Color whitecol = {255,255,255,255};

	srand(time(NULL));	// a quick 'n dirty way of initializing random seed

	// load scores
#ifdef WINDOWS
	FILE *scorefil = fopen("score.dat","rb");
#else
	char filen[256];
	snprintf(filen,256,"%s/.nasuscore",getenv("HOME"));
	FILE *scorefil = fopen(filen,"rb");
	chdir("/usr/share/games/nasu");
#endif
	if ( scorefil == NULL )
		score = 0;
	else
	{
		fread((void *)&score,sizeof(unsigned long int),1,scorefil);
		fclose(scorefil);
	}

	// parameter parsing
	// -fullscreen specifies that the game is fullscreen
	// -res WxH specifies resolution
	// -noscale does not scale virtual screen
	float ScreenMult = 2;
	int resx = 640, resy = 480;
	bool bIsFullscreen = false;
	bool bNoScale = false;
	bool bNoSound = false;
	for ( int i=1; i<argc; i++ )
	{
		if ( strcasecmp(argv[i],"-fullscreen") == 0 )
			bIsFullscreen = true;
		else if ( strcasecmp(argv[i],"-res") == 0 )
		{
			// expect next parameter to be a resolution in format WxH
			if ( argc <= i )
			{
				fprintf(stderr,"Expected video resolution for parameter -res in format WxH\n");
				return 1;
			}
			else
			{
				sscanf(argv[i+1],"%dx%d",&resx,&resy);
				if ( resx < 320 )
					resx = 320;
				if ( resy < 240 )
					resy = 240;
				
			}
		}
		else if ( strcasecmp(argv[i],"-noscale") == 0 )
			bNoScale = true;
		else if ( strcasecmp(argv[i],"-nosound") == 0 )
			bNoSound = true;
	}

	// calculate screen mult based on specified resolution
	int sm[2];
	sm[0] = floor(resx/320);
	sm[1] = floor(resy/240);
	ScreenMult = (sm[0]>sm[1])?sm[1]:sm[0];
	
	if ( bNoScale )
		ScreenMult = 1;

	atexit(savescore);
	if ( SDL_Init(SDL_INIT_EVERYTHING) == -1 )
 	{
		fprintf(stderr,"couldn't initialize SDL (%s)\n", SDL_GetError());
		return 1;
	}

	Uint8 blankcursor = 0;
	Uint8 blankcursormask = 0;
	SDL_Cursor *blankcur = SDL_CreateCursor(&blankcursor,&blankcursormask,1,1,0,0);
	SDL_SetCursor(blankcur);
	
	// load program icon
	SDL_Surface *icone = IMG_Load("nasuicon.png");
	if ( icone != NULL )
		SDL_WM_SetIcon(icone,NULL);
	SDL_WM_SetCaption("NASU","NASU");	// I don't really know why the two parameters but oh well~
	SDL_Surface *mainscreen = NULL;
	// Create window. If SDL can't set a fullscreen mode it'll fall back to windowed
	if ( bIsFullscreen && (SDL_VideoModeOK(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN) != 0) )
		mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN);
	else
	{
		bIsFullscreen = false;
		mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE);
	}

	if ( mainscreen == NULL )
	{
		fprintf(stderr,"couldn't create window (%s)\n", SDL_GetError());
		fflush(stderr);
		return 1;
	}
	SDL_Rect scrrect;
	SDL_GetClipRect(mainscreen,&scrrect);
	
	// real screen that will be resized to fit
	SDL_Surface *_realscreen = SDL_CreateRGBSurface(SDL_SWSURFACE,320,240,mainscreen->format->BitsPerPixel,mainscreen->format->Rmask,mainscreen->format->Gmask,mainscreen->format->Bmask,mainscreen->format->Amask);
	SDL_Surface *realscreen = SDL_DisplayFormatAlpha(_realscreen);
	SDL_FreeSurface(_realscreen);
	
	SDL_Rect rscrrect;
	SDL_GetClipRect(realscreen,&rscrrect);
	
	// load up player
	SDL_Surface *_playersprites = IMG_Load("player.png");
	SDL_Surface *playersprites = SDL_DisplayFormatAlpha(_playersprites);
	SDL_FreeSurface(_playersprites);
	NASU_Player player;
	player.graph = playersprites;
	player.res.w = 24;
	player.res.h = 24;
	player.pivot.x = 12.f;
	player.pivot.y = 12.f;
	player.pos.x = 160.f;
	player.pos.y = 149.f;
	player.vel.x = 0.f;
	player.vel.y = 0.f;
	player.tbox.x1 = -12.f;
	player.tbox.y1 = -4.f;
	player.tbox.x2 = 12.f;
	player.tbox.y2 = 12.f;
	player.dim.w = 24.f;
	player.dim.h = 24.f;
	player.scale = 1;
	player.bIsJumping = false;
	player.animframe = 0;
	player.bLeft = false;
	
	// load up main frame
	SDL_Surface *_mainframeimg = IMG_Load("mainscreen.png");
	SDL_Surface *mainframeimg = SDL_DisplayFormatAlpha(_mainframeimg);
	SDL_FreeSurface(_mainframeimg);
	NASU_Actor mainframe;
	mainframe.graph = mainframeimg;
	mainframe.res.w = 320;
	mainframe.res.h = 240;
	mainframe.pivot.x = 0.f;
	mainframe.pivot.y = 0.f;
	mainframe.pos.x = 0.f;
	mainframe.pos.y = 0.f;
	mainframe.vel.x = 0.f;
	mainframe.vel.y = 0.f;
	mainframe.tbox.x1 = 0.f;
	mainframe.tbox.y1 = 0.f;
	mainframe.tbox.x2 = 320.f;
	mainframe.tbox.y2 = 240.f;
	mainframe.dim.w = 320.f;
	mainframe.dim.h = 240.f;
	mainframe.scale = 1;
	mainframe.animframe = 0;
	
	// load up game screen
	SDL_Surface *_gamescreenimg = IMG_Load("gamescreen.png");
	SDL_Surface *gamescreenimg = SDL_DisplayFormatAlpha(_gamescreenimg);
	SDL_FreeSurface(_gamescreenimg);
	NASU_Actor gamescreen;
	gamescreen.graph = gamescreenimg;
	gamescreen.res.w = 184;
	gamescreen.res.h = 130;
	gamescreen.pivot.x = 0.f;
	gamescreen.pivot.y = 0.f;
	gamescreen.pos.x = 68.f;
	gamescreen.pos.y = 47.f;
	gamescreen.vel.x = 0.f;
	gamescreen.vel.y = 0.f;
	gamescreen.tbox.x1 = 0.f;
	gamescreen.tbox.y1 = 0.f;
	gamescreen.tbox.x2 = 320.f;
	gamescreen.tbox.y2 = 240.f;
	gamescreen.dim.w = 184.f;
	gamescreen.dim.h = 130.f;
	gamescreen.scale = 1;
	gamescreen.animframe = 0;

	// load up eggplants
	SDL_Surface *_nasuimg = IMG_Load("nasu.png");
	SDL_Surface *nasuimg = SDL_DisplayFormatAlpha(_nasuimg);
	SDL_FreeSurface(_nasuimg);
	NASU_Actor nasu;
	nasu.graph = nasuimg;
	nasu.res.w = 8;
	nasu.res.h = 8;
	nasu.pivot.x = 4.f;
	nasu.pivot.y = 4.f;
	nasu.pos.x = 4.f;
	nasu.pos.y = 4.f;
	nasu.vel.x = 0.f;
	nasu.vel.y = 0.f;
	nasu.tbox.x1 = -3.f;
	nasu.tbox.y1 = -3.f;
	nasu.tbox.x2 = 3.f;
	nasu.tbox.y2 = 3.f;
	nasu.dim.w = 8.f;
	nasu.dim.h = 8.f;
	nasu.scale = 1;
	nasu.animframe = 0;
	NASU_Actor nasu_b;
	nasu_b.graph = nasuimg;
	nasu_b.res.w = 8;
	nasu_b.res.h = 8;
	nasu_b.pivot.x = 4.f;
	nasu_b.pivot.y = 4.f;
	nasu_b.pos.x = 12.f;
	nasu_b.pos.y = 4.f;
	nasu_b.vel.x = 0.f;
	nasu_b.vel.y = 0.f;
	nasu_b.tbox.x1 = -3.f;
	nasu_b.tbox.y1 = -3.f;
	nasu_b.tbox.x2 = 3.f;
	nasu_b.tbox.y2 = 3.f;
	nasu_b.dim.w = 8.f;
	nasu_b.dim.h = 8.f;
	nasu_b.scale = 1;
	nasu_b.animframe = 1;

	TTF_Init();

	// load up score text
	TTF_Font *basefont = TTF_OpenFont("04B.TTF",8);
	NASU_ScrnText scoretxt;
	scoretxt.font = basefont;
	memset(&scoretxt.text,0,256);
	scoretxt.pos.x = 192.f;
	scoretxt.pos.y = 164.f;
	scoretxt.colr = whitecol;
	NASU_ScrnText scorenumtxt;
	scorenumtxt.font = basefont;
	memset(&scorenumtxt.text,0,256);
	scorenumtxt.pos.x = 240.f;
	scorenumtxt.pos.y = 164.f;
	scorenumtxt.colr = whitecol;
	
	NASU_ScrnText fpsnum;
	fpsnum.font = basefont;
	memset(&fpsnum.text,0,256);
	fpsnum.pos.x = 4.f;
	fpsnum.pos.y = 4.f;
	fpsnum.colr = whitecol;
	
	// load up the start/game over/paused text
	SDL_Surface *_textyimg = IMG_Load("texty.png");
	SDL_Surface *textyimg = SDL_DisplayFormatAlpha(_textyimg);
	SDL_FreeSurface(_textyimg);
	NASU_Actor texty;
	texty.graph = textyimg;
	texty.res.w = 72;
	texty.res.h = 8;
	texty.pivot.x = 36.f;
	texty.pivot.y = 4.f;
	texty.pos.x = 160.f;
	texty.pos.y = 120.f;
	texty.vel.x = 0.f;
	texty.vel.y = 0.f;
	texty.tbox.x1 = 0.f;
	texty.tbox.y1 = 0.f;
	texty.tbox.x2 = 0.f;
	texty.tbox.y2 = 0.f;
	texty.dim.w = 72.f;
	texty.dim.h = 8.f;
	texty.scale = 1;
	texty.animframe = 2;
	
	// load up score sprites
	
	SDL_Surface *_pointsimg = IMG_Load("scores.png");
	SDL_Surface *pointsimg = SDL_DisplayFormatAlpha(_pointsimg);
	SDL_FreeSurface(_pointsimg);
	NASU_Actor points1;
	points1.graph = pointsimg;
	points1.res.w = 40;
	points1.res.h = 12;
	points1.pivot.x = 20.f;
	points1.pivot.y = 6.f;
	points1.pos.x = 16.f;
	points1.pos.y = 16.f;
	points1.vel.x = 0.f;
	points1.vel.y = 0.f;
	points1.tbox.x1 = 0.f;
	points1.tbox.y1 = 0.f;
	points1.tbox.x2 = 0.f;
	points1.tbox.y2 = 0.f;
	points1.dim.w = 40.f;
	points1.dim.h = 12.f;
	points1.scale = 1;
	points1.animframe = 0;
	NASU_Actor points2;
	points2.graph = pointsimg;
	points2.res.w = 40;
	points2.res.h = 12;
	points2.pivot.x = 20.f;
	points2.pivot.y = 6.f;
	points2.pos.x = 16.f;
	points2.pos.y = 32.f;
	points2.vel.x = 0.f;
	points2.vel.y = 0.f;
	points2.tbox.x1 = 0.f;
	points2.tbox.y1 = 0.f;
	points2.tbox.x2 = 0.f;
	points2.tbox.y2 = 0.f;
	points2.dim.w = 40.f;
	points2.dim.h = 12.f;
	points2.scale = 1;
	points2.animframe = 1;
	NASU_Actor points3;
	points3.graph = pointsimg;
	points3.res.w = 40;
	points3.res.h = 12;
	points3.pivot.x = 20.f;
	points3.pivot.y = 6.f;
	points3.pos.x = 16.f;
	points3.pos.y = 48.f;
	points3.vel.x = 0.f;
	points3.vel.y = 0.f;
	points3.tbox.x1 = 0.f;
	points3.tbox.y1 = 0.f;
	points3.tbox.x2 = 0.f;
	points3.tbox.y2 = 0.f;
	points3.dim.w = 40.f;
	points3.dim.h = 12.f;
	points3.scale = 1;
	points3.animframe = 2;
	
	// load up sounds

	// TODO Pitch modification
	// step sounds: 1.1, 0.9, 1.5
	// nasu get sounds: 1.0, 1.1, 1.5

	Mix_Chunk *stepsnd[3];
	Mix_Chunk *getsnd[3];
	Mix_Chunk *losesnd;
	Mix_Music *titlemus;
	Mix_Music *gamemus;
	Mix_Music *losemus;
	if ( !bNoSound )
	{
		Mix_Init(MIX_INIT_OGG);
		Mix_OpenAudio(44100,AUDIO_S16SYS,2,1024);
		Mix_AllocateChannels(8);
	
		stepsnd[0] = Mix_LoadWAV("nasustep1.ogg");
		Mix_VolumeChunk(stepsnd[0], MIX_MAX_VOLUME*0.75f);
		stepsnd[1] = Mix_LoadWAV("nasustep2.ogg");
		Mix_VolumeChunk(stepsnd[1], MIX_MAX_VOLUME*0.75f);
		stepsnd[2] = Mix_LoadWAV("nasustep3.ogg");
		Mix_VolumeChunk(stepsnd[2], MIX_MAX_VOLUME*0.75f);
		getsnd[0] = Mix_LoadWAV("nasuget1.ogg");
		Mix_VolumeChunk(getsnd[0], MIX_MAX_VOLUME);
		getsnd[1] = Mix_LoadWAV("nasuget2.ogg");
		Mix_VolumeChunk(getsnd[1], MIX_MAX_VOLUME);
		getsnd[2] = Mix_LoadWAV("nasuget3.ogg");
		Mix_VolumeChunk(getsnd[2], MIX_MAX_VOLUME);
		losesnd = Mix_LoadWAV("nasulose.ogg");
		Mix_VolumeChunk(losesnd, MIX_MAX_VOLUME);
	
		titlemus = Mix_LoadMUS("nasutitle.ogg");
		gamemus = Mix_LoadMUS("nasugame.ogg");
		losemus = Mix_LoadMUS("nasuover.ogg");
		Mix_VolumeMusic(MIX_MAX_VOLUME*0.35f);
	}

	// game variables

	float pts1time = 0.f, pts2time = 0.f, pts3time = 0.f;
	unsigned long int cscore = 0;
	unsigned short int GameState = 0;
	float TimeUntilNextNasu = 2.0f, TimeUntilNextNasuB = 25.f;
	bool bLostGame = false;
	float blink = 0.f;
	unsigned short int blinkcounter = 0;
	bool bDerp = false;
	NASU_Vect Nasupos, Nasubpos;
	float deltatime = 0.f, calfps = 0.f;
	bool bShowFPS = false;
	
	float difficulty = 0.f;
	uint32_t lastframe = 0;
	char scrname[256];

	// start main loop!
	
	if ( !bNoSound )
		Mix_PlayMusic(titlemus,-1);
	bool bQueriedQuit = false;
	lastframe = SDL_GetTicks();
	while (!bQueriedQuit)
	{
		// input event polling
		SDL_Event Event;
		while ( SDL_PollEvent(&Event) )
		{
			switch (Event.type)
			{
			case SDL_QUIT:
				bQueriedQuit = true;
				break;
			case SDL_KEYDOWN:
				switch (Event.key.keysym.sym)
				{
				case SDLK_ESCAPE:
					bQueriedQuit = true;
					break;
				case SDLK_F12:
					#ifdef WINDOWS
					SDL_SaveBMP(realscreen,"screenshot.bmp");
					#else
					snprintf(scrname,256,"%s/nasu_screenshot.bmp",getenv("HOME"));
					SDL_SaveBMP(realscreen,scrname);
					#endif
					break;
				case SDLK_F10:
					bIsFullscreen = !bIsFullscreen;
					SDL_FreeSurface(mainscreen);
					mainscreen = NULL;
					if ( bIsFullscreen && (SDL_VideoModeOK(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN) != 0) )
						mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE|SDL_FULLSCREEN);
					else
					{
						bIsFullscreen = false;
						mainscreen = SDL_SetVideoMode(resx,resy,32,SDL_SWSURFACE);
					}
					break;
				case SDLK_F11:
					bShowFPS = !bShowFPS;
					break;
				case SDLK_RETURN:
					if (GameState == 0)
					{
						if ( !bNoSound )
							Mix_HaltMusic();
						GameState = 3;
						texty.animframe = 3;
					}
					break;
				case SDLK_p:
					if ( (GameState == 1) && !bLostGame )
					{
						GameState = 4;
						if ( !bNoSound )
							Mix_PauseMusic();
						texty.animframe = 4;
					}
					else if ( GameState == 4 )
					{
						GameState = 1;
						if ( !bNoSound )
							Mix_ResumeMusic();
						texty.animframe = 3;
					}
					break;
				case SDLK_LEFT:
				case SDLK_a:
					if ( !bLostGame && (GameState == 1) && (player.pos.x+player.tbox.x1 > gamescreen.pos.x) )
					{
						player.bLeft = true;
						player.vel.x = -60.f;
					}
					break;
				case SDLK_RIGHT:
				case SDLK_d:
					if ( !bLostGame && (GameState == 1) && (player.pos.x+player.tbox.x2 < gamescreen.pos.x+gamescreen.dim.w) )
					{
						player.bLeft = false;
						player.vel.x = 60.f;
					}
					break;
				case SDLK_UP:
				case SDLK_w:
				case SDLK_z:
				case SDLK_LSHIFT:
					if ( !bLostGame && (GameState == 1) && !player.bIsJumping )
					{
						player.bIsJumping = true;
						player.vel.y = -80.f;
						if ( !bNoSound )
							Mix_PlayChannel(-1,stepsnd[2],0);
					}
					break;
				default:
					break;
				}
				break;
			case SDL_KEYUP:
				switch (Event.key.keysym.sym)
				{
				case SDLK_LEFT:
				case SDLK_a:
					if ( !bLostGame && (GameState == 1) )
						player.vel.x = 0.f;
					break;
				case SDLK_RIGHT:
				case SDLK_d:
					if ( !bLostGame && (GameState == 1) )
						player.vel.x = 0.f;
					break;
				default:
					break;
				}
				break;
			default:
				break;
			}
		}

		// clear screen
		SDL_FillRect(mainscreen,&scrrect,SDL_MapRGB(mainscreen->format,0,0,0));
		SDL_FillRect(realscreen,&rscrrect,SDL_MapRGB(realscreen->format,0,0,0));

		// process game logic

		switch (GameState)
		{
		case 0:		// Title screen
			gamescreen.animframe = 2;
			RenderActor(realscreen,&gamescreen);
			snprintf(scorenumtxt.text,256,"%9u",score);
			scorenumtxt.pos.x = 320.f-(112.f+CalcTextW(&scorenumtxt));
			scorenumtxt.pos.y = 144.f;
			scoretxt.pos.x = 112.f;
			scoretxt.pos.y = 144.f;
			snprintf(scoretxt.text,256,"Hi Score:");
			RenderScrnText(realscreen,&scoretxt);
			RenderScrnText(realscreen,&scorenumtxt);
			break;
		case 2:		// Lose screen
			gamescreen.animframe = 3;
			RenderActor(realscreen,&gamescreen);
			blink += deltatime;
			if ( blink >= 7.f )
			{
				if ( !bNoSound )
					Mix_PlayMusic(titlemus,-1);
				GameState = 0;
			}
			texty.animframe = 2;
			snprintf(scorenumtxt.text,256,"%9lu",cscore);
			scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt));
			scorenumtxt.pos.y = 164.f;
			scoretxt.pos.x = 168.f;
			scoretxt.pos.y = 164.f;
			snprintf(scoretxt.text,256,"Score:");
			RenderScrnText(realscreen,&scoretxt);
			RenderScrnText(realscreen,&scorenumtxt);
			RenderActor(realscreen,&texty);
			break;
		case 3:		// Game preparation
			gamescreen.animframe = 0;
			RenderActor(realscreen,&gamescreen);
			blink += deltatime;
			if ( blink > 0.25f )
			{
				blinkcounter++;
				blink = 0.f;
				bDerp = !bDerp;
				if ( !bDerp )
					texty.animframe = 3;
				else
				{
					if ( blinkcounter < 7 )
						texty.animframe = 0;
					else
						texty.animframe = 1;
				}
			}
			if ( blinkcounter >= 8 )
			{
				bDerp = false;
				blinkcounter = 0;
				GameState = 1;
				if ( !bNoSound )
					Mix_PlayMusic(gamemus,-1);
			}
			difficulty = 0.f;
			cscore = 0;
			TimeUntilNextNasu = 2.0f;
			TimeUntilNextNasuB = 25.f;
			bLostGame = false;
			pts1time = 0.f;
			pts2time = 0.f;
			pts3time = 0.f;
			player.animframe = 0;
			player.bLeft = 0;
			player.bIsJumping = 0;
			player.pos.x = 160.f;
			player.pos.y = 149.f;
			nasu.pos.x = 4.f;
			nasu.pos.y = 4.f;
			nasu_b.pos.x = 12.f;
			nasu_b.pos.y = 4.f;
			points1.pos.x = 16.f;
			points1.pos.y = 16.f;
			points2.pos.x = 16.f;
			points2.pos.y = 32.f;
			points3.pos.x = 16.f;
			points3.pos.y = 48.f;
			RenderPlayer(realscreen,&player);
			snprintf(scorenumtxt.text,256,"%9lu",cscore);
			scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt));
			scorenumtxt.pos.y = 164.f;
			scoretxt.pos.x = 168.f;
			scoretxt.pos.y = 164.f;
			snprintf(scoretxt.text,256,"Score:");
			RenderScrnText(realscreen,&scoretxt);
			RenderScrnText(realscreen,&scorenumtxt);
			RenderActor(realscreen,&texty);
			break;
		case 4:		// Paused
			RenderActor(realscreen,&gamescreen);
			RenderPlayer(realscreen,&player);
			RenderActor(realscreen,&nasu);
			RenderActor(realscreen,&nasu_b);
			snprintf(scorenumtxt.text,256,"%9lu",cscore);
			scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt));
			scorenumtxt.pos.y = 164.f;
			scoretxt.pos.x = 168.f;
			scoretxt.pos.y = 164.f;
			snprintf(scoretxt.text,256,"Score:");
			RenderScrnText(realscreen,&scoretxt);
			RenderScrnText(realscreen,&scorenumtxt);
			RenderActor(realscreen,&texty);
			break;
		default:	// Main game
			if ( bLostGame )
			{
				player.vel.x = 0.f;
				player.vel.y = 0.f;
				blink += deltatime;
				if ( blink > 0.125f )
				{
					blinkcounter++;
					blink = 0.f;
					bDerp = !bDerp;
					if ( bDerp )
						gamescreen.animframe = 0;
					else
						gamescreen.animframe = 1;
				}
				if ( blinkcounter >= 12 )
				{
					blinkcounter = 0;
					if ( !bNoSound )
						Mix_PlayMusic(losemus,0);
					blink = 0.f;
					GameState = 2;
					bDerp = false;
				}
			}
			else
			{
				gamescreen.animframe = 0;
				blink += deltatime;
				if ( blink > 0.125f )
				{
					bDerp = !bDerp;
					blink = 0.f;
					if ( !bNoSound )
					{
						if ( player.vel.x != 0.f && !player.bIsJumping )
						{
							if ( bDerp )
								Mix_PlayChannel(-1,stepsnd[0],0);
							else
								Mix_PlayChannel(-1,stepsnd[1],0);
						}
					}
				}
				
				if ( TimeUntilNextNasu > 0.f )
				{
					TimeUntilNextNasu -= deltatime;
					nasu.pos.x = 4.f;
					nasu.pos.y = 4.f;
					
					if ( TimeUntilNextNasu <= 0.f )
					{
						TimeUntilNextNasu = 0.f;
						nasu.pos.x = (float)(rand()%160+80);
						nasu.pos.y = 0.f;
						nasu.vel.y = 50.f+difficulty*0.3f;
					}
				}
				else
				{
					MoveActor(&nasu,deltatime);
					Nasupos = nasu.pos;
					if ( CollidePlayer(&nasu,&player) && player.bIsJumping )
					{
						if ( (rand()%(30+(int)(difficulty*0.35f))) == 0 )
						{
							cscore += 1000;
							if ( cscore > score )
								score = cscore;
							TimeUntilNextNasu = 2.f-(difficulty*0.03f);
							if ( TimeUntilNextNasu <= 0.1f )
								TimeUntilNextNasu = 0.1f;
							nasu.pos.x = 4.f;
							nasu.pos.y = 4.f;
							if ( !bNoSound )
								Mix_PlayChannel(-1,getsnd[2],0);
							pts3time += 0.75f;
							points3.pos = Nasupos;
							points3.vel.y = -50.f;
							difficulty += 7.5f;
						}
						else
						{
							cscore += 10;
							if ( cscore > score )
								score = cscore;
							TimeUntilNextNasu = 2.f-(difficulty*0.03f);
							if ( TimeUntilNextNasu <= 0.1f )
								TimeUntilNextNasu = 0.1f;
							nasu.pos.x = 4.f;
							nasu.pos.y = 4.f;
							if ( !bNoSound )
								Mix_PlayChannel(-1,getsnd[0],0);
							pts1time += 0.75f;
							points1.pos = Nasupos;
							points1.vel.y = -50.f;
							difficulty += 1.f;
						}
					}
					else if ( nasu.pos.y >= 160.f )
					{
						if ( !bNoSound )
						{
							Mix_HaltMusic();
							Mix_PlayChannel(-1,losesnd,0);
						}
						bLostGame = true;
					}
				}
				
				if ( TimeUntilNextNasuB > 0.f )
				{
					TimeUntilNextNasuB -= deltatime;
					nasu_b.pos.x = 12.f;
					nasu_b.pos.y = 4.f;
					if ( TimeUntilNextNasuB <= 0.f )
					{
						TimeUntilNextNasuB = 0.f;
						int decideposb = rand()%2;
						switch (decideposb)
						{
						case 0:
							nasu_b.vel.x = (50.f+difficulty*0.15f);
							nasu_b.vel.y = 0.f;
							nasu_b.pos.x = 0.f;
							nasu_b.pos.y = 160.f;
							nasu_b.animframe = 2;
							break;
						default:
							nasu_b.vel.x = -(50.f+difficulty*0.15f);
							nasu_b.vel.y = 0.f;
							nasu_b.pos.x = 320.f;
							nasu_b.pos.y = 160.f;
							nasu_b.animframe = 1;
							break;
						}
					}
				}
				else
				{
					nasu_b.vel.y += (120.f+difficulty*0.75f)*deltatime;
					MoveActor(&nasu_b,deltatime);
					Nasubpos = nasu_b.pos;
					if ( CollidePlayer(&nasu_b,&player) && player.bIsJumping )
					{
						cscore += 300;
						if ( cscore > score )
							score = cscore;
						TimeUntilNextNasuB = 25.f+(difficulty*0.1f);
						nasu_b.pos.x = 12.f;
						nasu_b.pos.y = 4.f;
						if ( !bNoSound )
							Mix_PlayChannel(-1,getsnd[1],0);
						pts2time += 0.75f;
						points2.pos = Nasubpos;
						points2.vel.y = -50.f;
						difficulty += 2.5f;
					}
					if ( (nasu_b.vel.x > 0.f) && (nasu_b.pos.x > gamescreen.pos.x+gamescreen.dim.w) )
					{
						TimeUntilNextNasuB = 25.f+(difficulty*0.15f);
						nasu_b.pos.x = 12.f;
						nasu_b.pos.y = 4.f;
					}
					if ( (nasu_b.vel.x < 0.f) && (nasu_b.pos.x < gamescreen.pos.x) )
					{
						TimeUntilNextNasuB = 25.f+(difficulty*0.15f);
						nasu_b.pos.x = 12.f;
						nasu_b.pos.y = 4.f;
					}
					if ( nasu_b.pos.y >= 160.f )
						nasu_b.vel.y = -(80.f+difficulty*0.65f);
				}
				
				MovePlayer(&player,deltatime);
				if ( player.bIsJumping )
					player.vel.y += 480.f*deltatime;
				if ( player.pos.y >= 149.f )
				{
					player.pos.y = 149.f;
					player.bIsJumping = false;
				}
				if ( player.pos.x+player.tbox.x1 <= gamescreen.pos.x )
				{
					player.pos.x = gamescreen.pos.x-player.tbox.x1;
					player.vel.x = 0;
				}
				if ( player.pos.x+player.tbox.x2 >= gamescreen.pos.x+gamescreen.dim.w )
				{
					
					player.pos.x = (gamescreen.pos.x+gamescreen.dim.w)+player.tbox.x1;
					player.vel.x = 0;
				}
				if ( player.bIsJumping )
					player.animframe = 3;
				else if ( player.vel.x != 0.f )
				{
					if ( bDerp )
						player.animframe = 2;
					else
						player.animframe = 1;
				}
				else
					player.animframe = 0;
				
				if ( pts1time > 0.f )
				{
					pts1time -= deltatime;
					MoveActor(&points1,deltatime);
					if ( pts1time <= 0 )
					{
						points1.vel.y = 0.f;
						points1.pos.x = 16.f;
						points1.pos.y = 16.f;
					}
				}
				if ( pts2time > 0.f )
				{
					pts2time -= deltatime;
					MoveActor(&points2,deltatime);
					if ( pts2time <= 0 )
					{
						points2.vel.y = 0.f;
						points2.pos.x = 16.f;
						points2.pos.y = 32.f;
					}
				}
				if ( pts3time > 0.f )
				{
					pts3time -= deltatime;
					MoveActor(&points3,deltatime);
					if ( pts3time <= 0 )
					{
						points3.vel.y = 0.f;
						points3.pos.x = 16.f;
						points3.pos.y = 48.f;
					}
				}
			}
			RenderActor(realscreen,&gamescreen);
			RenderPlayer(realscreen,&player);
			RenderActor(realscreen,&nasu);
			RenderActor(realscreen,&nasu_b);
			RenderActor(realscreen,&points1);
			RenderActor(realscreen,&points2);
			RenderActor(realscreen,&points3);
			snprintf(scorenumtxt.text,256,"%9lu",cscore);
			scorenumtxt.pos.x = 320.f-(80.f+CalcTextW(&scorenumtxt));
			scorenumtxt.pos.y = 164.f;
			scoretxt.pos.x = 168.f;
			scoretxt.pos.y = 164.f;
			snprintf(scoretxt.text,256,"Score:");
			RenderScrnText(realscreen,&scoretxt);
			RenderScrnText(realscreen,&scorenumtxt);
			break;
		}

		// render frame
		RenderActor(realscreen,&mainframe);
		// blit frame to screen
		SDL_Surface *resizedframe = Upscale(realscreen,ScreenMult);
		BlitAt(resizedframe,NULL,mainscreen,resx/2,resy/2,true,true);
		SDL_FreeSurface(resizedframe);
		// flip screen and calculate fps
		calfps = 1000.f/(SDL_GetTicks()-lastframe);
		deltatime = 1.f/calfps;
		snprintf(fpsnum.text,256,"%.2f",calfps);
		fpsnum.pos.x = resx-(4+CalcTextW(&fpsnum));
		fpsnum.pos.y = 4.f;
		if ( bShowFPS )
			RenderScrnText(mainscreen,&fpsnum);
		if (SDL_Flip(mainscreen) == -1)
		{
			fprintf(stderr,"error updating screen (%s)\n", SDL_GetError());
			return 1;
		}
		lastframe = SDL_GetTicks();
	}
	if ( !bNoSound )
	{
		// Free audio
		Mix_FreeChunk(stepsnd[0]);
		Mix_FreeChunk(stepsnd[1]);
		Mix_FreeChunk(stepsnd[2]);
		Mix_FreeChunk(getsnd[0]);
		Mix_FreeChunk(getsnd[1]);
		Mix_FreeChunk(getsnd[2]);
		Mix_FreeChunk(losesnd);
		Mix_FreeMusic(titlemus);
		Mix_FreeMusic(gamemus);
		Mix_FreeMusic(losemus);
		Mix_AllocateChannels(0);
		Mix_CloseAudio();
	}
	// Free surfaces
	SDL_FreeSurface(playersprites);
	SDL_FreeSurface(mainframeimg);
	SDL_FreeSurface(gamescreenimg);
	SDL_FreeSurface(nasuimg);
	SDL_FreeSurface(textyimg);
	// Free font
	TTF_CloseFont(basefont);
	// Quit stuff
	Mix_Quit();
	TTF_Quit();
	SDL_Quit();

	return EXIT_SUCCESS;
}
Esempio n. 17
0
	void PlayerDefaultState::Execute(const shared_ptr<Player>& Obj) {
		auto PtrBehavior = Obj->GetBehavior<PlayerBehavior>();
		PtrBehavior->MovePlayer();
		auto PtrGrav = Obj->GetBehavior<Gravity>();
		PtrGrav->Execute();
	}
Esempio n. 18
0
int main(void)
{
	extern int mazeIdRequest;			// requested maze Id
	extern int seedRequest;				// requested random seed
	extern int quickModeRequest;		// whether quick mode is requested
	
	ActualTile maze[MAZE_DIMENSION][MAZE_DIMENSION];
	Coordinate playerLocation = { -1, -1 };

	SetupDisplay();
	// GenerateMazes("hundred.h",0,100); // HEHE, you can't do this!

	int mazeToUse = mazeIdRequest;
	int seedToUse = seedRequest;
	bool useQuickMode = quickModeRequest;
	int numMazes = 1;
	if (mazeToUse == 7) {
		numMazes = 100;		// scoring mode...
		useQuickMode = TRUE;
	}

	int totalTurns = 0;
	
	int metaTurn;
	for (metaTurn = 0; metaTurn < numMazes; metaTurn++) {
		// setup maze
		Coordinate dispDimension = SetupMaze(maze, mazeToUse, seedToUse, &playerLocation);
		int maxTurns = (dispDimension.x - 2)*(dispDimension.y - 2);   // approximately twice of walking space...
		
		// main loop
		Direction lastMoveDir = NO_MOVEMENT;
		bool lastMoveSucceed = FALSE;
		bool finishedMaze = FALSE;
		bool timeout = FALSE;
		
		int turn;
		for (turn = 0; turn <= maxTurns; turn++) {
			_turn = turn;
			// check winning/losing condition
			if (maze[playerLocation.y][playerLocation.x] == EXIT) {
				finishedMaze = TRUE;
			}
			else if (turn == maxTurns) {
				timeout = TRUE;    // last turn is an ending turn
			}

			// for every turn, display what we have if not in quick mode or not timeout/finished ...
			// (we also won't display when number of mazes is > 1)
			if (numMazes == 1 && (useQuickMode == FALSE || timeout || finishedMaze)) {
				ClearScreen();
				printf("CSC1140 Fall 2015 - The Dark Forest v.1.0\n\n");
				printf("Maze: #%d Seed: %d - Turn : %d/%d ", mazeIdRequest, seedRequest, turn, maxTurns);
				if (lastMoveDir != NO_MOVEMENT) {
					printf("| You just moved ");
					if (lastMoveDir == NORTH) printf("north ");
					else if (lastMoveDir == EAST) printf("east ");
					else if (lastMoveDir == SOUTH) printf("south ");
					else if (lastMoveDir == WEST) printf("west ");
					if (lastMoveSucceed == FALSE) printf("but failed!\n\n");
					else printf("\n\n");
				}
				else {
					printf("\n\n");
				}
				DisplayMaze(maze, dispDimension, playerLocation, timeout);

			}

			// break way if done
			if (timeout || finishedMaze) {
				break;
			}

			// if a normal turn, we ask for a step...
			static Tile vision[VISION_DIMENSION][VISION_DIMENSION];
			int i, j;
			for (i = 0; i < VISION_DIMENSION; i++) {
				for (j = 0; j < VISION_DIMENSION; j++) {

					int mapX = (playerLocation.x - VISION_RANGE + j + dispDimension.x) % dispDimension.x;
					int mapY = (playerLocation.y - VISION_RANGE + i + dispDimension.y) % dispDimension.y;
					if (mapX >= 0 && mapX < MAZE_DIMENSION
						&& mapY >= 0 && mapY < MAZE_DIMENSION) {
						vision[i][j] = maze[mapY][mapX] % TILE_CYCLE;
					}
				}
			}
			Direction playerMoveDir = Solve(playerLocation.x, playerLocation.y, vision);

			// really move it - but not on display yet...
			lastMoveSucceed = MovePlayer(maze, dispDimension, &playerLocation, playerMoveDir);
			lastMoveDir = playerMoveDir;


			// get key now so player debug messages can be seen
			if (useQuickMode == FALSE) {
				printf("\nPress Enter to continue (ctrl+C to terminate)...\n");
				getchar();
			}



		}
		
		// aftermath for each maze
		totalTurns += turn;
		if (numMazes == 1) {
			// normal single maze mode ending
			if (finishedMaze) {
				printf("\n       ******** And you escaped the maze in %d turns! ******** \n", turn);
				printf("       ******** Press q to quit                       ******** \n");

			}
			else {
				printf("\n       ******** You run out of energy and died in the maze...     ******** \n");
				printf("       ******** You will be missed by your CSCI1140 classmates... ******** \n");
			#if defined(_WIN32) || defined(_WIN64)
				printf("       ******** Press q to quit                                   ******** \n");
			#else
				printf("       ******** Press q then Enter to quit                        ******** \n");
			#endif

			}
			char c;
			do {
				c = GetKey();
			} while (c != 'q');

		}
		else {
			// multi-maze scoring mode
			if (finishedMaze) {
				printf("You escaped area %d in %d turns...\n", metaTurn, turn);
			}
			else {
				printf("You run out of energy in area %d and wake up at exit (%d turns counted)...\n", metaTurn, turn);
			}
		}

	}

	if (numMazes > 1) {
		printf("\n\n    ***                                               ***\n");
		printf("    *** Turns used to escape the Dark Forest: %6d  ***\n", totalTurns);
		printf("    ***                                               ***\n\n");
	}
	
	return 0;
}
Esempio n. 19
0
// エントリポイント
int WINAPI _tWinMain( HINSTANCE hInst, HINSTANCE, LPTSTR, int )
{
	LARGE_INTEGER			nNowTime, nLastTime;		// 現在とひとつ前の時刻
	LARGE_INTEGER			nTimeFreq;					// 時間単位

    // 画面サイズ
    g_nClientWidth  = VIEW_WIDTH;						// 幅
    g_nClientHeight = VIEW_HEIGHT;						// 高さ

	// Register the window class
    WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
                      _T( "D3D Sample" ), NULL };
    RegisterClassEx( &wc );

	RECT rcRect;
	SetRect( &rcRect, 0, 0, g_nClientWidth, g_nClientHeight );
	AdjustWindowRect( &rcRect, WS_OVERLAPPEDWINDOW, FALSE );
    g_hWnd = CreateWindow( _T( "D3D Sample" ), _T( "BillBoard_1_1" ),
						   WS_OVERLAPPEDWINDOW, 100, 20, rcRect.right - rcRect.left, rcRect.bottom - rcRect.top,
						   GetDesktopWindow(), NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D() ) && SUCCEEDED( MakeShaders() ) )
    {
        // Create the shaders
        if( SUCCEEDED( InitDrawModes() ) )
        {
			if ( SUCCEEDED( InitGeometry() ) ) {					// ジオメトリ作成
				
				InitPlayer();										// プレイヤーの初期化
				// Show the window
				ShowWindow( g_hWnd, SW_SHOWDEFAULT );
				UpdateWindow( g_hWnd );
				
				QueryPerformanceFrequency( &nTimeFreq );			// 時間単位
				QueryPerformanceCounter( &nLastTime );				// 1フレーム前時刻初期化

				// Enter the message loop
				MSG msg;
				ZeroMemory( &msg, sizeof( msg ) );
				while( msg.message != WM_QUIT )
				{
					MovePlayer();
					Render();
					do {
						if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
						{
							TranslateMessage( &msg );
							DispatchMessage( &msg );
						}
						QueryPerformanceCounter( &nNowTime );
					} while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 90 ) ) &&
							 ( msg.message != WM_QUIT ) );
					while( ( ( nNowTime.QuadPart - nLastTime.QuadPart ) < ( nTimeFreq.QuadPart / 60 ) ) &&
						   ( msg.message != WM_QUIT ) )
					{
						QueryPerformanceCounter( &nNowTime );
					}
					nLastTime = nNowTime;
					g_pSwapChain->Present( 0, 0 );					// 表示
				}
			}
        }
    }

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( _T( "D3D Sample" ), wc.hInstance );
    return 0;
}
Esempio n. 20
0
int
main( int argc, char* argv[] )
    {
    srand(time(nullptr));
    LabData lab( 31, 31 );

    // Setup SDL related stuff
    SDL_Init( SDL_INIT_VIDEO );
    atexit( SDL_Quit );
    atexit( IMG_Quit );

    size_t hwin = 17;
    size_t wwin = 16;
    Term::SDL::Context term( wwin, hwin );
    term.Tilemap( "tileset.png" );
    SDL_Surface* screen = SDL_SetVideoMode(
        term.Framebuffer().Width()  * term.TileWidth(),
        term.Framebuffer().Height() * term.TileHeight(),
        32, SDL_SWSURFACE );
    term.RenderTarget( screen );
    Term::Char clearChar('\0');
    clearChar.PriColor( Term::Color::Black );
    clearChar.SecColor( Term::Color::Black );
    term.Framebuffer().ClearChar( clearChar );
    SDL_EnableKeyRepeat( 100, 100 ); // Basically the movementspeed of the player.

    Term::TTY tty( term.Framebuffer() );

    GenerateLabyrinth( lab );
    MakePrettySymbols( lab );

    bool running = true;
    while(running)
        {
        SDL_Event event;
        while( SDL_PollEvent(&event) ) switch( event.type )
            {
            case SDL_QUIT:
                running = false; break;
            case SDL_KEYDOWN: switch( event.key.keysym.sym )
                {
                case SDLK_ESCAPE:
                    running = false; break;
                case SDLK_UP:
                    MovePlayer( lab, 0, -1 ); break;
                case SDLK_DOWN:
                    MovePlayer( lab, 0, 1 ); break;
                case SDLK_LEFT:
                    MovePlayer( lab, -1, 0 ); break;
                case SDLK_RIGHT:
                    MovePlayer( lab, 1, 0 ); break;
                default: break;
                } break;
            }

        if( lab.win )
            {
            std::string winstr( "!!!WIN!!!" );
            int x = rand() % (term.Framebuffer().Width()+winstr.length()) - winstr.length();
            int y = rand() % (term.Framebuffer().Height()+winstr.length()) - winstr.length();
            tty.PriColor( RandomColor() );
            tty.SecColor( RandomColor() );
            tty.Place(x,y).Put( winstr );
            }
        else
            {
            term.Framebuffer().Clear();
            term.Framebuffer().Copy( lab.symbuf, 0, 1,
                -(term.Framebuffer().Width()/2) + lab.xplayer,
                -(term.Framebuffer().Height()/2) + lab.yplayer,
                term.Framebuffer().Width(), term.Framebuffer().Height() );
            tty.Place( term.Framebuffer().Width()/2, term.Framebuffer().Height()/2+1 );
            tty.PriColor( Term::Color::White );
            tty.SecColor( Term::Color::Black );
            tty.Put( 1 );
            for( auto itoken : lab.tokens )
                {
                tty.Place(
                    (itoken % lab.width) +(term.Framebuffer().Width())/2 - lab.xplayer ,
                    (itoken / lab.width) +(term.Framebuffer().Height()/2) - lab.yplayer +1 );
                tty.Put( 9 );
                }
            tty.Place(0,0).PriColor( Term::Color::Black ).SecColor( Term::Color::White );
            if( lab.door == 0 )
                {
                tty.Put( "Tokens left: " );
                std::stringstream ss;
                ss << lab.tokens.size();
                tty.Put( ss.str() );
                }
            else
                {
                tty.Put( "Find the door!" );
                tty.Place(
                    lab.door % lab.width + term.Framebuffer().Width()/2 - lab.xplayer,
                    lab.door / lab.width + term.Framebuffer().Height()/2 + 1 - lab.yplayer );
                tty.Put( 239 );
                }
            }
        term.Print();
        SDL_Flip(screen);
        SDL_Delay(50);
        }
    }
Esempio n. 21
0
		void Player::Update(float dt) {
			SPADES_MARK_FUNCTION();
			auto* listener = world->GetListener();
			
			MovePlayer(dt);
			
			if(!IsAlive()) {
				// do death cleanup
				blockCursorDragging = false;
			}
			
			if(tool == ToolSpade){
				if(weapInput.primary){
					if(world->GetTime() > nextSpadeTime){
						UseSpade();
						nextSpadeTime = world->GetTime() + GetToolPrimaryDelay();
					}
				}else if(weapInput.secondary){
					if(world->GetTime() > nextDigTime){
						DigWithSpade();
						nextDigTime = world->GetTime() + GetToolSecondaryDelay();
						firstDig = false;
					}
				}
			}else if(tool == ToolBlock && IsLocalPlayer()){
				GameMap::RayCastResult result;
				auto *map = GetWorld()->GetMap();
				result = map->CastRay2(GetEye(), GetFront(), 12);
				canPending = false;
				
				if(blockCursorDragging) {
					// check the starting point is not floating
					auto start = blockCursorDragPos;
					if(map->IsSolidWrapped(start.x-1, start.y, start.z) ||
					   map->IsSolidWrapped(start.x, start.y-1, start.z) ||
					   map->IsSolidWrapped(start.x, start.y, start.z-1) ||
					   map->IsSolidWrapped(start.x+1, start.y, start.z) ||
					   map->IsSolidWrapped(start.x, start.y+1, start.z) ||
					   map->IsSolidWrapped(start.x, start.y, start.z+1)) {
						// still okay
					}else{
						// cannot build; floating
						if(listener &&
						   this == world->GetLocalPlayer()) {
							listener->
							LocalPlayerBuildError(BuildFailureReason::InvalidPosition);
						}
						blockCursorDragging = false;
					}
				}
				
				if(result.hit &&
				   (result.hitBlock + result.normal).z < 62 &&
				   (!OverlapsWithOneBlock(result.hitBlock + result.normal)) &&
				   BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f &&
				   !pendingPlaceBlock){
					
					// Building is possible, and there's no delayed block placement.
					blockCursorActive = true;
					blockCursorPos = result.hitBlock + result.normal;
					
				}else if(pendingPlaceBlock){
					
					// Delayed Block Placement: When player attempts to place a block while jumping and
					// placing block is currently impossible, building will be delayed until it becomes
					// possible, as long as player is airborne.
					if(airborne == false || blockStocks <= 0){
						// player is no longer airborne, or doesn't have a block to place.
						pendingPlaceBlock = false;
						lastSingleBlockBuildSeqDone = true;
						if(blockStocks > 0) {
							// cannot build; invalid position.
						}
					}else if((!OverlapsWithOneBlock(pendingPlaceBlockPos)) &&
							 BoxDistanceToBlock(pendingPlaceBlockPos) < 3.f){
						// now building became possible.
						SPAssert(this == world->GetLocalPlayer());
						
						if(GetWorld()->GetListener())
							GetWorld()->GetListener()->LocalPlayerBlockAction(pendingPlaceBlockPos, BlockActionCreate);
						
						pendingPlaceBlock = false;
						lastSingleBlockBuildSeqDone = true;
						// blockStocks--; decrease when created
						
						nextBlockTime = world->GetTime() + GetToolPrimaryDelay();
					}
					
				}else{
					// Delayed Block Placement can be activated only when the only reason making placement
					// impossible is that block to be placed overlaps with the player's hitbox.
					canPending = result.hit &&
								 (result.hitBlock + result.normal).z < 62 &&
								 BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f;
					
					blockCursorActive = false;
					int dist = 11;
					for(; dist >= 1 &&
						BoxDistanceToBlock(result.hitBlock + result.normal) > 3.f ; dist--) {
						result = GetWorld()->GetMap()->CastRay2(GetEye(),
																GetFront(),
																dist);
					}
					for(; dist < 12 &&
						BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f ; dist++) {
						result = GetWorld()->GetMap()->CastRay2(GetEye(),
																GetFront(),
																dist);
					}
					
					blockCursorPos = result.hitBlock + result.normal;
				}
				
			}else if(tool == ToolWeapon){
			}else if(tool == ToolGrenade){
				if(holdingGrenade){
					if(world->GetTime() - grenadeTime > 2.9f){
						ThrowGrenade();
					}
				}
			}
		
			if(tool != ToolWeapon)
				weapon->SetShooting(false);
			if(weapon->FrameNext(dt)){
				FireWeapon();
			}
			
			if(weapon->IsReloading()) {
				lastReloadingTime = world->GetTime();
			}else if(reloadingServerSide) {
				// for some reason a server didn't return
				// WeaponReload packet.
				if(world->GetTime() + lastReloadingTime + .8f) {
					reloadingServerSide = false;
					weapon->ForceReloadDone();
				}
			}
		}
Esempio n. 22
0
void PlayerActions(const int frameTicks)
{
	MovePlayer(frameTicks);
	MovePlayerBullets(frameTicks);
}
Esempio n. 23
0
		void Player::Update(float dt) {
			SPADES_MARK_FUNCTION();
			
			MovePlayer(dt);
			if(tool == ToolSpade){
				if(weapInput.primary){
					if(world->GetTime() > nextSpadeTime){
						UseSpade();
						nextSpadeTime = world->GetTime() + GetToolPrimaryDelay();
					}
				}else if(weapInput.secondary){
					if(world->GetTime() > nextDigTime){
						DigWithSpade();
						nextDigTime = world->GetTime() + GetToolSecondaryDelay();
						firstDig = false;
					}
				}
			}else if(tool == ToolBlock){
				GameMap::RayCastResult result;
				result = GetWorld()->GetMap()->CastRay2(GetEye(),
														GetFront(),
														12);
				canPending = false;
				if(result.hit && (result.hitBlock + result.normal).z < 62 &&
				   (!OverlapsWithOneBlock(result.hitBlock + result.normal)) &&
				   BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f &&
				   !pendingPlaceBlock){
					blockCursorActive = true;
					blockCursorPos = result.hitBlock + result.normal;
				}else if(pendingPlaceBlock){
					if(airborne == false || blockStocks <= 0){
						pendingPlaceBlock = false;
					}else if((!OverlapsWithOneBlock(pendingPlaceBlockPos)) &&
							 BoxDistanceToBlock(pendingPlaceBlockPos) < 3.f){
						SPAssert(this == world->GetLocalPlayer());
						
						if(GetWorld()->GetListener())
							GetWorld()->GetListener()->LocalPlayerBlockAction(pendingPlaceBlockPos, BlockActionCreate);
						
						pendingPlaceBlock = false;
						// blockStocks--; decrease when created
						
						nextBlockTime = world->GetTime() + GetToolPrimaryDelay();
					}
				}else{
					canPending = result.hit && (result.hitBlock + result.normal).z < 62 &&
					BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f;
					blockCursorActive = false;
					blockCursorPos = result.hitBlock + result.normal;
				}
			}else if(tool == ToolWeapon){
			}else if(tool == ToolGrenade){
				if(holdingGrenade){
					if(world->GetTime() - grenadeTime > 2.9f){
						ThrowGrenade();
					}
				}
			}
		
			if(tool != ToolWeapon)
				weapon->SetShooting(false);
			if(weapon->FrameNext(dt)){
				FireWeapon();
			}
			
			if(weapon->IsReloading()) {
				lastReloadingTime = world->GetTime();
			}else if(reloadingServerSide) {
				// for some reason a server didn't return
				// WeaponReload packet.
				if(world->GetTime() + lastReloadingTime + .8f) {
					reloadingServerSide = false;
					weapon->ForceReloadDone();
				}
			}
		}
Esempio n. 24
0
//==============================================================================
// Brief  : 通常更新処理
// Return : void								: なし
// Arg    : void								: なし
//==============================================================================
void SceneGame::normalUpdate(void)
{
	//PrintDebug( _T( "normalUpdate\n" ) );

	//	接続切れ確認
	if(wiiLostCheck() == false)
		return;


	//	カメラの逆行列を取得する
	D3DXMATRIX cameraInvMat;
	pCamera_->GetRenderMatrix()->GetMatrixView(&cameraInvMat);
	D3DXMatrixInverse(&cameraInvMat, nullptr, &cameraInvMat);

	//	カメラの逆行列をプレイヤーにセット
	player->setInvViewMatrix(cameraInvMat);


	{
		//	花火管理クラスの更新
		//MeasureTime("managerFireworksUpdate");
		managerFireworks->setInvViewMatrix(cameraInvMat);
		managerFireworks->Update(fireworksTable, &fireworksTableIndex);
	}
	//	ターゲットクラスの更新
	managerTarget->setInvViewMatrix(cameraInvMat);
	managerTarget->Update(targetTable, &targetTableIndex);
	{
		// ポイントスプライト管理クラスの更新
		//MeasureTime("managerPoint");
		managerPoint->Update();
	}

	//	プレイヤー移動処理
	MovePlayer();

	//	花火打ち上げ処理
	LaunchFireworks();



	PrintDebug( _T( "fireworksTableIndex = %d\n"), fireworksTableIndex);
	for(int count = 0;count < FIREWORKS_MAX;count++)
		PrintDebug( _T( "fireworksTable[%d] = %d\n"), count, fireworksTable[count]);
	PrintDebug( _T( "targetTableIndex = %d\n"), targetTableIndex);
	for(int count = 0;count < TARGET_MAX;count++)
		PrintDebug( _T( "targetTable[%d] = %d\n"), count, targetTable[count]);



	//	テスト用ここから
	//---------------------------------------------------------------------------------------------------------
	//PrintDebug( _T( "\nbuffDiffWiiAccel.x = %f"), buffDiffWiiAccel.x );
	//PrintDebug( _T( "\nbuffDiffWiiAccel.y = %f"), buffDiffWiiAccel.y );
	//PrintDebug( _T( "\nbuffDiffWiiAccel.z = %f"), buffDiffWiiAccel.z );
	//PrintDebug( _T( "\nbuffDiffWiiRot.x = %f"), buffDiffWiiRot.x );
	//PrintDebug( _T( "\nbuffDiffWiiRot.y = %f"), buffDiffWiiRot.y );
	//PrintDebug( _T( "\nbuffDiffWiiRot.z = %f\n"), buffDiffWiiRot.z );

	//	ターゲット出現
	if(targetAppearFlag == true)
	{
		targetAppearCount++;
		if(targetAppearCount == 500)
		{
			int buff;
			buff = managerTarget->Add(
				D3DXVECTOR3(RANDOM(400), (float)(rand() % 100), targetAppearPosZ),
				(COLOR_STATE)(rand() % COLOR_STATE_S));
			if(buff != -1)
			{
				targetTable[targetTableIndex] = buff;
				targetTableIndex++;
			}
	
			targetAppearCount = 0;
		}
	}
	//---------------------------------------------------------------------------------------------------------
	//	テスト用ここまで




	//	wiiリモコンの回転初期化
	//if(wiiContoroller->getPress(WC_PLUS) && wiiContoroller->getPress(WC_MINUS))
	//	wiiContoroller->rotReset();


	//	打ち上げる花火色切り替え
	//------------------------------------------------------------------
	if(pArgument_->pVirtualController_->IsTrigger(VC_LEFT))
	{
		colorState = (COLOR_STATE)(colorState - 1);
		if(colorState < COLOR_STATE_R)
			colorState = COLOR_STATE_B;

		fireworksUI->setColorState(colorState);
	}
	if(pArgument_->pVirtualController_->IsTrigger(VC_RIGHT))
	{
		colorState = (COLOR_STATE)(colorState + 1);
		if(colorState > COLOR_STATE_B)
			colorState = COLOR_STATE_R;

		fireworksUI->setColorState(colorState);
	}
	//------------------------------------------------------------------

	//	Aボタン押されたら
	if(pArgument_->pVirtualController_->IsTrigger(VC_BURN) == true)
	{
		//	ターゲットと花火の当たり判定
		collision_fireworks_target();
	}
	collision_fireworks_targetAuto();



	collision_fireworks_fireworks();



#ifdef _TEST

	//	+キーが押されたら
	if(pArgument_->pKeyboard_->IsTrigger(DIK_N))
	{
		gage->addPercentFuture(10);
	}

	//	-キーが押されたら
	if(pArgument_->pKeyboard_->IsTrigger(DIK_M))
	{
		gage->addPercentFuture(-10);
	}

	if(pArgument_->pKeyboard_->IsTrigger(DIK_T))
	{
		if(targetAppearFlag == false)
			targetAppearFlag = true;
		else
			targetAppearFlag = false;
	}

	if(autoLaunchFlag == false)
	{
		if(pArgument_->pKeyboard_->IsTrigger(DIK_R))
		{
			int buff;
			buff = managerTarget->Add(
				D3DXVECTOR3(0.0f, 100.0f, targetAppearPosZ),
				COLOR_STATE_R);
			if(buff != -1)
			{
				targetTable[targetTableIndex] = buff;
				targetTableIndex++;


				autoLaunchFlag = true;
				autoLaunchTarget = buff;
			}
		}

		if(pArgument_->pKeyboard_->IsTrigger(DIK_G))
		{
			int buff;
			buff = managerTarget->Add(
				D3DXVECTOR3(0.0f, 100.0f, targetAppearPosZ),
				COLOR_STATE_G);
			if(buff != -1)
			{
				targetTable[targetTableIndex] = buff;
				targetTableIndex++;

				fireworksTable[fireworksTableIndex] = buff;
				fireworksTableIndex++;


				autoLaunchFlag = true;
				autoLaunchTarget = buff;
			}
		}

		if(pArgument_->pKeyboard_->IsTrigger(DIK_B))
		{
			int buff;
			buff = managerTarget->Add(
				D3DXVECTOR3(0.0f, 100.0f, targetAppearPosZ),
				COLOR_STATE_B);
			if(buff != -1)
			{
				targetTable[targetTableIndex] = buff;
				targetTableIndex++;


				autoLaunchFlag = true;
				autoLaunchTarget = buff;
			}
		}

		if(pArgument_->pKeyboard_->IsTrigger(DIK_W))
		{
			int buff;
			buff = managerTarget->Add(
				D3DXVECTOR3(0.0f, 100.0f, targetAppearPosZ),
				COLOR_STATE_W);
			if(buff != -1)
			{
				targetTable[targetTableIndex] = buff;
				targetTableIndex++;


				autoLaunchFlag = true;
				autoLaunchTarget = buff;
			}
		}
	}

	if(pArgument_->pKeyboard_->IsTrigger(DIK_D))
	{
		LaunchSP();
	}

	if(combo->getScore() != combo->getScorePrev())
	{
		if(combo->getScore() % 10 == 0)
		{
			LaunchSP();
		}
	}

	if(autoLaunchFlag == true)
	{
		autoLaunchCount++;
		if(autoLaunchCount == 50)
		{
			int buff2 = -1;
			D3DXVECTOR3 buffPos = player->getPosition();

			if(managerTarget->getTarget(autoLaunchTarget)->getColorState() == COLOR_STATE_W)
			{
				buff2 = managerFireworks->AddW(
					ManagerFireworks::STATE_RIGHTSP,
					managerPoint,
					buffPos,
					buffDiffWiiRot,
					managerTarget->getTarget(autoLaunchTarget));

				if(buff2 != -1)
				{
					fireworksTable[fireworksTableIndex] = buff2;
					fireworksTableIndex++;
				}
			}
			else
			{
				buff2 = managerFireworks->Add(
						ManagerFireworks::STATE_RIGHTSP,
						managerPoint,
						buffPos,
						buffDiffWiiRot,
						managerTarget->getTarget(autoLaunchTarget));

				if(buff2 != -1)
				{
					fireworksTable[fireworksTableIndex] = buff2;
					fireworksTableIndex++;
				}
			}

			autoLaunchCount = 0;
			autoLaunchFlag = false;
		}
	}

#endif



	//	ポーズキーが押されたら
	if( pArgument_->pVirtualController_->IsTrigger(VC_PAUSE))
	{
		//	更新関数設定
		fpUpdate = &SceneGame::pauseUpdate;

		//	Objectの更新を止める
		pArgument_->pUpdate_->SetIsEnable( false );

		//	描画再開
		pauseFrame->SetEnableGraphic(true);
		stringReturn->SetEnableGraphic(true);
		stringStop->SetEnableGraphic(true);
		stringRetry->SetEnableGraphic(true);

		//	音再生
		desideSound->Play();

		if(finger != nullptr)
			finger->SetEnableGraphic(true);
	}
}
void ServerSideNetworkedGame::ReadPackets(void)
{
	char data[1400];

	int type;
	int ret;

	struct sockaddr address;

	ServerSideNetworkedClient *clList;

	dreamMessage mes;
	mes.Init(data, sizeof(data));

	// Get the packet from the socket
	try
	{
		while(ret = networkServer->GetPacket(mes.data, &address))
		{
			mes.SetSize(ret);
			mes.BeginReading();

			type = mes.ReadByte();

			// Check the type of the message
			switch(type)
			{
			case DREAMSOCK_MES_CONNECT:
				AddClient();
				break;

			case DREAMSOCK_MES_DISCONNECT:
				RemoveClient(&address);
				break;

			case USER_MES_FRAME:
//			LogString("Got frame (size: %d bytes)", ret);

				// Skip sequences
				mes.ReadShort();
				mes.ReadShort();

				// Find the correct client by comparing addresses
				clList = clientList;

				for( ; clList != NULL; clList = clList->next)
				{
					if(memcmp(&clList->address, &address, sizeof(address)) == 0)
					{
						ReadDeltaMoveCommand(&mes, clList);
						MovePlayer(clList);

						break;
					}
				}

				break;

			case USER_MES_NONDELTAFRAME:
				clList = clientList;
				ServerSideNetworkedClient *dataClient;

				for( ; clList != NULL; clList = clList->next)
				{
					clList->netClient->message.Init(clList->netClient->message.outgoingData,
						sizeof(clList->netClient->message.outgoingData));

					clList->netClient->message.WriteByte(USER_MES_NONDELTAFRAME);
					clList->netClient->message.WriteShort(clList->netClient->GetOutgoingSequence());
					clList->netClient->message.WriteShort(clList->netClient->GetIncomingSequence());

					for(dataClient = clientList; dataClient != NULL; dataClient = dataClient->next)
					{
						BuildMoveCommand(&clList->netClient->message, dataClient);
					}

					clList->netClient->SendPacket();
				}

				break;

			}
		}
	}
	catch(...)
	{
		LogString("Unknown Exception caught in Lobby ReadPackets loop");

#ifdef WIN32
		MessageBox(NULL, "Unknown Exception caught in Lobby ReadPackets loop", "Error", MB_OK | MB_TASKMODAL);
#endif
	}
}
Esempio n. 26
0
void MainLoop::Loop()
{

#ifdef MW_OS_WINDOWS

    MSG msg;
    while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {

        TranslateMessage(&msg);
        DispatchMessage(&msg);

    }
#else
    XEvent               event;
    while(XPending(dpy))
    {


        XNextEvent(dpy, &event);

        switch (event.type)
        {
        case KeyPress:
        {
            KeySym     keysym;
            XKeyEvent *kevent;
            char       buffer[1];

            kevent = (XKeyEvent *) &event;


            if( XLookupString((XKeyEvent *)&event,buffer,1,&keysym,NULL) != 1 )
                break;


            switch (keysym)
            {
            case XK_Up:

                break;

            case XK_Down:
                break;

			case XK_Escape:
			case XK_Q:
			case XK_q:
				exit(0);

            default:
                break;
            }
            break;
        }//key press

        case ButtonPress:
        {
            switch (event.xbutton.button)
            {
            case Button4:
                renderer->ZoomIn();
                break;

            case Button5:
                renderer->ZoomOut();
                break;

            default:
                break;
            }
        }//mouse button press
        break;

        case ConfigureNotify:
            // XResizeWindow( dpy, win, screen_x, screen_y );

        case Expose:
            break;

        }

    }

#endif
    prev_time= current_time;
    current_time= clock();
    level->PhysTick();
    MovePlayer();
    if( sound_system != NULL )
    {
        sound_system->SetListenerPos( player->Position() );
        sound_system->SetListenerAngle( player->AngXY() );
          sound_system->Tick();
    }

    renderer->Draw();
#ifdef MW_OS_WINDOWS
    ::SwapBuffers(hdc);
#else
    glXSwapBuffers(dpy, win);
#endif


    usleep(1000);//1 ms

}