예제 #1
0
파일: Door.cs 프로젝트: Jkoza/Vanish
        public void draw(PaintEventArgs e, Player player, Tile[,] grid)
        {
            if (!locked)    //if unlocked, use default gray door colour
            {
                brush = new SolidBrush(Color.FromArgb(175, Stat.Black));
            }
            e.Graphics.FillRectangle(brush, rect);

            if (sliding)
            {
                slide();  //continue slide animation every timer tick...
            } //Check Door Proximity
            else if (shouldSlide(player, grid))  //if it should slide
            {
                startSlide(); //start slide animation
            }
        }
예제 #2
0
파일: Collision.cs 프로젝트: Jkoza/Vanish
        //stop cone at walls
        public void EnemySightTiles(Tile[,] grid, List<Enemy> enemy)
        {
            bool noneUp = false;
            bool noneDown = false;
            bool noneLeft = false;
            bool noneRight = false;

            foreach (Tile t in grid)
            {
                if (t.initialized)  //if the tile is a wall
                {
                    foreach (Enemy e in enemy)
                    {
                        //for UP
                        if (e.sightDir == "up" &&
                            t.loc.Y + Stat.TileSize > e.sightPoints[1].Y && t.loc.Y + Stat.TileSize < e.sightPoints[0].Y && //in between enemy and end of sightline on the X
                            t.loc.X < e.sightPoints[0].X - ((t.loc.Y - e.sightPoints[0].Y) / 3) && t.loc.X > e.sightPoints[0].X + ((t.loc.Y - e.sightPoints[0].Y) / 3))
                        {
                            e.sightPoints[1].Y = t.loc.Y + Stat.TileSize;
                            e.sightPoints[2].Y = t.loc.Y + Stat.TileSize;
                            e.sightDist = e.sightPoints[0].Y - (t.loc.Y + Stat.TileSize); //sight dist should be positive even if being subtracted (accounted for in drawRect)
                            noneLeft = false;
                        }
                        //for DOWN
                        if (e.sightDir == "down" &&
                            t.loc.Y < e.sightPoints[1].Y && t.loc.Y > e.sightPoints[0].Y && //in between enemy and end of sightline on the X
                            t.loc.X > e.sightPoints[0].X - ((t.loc.Y - e.sightPoints[0].Y) / 3) && t.loc.X < e.sightPoints[0].X + ((t.loc.Y - e.sightPoints[0].Y) / 3))
                        {
                            e.sightPoints[1].Y = t.loc.Y;
                            e.sightPoints[2].Y = t.loc.Y;
                            e.sightDist = t.loc.Y - e.sightPoints[0].Y;
                            noneDown = false;
                        }

                        //for LEFT
                        if (e.sightDir == "left" &&
                            t.loc.X + Stat.TileSize > e.sightPoints[1].X && t.loc.X + Stat.TileSize < e.sightPoints[0].X && //in between enemy and end of sightline on the X
                            t.loc.Y < e.sightPoints[0].Y - ((t.loc.X - e.sightPoints[0].X) / 3) && t.loc.Y > e.sightPoints[0].Y + ((t.loc.X - e.sightPoints[0].X) / 3))
                        {
                            e.sightPoints[1].X = t.loc.X + Stat.TileSize;
                            e.sightPoints[2].X = t.loc.X + Stat.TileSize;
                            e.sightDist = e.sightPoints[0].X - (t.loc.X + Stat.TileSize); //sight dist should be positive
                            noneLeft = false;
                        }
                        //for RIGHT
                        if (e.sightDir == "right" &&
                            t.loc.X < e.sightPoints[1].X && t.loc.X > e.sightPoints[0].X && //in between enemy and end of sightline on the X
                            t.loc.Y > e.sightPoints[0].Y - ((t.loc.X - e.sightPoints[0].X) / 3) && t.loc.Y < e.sightPoints[0].Y + ((t.loc.X - e.sightPoints[0].X) / 3))
                        {
                            e.sightPoints[1].X = t.loc.X;
                            e.sightPoints[2].X = t.loc.X;
                            e.sightDist = t.loc.X - e.sightPoints[0].X;
                            noneRight = false;
                        }

                        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();
                    }
                }
            }
        }
예제 #3
0
파일: Collision.cs 프로젝트: Jkoza/Vanish
        //PLAYER INTERCEPTING TILES/DOORS   (Doors are technically a workaround in which walls are drawn beneath locked doors so you cannot walk through them)
        public void PlayerTiles(Player player, Tile[,] grid)
        {
            bool noneUp = true;
            bool noneDown = true;
            bool noneLeft = true;
            bool noneRight = true;
            foreach (Tile t in grid)
            {
                if (t.initialized)  //if a wall
                {
                    double xPosP = player.xPos + (player.size / 2); //new CENTRED position vars
                    double yPosP = player.yPos + (player.size / 2);
                    double xPosT = t.loc.X + (Stat.TileSize / 2);
                    double yPosT = t.loc.Y + (Stat.TileSize / 2);
                    double overcomeDist = (player.size + Stat.TileSize) / 2;

                    if (player.yPos <= 0 ||
                        yPosT - yPosP >= -overcomeDist && yPosT - yPosP <= 0 &&    //tile above
                        xPosT - xPosP <= (overcomeDist / 2) && xPosT - xPosP >= -(overcomeDist / 2))
                    {
                        player.upC = false;   //can't move up
                        noneUp = false;
                    }
                    if (player.yPos + player.size >= Stat.pbCanvasHeight ||
                        yPosT - yPosP <= overcomeDist && yPosT - yPosP >= 0 &&    //tile below
                        xPosT - xPosP <= (overcomeDist / 2) && xPosT - xPosP >= -(overcomeDist / 2))
                    {
                        player.downC = false;   //can't move down
                        noneDown = false;
                    }
                    if (player.xPos <= 0 ||
                        xPosT - xPosP >= -overcomeDist && xPosT - xPosP <= 0 &&    //tile on left
                        yPosT - yPosP <= (overcomeDist / 2) && yPosT - yPosP >= -(overcomeDist / 2))
                    {
                        player.leftC = false;   //can't move left
                        noneLeft = false;
                    }
                    if (player.xPos + player.size >= Stat.pbCanvasWidth ||
                        xPosT - xPosP <= overcomeDist && xPosT - xPosP >= 0 &&    //tile on right
                        yPosT - yPosP <= (overcomeDist / 2) && yPosT - yPosP >= -(overcomeDist / 2))
                    {
                        player.rightC = false;   //can't move right
                        noneRight = false;
                    }
                }
            }

            if (noneUp)     //if none in the way, let it pass through IF player.up == true also
            {
                player.upC = true;
            }
            if (noneDown)
            {
                player.downC = true;
            }
            if (noneLeft)
            {
                player.leftC = true;
            }
            if (noneRight)
            {
                player.rightC = true;
            }
        }
예제 #4
0
파일: World.cs 프로젝트: Jkoza/Vanish
 void fillGrid()
 {
     grid = new Tile[Stat.tilesWide, Stat.tilesHigh];
     for (int y = 0; y < Stat.tilesHigh; y++)
     {
         for (int x = 0; x < Stat.tilesWide; x++)
         {
             grid[x, y] = new Tile(new Point(x, y)); //create all tiles
         }
     }
 }
예제 #5
0
파일: Door.cs 프로젝트: Jkoza/Vanish
        //OPENING ANIMATION
        public bool shouldSlide(Player player, Tile[,] grid)
        {
            bool noneBetween = true;   //referring to wall tiles in the way of door (don't want the door opening if there's a wall separating the door from the player)
            foreach (Tile t in grid)
            {
                if (vert)
                {
                    if (t.initialized &&
                        ((t.loc.X > player.xPos && t.loc.X < xPosClosed) ||     //Tile X in between Player and Door (horizontally)
                        (t.loc.X < player.xPos && t.loc.X > xPosClosed))
                        &&                                                  //AND
                         (t.loc.Y > yPosClosed && t.loc.Y < yPosClosed + size))     //Tile Y in between door top and bottom
                    {
                        noneBetween = false;
                    }
                }
                else if (!vert)
                {
                    if (t.initialized &&
                        ((t.loc.Y > player.yPos && t.loc.Y < yPosClosed) ||     //Tile Y in between Player and Door (horizontally)
                        (t.loc.Y < player.yPos && t.loc.Y > yPosClosed))
                        &&                                                  //AND
                         (t.loc.X > xPosClosed && t.loc.X < xPosClosed + size))     //Tile X in between door top and bottom
                    {
                        noneBetween = false;
                    }
                }
            }

                //if there are none inbetween then:

            if (player.xPos + doorProximity > xPosClosed && player.xPos - doorProximity < xPosClosed &&    //proximal to door
                player.yPos + doorProximity > yPosClosed && player.yPos - doorProximity < yPosClosed &&
                noneBetween)    //FIX Door not working
            {
                if (open == -1 && locked == false)   //unopened and unlocked
                {
                    return true;  //open
                }
            }
            else
            {
                if (open == 1)  //if open
                {
                    return true;  //close
                }
            }

            return false;
        }