int main(int argc, char *argv[]){ double *collideField = NULL; double *streamField = NULL; int *flagField = NULL; int xlength = 0; double tau = 0.0; double velocityWall[3] = {0}; int timesteps = 0; int timestepsPerPlotting = 0; int t = 0; int readParamError = 0; const char *szProblem = "data_CFD_Assignment_02"; readParamError = readParameters(&xlength, &tau, velocityWall, ×teps, ×tepsPerPlotting, argc, argv); if(readParamError != 0) { printf("Please provide only one argument to the program; the path to the input file."); return -1; } /* Initialize pointers according to the D3Q19 discretization scheme */ collideField = malloc(19*(xlength+2)*(xlength+2)*(xlength+2)*sizeof(*collideField)); streamField = malloc(19*(xlength+2)*(xlength+2)*(xlength+2)*sizeof(*streamField)); flagField = malloc((xlength+2)*(xlength+2)*(xlength+2)*sizeof(*flagField)); initialiseFields(collideField, streamField, flagField, xlength); for(t = 0; t < timesteps; t++) { double *swap = NULL; doStreaming(collideField, streamField, flagField, xlength); swap = collideField; collideField = streamField; streamField = swap; doCollision(collideField, flagField, &tau, xlength); treatBoundary(collideField, flagField, velocityWall, xlength); if (t % timestepsPerPlotting == 0) { writeVtkOutput(collideField, flagField, szProblem, t, xlength); } } /* Free heap memory */ free(collideField); free(streamField); free(flagField); return 0; }
STATE GameState::update() { cam = { player.x + 80, player.y + 300 }; sfw::drawTexture(getTexture(backgroundName), 2150 - cam.x, 1100 - cam.y, backWidth, backHeight, 0, true, 1); int nEnemiesActive = 0; if (player.isActive) player.update(cam); for (int i = 0; i < bullets.size(); ++i) { if (bullets[i].isActive) { bullets[i].update(); for (int j = 0; j < enemies.size(); ++j) { if (enemies[j].isActive) { doCollision(enemies[j], bullets[i]); } } } } //example useful for determining when to spawn a new wave of enemies. for (int i = 0; i < enemies.size(); ++i) if (enemies[i].isActive) { nEnemiesActive++; enemies[i].update(); /* doCollision(player, bullets[i]);*/ } if (nEnemiesActive < 10 && enemySpawnTimer < 0) { makeEnemy(player.x, player.y, 50); enemySpawnTimer = 5.f; } enemySpawnTimer -= sfw::getDeltaTime(); // Collision detection between two objects of the same type /* for (int i = 0; i + 1 < bullets.size(); ++i) for (int j = i + 1; j < bullets.size(); ++j) { doCollision(bullets[i], bullets[j]); }*/ std::cout << nEnemiesActive << std::endl; return GAME; }
void Engine:: enterMainLoop() { doCapGtimeCalcDt(); m_delayTime = gameTime; while ( ! quit ) { doCapGtimeCalcDt(); doScripts(); doInput(); doUpdate(); doCollision(); doDelay(); doRender(); } }
void Ball::advance(int phase) { if(!phase) return; setPos(mapToScene(0,speed)); if(!scene()->sceneRect().contains(pos())) { setPos(startCoordinates); setSpeed(0); } doCollision(); if(canCollide > 0) {--canCollide;} }
bool FenwarBoss::update(float dt) { timeInState += dt; switch (state) { case FenwarStates::INACTIVE: doInactiveState(dt); break; case FenwarStates::TERRAFORMING: doTerraformingState(dt); break; case FenwarStates::BATTLE: doBattleState(dt); break; case FenwarStates::STUNNED_AFTER_LOSING_ORBS: doStunnedState(dt); break; case FenwarStates::DROPPING_SPIDERS: doDroppingSpidersState(dt); break; case FenwarStates::RETURN_TO_ARENA: doReturnToArenaState(dt); break; case FenwarStates::NEAR_DEATH: if (doNearDeathState(dt)) return true; break; } if (flashing && smh->timePassedSince(timeStartedFlashing) > FLASHING_DURATION) flashing = false; orbManager->update(dt); bulletManager->update(dt); bombManager->update(dt); doCollision(dt); return false; }
void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QRectF rect = boundingRect(); //basic collision detection if(scene()->collidingItems(this).isEmpty()) { //No Collision QPen pen(Qt::green, 5); painter->setPen(pen); } else { //collsion QPen pen(Qt::red, 5); painter->setPen(pen); //Set the position doCollision(); } painter->drawEllipse(rect); }
void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QRectF rect = boundingRect(); QBrush brush(Qt::gray); //basic colision detection if(scene()->collidingItems(this).isEmpty()) { //no collision brush.setColor(Qt::green); } else { //collision brush.setColor(Qt::red); //set the position doCollision(); } painter->fillRect(rect, brush); painter->drawRect(rect); }
void PlayerActor::doUpdatePhysics(float timePassed) { float xMove = controlsSource->getXMove(); bool jump = controlsSource->getJump(); //keep track of which direction we were facing last //check if a current direction is held down bool wasMoving = moving; //check if we were moving in the last frame; so we can set moving timer if not and current are moving //in the case we can't move or are dead, we'll just stay where we are float nextX = xPosition; float nextY = yPosition; //only do things if the character isn't dead if(!dead) { //check if we are holding left or right; whether we are moving if(controlsSource->getLeft()) { facingRight = false; moving = true; } else if(controlsSource->getRight()) { facingRight = true; moving = true; } else { moving = false; } //if we're moving and previously weren't, set the 'timer' for motion animation if(!wasMoving && moving) { prevTime = GetCurrentTime(); } if (jump) // if jump held { //only jump if the player is allowed to currently move if(canMove) { //jumpHeld = true; if (isOnGround && !jumpLastFrame) { Jump(); } if (jumpPower > 0.0f) { jumpPower -= timePassed; yVelocity = MAX_JUMP_SPEED; } jumpLastFrame = true; } } else { // jump button is not held if (!isOnGround) { jumpPower = 0.0f; } jumpLastFrame = false; } xVelocity += X_ACCEL_RATE * xMove * MAX_SPEED; xVelocity = min(max(xVelocity, -MAX_SPEED), MAX_SPEED); if (!xMove) { if (xVelocity > 0.0f) { xVelocity -= X_FRICTION * timePassed; } else if (xVelocity < 0.0f) { xVelocity += X_FRICTION * timePassed; } if (abs(xVelocity) < 0.01f) { xVelocity = 0.0f; } } if(!isOnGround && jumpPower <= 0.0f) { yVelocity -= FALL_GRAVITY * timePassed; yVelocity = max(MAX_FALL_SPEED, yVelocity); } //else we'll move according to velocity if(canMove && !dead) { nextX = xPosition + (timePassed * xVelocity); nextY = yPosition + (timePassed * yVelocity); doCollision(&nextX, &nextY); } //CHARACTER ANIMATION //check if in the air, either falling or jumping. Also check direction. if(!isOnGround) { if(facingRight) SetAnimSprite(3); else SetAnimSprite(7); } else //If we're not in the air, we're on the ground! Check for motion. { //if We're moving... if(moving) { //check how long we've been moving currentTime = GetCurrentTime(); int timeElapsed = currentTime - prevTime; //if its been more than stepTime since our last animation update... if(timeElapsed >= stepTime) { //increment our animation index movingIndex++; //loop around if at max (goes 0 1 2 3, with 3 being frame '1' so it alternates. See below.) if(movingIndex > 3) { movingIndex = 0; } //reset time counter prevTime = currentTime; } //if we're on frame '4' of our animation, use the middle idle animation that goes between walk frames. if(movingIndex == 3) { if(facingRight) SetAnimSprite(1); else SetAnimSprite(5); } //otherwise just use the movingIndex location. If facing left offset by 4. else { if(facingRight) SetAnimSprite(movingIndex); else SetAnimSprite(4+movingIndex); } } else //no motion { //we're not jumping, and not moving, we're standing still. So change the sprite. if(facingRight) SetAnimSprite(1); else SetAnimSprite(5); } } doTrapCollision(&nextX, &nextY); SetPosition(nextX, nextY); } else //if we're dead, show the dead animation for half the respawn time { //show the death sprite SetAnimSprite(8); SetPosition(nextX, nextY); currentTime = GetCurrentTime(); int timeElapsed = currentTime - prevTime; //once the respawn time is over, the player can move again and isn't dead. if(timeElapsed >= respawnTime) { canMove = true; dead = false; } //pause for half the respawn time to show the player where they died else if(timeElapsed > respawnTime/2) { //when we're at half respawn time passed, move the player to the last checkpoint dxm->KillPlayer(this, playerNumber); } } }