// Resolves problem where enemies can be recoiled on top of one another at the map's edge private void spreadApart(GameChar enemy) { foreach (GameChar otherEnemy in world.Enemies) { if (!enemy.Equals(otherEnemy)) // Ensure enemy is not referencing itself { if (enemy.Bounds.Intersects(otherEnemy.Bounds)) { // Enemy is left of other enemy if (enemy.Position.X < otherEnemy.Position.X) { enemy.Position.X -= SpreadApartSpeed; } // Enemy is right of other enemy else if (enemy.Position.X > otherEnemy.Position.X) { enemy.Position.X += SpreadApartSpeed; } // Enemy is above other enemy if (enemy.Position.Y < otherEnemy.Position.Y) { enemy.Position.Y -= SpreadApartSpeed; } // Enemy is below other enemy else if (enemy.Position.Y > otherEnemy.Position.Y) { enemy.Position.Y += SpreadApartSpeed; } enemy.SetBounds(); } } } }
public void Initialize(GameManager gm, GameChar currentChar) { this.gm = gm; this.currentChar = currentChar; CurrentSprite = 0; InvokeRepeating("UpdateSprite", 0.5f, 0.5f); }
private AI setAI(GameChar enemy) { bool nearbyDeadBall = false; foreach (Ball ball in world.Balls) { // Dodge if incoming alive ball // Presumes enemy is on Right team if (ball.Velocity.X > 0 && ball.IsAlive) { return(AI.Dodge); } // Pickup if nearby dead ball else if (ball.Bounds.Intersects(world.SideBounds[enemy.Side]) && !ball.IsAlive) { nearbyDeadBall = true; } } if (nearbyDeadBall) { return(AI.Pickup); } // Attack if holding a ball else if (enemy.BallsHeld > 0) { return(AI.Attack); } // Else, avoid opponent return(AI.Avoid); }
public static Point[] RandomPosition(int num ,char ch) { Point[] points = new Point[num]; GameChar[] copy = new GameChar[Map.Length]; int count = 0; foreach(GameChar gch in Map) { if(gch.Char == ch) { copy[count] = gch; count++; } } Random rand = new Random(); for (int i =0;i< num; i++) { int random = rand.Next(0, count); points[i].x = copy[random].x; points[i].y = copy[random].y; } return points; }
private void drawHealthBar(GameChar gameChar) { // Set color Color color; float healthPercentage = (float)gameChar.Health / gameChar.MaxHealth; if (healthPercentage <= VeryLowHealth) { color = Color.Red; } else if (healthPercentage <= LowHealth) { color = Color.Orange; } else if (healthPercentage <= MediumHealth) { color = Color.Yellow; } else { color = Color.Green; } Rectangle rect = new Rectangle( UI.HealthBar.X + gameChar.Bounds.X, UI.HealthBar.Y + gameChar.Bounds.Y, (int)(UI.HealthBar.Width * healthPercentage), UI.HealthBar.Height); drawRect(rect, color); }
public void AddTroll(int num) { Point[] p = CharMap.RandomPosition(num , ' '); foreach (Point points in p) { GameChar troll = new GameChar(points.x,points.y, 'T', ConsoleColor.Black, ConsoleColor.Red); CharMap.Map[points.x, points.y] = troll; } }
public static void Copy(GameChar source, GameChar target) { target.id = source.id; target.name = source.name; target.userid = source.userid; target.typeid = source.typeid; target.level = source.level; target.exp = source.exp; target.gold = source.gold; target.regdate = source.regdate; target.playtime = source.playtime; }
public CharMap() { String[] map = File.ReadAllLines(LargeMaze); Rows = map.Count(); Length = map[0].Length; Map = new GameChar[Length, Rows]; for (int x = 0; x < Length; x++) { for (int y = 0; y < Rows; y++) { Map[x, y] = new GameChar(x,y,map[y][x],ConsoleColor.Black,ConsoleColor.White); } } }
protected override void handleAttack(GameChar gameChar, float dt) { if (ai == AI.Attack) { gameChar.AttackTimer -= dt; if (gameChar.AttackTimer <= 0) { gameChar.AttackTimer = (float)random.NextDouble() * GameChar.EnemyAttackWaitMax; if (gameChar.BallsHeld > 0) { gameChar.BallsHeld--; throwBall(gameChar, world.Player.Position, false); // Always a normal throw } } } }
public static async Task Select(GameChar character, IPs4Controller controller) { switch (character) { case GameChar.Random: await controller.PressSequenceAsync(new[] { Ps4Button.Triangle, Ps4Button.Cross }, 1000); break; default: throw new ArgumentOutOfRangeException(nameof(character), character, null); } }
public Sprite[] GetCharacterSprites(GameChar character) { switch (character) { case GameChar.Takuya: return(takuya); case GameChar.Koji: return(koji); case GameChar.Zoe: return(zoe); case GameChar.JP: return(jp); case GameChar.Tommy: return(tommy); case GameChar.Koichi: return(koichi); } return(null); }
private void drawGameChar(GameChar gameChar) { if (gameChar.Side == GameChar.Team.Left) { drawEntity(gameChar, textures.GameChars[gameChar.AvatarType]); } else // Right { // Flip texture horizontally spriteBatch.Draw(textures.GameChars[gameChar.AvatarType], gameChar.Bounds, null, Color.White, 0, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0); } }
public override void Update(float dt) { for (int i = world.Enemies.Count - 1; i >= 0; i--) { GameChar enemy = world.Enemies[i]; ai = setAI(enemy); handleAttack(enemy, dt); setVelocity(enemy, dt); setPosition(enemy, dt); enemy.SetBounds(); spreadApart(enemy); boundsCheck(enemy); // Remove dead enemies if (enemy.Health <= 0) { world.AllGameChars.Remove(enemy); world.Enemies.RemoveAt(i); } } }
protected override void handleAttack(GameChar gameChar, float dt) { if (Input.Throw) { Input.Throw = false; if (gameChar.BallsHeld > 0) { gameChar.BallsHeld--; // Check for fast throw bool fastThrow = false; foreach (GameChar enemy in world.Enemies) { if (enemy.Bounds.Contains(Input.MouseVirtualPos)) { fastThrow = true; break; } } throwBall(gameChar, Input.ThrowHere, fastThrow); } } }
protected void throwBall(GameChar thrower, Vector2 throwHere, bool fastThrow) { Vector2 pos = new Vector2(thrower.Position.X, thrower.Position.Y); if (thrower.Side == GameChar.Team.Left) { pos.X += BallSpawnDist; } else // Right { pos.X -= BallSpawnDist; } Vector2 dir = Vector2.Subtract(throwHere, pos); if (dir.LengthSquared() > 0) // Prevents divide-by-zero crash if player clicks exactly on gameChar position { dir = Vector2.Normalize(dir); } world.Balls.Add(new Ball(pos, dir, true, fastThrow)); }
private void drawLungeBar(GameChar gameChar) { Color color; if (gameChar.LungeCooldown > 0) { color = Color.Gray; } else { color = Color.White; } float lungePercentage = (GameChar.LungeCooldownLength - gameChar.LungeCooldown) / GameChar.LungeCooldownLength; Rectangle lungeBar = gameChar.Side == GameChar.Team.Left ? UI.LeftLungeBar : UI.RightLungeBar; Rectangle rect = new Rectangle( lungeBar.X + gameChar.Bounds.X, lungeBar.Y + gameChar.Bounds.Y + (int)(lungeBar.Height * (1.0 - lungePercentage)), lungeBar.Width, (int)(lungeBar.Height * lungePercentage)); drawRect(rect, color); }
private void handleLunge(GameChar player, float dt) { // Update timers player.LungeTimer -= dt; if (player.LungeTimer < 0) { player.LungeTimer = 0; } player.LungeCooldown -= dt; if (player.LungeCooldown < 0) { player.LungeCooldown = 0; } // Start lunge if (Input.Lunge) { Input.Lunge = false; if (player.LungeCooldown <= 0) { player.LungeTimer = GameChar.LungeLength; player.LungeCooldown = GameChar.LungeCooldownLength; player.LungeDirection = Vector2.Subtract(Input.LungeHere, player.Position); if (player.LungeDirection.LengthSquared() > 0) // Prevents divide-by-zero crash if player clicks exactly on gameChar position { player.LungeDirection = Vector2.Normalize(player.LungeDirection); } } } // Change velocity if active lunge if (player.LungeTimer > 0) { player.Velocity = Vector2.Multiply(player.LungeDirection, GameChar.LungeSpeed); } }
// Checks that a recoiled enemy does not land on top of any other enemies private bool checkForEnemyRecoilCollision(GameChar recoiled, Vector2 recoil) { bool intersects = false; Vector2 futurePos = new Vector2(recoiled.Position.X, recoiled.Position.Y); futurePos.X += recoil.X; futurePos.Y += recoil.Y; Rectangle futureBounds = new Rectangle(recoiled.Bounds.X, recoiled.Bounds.Y, recoiled.Bounds.Width, recoiled.Bounds.Height); futureBounds.X = (int)(futurePos.X - futureBounds.Width / 2); futureBounds.Y = (int)(futurePos.Y - futureBounds.Height / 2); foreach (GameChar enemy in world.Enemies) { if (!recoiled.Equals(enemy)) // Ensure enemy is not referencing itself { if (futureBounds.Intersects(enemy.Bounds)) { intersects = true; break; } } } return(intersects); }
private void drawInventory(GameChar gameChar) { for (int i = 0; i < gameChar.MaxBallsHeld; i++) { Color color; if (gameChar.BallsHeld <= i) { color = Color.Gray; } else { color = Color.Red; } Rectangle inventory = gameChar.Side == GameChar.Team.Left ? UI.LeftInventory : UI.RightInventory; Rectangle rect = new Rectangle( inventory.X + gameChar.Bounds.X, inventory.Y + gameChar.Bounds.Y + UI.InventorySpacing * i, inventory.Width, inventory.Height); drawRect(rect, color); } }
public void SetGameChar(int x, int y,GameChar other) { Map[x, y] = new GameChar(x, y, other.Char, other.BackgroundColor, other.ForegroundColor); }
public TowersOfTimeGamePlan(GameChar c) { Char = c; }
public EndlessTowerGamePlan(GameChar c) { Char = c; }
protected abstract void handleAttack(GameChar gameChar, float dt);
public NewbieTowerGamePlan(GameChar c) { Char = c; }
public void Move(int x,int y) { Point p = new Point(GamePlayer.x + x,GamePlayer.y + y); if(CharMap.Map[p.x,p.y].Char == '#') { if (CharMap.Map[p.x + x, p.y + y].Char == ' ') { System.Diagnostics.Debug.WriteLine(CharMap.Map[GamePlayer.x, GamePlayer.y].Char.ToString() + CharMap.Map[p.x, p.y].Char.ToString() + CharMap.Map[p.x + x, p.y + y].Char.ToString()); pushing = true; } else { return; } } if(CharMap.Map[p.x,p.y].Char == 'T') { GameOver(); return; } if(CharMap.Map[p.x, p.y].Char == 'X') { WinScreen(); return; } if (pushing) { System.Diagnostics.Debug.WriteLine("!!!!"); cm.SetGameChar(GamePlayer.x, GamePlayer.y, CharMap.Map[p.x + x, p.y + y]); cm.SetGameChar(p.x + x, p.y + y, CharMap.Map[p.x, p.y]); cm.SetGameChar(p.x, p.y, GamePlayer); GamePlayer = CharMap.Map[p.x, p.y]; pushing = false; return; } cm.SetGameChar(GamePlayer.x, GamePlayer.y, CharMap.Map[p.x, p.y]); cm.SetGameChar(p.x, p.y, GamePlayer); GamePlayer = CharMap.Map[p.x, p.y]; }
public void AddCharacter() { Point[] p = CharMap.RandomPosition(1, ' '); GamePlayer = new GameChar(p[0].x, p[0].y, (char)PlayerMov.Left, ConsoleColor.Black, ConsoleColor.Yellow); CharMap.Map[GamePlayer.x, GamePlayer.y] = GamePlayer; }