// update the game logic here void updateGame() { updateBallPosition(ball); movePlayer(player1); if(ball.speed.x < 0) seek(player2, ball); if( testOnScreen(ball) ) { // ball hit side of screen if(ball.position.x < 50) { // player 1 lost player2Score++; } else { // player 2 lost player1Score++; } } if(g_gameOver == false) { if( abs(player1Score - player2Score) >= 3) { // Game Over g_gameOver = true; int highestScore = player1Score; if(player2Score > highestScore) { highestScore = player2Score; } for(int i=0; i<5; i++) { if(highestScore > g_highScores[i]) { g_highScores[i] = highestScore; break; } } // sort the high scores array sort(g_highScores, 5); } } if(ball.speed.x < 0) { if(checkPaddleCollision(ball, player1) == true) { ball.speed.x *= -1; } } else { if(checkPaddleCollision(ball, player2) == true) { ball.speed.x *= -1; } } RotateSprite(player1.sprite, 0); MoveSprite(player1.sprite, player1.position.x, player1.position.y); RotateSprite(player2.sprite, 0 ); MoveSprite(player2.sprite, player2.position.x, player2.position.y); MoveSprite(ball.sprite, (int)ball.position.x, (int)ball.position.y); }
void updateEnemy2Position (movableObject &obj) { static bool isfirstrun = true; static bool dirup = false; static int idircount = 0; static int icount = 0; if (isfirstrun) { icount = icount + 1; } if (icount >= 400) { icount = 0; isfirstrun = false; } if (!isfirstrun) { if (ienemy2 == 0 && g_gameOver == true) { MoveSprite(enemy2.sprite, enemy2.position.x, enemy2.position.y); enemy2.position.x = enemy2.position.x -1; } if (ienemy2 == 0 && g_gameOver == false) { int iNum = 0; srand(time(NULL)); float rands = rand(); iNum = (int)(rand() % 550 + 100); enemy2.position.x = 1380; enemy2.position.y = iNum; ienemy2 = 1; idircount = 0; } if (ienemy2 == 1) { MoveSprite(enemy2.sprite, enemy2.position.x, enemy2.position.y); enemy2.position.x = enemy2.position.x -1; if (enemy2.position.x <=-80) { ienemy2 = 0; } } idircount = idircount + 1; if (idircount <100) { enemy2.position.y = enemy2.position.y + .5; } if (idircount >= 100 && idircount <= 201) { enemy2.position.y = enemy2.position.y - .5; } if (idircount >= 201) { idircount = 0; } } }
void Drunkometer::Update(float drunkenness_) { drunkenness = drunkenness_; MoveSprite(drunkoBarSprite, pos.x, pos.y); //find starting/end points and lerp between float mugXStartingPoint = pos.x - settings->GetInt("DRUNKOMETER_W") /2; float mugXEndPoint = pos.x + settings->GetInt("DRUNKOMETER_W") /2; float mugXPos = Lerp(mugXStartingPoint, mugXEndPoint, drunkenness/100.f); MoveSprite(drunkoMugSprite, mugXPos, pos.y - 10); }
// initialization for sprite position // void initGame(DynamObject &redPaddle, DynamObject &bluePaddle, DynamObject &ball, int PaddleX, int PaddleY, float redInitX, float redInitY, float blueInitX, float blueInitY, int BallX, int BallY, float ballInitX, float ballInitY) { bgImage = CreateSprite( "./images/bgImage.png", 1280, 780, false ); redPaddle.sprite = CreateSprite( "./images/RedPaddle.png", PaddleX, PaddleY, false ); bluePaddle.sprite = CreateSprite("./images/BluePaddle.png", PaddleX, PaddleY, false); ball.sprite = CreateSprite("./images/Ball.png", BallX, BallY, false); MoveSprite(redPaddle.sprite, redInitX, redInitY); MoveSprite(bluePaddle.sprite, blueInitX, blueInitY); MoveSprite(ball.sprite, ballInitX, ballInitY); }
void updateEnemyPosition (movableObject &obj) { static int idircount = 0; if (ienemy == 0 && g_gameOver == true) { MoveSprite(enemy.sprite, enemy.position.x, enemy.position.y); enemy.position.x = enemy.position.x -1; } if (ienemy == 0 && g_gameOver == false) { idircount = 0; int iNum = 0; srand(time(NULL)); float rands = rand(); iNum = (int)(rand() % 550 + 100); enemy.position.x = 1380; enemy.position.y = iNum; ienemy = 1; } if (ienemy == 1) { static bool dirup = true; MoveSprite(enemy.sprite, enemy.position.x, enemy.position.y); enemy.position.x = enemy.position.x -2; if (enemy.position.x <=-10) { ienemy = 0; } idircount = idircount + 1; if (idircount <200) { dirup = true; } if (idircount > 200) { dirup = false; } if (idircount > 400) { idircount = 0; } if (dirup) { enemy.position.y = enemy.position.y - 1; } else { enemy.position.y = enemy.position.y + 1; } } }
void updateTitle(bool &bTitleActive, bool &bgamerunning, bool &bpongrunning) { testOnTitleScreen(titleball); updateTitleBallPosition(titleball); cursormove(cursor, bTitleActive, bgamerunning, bpongrunning); // titlepaddle matches ball.pos.y titlepaddle.position.y = titleball.position.y; titlewall.position.y = titleball.position.y; MoveSprite(titlepaddle.sprite, titlepaddle.position.x, titlepaddle.position.y); MoveSprite(titlewall.sprite, titlewall.position.x, titlewall.position.y); MoveSprite(titleball.sprite, titleball.position.x, titleball.position.y); MoveSprite(cursor.sprite, cursor.position.x, cursor.position.y); }
void Bilbo::OnMessage(Message& msg) { //if cat dead && msg = spawn -> respawn if (msg.msg == Message::SPAWN_REQUEST && !m_isAlive) { Vector2* pos = static_cast<Vector2*>(msg.data); m_position.x = pos->x; m_position.y = pos->y; MoveSprite(m_sprite, m_position.x, m_position.y); m_isAlive = true; msg.consumed = true; return; } if (msg.msg == Message::ON_CLICK && m_isAlive) { Vector2* pos = static_cast<Vector2*>(msg.data); const float left = m_position.x - (m_width * 0.5f); const float right = m_position.x + (m_width * 0.5f); const float bottom = m_position.y - (m_height * 0.5f); const float top = m_position.y + (m_height * 0.5f); if (pos->x >= left && pos->x <= right && pos->y <= top && pos->y >= bottom) { m_isAlive = false; msg.consumed = true; } } }
void PowerUp::Draw() { if (isActive){ MoveSprite(spriteID, (int)position.x, (int)position.y); DrawSprite(spriteID); } }
void Projectile::update() { x += xDir * speed; y += yDir * speed; if(abs(xDir) > 0) { pixelsTravellable -= (int)(abs(xDir) * speed); } else if(abs(yDir) > 0) { pixelsTravellable -= (int)(abs(yDir) * speed); } else { pixelsTravellable--; } for(int index = 0; index < 2; index++) { if(currentRotation > rotation) { currentRotation -= 5; } else if(currentRotation < rotation) { currentRotation += 5; } } RotateSprite(texture, currentRotation); MoveSprite(texture, x, y); if(pixelsTravellable <= 0) { getApplication()->removeDrawable(this); return; } }
static void _SetupPWChar( ChoosePasswordGlobals* choose ) { short txX, txY; segaCharRect charRect; // convert the numbers to 8*8 patches charRect.top = 0; charRect.left = 0; charRect.bottom = (kBoxHeight + 7) >> 3; charRect.right = (kBoxWidth + 7) >> 3; // make sure they are in groups of 4 charRect.bottom = (charRect.bottom + 3) & -4; charRect.right = (charRect.right + 3) & -4; // make a sprite now choose->charSprite = CreateTextSprite( &charRect, 0 ); MoveSprite ( choose->charSprite, kBoxLeft + kSpriteOffset, kBoxTop + kSpriteOffset ); DrawSprite ( choose->charSprite ); // clear out the PW entry ResetEnteredPassword( choose ); // save the password entry state choose->textState = GetTextStateReference(); }
void HermiteSpline::Draw() { DrawString("Hermite Spline Demo", screenWidth * 0.5f - 200, screenHeight * 0.9f); SColour color = SColour(0, 255, 0, 255); Vector2 p0 = GetSprite("start")->position; Vector2 p1 = GetSprite("end")->position; Vector2 t0 = GetSprite("p01")->position; Vector2 t1 = GetSprite("p02")->position; //draw curve for (int i = 0; i < 100; i++) { float t = i / 100.0f; float nextT = (i + 1) / 100.0f; Vector2 start = Vector2::HermiteSpline(p0, p1, t0, t1, t); Vector2 end = Vector2::HermiteSpline(p0, p1, t0, t1, nextT); DrawLine(start.x, start.y, end.x, end.y, color); } //draw sprites for (int i = 0; i < objectList.size(); i++) { Sprite* object = objectList[i]; MoveSprite(object->ID, object->position.x, object->position.y); DrawSprite(object->ID); } DrawString("<M> to return to MENU", screenWidth * 0.5f - 200, 50); }
void MoveEnemies(int deltaTime) { bool changeDirection = false; for (int i = 0; i < enemyArr1Length; i++) {//loops to get to each array for (int j = 0; j < enemyArr2Length; j++) { if (alienShips[i][j].Move(deltaTime, enemyDirection)) {//if something hits a wall it will Return true changeDirection = true;// this will allow the direction to change after all enemies have moved } MoveSprite(alienShips[i][j].iSpriteID, alienShips[i][j].x, alienShips[i][j].y);//commit sptie movement (multiple returns in move meathod make it easier to have this live here instaead) } } if (changeDirection) {//if someone hits a wall then we need to change direction. if (enemyDirection != eDOWN) {//if we arent alredy moving down then we need to. if (enemyDirection == eRIGHT) {//puts what direction we will be moving next in memory bassed on what direction we are curently going nextDirection = eLEFT; } else { nextDirection = eRIGHT; } enemyDirection = eDOWN;//finally changes the direction to down } else {// if we are moving down then we need to change to the next direction that we alredy set enemyDirection = nextDirection;//we dont need to change next direction again because the next direction will always be down } } }
void Enemy::Draw() { if (isActive) { MoveSprite(spriteID, position.x, position.y); DrawSprite(spriteID); } }
void Powerup::update() { MoveSprite(texture, (float)x, (float)y); timeLeft--; if(timeLeft <= 0) { getApplication()->removeDrawable(this); return; } }
void MoveEnemies(float deltaTime) { for (int i = 0; i < enemyArrLength; i++) {//loops to get to each array enemyTracker.InformOfMove(alienShips[i].Move(deltaTime, enemyTracker.GetDirection()));//if something hits a wall it will Return true MoveSprite(alienShips[i].iSpriteID, alienShips[i].x, alienShips[i].y);//commit sprtie movement (multiple returns in move meathod make it easier to have this live here instaead) } enemyTracker.EndMoveCycle(); }
// updates ball's position // void UpdateBall(DynamObject &ball) { ball.position.x += ball.speed.x; ball.position.y += ball.speed.y; MoveSprite(ball.sprite, ball.position.x, ball.position.y); }
Score::Score() { m_scoreBar = CreateSprite("./images/Scorebar.png", 640, 40, false); m_healthSprite = CreateSprite("./images/health.png", 20, 20, false); //68 * 73 original sprite size m_score = 0; MoveSprite(m_scoreBar, 0, 40); }
void Weapon::Draw() { //MoveSprite(spriteID, x, y); if (isActive) { MoveSprite(spriteID, x, y); DrawSprite(spriteID); } }
void Background::Scroll(float dt) { m_image1Y -= (150 * dt); MoveSprite(m_texture, 0, m_image1Y); DrawSprite(m_texture); m_image2Y -= (150 * dt); MoveSprite(m_texture, 0, m_image2Y); DrawSprite(m_texture); if (m_image1Y <= 0) { m_image1Y = 3200; m_image2Y = 6399; } }
// resets ball to the middle of the screen and nullifies it's movement // void RestartBallPosition(DynamObject &ball, bool &play) { play = false; ball.position.x = 640; ball.position.y = 390; MoveSprite(ball.sprite, ball.position.x, ball.position.y); ball.speed.x = 0; ball.speed.y = 0; }
Powerup::Powerup(char* type, SPRITE sprite, int x, int y, int stayTime) { width = height = 64; powerupType = type; texture = DuplicateSprite(sprite); MoveSprite(texture, (float)x, (float)y); SetSpriteScale(texture, width, height); this->x = x; this->y = y; timeLeft = stayTime; }
void animateship() { static int FrameA = -1; static int FrameB = -1; static int FrameC = -1; static bool IsFirstRun = true; if (IsFirstRun ) { FrameA = CreateSprite("./images/player/playeru.png", 100, 35, true); FrameB = CreateSprite("./images/player/playerd.png", 100, 45, true); FrameC = CreateSprite("./images/player/playerrb.png", 98,46, true); IsFirstRun = false; } if (ship.position.x <=199) { ship.position.x = ship.position.x + 1; MoveSprite(ship.sprite, ship.position.x, ship.position.y); } if (ship.position.x >=200 && ship.position.x <= 299) { ship.sprite = FrameA; ship.position.x = ship.position.x + 1; ship.position.y = ship.position.y - 2; MoveSprite(ship.sprite, ship.position.x, ship.position.y); } if (ship.position.x >= 300 && ship.position.x <=499) { ship.sprite = FrameB; ship.position.x = ship.position.x + 1; ship.position.y = ship.position.y + 2; MoveSprite(ship.sprite, ship.position.x, ship.position.y); } if (ship.position.x >=500 && ship.position.x <=599) { ship.sprite = FrameA; ship.position.x = ship.position.x + 1; ship.position.y = ship.position.y - 2; MoveSprite(ship.sprite, ship.position.x, ship.position.y); } if (ship.position.x >=600) { ship.sprite = FrameC; ship.position.x = ship.position.x + 3; MoveSprite(ship.sprite, ship.position.x, ship.position.y); } if (ship.position.x >= 1500) { huge.position.x = huge.position.x - 15; MoveSprite(huge.sprite, huge.position.x, huge.position.y); } if (huge.position.x == 645) { MoveSprite(title.sprite, 640, 390); } }
/** * \brief Animates and moves player sprite, and updates and centers score sprites. */ void processSprites(void){ //update player sprite if(scrollingOn) //if player is alive, decrement animation alarm { frame_tick--; } if(frame_tick == 0) //animation alarm has been reached, reset alarm and change sprite to next frame { frame_tick = 8; //reset alarm current_frame++; //move forward to next animation frame if(current_frame == max_frames) { current_frame=0; } current_sprite = player_sprites[current_frame+ghost_color]; //change our tracking variable to the correct sprite based on new frame and current color MapSprite2(0, current_sprite, 0); //actually reassign the sprites in memory to the correct images } //move player sprite to player position MoveSprite(0,player_x,player_y,3,3); //map score sprites and move score to correct place MapSprite2(9, numbers[score_ones],0); //assign ones place sprite and center it according to player score MoveSprite(9,score_x, 8,1,2); if(score_tens!=0) //if player score high enough to have tens digit, assign that sprite and move stuff over to recenter { MapSprite2(11, numbers[score_tens],0); MoveSprite(11,score_x, 8, 1, 2); MoveSprite(9,score_x+8, 8, 1, 2); } else //score is below 10, so move tens digit off screen (solves bug where old tens place digit from last game was in the way) { MoveSprite(11,SCREEN_TILES_H << 3, 8, 1, 2); } if(score_hundreds!=0) //score is somehow > 100, assign 100's place digit sprite and recenter score { MapSprite2(13, numbers[score_hundreds],0); MoveSprite(13,score_x, 8, 1, 2); MoveSprite(11,score_x+8, 8, 1, 2); MoveSprite(9,score_x+16, 8, 1, 2); } else //score is < 100, move 100's place digit sprite off screen for the same reason as the ten's digit above { MoveSprite(13,SCREEN_TILES_H << 3, 8, 1, 2); } }
// movement behaviour of the blue paddle // void AIBehaviour(DynamObject &paddle, DynamObject &ball) { if(ball.position.x > 640) { if(ball.position.y > paddle.position.y && paddle.position.y < 652) paddle.position.y += 1.3f; else//(ball.position.y > paddle.position.y && paddle.position.y > 0) paddle.position.y -= 1.3f; } MoveSprite(paddle.sprite, paddle.position.x, paddle.position.y); }
/** * \brief Performs setup and re-initialization needed before each new game. * * Resets the player score, resets variables for drawing columns, sets a new random ghost color, moves the player back to the starting position, erases columns from last game, * turns scrolling back on and makes the player visible again. */ static void gameSetup() { randomSky(); //fill screen with tile 1 again to erase menu ClearVram(); for(u8 i = 0; i < 4; i++) //reset column data with 0's to start fresh { pipe_x[i] = 0; pipe_y[i] = 0; } for(u8 k = 0; k < 32; k++) { bg[k] = 1; } //reset all score data from last game to 0 score = 0;//score = 0; score_ones=0; score_tens=0; score_hundreds=0; fake_x = 80; //reset how far we've flown player_x = 80; //reset player position player_y = 40; yspeed = 0; //make sure we start at 0 speed //draw the background for(u8 i = 0; i < VRAM_TILES_H; i++) { pipe_alarm=2; //make sure we never draw a column while we're drawing the starting screen loadNextStripe(); //go through each column and draw the background } //select a random color for the ghost and set the appropriate sprite ghost_color=(prng()%3); //the ghost has 3 frames and 3 color options, so we set the active sprite to the frame count (0 - 2) + the color (0, 3, or 6) to get the correct sprite ghost_color=(ghost_color+(ghost_color<<1)); current_sprite = player_sprites[current_frame+ghost_color]; //assign and move the player image to start the new game MoveSprite(0,player_x,player_y,3,3); MapSprite2(0,current_sprite,0); //make player visible SetSpriteVisibility(true); //reset variables to draw new columns correctly current_pipe=0; build_pipe=0; pipe_alarm = 1; pipe_col_drawn = 0; //turn scrolling on to begin the game scrollingOn=true; }
void UpdateMainMenu() { //purty tings MoveSprite(iArcadeMarquee, iScreenWidth / 2, iScreenHeight / 2); DrawSprite(iArcadeMarquee); //text SetFont(pInvadersFont); DrawString("INSERT COINS", iScreenWidth * 0.37f, iScreenHeight * 0.5f); DrawString(pkCredit, iScreenWidth* (0.37f + 0.1f), iScreenHeight * 0.45f); }
PyObject* AIE_MoveSprite(PyObject *self, PyObject *args) { unsigned int iSpriteID; float v2fPos[2]; if (!PyArg_ParseTuple(args, "iff", &iSpriteID, &v2fPos[0], &v2fPos[1]) ) { ParsePyTupleError( __func__, __LINE__ ); return nullptr; } MoveSprite( iSpriteID, v2fPos[0], v2fPos[1] ); Py_RETURN_NONE; }
void Spit::Update(float delta_) { if ( activeCounter > activeTime ) { active = false; return; } activeCounter += delta_; pos += velocity * delta_; MoveSprite(sprite, pos.x, pos.y); }
void shootshots() { if (ship.position.x == 100) { bulletOne.position.x = ship.position.x + 50; bulletOne.position.y = ship.position.y-2; MoveSprite (bulletOne.sprite, ship.position.x + 5, ship.position.y-2); } if (ship.position.x == 301) { bulletTwo.position.x = ship.position.x + 50; bulletTwo.position.y = ship.position.y-2; MoveSprite (bulletTwo.sprite, ship.position.x + 50, ship.position.y-2); } if (ship.position.x == 501) { bulletThree.position.x = ship.position.x + 50; bulletThree.position.y = ship.position.y-2; MoveSprite (bulletThree.sprite, ship.position.x + 5, ship.position.y-2); } } // 192, 588
//initialize all variables in the game void initGame() { srand(time(NULL)); //load the sprites g_uiBgImage = CreateSprite("./images/bg.png", SCREEN_X, SCREEN_Y, true ); MoveSprite(g_uiBgImage, SCREEN_X / 2, SCREEN_Y / 2); g_player1.iSprite = CreateSprite( "./images/player1.png", PLAYER1_W, PLAYER1_H, true ); g_player2.iSprite = CreateSprite( "./images/player2.png", PLAYER2_W, PLAYER2_H, true ); g_ball.iSprite = CreateSprite( "./images/ball.png", BALL_W, BALL_H, true ); g_powerUp.iSprite = CreateSprite( "./images/ball.png", BALL_W, BALL_H, true ); }