public void draw(PaintEventArgs e, Player player, World w) { if (doorForKey.locked) { if (color == Stat.Red) //depending on key colour { e.Graphics.DrawImage(Properties.Resources.keyRed, rect); //Draw different Key Image } if (color == Stat.Blue) { e.Graphics.DrawImage(Properties.Resources.keyBlue, rect); } if (color == Stat.Green) { e.Graphics.DrawImage(Properties.Resources.keyGreen, rect); } if (color == Stat.Gold) { e.Graphics.DrawImage(Properties.Resources.keyGold, rect); } if (player.xPos + player.size > xPos && player.xPos < xPos + width && //Player collides with key player.yPos + player.size > yPos && player.yPos < yPos + height || initially) { doorForKey.toggleLocked(w, this); initially = false; } } }
private void Vanish_Load(object sender, EventArgs e) { w = new World(level); //create world based on level selected pbCanvas.Location = new Point((int)Stat.pbCanvasLocX, (int)Stat.pbCanvasLocY); pbCanvas.Width = (int)Stat.pbCanvasWidth; //place pbCanvas in the middle of the form pbCanvas.Height = (int)Stat.pbCanvasHeight; this.MaximumSize = new Size((int)Stat.resolution.Width + 20, (int)Stat.resolution.Height + 40); this.MinimumSize = this.MaximumSize; }
private void pbCanvas_Paint(object sender, PaintEventArgs e) { w.refresh(e); //END GAME CHECK if (w.gameWonDone) { this.Close(); //close if game won } if (w.gameLostDone) { w = new World(level); //reset if game lost } }
//PLAYER PULSE INTERCEPTING ENEMY EARSHOT public void PlayerPulseEnemyHearing(Player player, List<Enemy> enemy, World w) { double dx, dy; double radiiP; if (!w.gameWon) { foreach (Enemy e in enemy) { if (player.moving && e.hearing) //if the player is moving and enemy can hear { dx = player.xPos - e.xPos; dy = player.yPos - e.yPos; radiiP = ((player.pulse / 2) + (e.hearDist / 2)); //pulse collision if (Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2)) <= radiiP) //pulses collide { w.gameLost = true; e.caughtPlayer = true; break; } } } } }
//PLAYER AND EXIT public void PlayerExit(Player player, Exit exit, World w) { if (player.xPos >= exit.xPos - 10 && player.xPos + player.size <= exit.xPos + exit.width + 10 && //check if player intersects with exit player.yPos >= exit.yPos - 10 && player.yPos + player.size <= exit.yPos + exit.height + 10) //10 pixel buffer { w.gameWon = true; } }
public void PlayerEnemySight(Player player, List<Enemy> enemy, World w) { bool noneUp = false; bool noneDown = false; bool noneLeft = false; bool noneRight = false; if (!w.gameWon) { foreach (Enemy e in enemy) { if (player.mode != "vanish") //player/enemy sight intersect does not apply to 'Vanish' mode { //for UP if (e.sightDir == "up" && player.yPos + player.size > e.sightPoints[1].Y && player.yPos + player.size < e.sightPoints[0].Y && //in between enemy and end of sightline on the X player.xPos < e.sightPoints[0].X - ((player.yPos - e.sightPoints[0].Y) / 3) && player.xPos > e.sightPoints[0].X + ((player.yPos - e.sightPoints[0].Y) / 3)) { w.gameLost = true; e.caughtPlayer = true; } //for DOWN if (e.sightDir == "down" && player.yPos < e.sightPoints[1].Y && player.yPos > e.sightPoints[0].Y && //in between enemy and end of sightline on the X player.xPos + player.size > e.sightPoints[0].X - ((player.yPos - e.sightPoints[0].Y) / 3) && player.xPos + player.size < e.sightPoints[0].X + ((player.yPos - e.sightPoints[0].Y) / 3)) { w.gameLost = true; e.caughtPlayer = true; } //for LEFT if (e.sightDir == "left" && player.xPos + player.size > e.sightPoints[1].X && player.xPos + player.size < e.sightPoints[0].X && //in between enemy and end of sightline on the X player.yPos + player.size < e.sightPoints[0].Y - ((player.xPos - e.sightPoints[0].X) / 3) && player.yPos + player.size > e.sightPoints[0].Y + ((player.xPos - e.sightPoints[0].X) / 3)) { w.gameLost = true; e.caughtPlayer = true; } //for RIGHT if (e.sightDir == "right" && player.xPos < e.sightPoints[1].X && player.xPos > e.sightPoints[0].X && //in between enemy and end of sightline on the X player.yPos > e.sightPoints[0].Y - ((player.xPos - e.sightPoints[0].X) / 3) && player.yPos < e.sightPoints[0].Y + ((player.xPos - e.sightPoints[0].X) / 3)) { w.gameLost = true; e.caughtPlayer = true; } if (noneUp) { e.sightDist = e.SIGHT_DIST; } if (noneDown) { e.sightDist = e.SIGHT_DIST; } if (noneLeft) { e.sightDist = e.SIGHT_DIST; } if (noneRight) { e.sightDist = e.SIGHT_DIST; } e.drawRect(); } } } }
//to draw enemies public void draw(PaintEventArgs e, World w) { e.Graphics.FillEllipse(brush, rect); if (hearing) { e.Graphics.FillEllipse(hearBrush, hearRect); } if (seeing) { w.collision.EnemySightTiles(w.grid, w.enemies); //check for cone size before drawing e.Graphics.FillPolygon(sightBrush, sightPoints); } }
//for locked only public void toggleLocked(World w, Key k) { if (locked && !k.initially) { locked = false; } else { locked = true; } if (vert) //to make sure the player can't walk through a door that won't open { //initialize tiles under the door so it's like a wall for (int i = (int)(yPos / Stat.TileSize); i < (int)(yPos / Stat.TileSize) + (int)(size / Stat.TileSize); i++) { w.grid[(int)(xPos / Stat.TileSize), i].toggle(); } } else { for (int i = (int)(xPos / Stat.TileSize); i < (int)(xPos / Stat.TileSize) + (int)(size / Stat.TileSize); i++) { w.grid[i, (int)(yPos / Stat.TileSize)].toggle(); } } }
public void PlayerMove(World w) { PrevLoc = new PointF(Convert.ToSingle(xPos), Convert.ToSingle(yPos)); if (up && upC) { yPos -= Speed; } if (down && downC) { yPos += Speed; } if (left && leftC) { xPos -= Speed; } if (right && rightC) { xPos += Speed; } if (xPos != PrevLoc.X || yPos != PrevLoc.Y) { moving = true; } else { moving = false; } if ((mode == "rush" || mode == "stealth") && moving && !w.gameLost) { if (pulse >= 0 && pulse <= pulseLim) { pulse += pulseChange; } if (pulse >= pulseLim) { pulse = 0; } } if (!moving && !w.gameLost) { pulse = 0; } }