void EditorMenuWidget::start(){
	placeBallButton->setStyleSheet("color: black; background-color: red");
	editLineButton->setStyleSheet("color: black; background-color: white");
	p1AICheckBox->setChecked(gameState->isP1ControlledByAI());
	p2AICheckBox->setChecked(gameState->isP2ControlledByAI());
	updatePlayer();
}
Exemplo n.º 2
0
//the game loop, calls all of the supplemental
//methods of the application to continuously
//update and maintain the functionality of the
//game
void Application::gameLoop()
{
    while(gameRunning)
    {
        handleEnvironment();

        updateMonsters();

        handleEvents();

        updatePlayer();

        handleArrows();

        handlePhysics();

        delta.start();

        checkBoundaries();
        updateFPS();
        updatePoints();
        drawSurface();

        if(finished)
        {
            showFinal();
        }

    }
}
Exemplo n.º 3
0
void GameLayer::ccTouchMoved(CCTouch* touch, CCEvent* event)
{
	CCLOG("Touch Moved");

		endPos = CCDirector::sharedDirector()->convertToGL(touch->getLocation());
		tempPos = endPos - startPos;
		startPos = endPos;


	pigeonPos = pigeonSprite->getPosition();

	if (tempPos.y < 0 && pigeonPos.y < 3200)
	{
		pigeonPos.y += 5.0f;
	}
	else if (tempPos.y > 0 && pigeonPos.y > 2735)
	{
		pigeonPos.y -= 5.0f;
	}

	if (tempPos.x > 10 )
	{
			//pigeonPos.x += 4.0f;
			angle = -1.0f;
			
	}

	else if (tempPos.x < -10 )
	{
			//pigeonPos.x -= 4.0f;
			angle = 1.0f;
	}

	updatePlayer();
}
Exemplo n.º 4
0
/////////////////////////////////////////////////////////////////////////////
// startup
/////////////////////////////////////////////////////////////////////////////
BOOL CNetworkPlayCardDialog::OnInitDialog() 
{
	CHelpDialog::OnInitDialog();

	//help system
	m_strHelp = HELP_PLAYCARD;

	//get the current player
	m_iPlayer = VIEW->getPlayer();

	//disable image window
	m_ImageButton.EnableWindow(FALSE);

	//disable OK button until selection
	m_OKButton.EnableWindow(FALSE);

	//hide build options
	VIEW->showBuildOptions(FALSE);

	//update the player
	updatePlayer();

	//set focus to the cancel button
	GetDlgItem(IDCANCEL)->SetFocus();
	
	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Exemplo n.º 5
0
void MainWindow::on_pushButton_clicked()
{
    ++mediaIt;
    if(mediaIt == media.end())
        mediaIt = media.begin();
    updatePlayer();
}
Exemplo n.º 6
0
void Level::killCreature(Creature* creature) {
  bucketMap.removeElement(creature->getPosition(), creature);
  removeElement(creatures, creature);
  getSquare(creature->getPosition())->removeCreature();
  model->removeCreature(creature);
  if (creature->isPlayer())
    updatePlayer();
}
Exemplo n.º 7
0
void Level::killCreature(Creature* creature, Creature* attacker) {
  bucketMap->removeElement(creature->getPosition(), creature);
  removeElement(creatures, creature);
  getSafeSquare(creature->getPosition())->killCreature(attacker);
  model->killCreature(creature, attacker);
  if (creature->isPlayer())
    updatePlayer();
}
Exemplo n.º 8
0
/**
* \fn int main(int argc, char* argv[])
* \brief Main function.
* \param[in] argc Number of argument passed to the program.
* \param[in] argv Arguments passed to the program.
*/
int main(int argc, char* argv[]) {

   unsigned int frameLimit;

   /*Create the Game structure*/
   Game* game = createGame();

   frameLimit = SDL_GetTicks()+16;

   /* initializes SDL */
   initGame("MyLittleProject",game);

   /* initializes player */
   initializePlayer(game->player);

   /* loads resources */
   loadGame(game);

   /* Main loop */
   while(game->go == 1) {
      /* reads input from keyboard */
      getInput(game->input, game);

      /* checks if menu is used */
      if(game->onMenu == 0) {
         /* updates game */
         updatePlayer(game->player,game);
         updateObject(game);

         /* displays everything */
         draw(game);

      } else {
         switch(game->menuType) {

         case START :
            updateStartMenu(game->input,game);
            drawStartMenu(game); // ya un bug ici !
            break;

         case SELECT_LEVEL :
            updateSelectLevelMenu(game->input,game);
            drawSelectLevelMenu(game);

         }
      }

      /*set the framerate at 60 FPS*/
      delay(frameLimit);
      frameLimit = SDL_GetTicks()+16;
   }

   /*free everything*/
   destroyGame(game);

   return EXIT_SUCCESS;
}
Exemplo n.º 9
0
int main (int argc, char* argv[])
{


	if (!loadMapFromFile ("maps/level1.map"))
	{
		printf ("Can't locate map!");
	}

	initGUI();
	initMap();
	initPlayer();

	SDL_Event e;
	int quit = 0;

	int start_time;
	int urd_time;
	int wait_time;
	int target_time = 1000/FPS;

	while (!quit)
	{
		start_time = SDL_GetTicks();

		while (SDL_PollEvent (&e))
		{
			if (e.type == SDL_QUIT)
			{
				quit = 1;
			}
			else
			{
				player->left = 0;
				player->right = 0;
			}
			processInput ();
		}

		clearScreen();
		updatePlayer (player);
		renderBackground();
		renderMap();
		renderPlayer (player);
		draw();

		urd_time = (SDL_GetTicks() - start_time);
		wait_time = target_time - urd_time;

		SDL_Delay (wait_time);
	}

	destroyGUI();
	deletePlayer (player);

	return 0;
}
Exemplo n.º 10
0
void gameLoop() {
    while (game_state != GAME_DONE && quit != TRUE && player.is_dead == FALSE) {
        getPlayerInput();
        if (quit == FALSE) {
            updatePlayer();
            drawPlayArea();
            drawStatsArea();
        }
    }
}
Exemplo n.º 11
0
void SetupScreen::playerSwitchRole(std::string uniqueId, std::string name, std::string oldRole, std::string newRole)
{
    PlayerObj player;
    player.uniqueId = uniqueId;
    player.name = name;
    player.role = oldRole;
    removePlayer(player);
    player.role = newRole;
    updatePlayer(player);
}
LRESULT CALLBACK
Cieambulant::PluginWinProc(UINT msg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) {
	typedef HRGN NPRegion;
	if (updatePlayer() != S_OK)
		return S_FALSE;

	switch (msg) {
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdc = BeginPaint(&ps);
			if (m_hwnd && m_ambulant_player) {
				HDC hdc = ::GetDC(m_hwnd);
				m_ambulant_player->redraw(m_hwnd, hdc, NULL); // XXX Should pass dirty rect
				::ShowWindow(m_hwnd, SW_SHOW);
				::ReleaseDC(m_hwnd, hdc);
			}
			EndPaint(&ps);
		}
		break;
	case WM_LBUTTONDOWN:
	case WM_MOUSEMOVE:
		POINT point;
		point.x=GET_X_LPARAM(lParam);
		point.y=GET_Y_LPARAM(lParam);
		if (m_ambulant_player) {
			if (msg == WM_MOUSEMOVE) {
				// code copied from MmView.cpp
				int new_cursor_id = m_ambulant_player->get_cursor(point.x, point.y, m_hwnd);
				if(new_cursor_id != m_cursor_id) {
					HINSTANCE hIns = 0;
					HCURSOR new_cursor = 0;
					if(new_cursor_id == 0) {
						new_cursor = LoadCursor(hIns, IDC_ARROW);
					} else {
						new_cursor = LoadCursor(hIns, IDC_HAND);
					}
					SetClassLongPtr(m_hwnd, GCLP_HCURSOR, HandleToLong(new_cursor));
					m_cursor_id = new_cursor_id;
				}
			} else {
				m_ambulant_player->on_click(point.x, point.y, m_hwnd);
			}
		}
		break;

	default:
		break;
	}
	BOOL rv = DefWindowProc(msg, wParam, lParam);
	bHandled = rv;
	return rv;
}
Exemplo n.º 13
0
void SetupScreen::playerJoined(std::string uniqueId, std::string name, std::string role)
{
    PlayerObj player;
    player.uniqueId = uniqueId;
    player.name = name;
    player.role = role;
    updatePlayer(player);
    if(_gameSetup->isHosting() && player2.uniqueId == "")
    {
        // force the new player role to be 2
        _gameSetup->assignRole(uniqueId, "2");
    }
}
Exemplo n.º 14
0
int		Menu::update(gdl::Input & input_)
{
  int		ret;
  
  if (input_.isKeyDown(gdl::Keys::Back) && this->which != 0)
    this->which = 0;
  if (this->which == 0)
    ret = updateMain(input_);
  else if (this->which == 1)
    ret = updateNew(input_);
  else if (this->which == 2)
    ret = updateLoad(input_);
  else if (this->which == 3)
    ret = updatePlayer(input_);
  return (ret);
}
Exemplo n.º 15
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    mediaPlayer(std::make_unique<MediaPlayer>(nullptr))
{
    ui->setupUi(this);
    ui->verticalLayout->addWidget(mediaPlayer.get());

    media.emplace_back("../../dummyImage.jpg", QList<Medium::Annotation>({Medium::Annotation(0, QRect(100,200,100,50))}));
    media.emplace_back("../../dummyImage_small.jpg", QList<Medium::Annotation>());
    media.emplace_back("../../dummyImage_big.jpg", QList<Medium::Annotation>({Medium::Annotation(0, QRect(965,200,115,400)), Medium::Annotation(0, QRect(310,310,225,175))}));

    mediaIt = media.begin();

    updatePlayer();
}
Exemplo n.º 16
0
Mode PlayMode::frame()
{
  if(!paused)
  {
    background->draw();
    if(!handleInput())
      return MENU;
    if(!crashed)
    {
      moveField();
      background->update();
      updatePlayer();
      generateWalls();
      generateObstacles();
      generateItems();
    }
    updatePlayerTail();
    particles->draw(0);
    particles->draw(2);
    drawStuff();
    particles->draw(4);
    drawPlayer();
    particles->draw(1);
    floating->draw();
    collisionDetect();
    obstacleCounter();
    drawScorePanel();
    if(crashed && !gameOverExplosionTime--)
    {
      globalStore->seconds = playtime / 60;
      globalStore->score = score;
      globalStore->obstacles = passed;
      globalStore->stars = collected;
      storage->read();
      storage->insert(score);
      return GAMEOVER;
    }
    particles->update();
    floating->update();
  } else
  {
    drawPauseScreen();
    if(!handleInput())
      return MENU;
  }
  return PLAY;
}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
	unsigned int frameLimit = SDL_GetTicks() + 16;
	int go;

   	/* Initialisation de la SDL */

	init("RageGame");

    /* On initialise le joueur */
     initializePlayer();

	/* Chargement des ressources (graphismes, sons) */
	loadGame();

	/* Appelle la fonction cleanup à la fin du programme */

	atexit(cleanup);

	go = 1;


	/* Boucle infinie, principale, du jeu */

	while (go == 1)
	{

		/* On prend on compte les input (clavier, joystick... */
		getInput();

		/* On met à jour le jeu */
		updatePlayer();

		/* On affiche tout */
		draw();

		/* Gestion des 60 fps (1000ms/60 = 16.6 -> 16 */
		delay(frameLimit);
		frameLimit = SDL_GetTicks() + 16;

	}

	/* Exit */

	exit(0);
}
Exemplo n.º 18
0
void update(int value)
{
	updateAnimations();
	updatePointer();
	updatePlayer();
	updateBullet();
	updateCubes();
	updateExplosions();
	updateScore();

	// comunica cata cuburi mai sunt
	sprintf_s(_windowTitle, 39, "JakCube - %d cubes left", _evilCubes.size());
	_windowTitle[39] = NULL;
	glutSetWindowTitle(_windowTitle);

	glutPostRedisplay();
	glutTimerFunc(25, update, 0);
}
Exemplo n.º 19
0
//The main game loop
void runGame(void) {
	undrawPlayers();
	
	//Update player structs
	updateActions();
	int i;

	//Draws the player
	for (i = 0; i < numPlayers; i++) {
		if(p[i].alive)updatePlayer(i);
	}

	//Redraw UI
	drawBullet(p[turn].bulletType);
	drawGas(p[turn].gas);
	drawPower(p[turn].power);
	updateScreen();
}
Exemplo n.º 20
0
/*
The Play method : makes use of the Load,update,settings and the playlist class

*/
void PlayerFMOD::play()
{
load();

    /*
        Main loop.
    */
    do
    {
        
         checkNplayNext();
          controlPlayer();
           updatePlayer();

        Sleep(10);

    } while (key != 27);
     
    printf("\n");


}
Exemplo n.º 21
0
void GameScene::updateGame(sf::RenderWindow& window, sf::Event& Event)
{
	
	backgroundSpriteMed.setPosition(0, backgroundOffsetMed);

	deltaTime = (deltaTimer.getElapsedTime() - lastFrameTime).asSeconds();
	lastFrameTime = deltaTimer.getElapsedTime();


	if(updatePlayer() == 1 && windowUpdating)
		window.close();

	backgroundOffsetLow += 320 * deltaTime;

	if (backgroundOffsetLow > 512)
		backgroundOffsetLow -= 512;

	backgroundSpriteLow.setPosition(0, backgroundOffsetLow);
	backgroundOffsetMed += 400 * deltaTime;

	if (backgroundOffsetMed > 512)
		backgroundOffsetMed -= 512;

	backgroundSpriteMed.setPosition(0, backgroundOffsetMed);

	if(Event.type == sf::Event::Closed || Event.key.code == sf::Keyboard::Escape)
	{
		done = true;
	}
	if(Event.type == sf::Event::KeyReleased)
	{

	}
	std::string enemyInfo = "";
	for(int x = 0; x < enemyPlayers.size(); x++)
		enemyInfo += enemyPlayers[x]->getName() + " " + std::to_string(enemyPlayers[x]->getScore()) + "\n";
	userNameText.setString(playerName + " " + std::to_string(mainPlayer->getScore()) + "\n" + enemyInfo);
}
Exemplo n.º 22
0
void PlayState::update()
{
	// Shake the background up and down when bomb is used
	if(bombAnimation)
	{
		bombAnimationCount++;
		bombShakeCounter++;
		// Up
		if(bombShakeCounter < 5)
		{
			starsBG_Pos.y -= 2;
		}
		// Down + Down
		else if(bombShakeCounter < 15)
		{
			starsBG_Pos.y += 2;
		}
		// Up
		else if(bombShakeCounter < 20)
		{
			starsBG_Pos.y -= 2;
		}
		// Reset
		else
		{
			bombShakeCounter = 0;
			--starsBG_Pos.y;
		}

		if(bombAnimationCount == BOMB_ANIMATION_LENGTH)
		{
			bombAnimationCount = 0;
			bombAnimation = false;
		}
	}

	// Move BG
	++bgMoveCounter;

	if(bgMoveCounter > 2)
	{
		++starsBG_Pos.x;
		bgMoveCounter = 0;
	}

	REG_BG0VOFS = starsBG_Pos.y;
	REG_BG0HOFS = starsBG_Pos.x;

	updateText();

	// Update the stage
	currentStage->update();

	// Checks for button pushes and updates accordingly
	checkInput();

	updatePlayer();
	
	// Udates the PowerUp and checks for collisions
	updatePowerUp();

	// Updates all of the enemies and has them fire.
	updateEnemies();

	// Updates all of the bullets and checks for collisions
	updateBullets();
}
Exemplo n.º 23
0
static inline void render1(void)
{
	scanKeys();
	
	// cpuEndSlice();
	playerControls(NULL);
	updateControls();
	// iprintf("controls : %d  \n",cpuEndSlice());
	
		updatePlayer(NULL);
	// iprintf("player : %d  \n",cpuEndSlice());
	
		updatePortals();
		updateTurrets();
		updateBigButtons();
		updateTimedButtons();
		updateEnergyDevices();
		updateEnergyBalls();
		updatePlatforms();
		updateCubeDispensers();
		updateEmancipators();
		updateEmancipationGrids();
		updateDoors();
		updateWallDoors();
	// iprintf("updates : %d  \n",cpuEndSlice());
	
	// if(currentPortal)GFX_CLEAR_COLOR=currentPortal->color|(31<<16);
	// else GFX_CLEAR_COLOR=0;
	u16 color=getCurrentPortalColor(getPlayer()->object->position);
	// NOGBA("col %d",color);
	// GFX_CLEAR_COLOR=color|(31<<16);
	GFX_CLEAR_COLOR=RGB15(0,0,0)|(31<<16);
	
	#ifdef DEBUG_GAME
		if(fifoCheckValue32(FIFO_USER_08))iprintf("\x1b[0J");
		while(fifoCheckValue32(FIFO_USER_08)){int32 cnt=fifoGetValue32(FIFO_USER_08);iprintf("ALERT %d      \n",cnt);NOGBA("ALERT %d      \n",cnt);}
	#else
		while(fifoCheckValue32(FIFO_USER_08)){int32 cnt=fifoGetValue32(FIFO_USER_08);NOGBA("ALERT %d      \n",cnt);}
	#endif
	
	projectCamera(NULL);

	glPushMatrix();
		
		glScalef32(SCALEFACT,SCALEFACT,SCALEFACT);
		
		renderGun(NULL);
		
		transformCamera(NULL);
		
		cpuEndSlice();
			// drawRoomsGame(128, color);
			drawRoomsGame(0, color);
			// drawCell(getCurrentCell(getPlayer()->currentRoom,getPlayerCamera()->position));
		// iprintf("room : %d  \n",cpuEndSlice());
		
		updateParticles();
		drawParticles();
		// iprintf("particles : %d  \n",cpuEndSlice());
		
			drawOBBs();
		// iprintf("OBBs : %d  \n",cpuEndSlice());
			drawBigButtons();
			drawTimedButtons();
			drawEnergyDevices();
			drawEnergyBalls();
			drawPlatforms();
			drawCubeDispensers();
			drawTurretsStuff();
			drawEmancipators();
			drawEmancipationGrids();
			drawDoors();
			drawWallDoors(NULL);
			drawSludge(&gameRoom);
		// iprintf("stuff : %d  \n",cpuEndSlice());
		
		drawPortal(&portal1);
		drawPortal(&portal2);
			
	glPopMatrix(1);

	//HUD TEST
	if(levelInfoCounter>0 && (levelTitle || levelAuthor))
	{
		levelInfoCounter--;
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
			glLoadIdentity();
			glOrthof32(inttof32(0), inttof32(255), inttof32(191), inttof32(0), -inttof32(1), inttof32(1));
			
			glMatrixMode(GL_MODELVIEW);
			glPushMatrix();
				glLoadIdentity();

				if(levelTitle)drawCenteredString(levelTitle, inttof32(17)/10, (82));
				if(levelAuthor)drawCenteredString(levelAuthor, inttof32(1), (100));

			glPopMatrix(1);
			glMatrixMode(GL_PROJECTION);
		glPopMatrix(1);
	}
	
	glFlush(0);
}
Exemplo n.º 24
0
void CharCreateDialog::action(const gcn::ActionEvent &event)
{
    const std::string id = event.getId();
    if (id == "create")
    {
        if (
#ifdef MANASERV_SUPPORT
            Net::getNetworkType() == ServerInfo::MANASERV ||
#endif
            getName().length() >= 4)
        {
            // Attempt to create the character
            mCreateButton->setEnabled(false);

            std::vector<int> atts;
            for (unsigned i = 0; i < mAttributeSlider.size(); i++)
            {
                atts.push_back(static_cast<int>(
                    mAttributeSlider[i]->getValue()));
            }

            int characterSlot = mSlot;
#ifdef MANASERV_SUPPORT
            // On Manaserv, the slots start at 1, so we offset them.
            if (Net::getNetworkType() == ServerInfo::MANASERV)
                ++characterSlot;
#endif

            Net::getCharHandler()->newCharacter(getName(), characterSlot,
                mFemale->isSelected(), mHairStyle, mHairColor, mRace, atts);
        }
        else
        {
            new OkDialog(_("Error"),
                _("Your name needs to be at least 4 characters."),
                DIALOG_ERROR, true,  this);
        }
    }
    else if (id == "cancel")
    {
        scheduleDelete();
    }
    else if (id == "nextcolor")
    {
        mHairColor ++;
        updateHair();
    }
    else if (id == "prevcolor")
    {
        mHairColor --;
        updateHair();
    }
    else if (id == "nextstyle")
    {
        mHairStyle ++;
        updateHair();
    }
    else if (id == "prevstyle")
    {
        mHairStyle --;
        updateHair();
    }
    else if (id == "nextrace")
    {
        mRace ++;
        updateRace();
    }
    else if (id == "prevrace")
    {
        mRace --;
        updateRace();
    }
    else if (id == "statslider")
    {
        updateSliders();
    }
    else if (id == "gender")
    {
        if (mMale->isSelected())
            mPlayer->setGender(GENDER_MALE);
        else
            mPlayer->setGender(GENDER_FEMALE);
    }
    else if (id == "action")
    {
        mAction ++;
        if (mAction >= 5)
            mAction = 0;
        updatePlayer();
    }
    else if (id == "rotate")
    {
        mDirection ++;
        if (mDirection >= 4)
            mDirection = 0;
        updatePlayer();
    }
}
Exemplo n.º 25
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot):
    Window(_("New Character"), true, parent, "charcreate.xml"),
    mCharSelectDialog(parent),
    mRace(0),
    mSlot(slot),
    mAction(0),
    mDirection(0)
{
    setStickyButtonLock(true);
    setSticky(true);
    setWindowName("NewCharacter");

    mPlayer = new Being(0, ActorSprite::PLAYER, mRace, nullptr);
    mPlayer->setGender(GENDER_MALE);

    maxHairColor = CharDB::getMaxHairColor();
    minHairColor = CharDB::getMinHairColor();
    if (!maxHairColor)
        maxHairColor = ColorDB::getHairSize();

    maxHairStyle = CharDB::getMaxHairStyle();
    minHairStyle = CharDB::getMinHairStyle();
    if (!maxHairStyle)
        maxHairStyle = mPlayer->getNumOfHairstyles();

    mHairStyle = (rand() % maxHairStyle) + minHairStyle;
    mHairColor = (rand() % maxHairColor) + minHairColor;

    mNameField = new TextField("");
    mNameField->setMaximum(24);
    mNameLabel = new Label(_("Name:"));
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    mNextHairColorButton = new Button(_(">"), "nextcolor", this);
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    mPrevHairColorButton = new Button(_("<"), "prevcolor", this);
    mHairColorLabel = new Label(_("Hair color:"));
    mHairColorNameLabel = new Label("");
    mNextHairStyleButton = new Button(_(">"), "nextstyle", this);
    mPrevHairStyleButton = new Button(_("<"), "prevstyle", this);
    mHairStyleLabel = new Label(_("Hair style:"));
    mHairStyleNameLabel = new Label("");
    mActionButton = new Button(_("^"), "action", this);
    mRotateButton = new Button(_(">"), "rotate", this);

    if (serverVersion >= 2)
    {
        mNextRaceButton = new Button(_(">"), "nextrace", this);
        mPrevRaceButton = new Button(_("<"), "prevrace", this);
        mRaceLabel = new Label(_("Race:"));
        mRaceNameLabel = new Label("");
    }

    mCreateButton = new Button(_("Create"), "create", this);
    mCancelButton = new Button(_("Cancel"), "cancel", this);
    mMale = new RadioButton(_("Male"), "gender");
    mFemale = new RadioButton(_("Female"), "gender");
    mOther = new RadioButton(_("Other"), "gender");

    // Default to a Male character
    mMale->setSelected(true);

    mMale->setActionEventId("gender");
    mFemale->setActionEventId("gender");
    mOther->setActionEventId("gender");

    mMale->addActionListener(this);
    mFemale->addActionListener(this);
    mOther->addActionListener(this);

    mPlayerBox = new PlayerBox(mPlayer);
    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mAttributesLeft = new Label(
            strprintf(_("Please distribute %d points"), 99));

    int w = 480;
    int h = 350;
    setContentSize(w, h);
    mPlayerBox->setDimension(gcn::Rectangle(350, 40, 110, 90));
    mActionButton->setPosition(375, 140);
    mRotateButton->setPosition(405, 140);

    mNameLabel->setPosition(5, 10);
    mNameField->setDimension(
            gcn::Rectangle(60, 10, 300, mNameField->getHeight()));

    int leftX = 120;
    int rightX = 300;
    int labelX = 5;
    int nameX = 145;
    mPrevHairColorButton->setPosition(leftX, 40);
    mNextHairColorButton->setPosition(rightX, 40);
    mHairColorLabel->setPosition(labelX, 45);
    mHairColorNameLabel->setPosition(nameX, 45);
    mPrevHairStyleButton->setPosition(leftX, 69);
    mNextHairStyleButton->setPosition(rightX, 69);
    mHairStyleLabel->setPosition(labelX, 74);
    mHairStyleNameLabel->setPosition(nameX, 74);

    if (serverVersion >= 2)
    {
        mPrevRaceButton->setPosition(leftX, 103);
        mNextRaceButton->setPosition(rightX, 103);
        mRaceLabel->setPosition(labelX, 108);
        mRaceNameLabel->setPosition(nameX, 108);
    }

    mAttributesLeft->setPosition(15, 280);
    updateSliders();
    mCancelButton->setPosition(
            w / 2,
            h - 5 - mCancelButton->getHeight());
    mCreateButton->setPosition(
            mCancelButton->getX() - 5 - mCreateButton->getWidth(),
            h - 5 - mCancelButton->getHeight());

    mMale->setPosition(30, 120);
    mFemale->setPosition(100, 120);
    mOther->setPosition(170, 120);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mHairColorNameLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mHairStyleNameLabel);
    add(mActionButton);
    add(mRotateButton);

    if (serverVersion >= 2)
    {
        add(mNextRaceButton);
        add(mPrevRaceButton);
        add(mRaceLabel);
        add(mRaceNameLabel);
    }

    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    add(mMale);
    add(mFemale);
    add(mOther);

    center();
    setVisible(true);
    mNameField->requestFocus();

    updateHair();
    if (serverVersion >= 2)
        updateRace();

    updatePlayer();

    addKeyListener(this);
}
Exemplo n.º 26
0
CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
                                   const int slot) :
    // TRANSLATORS: char create dialog name
    Window(_("New Character"), Modal_true, parent, "charcreate.xml"),
    ActionListener(),
    KeyListener(),
    mCharSelectDialog(parent),
    mNameField(new TextField(this, "")),
    // TRANSLATORS: char create dialog label
    mNameLabel(new Label(this, _("Name:"))),
    // TRANSLATORS: This is a narrow symbol used to denote 'next'.
    // You may change this symbol if your language uses another.
    // TRANSLATORS: char create dialog button
    mNextHairColorButton(new Button(this, _(">"), "nextcolor", this)),
    // TRANSLATORS: This is a narrow symbol used to denote 'previous'.
    // You may change this symbol if your language uses another.
    // TRANSLATORS: char create dialog button
    mPrevHairColorButton(new Button(this, _("<"), "prevcolor", this)),
    // TRANSLATORS: char create dialog label
    mHairColorLabel(new Label(this, _("Hair color:"))),
    mHairColorNameLabel(new Label(this, "")),
    // TRANSLATORS: char create dialog button
    mNextHairStyleButton(new Button(this, _(">"), "nextstyle", this)),
    // TRANSLATORS: char create dialog button
    mPrevHairStyleButton(new Button(this, _("<"), "prevstyle", this)),
    // TRANSLATORS: char create dialog label
    mHairStyleLabel(new Label(this, _("Hair style:"))),
    mHairStyleNameLabel(new Label(this, "")),
    mNextRaceButton(nullptr),
    mPrevRaceButton(nullptr),
    mRaceLabel(nullptr),
    mRaceNameLabel(nullptr),
    mNextLookButton(nullptr),
    mPrevLookButton(nullptr),
    mLookLabel(nullptr),
    mLookNameLabel(nullptr),
    // TRANSLATORS: char create dialog button
    mActionButton(new Button(this, _("^"), "action", this)),
    // TRANSLATORS: char create dialog button
    mRotateButton(new Button(this, _(">"), "rotate", this)),
    mAttributeSlider(),
    mAttributeLabel(),
    mAttributeValue(),
    mAttributesLeft(new Label(this,
        // TRANSLATORS: char create dialog label
        strprintf(_("Please distribute %d points"), 99))),
    // TRANSLATORS: char create dialog button
    mCreateButton(new Button(this, _("Create"), "create", this)),
    // TRANSLATORS: char create dialog button
    mCancelButton(new Button(this, _("Cancel"), "cancel", this)),
    mPlayer(new Being(BeingId_zero,
            ActorType::Player,
            BeingTypeId_zero,
            nullptr)),
    mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml",
        "charcreate_selectedplayerbox.xml")),
    mGenderStrip(nullptr),
    mMaxPoints(0),
    mUsedPoints(0),
    mRace(CharDB::getMinRace()),
    mLook(0),
    mMinLook(CharDB::getMinLook()),
    mMaxLook(CharDB::getMaxLook()),
    mMinRace(CharDB::getMinRace()),
    mMaxRace(CharDB::getMaxRace()),
    mHairStyle(0),
    mHairColor(0),
    mSlot(slot),
    mDefaultGender(Gender::FEMALE),
    mGender(Gender::UNSPECIFIED),
    maxHairColor(CharDB::getMaxHairColor()),
    minHairColor(CharDB::getMinHairColor()),
    maxHairStyle(CharDB::getMaxHairStyle()),
    minHairStyle(CharDB::getMinHairStyle()),
    mAction(0),
    mDirection(0)
{
    setStickyButtonLock(true);
    setSticky(true);
    setWindowName("NewCharacter");

    const int w = 480;
    const int h = 350;
    setContentSize(w, h);

    mPlayer->setGender(Gender::MALE);
    const std::vector<int> &items = CharDB::getDefaultItems();
    int i = 1;
    for (std::vector<int>::const_iterator it = items.begin(),
         it_end = items.end();
         it != it_end; ++ it, i ++)
    {
        mPlayer->setSprite(i, *it);
    }

    if (!maxHairColor)
        maxHairColor = ColorDB::getHairSize();
    if (!maxHairStyle)
        maxHairStyle = mPlayer->getNumOfHairstyles();

    if (maxHairStyle)
    {
        mHairStyle = (static_cast<unsigned int>(rand())
            % maxHairStyle) + minHairStyle;
    }
    else
    {
        mHairStyle = 0;
    }
    if (maxHairColor)
    {
        mHairColor = (static_cast<unsigned int>(rand())
            % maxHairColor) + minHairColor;
    }
    else
    {
        mHairColor = 0;
    }

    mNameField->setMaximum(24);

    if (serverFeatures->haveRaceSelection())
    {
        // TRANSLATORS: char create dialog button
        mNextRaceButton = new Button(this, _(">"), "nextrace", this);
        // TRANSLATORS: char create dialog button
        mPrevRaceButton = new Button(this, _("<"), "prevrace", this);
        // TRANSLATORS: char create dialog label
        mRaceLabel = new Label(this, _("Race:"));
        mRaceNameLabel = new Label(this, "");
    }
    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        // TRANSLATORS: char create dialog button
        mNextLookButton = new Button(this, _(">"), "nextlook", this);
        // TRANSLATORS: char create dialog button
        mPrevLookButton = new Button(this, _("<"), "prevlook", this);
        // TRANSLATORS: char create dialog label
        mLookLabel = new Label(this, _("Look:"));
        mLookNameLabel = new Label(this, "");
    }

    if (serverFeatures->haveCreateCharGender())
    {
        const int size = config.getIntValue("fontSize");
        mGenderStrip = new TabStrip(this,
            "gender_" + getWindowName(),
            size + 16);
        mGenderStrip->setPressFirst(false);
        mGenderStrip->addActionListener(this);
        mGenderStrip->setActionEventId("gender_");
        // TRANSLATORS: one char size female character gender
        mGenderStrip->addButton(_("F"), "f", false);
        // TRANSLATORS: one char size male character gender
        mGenderStrip->addButton(_("M"), "m", false);
        // TRANSLATORS: one char size unknown character gender
        mGenderStrip->addButton(_("U"), "u", true);
        mGenderStrip->setVisible(Visible_true);
        add(mGenderStrip);

        mGenderStrip->setPosition(385, 130);
        mGenderStrip->setWidth(500);
        mGenderStrip->setHeight(50);
    }

    mPlayerBox->setWidth(74);

    mNameField->setActionEventId("create");
    mNameField->addActionListener(this);

    mPlayerBox->setDimension(Rect(360, 0, 110, 90));
    mActionButton->setPosition(385, 100);
    mRotateButton->setPosition(415, 100);

    mNameLabel->setPosition(5, 2);
    mNameField->setDimension(
            Rect(60, 2, 300, mNameField->getHeight()));

    const int leftX = 120;
    const int rightX = 300;
    const int labelX = 5;
    const int nameX = 145;
    int y = 30;

    mPrevHairColorButton->setPosition(leftX, y);
    mNextHairColorButton->setPosition(rightX, y);
    y += 5;
    mHairColorLabel->setPosition(labelX, y);
    mHairColorNameLabel->setPosition(nameX, y);
    y += 24;
    mPrevHairStyleButton->setPosition(leftX, y);
    mNextHairStyleButton->setPosition(rightX, y);
    y += 5;
    mHairStyleLabel->setPosition(labelX, y);
    mHairStyleNameLabel->setPosition(nameX, y);

    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        y += 24;
        if (mPrevLookButton)
            mPrevLookButton->setPosition(leftX, y);
        if (mNextLookButton)
            mNextLookButton->setPosition(rightX, y);
        y += 5;
        if (mLookLabel)
            mLookLabel->setPosition(labelX, y);
        if (mLookNameLabel)
            mLookNameLabel->setPosition(nameX, y);  // 93
    }
    if (serverFeatures->haveRaceSelection())
    {
        y += 24;
        if (mPrevRaceButton)
            mPrevRaceButton->setPosition(leftX, y);
        if (mNextRaceButton)
            mNextRaceButton->setPosition(rightX, y);
        y += 5;
        if (mRaceLabel)
            mRaceLabel->setPosition(labelX, y);
        if (mRaceNameLabel)
            mRaceNameLabel->setPosition(nameX, y);
    }

    updateSliders();
    setButtonsPosition(w, h);

    add(mPlayerBox);
    add(mNameField);
    add(mNameLabel);
    add(mNextHairColorButton);
    add(mPrevHairColorButton);
    add(mHairColorLabel);
    add(mHairColorNameLabel);
    add(mNextHairStyleButton);
    add(mPrevHairStyleButton);
    add(mHairStyleLabel);
    add(mHairStyleNameLabel);
    add(mActionButton);
    add(mRotateButton);

    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
    {
        add(mNextLookButton);
        add(mPrevLookButton);
        add(mLookLabel);
        add(mLookNameLabel);
    }

    if (serverFeatures->haveRaceSelection())
    {
        add(mNextRaceButton);
        add(mPrevRaceButton);
        add(mRaceLabel);
        add(mRaceNameLabel);
    }

    add(mAttributesLeft);
    add(mCreateButton);
    add(mCancelButton);

    center();
    setVisible(Visible_true);
    mNameField->requestFocus();

    updateHair();
    if (serverFeatures->haveRaceSelection())
        updateRace();
    if (serverFeatures->haveLookSelection() && mMinLook < mMaxLook)
        updateLook();
    updatePlayer();

    addKeyListener(this);
}
Exemplo n.º 27
0
void CharCreateDialog::action(const ActionEvent &event)
{
    const std::string &id = event.getId();
    if (id == "create")
    {
        if (getName().length() >= 4)
        {
            // Attempt to create the character
            mCreateButton->setEnabled(false);

            std::vector<int> atts;
            for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
            {
                atts.push_back(static_cast<int>(
                    mAttributeSlider[i]->getValue()));
            }

            const int characterSlot = mSlot;

            charServerHandler->newCharacter(getName(),
                characterSlot,
                mGender,
                mHairStyle,
                mHairColor,
                static_cast<unsigned char>(mRace),
                static_cast<unsigned char>(mLook),
                atts);
        }
        else
        {
            CREATEWIDGET(OkDialog,
                // TRANSLATORS: char creation error
                _("Error"),
                // TRANSLATORS: char creation error
                _("Your name needs to be at least 4 characters."),
                // TRANSLATORS: ok dialog button
                _("OK"),
                DialogType::ERROR,
                Modal_true,
                ShowCenter_true,
                nullptr,
                260);
        }
    }
    else if (id == "cancel")
    {
        scheduleDelete();
    }
    else if (id == "nextcolor")
    {
        mHairColor ++;
        updateHair();
    }
    else if (id == "prevcolor")
    {
        mHairColor --;
        updateHair();
    }
    else if (id == "nextstyle")
    {
        mHairStyle ++;
        updateHair();
    }
    else if (id == "prevstyle")
    {
        mHairStyle --;
        updateHair();
    }
    else if (id == "nextrace")
    {
        mRace ++;
        updateRace();
    }
    else if (id == "prevrace")
    {
        mRace --;
        updateRace();
    }
    else if (id == "nextlook")
    {
        mLook ++;
        updateLook();
    }
    else if (id == "prevlook")
    {
        mLook --;
        updateLook();
    }
    else if (id == "statslider")
    {
        updateSliders();
    }
    else if (id == "action")
    {
        mAction ++;
        if (mAction >= 5)
            mAction = 0;
        updatePlayer();
    }
    else if (id == "rotate")
    {
        mDirection ++;
        if (mDirection >= 4)
            mDirection = 0;
        updatePlayer();
    }
    else if (id == "gender_m")
    {
        mGender = Gender::MALE;
        mPlayer->setGender(Gender::MALE);
    }
    else if (id == "gender_f")
    {
        mGender = Gender::FEMALE;
        mPlayer->setGender(Gender::FEMALE);
    }
    else if (id == "gender_u")
    {
        mGender = Gender::UNSPECIFIED;
        mPlayer->setGender(mDefaultGender);
    }
}
Exemplo n.º 28
0
int main(int argc, char *argv[]){
	getinfo(&screen);
	clear(0);
	
	Triangle tri[] = {
	    {-1,0,1, -1,1,1, -2,0,1, 0xFFFF},{-2,1,1, -1,1,1, -2,0,1, 0xFFFF},
	    {-1,0,0, -1,1,0, -2,0,0, 0xFFFF},{-2,1,0, -1,1,0, -2,0,0, 0xFFFF},
	    
	    {-1,0,0, -1,0,1, -2,0,0, 0xFFFF},{-2,0,0, -1,0,1, -2,0,1, 0xFFFF},
	    {-1,1,0, -1,1,1, -2,1,0, 0xFFFF},{-2,1,0, -1,1,1, -2,1,1, 0xFFFF},
	    
	    {-1,0,0, -1,1,1, -1,0,1, 0xFFFF},{-1,0,0, -1,1,1, -1,1,0, 0xFFFF},
	    {-2,0,0, -2,1,1, -2,0,1, 0xFFFF},{-2,0,0, -2,1,1, -2,1,0, 0xFFFF}
	};
	
	Line complex[] = {
	    {2,2,2, 3,2,2, 0xFFFFFF},
	    {2,2,2, 2,2,3, 0xFFFFFF},
	    {3,2,2, 3,2,3, 0xFFFFFF},
	    {2,2,3, 3,2,3, 0xFFFFFF},

	    {2,2,2, 2.5,1,2.5, 0xFFFFFF},
	    {2,2,3, 2.5,1,2.5, 0xFFFFFF},
	    {3,2,2, 2.5,1,2.5, 0xFFFFFF},
	    {3,2,3, 2.5,1,2.5, 0xFFFFFF}
	};
	
	Camera defaultcam = {0, 0, -2, 0, 0, 0, 0, 0, 1};
	Player p = {defaultcam, {100,2,0.5,0.25, //size
				defaultcam.cx,defaultcam.cy,defaultcam.cz, //position
				0,0,0, //velocity
				0,0,0, //force
				defaultcam.ox,defaultcam.oy,defaultcam.oz, //orientation
				0,0,0, //angular speed
				0,0,0 //torque
				}};
	int i;
	Cube c[] = {newCube(0.25, 0, 0, 0, 0xFF),
		    newCube(0.5, 1, 1, 1, 0xFF00),
		    newCube(1, -2, 2, 2, 0xFF0000)};
	char update = 1;
	while(!checkkey(KEYQ)){
		if(checkkey(KEYW)) movePlayer(&p, 0, 0, 0.2);
		if(checkkey(KEYA)) movePlayer(&p, 0.2, 0, 0);
		if(checkkey(KEYS)) movePlayer(&p, 0, 0, -0.2);
		if(checkkey(KEYD)) movePlayer(&p, -0.2, 0, 0);
		if(checkkey(KEYSPACE) & p.o.y==0){
		    p.o.vy = 0.2;
		}
		//if(checkkey(KEYLEFTCONTROL)) movePlayer(&p, 0, -0.2, 0);
		
		if(checkkey(KEYK)>0 & p.o.ox < M_PI/2) p.o.ox += 0.05;
		if(checkkey(KEYI)>0 & p.o.ox > -M_PI/2) p.o.ox -= 0.05;
		if(checkkey(KEYL)) p.o.oy += 0.05;
		if(checkkey(KEYJ)) p.o.oy -= 0.05;
		
		if(checkkey(KEYE)==1) wireframe = !wireframe;
		
		if(checkkey(KEYX)) resetPlayer(&p, defaultcam);
		
		
		    updatePlayer(&p);
		    
		    clear(0);
		
		    drawTriangles3D(tri, sizeof(tri)/sizeof(Triangle), p.c);
		    drawSphere(1,1,-1,0.2,0xFF00FF,p.c);
		    for(i = 0; i < sizeof(c)/sizeof(Cube); i++) drawCube(c[i], p.c);
		    drawLines3D(complex, sizeof(complex)/sizeof(Line), p.c);
		    
		    drawtext(0,0,"Wireframe test. Press q to exit.",0xFFFFFF);
		    drawline(screen.x/2-8,screen.y/2,screen.x/2+8,screen.y/2,0xFFFFFF);
		    drawline(screen.x/2,screen.y/2-8,screen.x/2,screen.y/2+8,0xFFFFFF);

		for(i = 0; i < 7; i++) hlt();
	}
	reset();
	return 0;
}
Exemplo n.º 29
0
int main(void)
{
	srand(time(NULL));
	//char *sdl_error=NULL;
  int run=1;
  int width=getWindowWidth(), height=getWindowHeight(), fps_ms=getFramems();
	unsigned int drawn_frames=0, i=0, eye_left, eye_top, lives = 10;
	float m=0.f;
	Uint32 fps_helper,fps_now,fps_next,hit_helper=0,zombie_start_time,zombie_end_time;
	SDL_Surface *screen;
	SDL_Event event;
	SDL_Rect bg, eye;
	zombie enemy[ZOMBIES], player;
	vec2f enemy_random_movement[ZOMBIES];
	Uint8 *keys;
  SDL_Rect **modes;

 /* modes = SDL_ListModes(NULL, SDL_HWSURFACE | SDL_DOUBLEBUF);
  
   Check is there are any modes available
  if(modes == (SDL_Rect **)0){
    printf("No modes available!\n");
    exit(-1);
  }
     Print valid modes 
    printf("Available Modes\n");
    for(i=0;modes[i];++i)
      printf("  %d x %d\n", modes[i]->w, modes[i]->h); */
  
	if(SDL_Init(SDL_INIT_VIDEO)==-1)
	{
		printf("Fehler, SDL konnte nicht initialisiert werden: %s\n", SDL_GetError());
		SDL_Quit();
		return -1;
	}
	
	bg.x = 0;
	bg.y = 0;
	bg.w = width;
	bg.h = height;
	
	eye.w = (int)SQR_SIZE/5;
	eye.h = (int)SQR_SIZE/4;
	eye_left = eye.w;
	eye_top = eye.h;
	
	screen = window(width,height,32,SDL_HWSURFACE | SDL_DOUBLEBUF,"Zombie Blocks - http://gamer-source.org","Zombie Blocks"); // Fenster initalisieren

  player.rect.w = P_SIZE;
  player.rect.h = P_SIZE;	
	player.rect.x = (int) width/2-(int)player.rect.w/2;
	player.rect.y = (int) height/2-(int)player.rect.h/2;
	player.speed = PLAYER_SPEED;
	
	for(i=0;i<ZOMBIES;i++)
	{
    enemy[i].rect.w = ZMB_SIZE;
    enemy[i].rect.h = ZMB_SIZE;
		enemy[i].rect.x = (rand()%2)?rand()%((int)width/3):width-rand()%((int)width/3-SQR_SIZE)+SQR_SIZE;
		enemy[i].rect.y = (rand()%2)?rand()%((int)height/3):height-rand()%((int)height/3-SQR_SIZE)+SQR_SIZE;

    enemy[i].speed = (float) ZOMBIE_SPEED+(float)((rand()%3000)/1001.f);
		enemy_random_movement[i] = genStartBaseVec((rand()%5000)/5000.f);
    enemy[i].direction = getVector(rand()%360);
	}
	
	zombie_start_time = SDL_GetTicks();
	fps_helper = zombie_start_time+5000;
	fps_next = zombie_start_time+fps_ms;
	// MAIN LOOP
	while(run)
	{
		while (SDL_PollEvent(&event))
		{
			switch(event.type)
			{
				case SDL_QUIT:
				{
					run=0;
					zombie_end_time = SDL_GetTicks();
					break;
				}
				case SDL_KEYDOWN:
				{
					if(event.key.keysym.sym==SDLK_ESCAPE)
					{
						run=0;
						zombie_end_time = SDL_GetTicks();
					}
					break;
				}
			}
		}
// 		keys = SDL_GetKeyState(NULL);
    player = updatePlayer(player, SDL_GetKeyState(NULL));
		// GAME LOGIC
		//fps_now = SDL_GetTicks();
		for(i=0;i<ZOMBIES;i++)
		{		
			if(collideBoxes(player.rect, enemy[i].rect) && hit_helper<(fps_now = SDL_GetTicks()))
			{				
				lives--;
				printf("Lives: %u\n",lives);
				hit_helper = fps_now + 2000;
				player.rect.x = 0;
				player.rect.y = 0;
			}
			isInRange(enemy[i].rect, player.rect, 50);
			enemy[i].rect = calcEnemyPosRanged(enemy[i], player.rect, RANGE, &enemy_random_movement[i]);
		}
		if(lives==0)
		{
			run = 0;
			zombie_end_time = SDL_GetTicks();
		}
		// DRAWING <- should be replaced by OpenGL directives ... 
		SDL_FillRect(screen, &bg, SDL_MapRGB(screen->format, 151, 151, 151)); // draw background
#ifdef DEBUG
		for(i=0;i<ZOMBIES;i++)
		{
			SDL_Rect tmp_rect;
			tmp_rect.x = enemy[i].rect.x-RANGE+ZMB_SIZE/2;
			tmp_rect.y = enemy[i].rect.y-RANGE+ZMB_SIZE/2;
			tmp_rect.w = 2*RANGE;
			tmp_rect.h = tmp_rect.w;
			SDL_FillRect(screen, &tmp_rect, SDL_MapRGB(screen->format, 0, 100, 255)); // draw range field
		}
#endif	
		SDL_FillRect(screen, &player.rect, SDL_MapRGB(screen->format, 255, 255, 0)); // draw player
		eye.x = player.rect.x + eye_left;
		eye.y = player.rect.y + eye_top;
		SDL_FillRect(screen, &eye, SDL_MapRGB(screen->format, 0, 250, 0)); // draw player's left eye
		eye.x += 2*eye_left;
		SDL_FillRect(screen, &eye, SDL_MapRGB(screen->format, 0, 0, 250)); // draw player's right eyes
		// draw zombies
		for(i=0;i<ZOMBIES;i++)
		{
			SDL_FillRect(screen, &enemy[i].rect, SDL_MapRGB(screen->format, 255, 0, 0)); // draw body
			eye.x = enemy[i].rect.x + eye_left;
			eye.y = enemy[i].rect.y + eye_top;
			SDL_FillRect(screen, &eye, SDL_MapRGB(screen->format, 0, 0, 0)); // draw ZOMBIE's left eye
			eye.x += 2*eye_left;
			SDL_FillRect(screen, &eye, SDL_MapRGB(screen->format, 0, 0, 0)); // draw ZOMBIE's right eye
		}
		SDL_Flip(screen);
		
		// FPS output
		drawn_frames++;
		if(fps_helper<(fps_now = SDL_GetTicks()))
		{
			printf("%d Frames after %.3f Seconds => fps: %.3f\n",drawn_frames,(fps_now-fps_helper+5000)/1000.0f,drawn_frames/((fps_now-fps_helper+5000)/1000.0f));
			fps_helper = fps_now+5000;
			drawn_frames=0;
		}
		fps_now = SDL_GetTicks();
		SDL_Delay((fps_next<=fps_now)?0:fps_next-fps_now);
		fps_next += fps_ms;
	}
	
	// Quitting game
	printf("You've played %.2f seconds!\n",(float)(zombie_end_time-zombie_start_time)/1000.f);
	SDL_FreeSurface(screen);
	SDL_Quit();
	return 0;
}
Exemplo n.º 30
0
/////////////////////////////////////////////////////////////////////////////
// set offer data
/////////////////////////////////////////////////////////////////////////////
void CTradeOfferDialog::setOffer(int *iTo, int *iFor, UINT uiID)
{
	int i, j, k;
	int iRes;
	int iPlayer;
	BOOL bCanTrade = TRUE;
	BOOL bAnyTrade = FALSE;
	CRect rect;
	CRect rectClient;
	CString str;
	CDC *dc;
	HDC hDC;
	CHoverStatic *pStatic;
	CHoverStatic *pText;
	CButtonST *pButton;

	//reset trade counter
	m_iNumTrade = 0;

	//reset the changed flag
	m_bChanged = FALSE;

	//get the device context
	dc = GetDC();
	hDC = dc->GetSafeHdc();
	
	//get screen rect
	GetWindowRect(&rect);

	//get client rect
	GetClientRect(&rectClient);

	//enable counter button
	m_CounterButton.EnableWindow();

	//set data
	memcpy(m_iTrade, iTo, sizeof(m_iTrade));
	memcpy(m_iOTrade, iFor, sizeof(m_iOTrade));

	//reset trade places
	memset(m_iTradePlace, -1, sizeof(m_iTradePlace));
	memset(m_iOTradePlace, -1, sizeof(m_iOTradePlace));

	//set trade places
	for(i = 0, j = 0, k = 0; i < 5; i++)
	{
		if(0 < m_iTrade[i])
		{
			m_iTradePlace[j++] = i;		
		}
		if(0 < m_iOTrade[i])
		{
			m_iOTradePlace[k++] = i;
		}
	}

	//trade id
	m_uiTradeID = uiID;

	//set various text
	iPlayer = VIEW->getPlayer();

	//set title text
	str.Format("%s wants to trade!", GAME->m_players[iPlayer].m_player.getName());
	SetWindowText(str);

	//set static text
	str.Format("%s is offering these cards", GAME->m_players[iPlayer].m_player.getFirstName());
	m_PlayerStatic.SetWindowText(str);

	//set player to who we are
	iPlayer = GAME->m_iIndex;

	//update statics
	for(i = 0; i < 4; i++)
	{
		//get controls
		pText = &m_Trade1Text + i;
		pStatic = &m_Trade1Qty + i;
		pButton = &m_Trade1Button + i;

		//get the res
		iRes = m_iTradePlace[i];

		//show/hide from trader
		if(-1 != iRes)
		{
			m_iNumTrade++;
			pText->SetText(VIEW->getResName(iRes));
			pText->ShowWindow(SW_SHOW);
			pButton->SetBitmaps(VIEW->getResImage(iRes, dc->GetSafeHdc()), COLOR_TRANSP, VIEW->getResImage(iRes, dc->GetSafeHdc()), COLOR_TRANSP);
			pButton->ShowWindow(SW_SHOW);
			pButton->EnableWindow(FALSE);
			str.Format("%d", m_iTrade[iRes]);
			pStatic->SetText(str);
			pStatic->ShowWindow(SW_SHOW);
		}
		else
		{
			pText->ShowWindow(SW_HIDE);
			pButton->ShowWindow(SW_HIDE);
			pStatic->ShowWindow(SW_HIDE);
		}

		//get controls
		pText = &m_OTrade1Text + i;
		pStatic = &m_OTrade1Qty + i;
		pButton = &m_OTrade1Button + i;

		//get the res
		iRes = m_iOTradePlace[i];

		//show/hide
		if(-1 != iRes)
		{
			pText->SetText(VIEW->getResName(iRes));
			pText->ShowWindow(SW_SHOW);
			pButton->SetBitmaps(VIEW->getResImage(iRes, dc->GetSafeHdc()), COLOR_TRANSP, VIEW->getResImage(iRes, dc->GetSafeHdc()), COLOR_TRANSP);
			pButton->ShowWindow(SW_SHOW);
			pButton->EnableWindow(FALSE);
			str.Format("%d", m_iOTrade[iRes]);
			pStatic->SetText(str);
			pStatic->ShowWindow(SW_SHOW);
		}
		else
		{
			pText->ShowWindow(SW_HIDE);
			pButton->ShowWindow(SW_HIDE);
			pStatic->ShowWindow(SW_HIDE);
		}

		//see if they can even do this trade
		if(GAME->m_players[iPlayer].m_iRes[iRes] < m_iOTrade[iRes])
		{
			bCanTrade = FALSE;
		}
	}

	//reset the counteroffer buttons to be on (turned off in OnCounter)
	for(i = 0; i < 5; i++)
	{
		pButton = &m_OHand1Button + i;
		pButton->EnableWindow();

		pButton = &m_InHand1Button + i;
		pButton->EnableWindow();

		pText = &m_OHand1Text + i;
		pText->EnableWindow();

		pText = &m_Inhand1Text + i;
		pText->EnableWindow();

		pText = &m_Inhand1Qty + i;
		pText->EnableWindow();

		//see if we even have the ability to counteroffer
		if(0 < GAME->m_players[iPlayer].m_iRes[i])
		{
			bAnyTrade = TRUE;
		}
	}

	//enable/disable ability to trade
	m_OKButton.EnableWindow(bCanTrade);
	m_CounterButton.EnableWindow(bAnyTrade);

	//update the current player
	updatePlayer();	

	//update other player
	updateOPlayer();

	//set auto-reject timer
	m_iTime = GetPrivateProfileInt(INI_GENERAL, INI_TRADE_TIMEOUT, 15, INI_FILE);
	m_uiReject = SetTimer(TIMER_REJECT_TRADE, 1000, NULL);

	//set window pos sans counter	
	SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height() - rectClient.Height() + 105, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);

	//show ourselves
	ShowWindow(SW_SHOWNOACTIVATE);

	//release context
	ReleaseDC(dc);

	//set the focus to the view
	VIEW->SetFocus();
}