void spawnItem(int i, Vector2 position) { int num = i; Vector2 pos = position; if (i == 0) num = RandomProvider.GetRandom().Next(1, 9); if (position == Vector2.Zero) pos = new Vector2(RandomProvider.GetRandom().Next((int)(TurkeySmashGame.WindowSize.X / 6), (int)(5 * TurkeySmashGame.WindowSize.X / 6)), TurkeySmashGame.WindowSize.Y / 6); PhysicsObject item = null; switch (num) { case 1: itemsSprite.Add(football); item = new RoundPhysicsObject(world, pos, 3f, 0.7f, football); break; case 2: itemsSprite.Add(caisseSprite); item = new RectPhysicsObject(world, pos, 2.0f, caisseSprite); break; case 3: itemsSprite.Add(blocSwag); item = new RectPhysicsObject(world, pos, 1f, blocSwag); break; case 4: itemsSprite.Add(pingpong); item = new RoundPhysicsObject(world, pos, 5, 0.90f, pingpong); break; case 5: itemsSprite.Add(baguette); item = new RectPhysicsObject(world, pos, 4, baguette); break; case 6: itemsSprite.Add(pneu); item = new RoundPhysicsObject(world, pos, 5, 0.75f, pneu); break; case 7: itemsSprite.Add(pq); item = new RectPhysicsObject(world, pos, 5, pq); break; case 8: itemsSprite.Add(tv); item = new RectPhysicsObject(world, pos, 1, tv); break; } FarseerBodyUserData userData = new FarseerBodyUserData { IsCharacter = false, IsBonus = false, IsItem = true, }; item.body.UserData = userData; item.body.Mass = massItem; items.Add(item); }
public override void Update(GameTime gameTime) { #region Reset Anim if (FinishedAnimation) { inAction = false; Reset(new Point(0, 1)); TimeBetweenFrame = 100; canHit = true; isHit = false; } #endregion position = ConvertUnits.ToDisplayUnits(bodyPosition) - bodySize; // update de la position de l'image newPosition = bodyPosition; newColor = color; FarseerBodyUserData userdata = (FarseerBodyUserData)body.UserData; userdata.Protecting = isProtecting; invincible = userdata.Invincible; powerUp = userdata.PowerUp; int time = gameTime.ElapsedGameTime.Milliseconds; #region animatedEffects & particules update if (animatedEffects.Count > 0) { for (int k = 0; k < animatedEffects.Count; k++) { animatedEffects[k].Update(gameTime); if (animatedEffects[k].FinishedAnimation) animatedEffects.RemoveAt(k); } } if (particles.Count > 0) { for (int index = 0; index < particles.Count; index++) { particles[index].Update(gameTime, ConvertUnits.ToDisplayUnits(bodyPosition)); if (particles[index].particles.Count == 0) particles.RemoveAt(index); } } #endregion #region Hit if (inAction & CurrentFrame.X == frameHit & canHit) { punchMiss.Play(); RectPhysicsObject hit = new RectPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(body.Position.X) + (allongeCoup + (bodySize.X / 2)) * x, ConvertUnits.ToDisplayUnits(body.Position.Y) + (allongeCoup + bodySize.Y) * y), 1, new Vector2(bodySize.X / 2, bodySize.Y / 2)); hit.body.IsSensor = true; hit.body.OnCollision += hitOnColision; world.Step(1 / 3000f); world.RemoveBody(hit.body); canHit = false; } #endregion if (pourcent > oldPourcent) isHit = true; #region Protection if (compteurProtection > tempsProtection) { isProtecting = false; userdata.Protecting = false; } else { if (isProtecting) { particles.Add(new ParticleEngine(TurkeySmashGame.content.Load<Texture2D>("Jeu\\effets\\bulleProtectrice"), ConvertUnits.ToDisplayUnits(new Vector2(bodyPosition.X, bodyPosition.Y - 0.1f)), Vector2.Zero, Color.Red, 1, BlendState.Additive, 0, 1.0f, false, false, false, false, false, false)); } } #endregion #region Invincible if (compteurInvincible > tempsInvincibilite) { invincible = false; userdata.Invincible = false; } else { compteur += time; if (invincible & compteur > 50) { particles.Add(new ParticleEngine(textures, ConvertUnits.ToDisplayUnits(new Vector2(bodyPosition.X, bodyPosition.Y - 0.15f)), Vector2.Zero, Color.Yellow, 4, 600, 1.0f, false, true, false, false)); color = lastColor == Color.Yellow ? Color.White : Color.Yellow; compteur = 0; } } #endregion #region PowerUp if (compteurPowerUp > tempsPowerUp) { powerUp = false; userdata.PowerUp = false; } else { compteur0 += time; if (powerUp & compteur0 > 600) { color = new Color(210,70,90); compteur0 = 0; } } #endregion #region Chute if (newPosition.Y > (oldPosition.Y + 0.1f) & !inAction) { CurrentFrame = new Point(4, 2); definition.Loop = false; FinishedAnimation = true; } #endregion #region Flip Droite/Gauche if (!inAction) { if (lookingRight) spriteEffects = SpriteEffects.None; else spriteEffects = SpriteEffects.FlipHorizontally; } #endregion #region Filtre couleur + Anim coup reçu if (isHit) { color = Color.Red; i = 5; if (newPosition.X > (oldPosition.X + 0.1f) || newPosition.X < (oldPosition.X - 0.1f)) { Reset(new Point(0, 8)); TimeBetweenFrame = 50; } else { CurrentFrame = new Point(0, 10); FinishedAnimation = true; } inAction = true; definition.Loop = false; } else if (i > 0) { color = Color.Red; i--; if (FinishedAnimation) { CurrentFrame = new Point(0, 10); definition.Loop = false; FinishedAnimation = true; } } else { if (!invincible & !powerUp) color = Color.White; } #endregion #region Update Compteurs if (!inAction) compteurRoulade += time; else compteurRoulade = 0; if (isProtecting) compteurProtection += time; else compteurProtection -= compteurProtection > 0 ? time : 0; if (invincible) compteurInvincible += time; else compteurInvincible = 0; if (powerUp) { compteurPowerUp += time; puissPowerUp = 1.5f; pourcentageInflige = 14; } else { puissPowerUp = 1; compteurPowerUp = 1; pourcentageInflige = 7; } #endregion body.OnCollision += bodyOnCollision; oldPourcent = pourcent; oldDirection = direction; direction = Direction.Nodirection; pourcent = userdata.Pourcent; oldPosition = newPosition; lastColor = newColor; isMoving = false; isProtecting = false; base.Update(gameTime); }
void spawnBonus(int i, Vector2 position) { PhysicsObject thisBonus = null; int num = i; Vector2 pos = position; if (i == 0) num = RandomProvider.GetRandom().Next(1, 5); if (position == Vector2.Zero) pos = new Vector2(RandomProvider.GetRandom().Next((int)(TurkeySmashGame.WindowSize.X / 6), (int)(5 * TurkeySmashGame.WindowSize.X / 6)), TurkeySmashGame.WindowSize.Y / 6); switch (num) { case 1: thisBonus = new RectPhysicsObject(world, pos, 1, dinde); bonusSprite.Add(dinde); FarseerBodyUserData userData1 = new FarseerBodyUserData { IsCharacter = false, IsBonus = true, IsUsed = false, BonusType = "dinde" }; thisBonus.body.UserData = userData1; break; case 2: thisBonus = new RectPhysicsObject(world, pos, 1, hamburger); FarseerBodyUserData userData2 = new FarseerBodyUserData { IsCharacter = false, IsBonus = true, IsUsed = false, BonusType = "pourcent" }; thisBonus.body.UserData = userData2; bonusSprite.Add(hamburger); break; case 3: thisBonus = new RectPhysicsObject(world, pos, 1, raquette); FarseerBodyUserData userData3 = new FarseerBodyUserData { IsCharacter = false, IsBonus = true, IsUsed = false, BonusType = "raquette" }; thisBonus.body.UserData = userData3; bonusSprite.Add(raquette); break; case 4: thisBonus = new RectPhysicsObject(world, pos, 1, invincible); FarseerBodyUserData userData4 = new FarseerBodyUserData { IsCharacter = false, IsBonus = true, IsUsed = false, BonusType = "invincible" }; thisBonus.body.UserData = userData4; bonusSprite.Add(invincible); break; } bonus.Add(thisBonus); }