protected override void Init() { Random rand = new Random(); if (offsets.Count > 0) { offsets.Clear(); } numIllusions = rand.Next(2, 5); for (int i = 0; i < numIllusions; i++) { GameObject obj = new GameObject(false, player.orientation); if (player.team == Global.RED_TEAM) obj.SetTexture("Assets/RedPlayer"); else if (player.team == Global.BLUE_TEAM) obj.SetTexture("Assets/BluePlayer"); else System.Console.WriteLine("LOADING PLAYER IMAGE FAILED: NO TEAM ASSIGNED!"); illusions.Add(obj); } draw = true; for (int i = 0; i < numIllusions; i++) { float x = (float)((i + 1) * 50) + rand.Next(-100, 100); float y = (float)((i + 1) * 50) + rand.Next(-100, 100); Vector2 pos = new Vector2(x, y); offsets.Add(pos); illusions.ElementAt(i).position.X = player.position.X + offsets[i].X; illusions.ElementAt(i).position.Y = player.position.Y + offsets[i].Y; } prevLevel = player.pushSpeed.level; player.pushSpeed.SetLevel(prevLevel + numIllusions); base.Init(); }
public Play(int teamSize) { pickupManager = new PickupManager(); paused = false; this.teamSize = teamSize; pauseSelect = RESUME; pauseMenuPos = new Vector2(440, 295); resume = new Sprite(); quit = new Sprite(); aContinue = new Sprite(); if (teamSize == Global.MIN_TEAM_SIZE) { MAX_STAMINA = 100.0f; } else if (teamSize == Global.MAX_TEAM_SIZE) { MAX_STAMINA = 200.0f; } rtStamina = btStamina = MAX_STAMINA; redCourt = new Court((int)Court.Type.RED); blueCourt = new Court((int)Court.Type.BLUE); wall = new GameObject(true, (int)GameObject.Orientation.NONE); wall.name = "wall"; wall.speed.X = 1; redVictorySprite = new Sprite((int)Sprite.Orientation.NONE); blueVictorySprite = new Sprite((int)Sprite.Orientation.NONE); hud = new HUD(teamSize); collisionArray = new List<GameObject>(); }
private void HandleCollision(GameObject obj, int index) { bool collidable = obj.collidable; if (obj.name == "wall") { if (team == Global.RED_TEAM) obj.position.X += pushSpeed.value; else obj.position.X -= pushSpeed.value; staminaUsed -= 0.25f; wallHit = true; canFire = false; } if (obj is Projectile) { Projectile proj = (Projectile)obj; if (proj.team != this.team) { if (!proj.piercing) { proj.SetActive(false); staminaUsed -= proj.damage; } else { staminaUsed -= (proj.damage / (damage.level * 3)); } } } if (obj is Pickup) { Pickup pickup = (Pickup)obj; if (pickup.active) { pickup.Activate(this); TimedText(pickup.description); pickup.Destroy(); Play.collisionArray.RemoveAt(index); Play.pickupManager.RemovePickup(); } } if (collidable) { // Please note these are approximations bool above = false; bool below = false; // Above object if ((previousPosition.Y + height + speed.Y) <= obj.position.Y) { position.Y = obj.position.Y - height; above = true; speed.Y = 0; } // Below object if ((previousPosition.Y + speed.Y) >= (obj.position.Y + obj.height)) { position.Y = obj.position.Y + obj.height; speed.Y = 0; below = true; } if (!above && !below) { // Left of object if ((previousPosition.X - speed.X) < obj.position.X) { position.X = obj.position.X - width; speed.X = 0; } // Right of object if ((previousPosition.X - speed.X) > obj.position.X) { position.X = obj.position.X + obj.width; speed.X = 0; } } } }