//============================================================================= // Get toClientData from server. // called by client to get game state from server //============================================================================= void NetworkClient::getInfoFromServer() { int size; size = sizeof(toClientData); int readStatus = net.readData((char *)&toClientData, size, remoteIP, remotePort); if( readStatus == netNS::NET_OK && size > 0) { distantPosition = toClientData.postition; for(int i=0; i<MAX_CLIENT; i++) // for all player positions { // load new data into each player // player[i].setNetData(toClientData.player[i].playerData); } // Game state // Bit 0 = roundStart // Bits 1-7 reserved for future use if((toClientData.gameState & ROUND_START_BIT) && countDownOn == false) roundStart(); gameState = toClientData.gameState; // save new game state commErrors = 0; commWarnings = 0; } }
void Purgatory::update() { if(player1.getActive()) { if (input->isKeyDown(VK_LEFT) || input->getGamepadDPadLeft(0)) //MOVE LEFT { background[0].setmoving(false);background[1].setmoving(false); player1.setmoving(true); player1.setDirectL(true); } else{input->clearKeyPress(VK_LEFT);player1.setmoving(false);player1.setDirectL(false);} if (input->isKeyDown(VK_RIGHT) || input->getGamepadDPadRight(0))//MOVE RIGHT { background[0].setmoving(true); background[1].setmoving(true); player1.setmoving(true); player1.setDirectR(true); } else { input->clearKeyPress(VK_RIGHT); player1.setmoving(false); player1.setDirectR(false); background[0].setmoving(false); background[1].setmoving(false); } if(input->isKeyDown(VK_UP)) { if(player1.getonground()) { player1.setjump(true); } } } if(roundOver) { roundStart(); } for(int i=0;i<3;i++) { if(enemy[i].getActive()) { enemy[i].setmoving(true); } if(enemy[i].getX()<=0) { playerScore+=1; } enemy[i].update(frameTime); } player1.update(frameTime); for(int j=0;j<2;j++) { background[j].update(frameTime); } }
//============================================================================= // Update all game items //============================================================================= void Spacewar::update() { if (menuOn) { if (input->anyKeyPressed()) { menuOn = false; input->clearAll(); roundStart(); } } else if(countDownOn) { countDownTimer -= frameTime; if(countDownTimer <= 0) countDownOn = false; } else { if (ship1.getActive()) { if (input->isKeyDown(SHIP1_FORWARD_KEY) || input->getGamepadDPadUp(0)) // if engine on { ship1.setEngineOn(true); audio->playCue(ENGINE1); } else { ship1.setEngineOn(false); audio->stopCue(ENGINE1); } ship1.rotate(shipNS::NONE); if (input->isKeyDown(SHIP1_LEFT_KEY) || input->getGamepadDPadLeft(0)) // if turn ship1 left ship1.rotate(shipNS::LEFT); if (input->isKeyDown(SHIP1_RIGHT_KEY) || input->getGamepadDPadRight(0)) // if turn ship1 right ship1.rotate(shipNS::RIGHT); } if(roundOver) { roundTimer -= frameTime; if(roundTimer <= 0) roundStart(); } } // Update the entities ship1.update(frameTime); // move space in X direction opposite ship space.setX(space.getX() - frameTime * ship1.getVelocity().x); // move space in Y direction opposite ship space.setY(space.getY() - frameTime * ship1.getVelocity().y); // Wrap space image around at edge // if left edge of space > screen left edge if (space.getX() > 0) // move space image left by SPACE_WIDTH space.setX(space.getX() - SPACE_WIDTH); // if space image off screen left if (space.getX() < -SPACE_WIDTH) // move space image right by SPACE_WIDTH space.setX(space.getX() + SPACE_WIDTH); // if top edge of space > screen top edge if (space.getY() > 0) // move space image up by SPACE_HEIGHT space.setY(space.getY() - SPACE_HEIGHT); // if space image off screen top if (space.getY() < -SPACE_HEIGHT) // move space image down by SPACE_IMAGE space.setY(space.getY() + SPACE_HEIGHT); }
int main() { cursorY = 0; cursorX = 0; int deltaY = 0; int deltaX = 0; srand(time(0)); initscr(); raw(); keypad(stdscr, TRUE); noecho(); curs_set(0); start_color(); resize_term(30, 80); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_RED, COLOR_BLACK); init_pair(4, COLOR_CYAN, COLOR_BLACK); init_pair(5, COLOR_WHITE, COLOR_RED); init_pair(6, COLOR_WHITE, COLOR_GREEN); init_pair(7, COLOR_WHITE, COLOR_YELLOW); init_pair(8, COLOR_RED, COLOR_RED); init_pair(9, COLOR_RED, COLOR_GREEN); init_pair(10, COLOR_RED, COLOR_YELLOW); init_pair(11, COLOR_WHITE, COLOR_BLACK); init_pair(12, COLOR_MAGENTA, COLOR_BLACK); while(retry){ Shop shop; SkillTree skillTree; breakLoop = false; int timeStart = time(0); clear(); cursorY = mapHeight/2; cursorX = mapWidth/2+5; playerMovementSpeed = 50; playerMovementSpeedHelper = 0; playerHealth = 100; playerMaxHealth = 100; playerStamina = 10; playerMaxStamina = 10; playerStaminaRegen = 250; playerStaminaRegenHelper = 0; playerAmmo = 100; playerBulletSpeed = 30; playerDamage = 1; playerBulletRange = 20; playerFiringSpeed = 500; playerFiringSpeedHelper = 0; playerClip = 10; playerClipLimit = 10; playerHiddenClip = 0; playerReloading = false; playerReloadingRate = 4000; playerReloadingHelper = 0; playerReloadingModifier = 0; playerSpecialWeaponTypes = {0,0,0,0,0,0,0,0,0,0}; playerWeaponName = {'P','i','s','t','o','l'}; playerCurrentWeapon = {0,0}; playerBandages = 0; playerBandaging = false; playerBandagesHelper = 0; playerMeleeDamage = 0; playerMeleeDirecton = 0; playerMeleeHelper = 0; playerStaminaPills = 0; playerMoney = 0; killMoney = 1; playerXP = 0; playerXPNeeded = 10; playerXPGet = 1; playerSkillPoints = 0; playerLevel = 1; lastTiersUnlocked = false; round = 1; roundZombies = 5; roundZombiesFloat = 5; roundZombiesHelper = 0; zombieSpawnRate = 5000; zombieSpawnRateHelper = 0; betweenRoundPause = false; betweenRoundPauseHelper = 0; zombieForceSpawnHelper = 500; playerTimeSurvived = 0; playerZombiesKilled = 0; playerBulletsFired = 0; playerTotalMoneyEarned = 0; playerMoves = 0; playerTimesBandaged = 0; playerTimesReloaded = 0; playerAmountBought = 0; playerAmountEnteredShop = 0; playerAmountEnteredSkillTree = 0; playerPeakMoneyOwned = 0; playerTotalStaminaPillsUsed = 0; playerAmountMelee = 0; playerTotalAmountForce = 0; playerTimesHit = 0; playerTimesPaused = 0; timeout(0); //time before the getch passes with no input for(int i = 0; i < MAX_ACTORS; i++){ actorList[i] = NULL; } for(int i = 0; i < MAX_BULLETS; i++){ bulletList[i] = NULL; } for(int y = 0; y < mapHeight; y++){ for(int x = 0; x < mapWidth; x++){ if(mapArray[y][x] == 7){ mapArray[y][x] = 0; } } } int z = 25 + rand() % 125; for(int i = 0; i < z; i++){ int y = rand() % mapHeight; int x = rand() % mapWidth; if(mapArray[y][x] == 0 && isPassable(y, x) && (cursorY != y || cursorX != x) && mapArray[y-1][x] != 2){ mapArray[y][x] = 7; } } //put stuff before the game loop here while(!breakLoop){ drawMap(); drawStats(); playerTimeSurvived = time(0) - timeStart; if(playerMoney > playerPeakMoneyOwned) playerPeakMoneyOwned = playerMoney; if(playerHealth <= 0){ if(gameOver()){ breakLoop = true; retry = true; }else{ breakLoop = true; retry = false; } } if(playerStaminaRegenHelper >= playerStaminaRegen){ if(playerStamina < playerMaxStamina){ playerStamina++; } playerStaminaRegenHelper = 0; } if(playerClip == 0 && !playerReloading && playerAmmo > 0){ reloadGun(); } if(playerXP >= playerXPNeeded){ playerSkillPoints++; playerLevel++; playerXPNeeded *= 1.1; playerXP = 0; } for(int i = 0; i < MAX_ACTORS; i++){ if(actorList[i] != NULL && actorList[i]->checkActive()){ actorList[i]->update(); actorList[i]->draw(); } } for(int i = 0; i < MAX_BULLETS; i++){ if(bulletList[i] != NULL && bulletList[i]->checkActive()){ bulletList[i]->update(); bulletList[i]->draw(); } } for(int i = 0; i < MAX_BULLETS; i++){ if(specialBulletList[i] != NULL && specialBulletList[i]->checkActive()){ specialBulletList[i]->update(); specialBulletList[i]->draw(); } } if(roundZombiesHelper >= roundZombies){ betweenRoundPause = true; } if(betweenRoundPause){ betweenRoundPauseHelper++; if(betweenRoundPauseHelper >= 100000){ roundStart(); } } if(zombieSpawnRateHelper >= zombieSpawnRate && !betweenRoundPause){ int y, x; int side = rand() % 4; switch(side){ case 0: y = 0; x = rand() % mapWidth; break; case 1: y = mapHeight - 1; x = rand() % mapWidth; break; case 2: y = rand() % mapHeight; x = 0; break; case 3: y = rand() % mapHeight; x = mapWidth - 1; break; } if(isPassable(y, x)){ Actor *newActor = new Actor(); newActor->setAppearance('@', 1); newActor->setPos(y, x); newActor->setSpeed(600-round*3); newActor->setHealth(10); newActor->setMaxRange(20); addActorToList(newActor); zombieSpawnRateHelper = 0; roundZombiesHelper++; } } attron(COLOR_PAIR(0)); move(cursorY, cursorX); addch('@'); attroff(COLOR_PAIR(0)); bool donePause = false; int input = getch(); switch(input){ case KEY_UP: deltaY = -1; playerMeleeDirecton = 0; break; case KEY_DOWN: deltaY = 1; playerMeleeDirecton = 1; break; case KEY_LEFT: deltaX = -1; playerMeleeDirecton = 2; break; case KEY_RIGHT: deltaX = 1; playerMeleeDirecton = 3; break; case 'w': addBulletToList(0); break; case 's': addBulletToList(1); break; case 'a': addBulletToList(2); break; case 'd': addBulletToList(3); break; case 'r': reloadGun(); break; case 'n': if(betweenRoundPause){ roundStart(); playerTotalAmountForce++; } break; case 'm': if(!betweenRoundPause && zombieForceSpawnHelper >= 500){ int y, x; int side = rand() % 4; switch(side){ case 0: y = 0; x = rand() % mapWidth; break; case 1: y = mapHeight - 1; x = rand() % mapWidth; break; case 2: y = rand() % mapHeight; x = 0; break; case 3: y = rand() % mapHeight; x = mapWidth - 1; break; } if(isPassable(y, x)){ Actor *newActor = new Actor(); newActor->setAppearance('@', 1); newActor->setPos(y, x); newActor->setSpeed(600-round*3); newActor->setHealth(10); newActor->setMaxRange(20); addActorToList(newActor); zombieSpawnRateHelper = 0; roundZombiesHelper++; zombieForceSpawnHelper = 0; } playerTotalAmountForce++; } break; case 't': playerAmountEnteredSkillTree++; skillTree.skillScreen(); break; case 'b': if(playerHealth < playerMaxHealth && playerBandages > 0 && !playerReloading){ playerBandaging = true; } break; case 'v': if(playerStaminaPills > 0 && playerStamina < playerMaxStamina){ if(playerStamina + playerStamina/2 <= playerMaxStamina){ playerStamina += playerStamina/2; }else{ playerStamina = playerMaxStamina; } playerStaminaPills--; } case 'e': if(playerMeleeDamage > 0 && playerMeleeHelper >= 500){ for(int i = 0; i < MAX_BULLETS; i++){ if(bulletList[i] == NULL || !bulletList[i]->checkActive()){ int y, x; Bullet *newBullet = new Bullet(); y = cursorY; x = cursorX; newBullet->setDirection(playerMeleeDirecton); if(playerMeleeDamage < 4){ if(playerMeleeDirecton == 0 || playerMeleeDirecton == 1){ newBullet->setAppearance('|', 11); }else if(playerMeleeDirecton == 2 || playerMeleeDirecton == 3){ newBullet->setAppearance('-', 11); } }else if(playerMeleeDamage >= 4){ if(playerMeleeDirecton == 0 || playerMeleeDirecton == 1){ newBullet->setAppearance('|', 12); }else if(playerMeleeDirecton == 2 || playerMeleeDirecton == 3){ newBullet->setAppearance('-', 12); } } newBullet->setPos(y, x); newBullet->setSpeed(50); if(playerMeleeDamage == 5){ newBullet->setRange(3); }else{ newBullet->setRange(2); } newBullet->setDamage(playerMeleeDamage); bulletList[i] = newBullet; playerMeleeHelper = 0; playerAmountMelee++; break; } } } break; case 'p': mvprintw(13, mapWidth+2, "GAME PAUSED - PRESS P TO UNPAUSE"); mvprintw(14, mapWidth+2, "PRESS R TO RESET THE GAME"); mvprintw(15, mapWidth+2, "WARNING: YOU WON'T SEE THE FINAL STATS"); playerTimesPaused++; while(!donePause){ int input = getch(); if(input == 'p'){ donePause = true; }else if(input == 'r'){ breakLoop = true; donePause = true; } } break; case ' ': if(mapArray[cursorY][cursorX] == 5){ playerAmountEnteredShop++; shop.shopScreen(); } break; default: break; } if(isPassable(cursorY + deltaY, cursorX + deltaX) && playerMovementSpeedHelper >= playerMovementSpeed && playerStamina > 0){ cursorY += deltaY; cursorX += deltaX; if(input == KEY_UP || input == KEY_DOWN || input == KEY_LEFT || input == KEY_RIGHT){ playerMovementSpeedHelper = 0; playerMoves++; playerStamina--; playerStaminaRegenHelper = 0; } } deltaX = 0; deltaY = 0; playerMovementSpeedHelper++; playerStaminaRegenHelper++; playerFiringSpeedHelper++; playerMeleeHelper++; zombieSpawnRateHelper++; zombieForceSpawnHelper++; if(playerReloading){ playerReloadingHelper++; if(playerReloadingHelper >= playerReloadingRate){ playerReloading = false; playerAmmo += playerHiddenClip; if(playerAmmo - playerClipLimit > 0){ playerAmmo -= playerClipLimit; playerClip = playerClipLimit; }else{ playerAmmo -= playerClipLimit; playerClip = playerClipLimit + playerAmmo; playerAmmo = 0; } playerTimesReloaded++; playerHiddenClip = 0; playerReloadingHelper = 0; } } if(playerBandaging){ playerBandagesHelper++; if(playerBandagesHelper >= 1500){ if(playerHealth + (playerMaxHealth/4) <= playerMaxHealth){ playerHealth += (playerMaxHealth/4); }else{ playerHealth = playerMaxHealth; } playerBandaging = false; playerBandages--; playerTimesBandaged++; playerBandagesHelper = 0; } } refresh(); } } endwin(); }
//============================================================================= // Update all game items //============================================================================= void WeaponTest::update() { fTimer.nextFrame(); timer += frameTime; frameCount += 1; if (menuOn) { if (input->anyKeyPressed()) { menuOn = false; input->clearAll(); roundStart(); } } else { //testGun->setAngle(atan2(input->getMouseY()-testGun->getCenterY(), input->getMouseX()-testGun->getCenterX())); testGun->setAngle(atan2(camera.getRealPos(input->getMouseX(), input->getMouseY()).y-testGun->getCenterY(), camera.getRealPos(input->getMouseX(), input->getMouseY()).x-testGun->getCenterX())); testGun->act(frameTime, input->getMouseLButton(), input->getMouseRButton(), false, false, false); //testGun->mag->updateMagsProjectiles(frameTime); if(input->getMouseLButton()) { //testMag->fire(D3DXVECTOR2(input->getMouseX()+10, input->getMouseY() - 10), PI*(((rand()%1000)-500)/1000.0)/6); } if(input->getMouseRButton()) { //testGun->fire(frameTime); camera.centerPosition = D3DXVECTOR2(input->getMouseX(), input->getMouseY()); } //testMag->updateMagsProjectiles(frameTime); //testMag->projectile->update(frameTime); if(input->isKeyDown('1')) { camera.zoom = max(0.1, camera.zoom - frameTime*.5); } if(input->isKeyDown('2')) { camera.zoom = min(10, camera.zoom + frameTime*.5); } if(input->isKeyDown('3')) { testBox->setDegrees(testBox->getDegrees()+45*frameTime); testBox->generateSideEquations(); } if(input->isKeyDown('4')) { testBox->setDegrees(testBox->getDegrees()-45*frameTime); testBox->generateSideEquations(); } /*if(testProjectile->getActive()) { testProjectile->update(frameTime); }*/ testBox->update(frameTime); //Used for collisions VECTOR2 collisionVector; fTimer.starting(1); for(int i(0); i < testMag->size+1; i++) { if(testMag->projArray[i]->getActive()) { float ft = frameTime; float angle = 0; if(collidesWithMoving(const_cast<D3DXVECTOR2*>(testMag->projArray[i]->getCenter()), const_cast<D3DXVECTOR2*>(&testMag->projArray[i]->getVelocity()), testBox, angle, ft)) // if(collidesWithMovingRay(testMag->projArray[i], testBox->m[0], testBox->b[0], testBox->corners[0], testBox->corners[3], collisionVector, frameTime)) { //throw "GHJKL:"; // float newAngle = angle; // newAngle -= abs(testMag->projArray[i]->getRadians()-newAngle); //newAngle = (testMag->projArray[i]->getRadians()+PI); //newAngle -= (newAngle - testMag->projArray[i]->getRadians()); //newAngle = PI - newAngle; //testMag->projArray[i]->update(frameTime-ft); // testMag->projArray[i]->setVelocity(D3DXVECTOR2(testMag->projArray[i]->muzzelVelocity*cos(newAngle),testMag->projArray[i]->muzzelVelocity*sin(newAngle))); // testMag->projArray[i]->setRadians(newAngle); testMag->projArray[i]->setActive(false); testMag->projArray[i]->setVisible(false); }else{ //Need to use mag update just for this //testMag->projArray[i]->update(frameTime); } } } fTimer.ending(1, timerFreq); if(testMag != 0) { testMag->updateMagsProjectiles(frameTime); } } }