//============================================================================= // Update all game items //============================================================================= void myGame::update() { updateGameState(); if (gameStates == PLAY) { audio->playCue(OOO); ghosts.update(frameTime); player.update(frameTime); } }
void init() { for (int i = 0 ; i < 9 ; i++) { game.getItemLoc(items[i], i); } updateGameState(); origin[0] = origin[1] = origin[2] = 0.0f; move_state = GET_SCORE_PACKS; att_state = FACE_OTHER; itemID = recalibrate(3, 6); DEBUG(("Hello from SHA-2468!")); }
void Antimony::step() { timer.catchTime(TIMER_FRAME_GLOBAL); delta = timer.getDelta(); double fstep = delta * worldSpeed; cpuUsage.GetUsage(0); if (GetForegroundWindow() == window_main.hWnd && mouse.isExclusive()) { mouse.acquire(false); } else { mouse.release(false); /*SetCursor(arrow); SetClassLong(window_main.hWnd, GCL_HCURSOR, (DWORD)arrow);*/ } updateGameState(); if (ifGameState(GAMESTATE_INGAME)) // In-game (non-paused, non-menu etc.) { if (devConsole.isOpen()) { player.lock(); camera_main.lock(); } else { player.unlock(); camera_main.unlock(); } updateAI(fstep); // update AI/scripts etc. (TBI) updateWorld(fstep); // update moving objects, triggers etc. (TBI) player.update(delta, m_objectsCollisions); updatePlayerControls(&keys, &controller[0], fstep); // update player inputs updatePhysics(fstep); // btWorld step updateCameraControls(&mouse, &keys, &controller[0], fstep); // update camera (--> mat_view) } else if (ifGameState(GAMESTATE_PAUSED) && devConsole.isClosed()) // Game is paused { camera_main.unlock(); updateCameraControls(&mouse, &keys, &controller[0], fstep); // update camera (--> mat_view) } prepareFrame(); // prepare the frame for rendering }
/** * Initialisiert das Spiel. */ void initGame() { LOG("initGame"); // Start-Zustand setzen updateGameState(GAME_STATE_SHOW_HINT_MARKER_NEEDED); // Spieler initialisieren for (int i = 0; i < PLAYER_COUNT; ++i) { // Spielertyp initialisieren players[i].type = PLAYER_TYPES[i]; initPlayer(&players[i]); // Spielernamen setzen sprintf(players[i].name, "Spieler %d", i + 1); // Farbe der Spielfigur setzen players[i].pawn.light = PAWN_LIGHTS[i]; } }
void wsGameLoop::iterateLoop() { wsAssert(_mInitialized, "The object wsGame must be initialized via the startUp() method before use."); // Get the starting time of our iteration t32 beginTime = wsGetTime(); u32 framesSkipped = 0; // Update the gamestate and draw the game updateGameState(); wsRenderer.drawScene(game->getCurrentScene()); // Get the ending time of our state update t32 timeDiff = wsGetTime() - beginTime; t32 sleepTime = frameDuration - timeDiff; if (sleepTime > 0) { // Wait so the game won't run too fast //wsEcho("Slow down! Sleeping for %f seconds.", sleepTime); wsWait(sleepTime); } else { // Update the game as many times as is reasonable to catch up to the rendering. while (sleepTime < 0 && framesSkipped < maxFrameSkips) { updateGameState(); sleepTime += frameDuration; ++framesSkipped; } } // wsEcho(WS_LOG_MAIN, "Iteration time: %f seconds\n", (wsGetTime() - beginTime)); }
void GameScene::Update(const Ogre::FrameEvent& evt) { player->Update(evt,gameMap); updateMapGridType(); updateEnemyList(evt,gameMap); gameMap->Update(evt); updatePlayerLifecycle(); updatePlayerLifeDisplay(); updateBonus(evt); updateGameState(evt); }
void init(){ for (int i = 0 ; i < 9 ; i++) { game.getItemLoc(items[i], i); } updateGameState(); origin[0] = origin[1] = origin[2] = earth[0] = earth[1] = 0.0f; earth[2] = 1.0f; itemNum = recalibrate(7,8); memcpy(target,items[itemNum],3*sizeof(float)); //do this here so we don't have to do it in GET_MIRROR move_state = GET_MIRROR; att_state = FACE_ENEMY; DEBUG(("Hello from SHA-2468!")); }
/* Initializes everything */ void init() { for (n = 0 ; n < 9 ; n++) { game.getItemLoc(items[n], n); } updateGameState(); origin[0] = origin[1] = origin[2] = earth[0] = earth[1] = 0.0f; earth[2] = 1.0f; movestate = GET_ITEM; rotatestate = NORMAL; targetID = minDistEl(items, me, 3, 7); if (targetID == -1) { // if there is no avaliable item movestate = ON_TOP; } }
/* Initializes everything */ void init() { for (n = 0 ; n < 9 ; n++) { game.getItemLoc(items[n], n); } updateGameState(); origin[0] = origin[1] = origin[2] = earth[0] = earth[1] = 0.0f; earth[2] = 1.0f; movestate = GET_ENERGY; rotatestate = NORMAL; targetID = minDistEl(items, me, 0, 3); // find the min distance energy pack am_i_blue = me[0] > 0; n = 0; strcpy(debugs[0], "we renouce weapons, hate and violence"); strcpy(debugs[1], "we strive for peace and understanding"); strcpy(debugs[2], "we wish for a better world in the future"); strcpy(debugs[3], "we condemn the terrible actions taken"); strcpy(debugs[4], "and pray for the lives that were lost"); }
void init() { updateGameState(); for (c = 0 ; c < 9 ; c++) { game.getItemLoc(items[c], c); } zero[0] = 0.0f; zero[1] = 0.0f; zero[2] = 0.0f; items[3][0] = 9999; items[3][1] = 9999; items[3][2] = 9999; movestate = tisShinyCptn; rotatestate = normal; targetID = minDistEl(items, me, 7, 9); rotateZ[0] = 0.0f; rotateZ[1] = 0.0f; rotateZ[2] = 1.0f; }
void MainWindow::on_pushButton_7_clicked() { updateGameState(6,7); }
void ColoredCubeApp::updateScene(float dt) { updateGameState(); if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) PostQuitMessage(0); if(gamestate == title) { float rad = 0.0f; camera.update(mTheta,mPhi,rad,0,dt,player,mView,mEyePos,true); maze.update(dt); if(once) { maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"Title Screen.jpg",L"brickwork-bump-map.jpg"); once = false; } ambientLight = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f); //set ceiling texture here } if(gamestate == controls) { float rad = 0.0f; camera.update(mTheta,mPhi,rad,0,dt,player,mView,mEyePos,true); maze.update(dt); if(onceAgain) { maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"Rules Screen.jpg",L"brickwork-bump-map.jpg"); onceAgain = false; } ambientLight = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f); //set ceiling texture here } if(gamestate == level1 || gamestate == level2) { ambientLight = D3DXCOLOR(0.3f, 0.03f, 0.2f, 1.0f); if(onceAgainStart) { maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg"); onceAgainStart = false; } if(GetAsyncKeyState('Y') & 0x8000) perspective = true; else perspective = false; if(oldBLevel!=0 && flashLightObject.getPowerLevel()<=0) { audio->playCue(BATTERY_DIE); } oldBLevel = flashLightObject.getPowerLevel(); //check for win game conditions auto oldP = player.getPosition(); timer -= dt; std::wostringstream outs; //update the camera camera.update(mTheta,mPhi,mRadius,0,dt,player,mView,mEyePos,perspective); //move the player camera.movePlayer(player,30,camera.getTarget(),perspective); player.update(dt); Location playerLoc; playerLoc.x = player.getPosition().x; playerLoc.z = player.getPosition().z; //collision detection if(player.getPosition()!=oldP) { if(maze.collided(playerLoc)) { player.setPosition(oldP); player.setVelocity(Vector3(0,0,0)); player.update(dt); } } for(int i = 0; i < numLightObjects; i++) { lamps[i].update(dt); } for(int i = 0; i < numBatteries; i++) { batteries[i].update(dt); if(player.collided(&batteries[i])) { batteries[i].setInActive(); flashLightObject.getBattery(); audio->playCue(BATTERY_CHARGE); } } if(gamestate == level1) { for(int i = 0; i < totalKeys; i++) { keyObject[i].update(dt); if(player.collided(&keyObject[i])) { currentKeys++; keyObject[i].setInActive(); audio->playCue(ITEM); } } } if(gamestate==level2) { for(int i = 0; i < ghosts.getNumEnemies(); i++) { if(flashLightObject.hitTarget(&ghosts.getEnemies()[i])) { ghosts.getEnemies()[i].decreaseHealth(); audio->playCue(G_HIT); } } } if(gamestate==level2) { if(player.collided(&endCube)) { gamestate = win; maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"You Win.jpg",L"brickwork-bump-map.jpg"); maze.update(dt); } } if(player.getHealth()<=0) { gamestate = gameover; maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"You Lose.jpg",L"brickwork-bump-map.jpg"); maze.update(dt); } endCube.update(dt); lights[1].ambient = ambientLight; if(gamestate == level2) { for(int i = 0; i < ghosts.getNumEnemies(); i++) { //player gets hit by a ghost if(player.collided(&ghosts.getEnemies()[i])) { player.setHealth(player.getHealth()-1); lights[1].ambient = hurtLight; //make flash take longer ghosts.getEnemies()[i].setInActive(); audio->playCue(P_HIT); } } } maze.update(dt); if(flashLightObject.getPosition()!=(player.getPosition()+(camera.getTarget()*5))) { flashLightObject.setPosition(player.getPosition() + camera.getTarget()*5); int i = 0; } //orientating the flashlight if(flashLightObject.lightSource.dir!=camera.getTarget()) { //vectors for caluclating z-rotation Vector2 cameraXY = Vector2(camera.getTarget().x,camera.getTarget().y); Vector2 startXY = Vector2(flashLightObject.lightSource.dir.x,flashLightObject.lightSource.dir.y); //vectors for calculating y-rotation Vector2 cameraXZ = Vector2(camera.getTarget().x,camera.getTarget().z); Vector2 startXZ = Vector2(flashLightObject.lightSource.dir.x,flashLightObject.lightSource.dir.z); //vectors for calculating x-rotation Vector2 cameraYZ = Vector2(camera.getTarget().y,camera.getTarget().z); Vector2 startYZ = Vector2(flashLightObject.lightSource.dir.y,flashLightObject.lightSource.dir.z); float xAngle = flashLightObject.getRotation().x; float yAngle = flashLightObject.getRotation().y; float zAngle = flashLightObject.getRotation().z; float topEquation; float bottomEquation; topEquation = Dot2(&cameraXY,&startXY); bottomEquation = Length2(&cameraXY)*Length2(&startXY); if(bottomEquation>0) { zAngle+=acos((topEquation/bottomEquation)); } topEquation = Dot2(&cameraXZ,&startXZ); bottomEquation = Length2(&cameraXZ)*Length2(&startXZ); if(bottomEquation>0) { yAngle+=acos((topEquation/bottomEquation)); } topEquation = Dot2(&cameraYZ,&startYZ); bottomEquation = Length2(&cameraYZ)*Length2(&startYZ); if(bottomEquation>0) { xAngle+=acos((topEquation/bottomEquation)); } flashLightObject.setRotation(Vector3(xAngle,yAngle,zAngle)); flashLightObject.lightSource.dir = camera.getTarget(); } flashLightObject.update(dt); //batteryObject.update(dt); ghosts.update(dt,&player); //lightObject1.update(dt); /*floor.update(dt); wall1.update(dt); wall2.update(dt); wall3.update(dt); wall4.update(dt);*/ //flashLightObject.setRotation( /*if(player.collided(&batteryObject)) { flashLightObject.getBattery(); }*/ //mParallelLight.pos = testCube.getPosition(); //set up the flashlight light direction based on the direction the geometry is pointing //D3DXVec3Normalize(&mParallelLight.dir, &(playerCamera.getTarget()-testCube.getPosition())); outs.precision(2); outs << L"Health: " << player.getHealth() << L"\n"; outs.precision(3); outs << "Battery: " << flashLightObject.getPowerLevel(); mTimer = outs.str(); } if(gamestate == gameover) { float rad = 0.0f; camera.update(mTheta,mPhi,rad,0,dt,player,mView,mEyePos,true); //set ceiling texture here if(onceAgainEnd) { maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"Rules Screen.jpg",L"brickwork-bump-map.jpg"); onceAgainEnd = false; onceAgainStart = true; } } }
/* Runs every second */ void loop() { if (game.getCurrentTime() < 5) { if (am_i_blue) { DEBUG(("%s\n", debugs[n])); n++; } } else if (game.getCurrentTime() < 10) { if (!am_i_blue) { DEBUG(("%s\n", debugs[n])); n++; } } else { updateGameState(); changeState(); if (game.getFuelRemaining() == 0) { game.takePic(); } /* Design concept: 2 separate state vars, * rotatestate governs the picture taking mechanism/rotation * movestate governs the item getting mechanism/movement */ DEBUG(("%f\n", mathVecMagnitude(me + 3, 3))); switch (rotatestate) { case NORMAL: if (game.posInArea(other) > 0 && game.isFacingOther() && game.getEnergy() > 1 && // don't nuke yourself game.getPicPoints() > 0) { // shortcircuit eval makes sure doesn't waste energy game.takePic(); } else { mathVecSubtract(facing, other, me, 3); api.setAttitudeTarget(facing); // always face toward the other } break; case UPLOAD: api.setAttitudeTarget(earth); if (game.getEnergy() > 1 && checkUpload(me)) { game.uploadPics(); } break; case STOP: api.setAttRateTarget(origin); break; } switch (movestate) { case GET_ITEM: // item + try to point to the other sphere if (game.hasItem(targetID) == -1) { if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(earth); } else { moveTo(items[targetID]); } } else { moveTo(items[targetID]); } break; case GET_ENERGY: if (game.hasItem(targetID) == -1) { targetID = minDistEl(items, me, 0, 3); if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(earth); } else { moveTo(items[targetID]); } } else { targetID = minDistEl(items, me, 3, 7); movestate = GET_ITEM; } break; //case GET_MIRROR: // get mirror // deprecated for now // if (game.hasItem(targetID) == -1) { // targetID = minDistEl(items, me, 7, 9); // if (areWeThereYet(items[targetID], me)) { // api.setAttRateTarget(earth); // } // else { // moveTo(items[targetID]); // } // } // else { // targetID = minDistEl(items, me, 3, 7); // movestate = GET_ITEM; // } // break; case ON_TOP: getAbove(other, -0.4); break; case STOP: // if we have extremely low energy api.setVelocityTarget(origin); break; case TO_ORIGIN: moveTo(origin); break; } } }
static pos createFood(int width, int height, posList snake) { // The high level view of how this code works: (1) Creates a list of // open positions (i.e positions not occuipied by the snake) and (2) // grabs a random element from that list. But it does this without // creating a list of open positions. int maxRand = width*height - snake.len; if (maxRand <= 0) { return (pos){ .x = -1, .y = -1 }; } int randIndex = rand() % maxRand; int curRandIndex = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { pos p = { .x = x, .y = y }; if (posList_contains(snake, p)) { continue; } if (curRandIndex == randIndex) { return p; } curRandIndex++; } } // This should never be reached but I added it to get rid of the // compiler warning. return (pos){ .x = -1, .y = -1 }; } static const dir NO_DIRECTION = { .x = 0, .y = 0 }; static dir actionToDirection(playeraction a) { if (a == UP) { return (dir){ .x = 0, .y = -1 }; } if (a == DOWN) { return (dir){ .x = 0, .y = 1 }; } if (a == LEFT) { return (dir){ .x = -1, .y = 0 }; } if (a == RIGHT) { return (dir){ .x = 1, .y = 0 }; } return NO_DIRECTION; } static void initState(int width, int height, posList *snake, pos *food, playeractionQueue *queue, dir *curDirection, bool *paused, int *score) { srand(time(NULL)); snake->len = 4; snake->list[0] = (pos){ .x = 0, .y = 1 }; snake->list[1] = (pos){ .x = 0, .y = 0 }; snake->list[2] = (pos){ .x = 1, .y = 0 }; snake->list[3] = (pos){ .x = 1, .y = 1 }; *food = createFood(width, height, *snake); while (playeractionQueue_dequeue(queue) != NO_ACTION); *curDirection = actionToDirection(DOWN); *paused = false; *score = 0; } static bool gameIsWon(int width, int height, posList snake) { return width*height == snake.len; } static bool gameIsLost(int width, int height, posList snake) { { posList headless = snake; headless.len--; if (posList_contains(headless, snake.list[snake.len-1])) { return true; } } { pos head = snake.list[snake.len-1]; if (head.x < 0 || width <= head.x) { return true; } if (head.y < 0 || height <= head.y) { return true; } } return false; } static void updateGameState(playeraction action, int width, int height, bool *paused, posList *snake, pos *food, dir *d, int *score) { if (action == PAUSE) { *paused = !(*paused); return; } if (*paused) { return; } dir newDir = actionToDirection(action); if (!dir_equal(newDir, NO_DIRECTION)) { *d = newDir; } pos newHead = { .x = snake->list[snake->len-1].x + d->x, .y = snake->list[snake->len-1].y + d->y }; if (pos_equal(newHead, *food)) { *snake = posList_append(*snake, newHead); *food = createFood(width, height, *snake); (*score)++; } else { for (int i = 0; i < snake->len-1; i++) { snake->list[i] = snake->list[i+1]; } snake->list[snake->len-1].x += d->x; snake->list[snake->len-1].y += d->y; } } char *playeraction_toString(playeraction p) { switch (p) { case NO_ACTION: return "no action"; case UP: return "move the snake up"; case DOWN: return "move the snake down"; case LEFT: return "move the snake left"; case RIGHT: return "move the snake right"; case PAUSE: return "pause the game"; case QUIT: return "quit the game"; case NEW_GAME: return "start a new game"; default: return "BUG!!! Unknown player action, please add another case to the switch statement"; } } void playeractionQueue_enqueue(playeractionQueue *q, playeraction c) { if (q->isFull) { return; } pthread_mutex_lock(q->mu); q->arr[q->tail] = c; q->tail = (q->tail+1) % PLAYERACTIONQUEUE_SIZE; if (q->tail == q->head) { q->isFull = 1; } pthread_mutex_unlock(q->mu); } size_t snakeSpaceRequired(int width, int height) { posList snake; return width * height * sizeof(*snake.list); } void snake(int width, int height, struct timespec frameRate, void *snakeMem, playeractionQueue *actionsQueue, void (*render)(int width, int height, posList snake, pos food, bool paused, int score, bool gameIsWon, bool gameIsLost)) { posList snake; pos food; dir curDirection; bool paused; int score; snake.list = snakeMem; initState(width, height, &snake, &food, actionsQueue, &curDirection, &paused, &score); while (true) { bool won = gameIsWon(width, height, snake); bool lost = gameIsLost(width, height, snake); render(width, height, snake, food, paused, score, won, lost); nanosleep(&frameRate, NULL); playeraction action = playeractionQueue_dequeue(actionsQueue); while (!dir_orthogonal(curDirection, actionToDirection(action))) { action = playeractionQueue_dequeue(actionsQueue); } if (action == QUIT) { break; } if (action == NEW_GAME) { initState(width, height, &snake, &food, actionsQueue, &curDirection, &paused, &score); continue; } if (won || lost) { continue; } updateGameState(action, width, height, &paused, &snake, &food, &curDirection, &score); } }
void loop(){ /*----------------PRE-SWITCH FUNCTIONS----------------*/ updateGameState(); changeState(); //DEBUG(("move state: %d\n", move_state)); //DEBUG(("MY SPEED: %f\n", mathVecMagnitude(me + 3, 3))); if(game.getFuelRemaining() == 0) game.takePic(); /* temp position to estimate in advance */ memcpy(temp, me, 3*sizeof(float)); temp[1] -= 0.17; /* If time > 130 and we have memory and substantial energy and we are not going to be uploading while in dark THEN upload */ if(time > 130 && game.getMemoryFilled() > 0 && energy > 2 && game.posInDark(temp) && !game.posInLight(me)) { att_state = UPLOAD; } /* If we have a mirror and our temp position is not in dark If we are far enough to take a picture and our y coordinate is lower and we have enough energy OR We have taken two pictures THEN use the mirror */ if(game.getNumMirrorsHeld() > 0 && !game.posInDark(temp) && ((distance(me,other) > 0.45 && me[1] < other[1] && game.getOtherEnergy() > 1) || game.getMemoryFilled() == 2)){ game.useMirror(); if(game.getMemoryFilled() > 0) att_state = UPLOAD; //if we have a picture then upload while mirror } /*----------------MOVE STATES----------------*/ switch(move_state) { case GET_MIRROR: /* Go for mirror, then switch to GET_SCORE_PACKS if we have it. */ if(time < 4 || time > 17) api.setPositionTarget(target); //save fuel and energy break; case GET_SCORE_PACKS: //second score pack /* Set target to the item we are going for, and face the enemy */ memcpy(target,items[itemNum],3*sizeof(float)); api.setPositionTarget(target); break; case END_GAME: /* If we are not above a certain threshold, try and reach it. Else: If we are in dark, move towards the -Y slowly. If we are in grey/light, move towards the -Y quickly. */ if( me[2] > -0.475 ){ if(me[0] > 0){ target[0] = 0.53; } else { target[0] = -0.53; } target[1] = 0.4; target[2] = -0.5; api.setPositionTarget(target); } else{ if( me[1] > -0.5 ){ /* Make sure our x coordinate is in the bounds of the game */ if(fabsf(me[0]) > 0.53) me[0] = me[0]/fabsf(me[0]) * 0.53; /* If we are in dark, move slowly Else move fast */ if( game.posInDark(me) ){ memcpy( target, me, 3*sizeof(float) ); target[1] -= 0.04; } else{ memcpy( target, me, 3*sizeof(float) ); target[1] -= 0.25; } /* Keep our y-coor greater than or equal to 0.125 */ if( target[1] < 0.125 ) target[1] = 0.125; api.setPositionTarget(target); } else{ api.setPositionTarget(me); } } break; case STOP: api.setVelocityTarget(origin); break; } /*----------------ATTITUDE STATES----------------*/ switch(att_state){ case FACE_ENEMY: mathVecSubtract(temp, other, me, 3); api.setAttitudeTarget(temp); if(checkPhoto(me,other)) game.takePic(); break; case UPLOAD: /* Face Earth If we have enough energy and are facing correctly, upload. */ api.setAttitudeTarget(earth); if( energy > 1 && checkUpload(me) ) game.uploadPics(); break; } }
/*** MAIN *********************************************************************/ void loop() { updateGameState(); changeState(); if (game.getFuelRemaining() == 0) { game.takePic(); } //DEBUG(("%d\n", inBounds(other))); /* Design concept: 2 separate state vars, * rotatestate governs the picture taking mechanism/rotation * movestate governs the item getting mechanism/movement */ switch (rotatestate) { case NORMAL: if (game.posInArea(other) >= 0 && game.isFacingOther() && game.getEnergy() > 1 && // don't nuke yourself game.getPicPoints() > 0) { // shortcircuit eval makes sure doesn't waste energy game.takePic(); } else { mathVecSubtract(facing, other, me, 3); api.setAttitudeTarget(facing); // always face toward the other } break; case UPLOAD: if (game.getEnergy() > 1 && checkUpload(me)) { game.uploadPics(); } else { api.setAttitudeTarget(earth); } break; case STOP: api.setAttRateTarget(origin); break; } switch (movestate) { case GET_ITEM: // item + try to point to the other sphere if (game.hasItem(targetID) == -1) { if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(earth); } else { moveTo(items[targetID]); } } else { moveTo(items[targetID]); } break; case ON_TOP: getAbove(other, -0.4); break; case STOP: // if we have extremely low energy api.setVelocityTarget(origin); break; case TO_ORIGIN: moveTo(origin); break; } }
/** * Aktualisiert den aktuellen Spiel-Zustand. * * @param newGameState Neuer Spielzustand. */ void updateGameState(int newGameState) { LOGD("updateGameState"); // nichts tun, wenn sich der Zustand nicht verändert hat if (newGameState == gameState) { return; } // Spielzustand speichern gameState = newGameState; // Buffer für Toast-Inhalte char text[256]; // Spiel-Zustand auswerten und die entsprechenden Aktionen ausführen switch (gameState) { case GAME_STATE_SHOW_HINT_MARKER_NEEDED: // um spielen zu können, muss die Kamera auf den Marker gerichtet sein sprintf(text, "Halte die Kamera auf den Marker."); showToast(text, TOAST_DURATION_LONG); gameState = GAME_STATE_WAITING_FOR_MARKER; break; case GAME_STATE_WAITING_FOR_MARKER: // warten, bis die Handy-Kamera auf das Bild gerichtet ist break; case GAME_STATE_SHOW_HINT_CREATE_SPACES: // Hinweise anzeigen, wie das Spielfeld erzeugt werden kann sprintf(text, "Halte die Kamera weiterhin auf den Marker."); showToast(text, TOAST_DURATION_LONG); sprintf(text, "Erzeuge nun ein Spielfeld, indem du auf den Bildschirm tippst oder ..."); showToast(text, TOAST_DURATION_LONG); sprintf(text, "... mit einem Finger langsam ueber den Bildschirm ziehst."); showToast(text, TOAST_DURATION_LONG); sprintf(text, "Einzelne Felder koennen durch Antippen in Sonderfelder umgewandelt werden."); showToast(text, TOAST_DURATION_LONG); sprintf(text, "Bleibt ein Spieler auf einem Sonderfeld stehen, ..."); showToast(text, TOAST_DURATION_LONG); sprintf(text, "... darf er um ein paar Felder vorruecken oder muss ein paar Felder zurueck."); showToast(text, TOAST_DURATION_LONG); gameState = GAME_STATE_CREATING_FIELD; break; case GAME_STATE_CREATING_FIELD: // Spielfeld kann erzeugt werden break; case GAME_STATE_DRAWING_BEGINNING_PLAYER: // ersten Spieler durch Würfeln bestimmen LOGI("Drawing beginning player"); // Die Felder auf denen die Spielfiguren stehen, können erst jetzt initialisiert werden, // weil die Positionen der Felder erst jetzt bekannt sind. for (int i = 0; i < PLAYER_COUNT; ++i) { initPawnSpaces(&players[i].pawn); } // currentPlayerTextView anzeigen showView("currentPlayerTextView"); // aktuellen Spieler auswürfeln und setzen setCurrentPlayer(rand() % PLAYER_COUNT); // "Würfeln"-Buuton anzeigen, damit der menschliche Spieler würfeln kann if (currentPlayer->type == PLAYER_TYPE_HUMAN) { showView("diceButton"); } updateGameState(GAME_STATE_RUNNING); break; case GAME_STATE_RUNNING: // Spiel läuft break; default: LOGE("Unknown game state: %d", gameState); break; } }
void MainWindow::on_pushButton_14_clicked() { updateGameState(13,0); }
void loop() { updateGameState(); if (game.posInArea(me) > 0 && game.getLightSwitchTime() > 2) { game.useMirror(); } changeState(); DEBUG(("STATE: %d\n", movestate)); // Design concept: 2 separate state vars, // rotatestate governs the picture taking mechanism // movestate governs the item getting mechanism // Note that rotatestate does not govern movement, but rather governs rotation switch (rotatestate) { case normal: if (game.posInArea(other) > 0 && game.isFacingOther() && game.getEnergy() > 1.5 && game.getPicPoints() > 0) { game.takePic(); } else { mathVecSubtract(facing, other, me, 3); api.setAttitudeTarget(facing); } break; case upload: if (game.getMemoryFilled() == 0) { movestate = getItem; } else { api.setAttitudeTarget(rotateZ); if (game.getEnergy() > 1 && checkUpload(me)) { game.uploadPics(); } } break; case stop: api.setAttRateTarget(zero); break; } switch (movestate) { case getItem: // item + try to point to the other sphere if (game.hasItem(targetID) == -1) { if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(rotateZ); } else { api.setPositionTarget(items[targetID]); } } else { api.setPositionTarget(items[targetID]); } break; case tisShinyCptn: if (game.hasItem(targetID) == -1) { targetID = minDistEl(items, me, 7, 9); if (areWeThereYet(items[targetID], me)) { api.setAttRateTarget(rotateZ); } else { api.setPositionTarget(items[targetID]); } } else { targetID = minDistEl(items, me, 3, 7); movestate = getItem; } break; case on_top: getAbove(other, -0.4); //temp[0] = other[0]; //temp[1] = other[1]; //temp[2] = other[2]; //if (!winning) { // if (game.posInLight(temp)) { // temp[1] = -temp[1] / fabsf(temp[1]) * 0.12; // } // else { // temp[1] = temp[1] / fabsf(temp[1]) * 0.12; // } //} //else { // temp[1] = temp[1] * 0.12; //} //DEBUG(("CURRENT LOC: %f, %f, %f\n", me[0], me[1], me[2])); //DEBUG(("GOING TO: %f, %f, %f\n", temp[0], temp[1], temp[2])); //api.setPositionTarget(temp); break; case stop: // if we have extremely low energy api.setVelocityTarget(zero); break; } }
void updateChopperDrop(ChopperDrop* game) { int ipc_status; message msg; resetTickedFlag(game->timer); if (driver_receive(ANY, &msg, &ipc_status) != 0) return; if (is_ipc_notify(ipc_status)) { switch (_ENDPOINT_P(msg.m_source)) { case HARDWARE: // Keyboard if (msg.NOTIFY_ARG & game->IRQ_SET_KB) game->scancode = readFromKBC(0); // Timer if (msg.NOTIFY_ARG & game->IRQ_SET_TIMER) timerHandler(game->timer); // Mouse if (msg.NOTIFY_ARG & game->IRQ_SET_MOUSE) updateMouse(); // RTC if (msg.NOTIFY_ARG & game->IRQ_SET_RTC) updateDate(game->date); break; default: break; } } if (game->timer->ticked) { // Update game states and mouse at 60 FPS getMouse()->draw = 1; switch(game->currentState) { case MAIN_MENU_STATE: updateMainMenuState(game->state, game->scancode); break; case GAME_STATE: updateGameState(game->state, game->scancode, game->timer->counter); break; case GAME_OVER_STATE: updateGameOverState(game->state, game->scancode); break; case GAME_WON_STATE: updateGameWonState(game->state, game->scancode); break; default: break; } game->scancode = 0; game->draw = 1; } checkIfStateIsDone(game); }
/* MAIN ***********************************************************************/ void loop() { //blah(); updateGameState(); changeState(); if (game.getEnergy() < ENERGY_SHUTDOWN_THRESHOLD) { api.setVelocityTarget(origin); return; } switch (att_state) { case FACE_OTHER: mathVecSubtract(temp, other, me, 3); api.setAttitudeTarget(temp); if (checkPhoto()) { game.takePic(); } break; case UPLOAD: temp[0] = 0.0f; temp[1] = 0.0f; temp[2] = 1.0f; api.setAttitudeTarget(temp); if (checkUpload()) { game.uploadPics(); } break; } switch (move_state) { case GET_SCORE_PACKS: if (game.getScore() == 0) { mathVecAdd(temp, me, me + 3, 3); // where we will be if (!game.posInDark(temp)) { api.setVelocityTarget(origin); // steady... } else { temp[0] = game.getCurrentTime(); if (temp[0] < 4 || temp[0] > 17) { api.setPositionTarget(items[itemID]); } } } else { api.setPositionTarget(items[itemID]); } break; case END_GAME: memcpy(temp, other, 3 * sizeof(float)); mathVecNormalize(temp, 3); mathVecMultiply(temp, -0.3, 3); mathVecAdd(target, temp, other, 3); api.setPositionTarget(target); break; case TO_ORIGIN: api.setPositionTarget(origin); break; } }
void MainWindow::on_pushButton_9_clicked() { updateGameState(8,0); }