//KOLLAR OM MAN HAR KOLLIDERAT MED TEDDY; OCH PÅ VILKA BANOR DET I SÅ FALL HÄNDER. SÄTTER HUR MAN KOLLIDERAR. //HAR MAN KOLLIDERAT MED TEDDY SÅ RITAS FLICKAN UT: KOLLIDERAR MAN SEN MED EMPTY TILE SÅ FÖRSVINNER FLICKAN public bool IsCollidingAtTeddy(Vector2 a_newPos, Vector2 a_size, SoundObserver a_soundobserver) { Vector2 topLeft = new Vector2(a_newPos.X, a_newPos.Y - a_size.Y); Vector2 bottomRight = new Vector2(a_newPos.X, a_newPos.Y); for (int x = 0; x < g_levelWidth; x++) { for (int y = 0; y < g_levelHeight; y++) { if (bottomRight.X < (float)x - 0.4) continue; if (bottomRight.Y < (float)y) continue; if (topLeft.X > (float)x + 1.0f) continue; if (topLeft.Y > (float)y + 0.7f) continue; if (m_tiles[x, y] == Tile.T_TEDDY) { m_tiles[25, g_levelHeight - 3] = Tile.T_EMPTY; m_tiles[29, g_levelHeight - 3] = Tile.T_GIRL; a_soundobserver.ScreamSound(); return true; } else if (m_tiles[x, y] == Tile.T_VANISH) { m_tiles[29, g_levelHeight - 3] = Tile.T_EMPTY; } } } return false; }
//EN UPPDATE SOM HÅLLER REDA PÅ SPELAREN public void UpdatePlayer(float a_elapsedTime, SoundObserver a_sound, ILevelObserver a_observer, int difficulty) { Vector2 oldPos = m_player.GetPosition(); //get a new position for the player m_player.Update(a_elapsedTime); Vector2 newPos = m_player.GetPosition(); m_hasCollidedWithGround = false; Vector2 speed = m_player.GetSpeed(); Vector2 afterCollidedPos = Collide(oldPos, newPos, m_player.m_sizes, ref speed, out m_hasCollidedWithGround, a_elapsedTime, a_observer); //set the new speed and position after collision m_player.SetPosition(afterCollidedPos.X, afterCollidedPos.Y); m_player.SetPosition(afterCollidedPos.X, afterCollidedPos.Y); m_player.SetSpeed(speed.X, speed.Y); //KOLLAR OM MAN HAR KOLLIDERAT MED EN TEDDY if (m_levels.IsCollidingAtTeddy(newPos, m_player.m_sizes, a_sound)) { m_player.SetSpeed(-2, 0); a_sound.ScreamSound(); } /*if(m_levels.IsCollidingAtEnemy(newPos, m_player.m_sizes, m_player)) { if(!hasBeenHit) { m_player.SetLifeChange(m_modelEnemy.GetEnemyDamage(), true); hasBeenHit = true; } }*/ //KOLLAR OM MAN HAR KOLLIDERAT MED FÄLLORA if (m_levels.IsCollidingAtTrap(newPos, m_player.m_sizes)) { DoDeath(a_observer); } /* if (m_levels.IsCollidingAtBoltEnemy(newPos, m_player.m_sizes)) { m_player.SetPosition(5, 15); m_player.SetSpeed(0, 0); }*/ //KOLLAR OM MAN KILLIDERAT MED HJÄRTAT; INTE IMPLEMENTERAT MEN FUNKTIONEN FINNS if (m_levels.IsCollidingAtHeart(newPos, m_player.m_sizes, a_sound)) { // m_playerHp += 50; } //KOLLAR KOLLISIONEN MED RUSHINGENEMY if(CollideWithRushingEnemy(newPos)) { // m_levels.Restart(a_observer); if (!hasBeenHit) { m_player.SetLifeChange(m_modelEnemy.GetEnemyDamage(), true); hasBeenHit = true; } if (!m_player.IsAlive()) { DoDeath(a_observer); } } //KOLLAR KOLLISIONEN MED BOLT ENEMY if (CollideWithBoltEnemy(newPos)) { if (!hasBeenHit) { m_player.SetLifeChange(m_modelEnemyBolt.GetEnemyDamage(), true); hasBeenHit = true; } if (!m_player.IsAlive()) { DoDeath(a_observer); } } //KOLLAR OM MAN HAR KOLLIDERAT MED SLUTET AV BANAN. if (afterCollidedPos.X > Levels.g_levelWidth - 3) { speed = new Vector2(0.0f, 0.0f); afterCollidedPos = new Vector2(5.0f, 0.0f); hasReachedEnd = true; } }