Example #1
0
        public override void enterState()
        {
            new Background("bgs/bgtile", 0, 0);
            RenderingEngine.camera.setScale(Constants.GAMESCALE * (Constants.DEBUG ? 1366f / 1920f : 1));
            RenderingEngine.camera.setPosition(new Vector2(1920 / 2, 1080 / 2));
            RenderingEngine.ambientLight = Color.Gray;

            RenderingEngine.UI.addText(ai_data = new HUDText("AI Level", new Vector2(1250, 20), customfont, Color.White));
            RenderingEngine.UI.addText(time = new HUDText("Timer", new Vector2(50, 20), customfont, Color.White));
            timer = Constants.TIMEINTRO + Constants.TIMEMILLIS;

            map = new Map(mapname, content);
            players = new Player[4];
            scores = new HUDText[4];
            large = new HUDText("Starting", new Vector2(880, 500), customfont2, Color.White);
            RenderingEngine.UI.addText(large);
            toggles = new bool[4];

            this.spawns = map.spawns;

            for (int i = 0; i < 4; i++)
            {
                players[i] = new Player(map.spawns, i + 1, this);
                scores[i] = new HUDText("0", new Vector2(500 + i * 140, 20), customfont, (i == 0 ? Color.Red : (i == 1 ? Color.Yellow : (i == 2 ? Color.LightGreen : Color.Blue))));
                RenderingEngine.UI.addText(scores[i]);
                toggles[i] = false;
            }
            //SoundManager.PlayMusicLooped("sound/4614(2)");

            fs = File.Open("dw_kb_" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".txt", FileMode.OpenOrCreate, FileAccess.Write);
            writeString(mapname);
        }
Example #2
0
        public void collisionDetectionVsMap(Map m)
        {
            if (player.holdingDisk)
                return;

            bool aa = false, ab = false, ac = false, ba = false, bc = false, ca = false, cb = false, cc = false;
            int ax = (int)((animation.position.X - diskRadius + Constants.TILESIZE / 2) / Constants.TILESIZE),
                ay = (int)((animation.position.Y - diskRadius + Constants.TILESIZE / 2) / Constants.TILESIZE);
            int bx = (int)((animation.position.X + Constants.TILESIZE / 2) / Constants.TILESIZE),
                by = (int)((animation.position.Y + Constants.TILESIZE / 2) / Constants.TILESIZE);
            int cx = (int)((animation.position.X + diskRadius + Constants.TILESIZE / 2) / Constants.TILESIZE),
                cy = (int)((animation.position.Y + diskRadius + Constants.TILESIZE / 2) / Constants.TILESIZE);

            if (ay >= 0 && ay < Constants.MAPY)
            {
                if (ax >= 0 && ax < Constants.MAPX) aa = m.tiles[ax, ay].type == Map.TILE.wall && m.tiles[ax, ay].wall != Map.WALL.pass;
                if (bx >= 0 && bx < Constants.MAPX) ab = m.tiles[bx, ay].type == Map.TILE.wall && m.tiles[bx, ay].wall != Map.WALL.pass;
                if (cx >= 0 && cx < Constants.MAPX) ac = m.tiles[cx, ay].type == Map.TILE.wall && m.tiles[cx, ay].wall != Map.WALL.pass;
            }
            if (by >= 0 && by < Constants.MAPY)
            {
                if (ax >= 0 && ax < Constants.MAPX) ba = m.tiles[ax, by].type == Map.TILE.wall && m.tiles[ax, by].wall != Map.WALL.pass;
                if (cx >= 0 && cx < Constants.MAPX) bc = m.tiles[cx, by].type == Map.TILE.wall && m.tiles[cx, by].wall != Map.WALL.pass;
            }
            if (cy >= 0 && cy < Constants.MAPY)
            {
                if (ax >= 0 && ax < Constants.MAPX) ca = m.tiles[ax, cy].type == Map.TILE.wall && m.tiles[ax, cy].wall != Map.WALL.pass;
                if (bx >= 0 && bx < Constants.MAPX) cb = m.tiles[bx, cy].type == Map.TILE.wall && m.tiles[bx, cy].wall != Map.WALL.pass;
                if (cx >= 0 && cx < Constants.MAPX) cc = m.tiles[cx, cy].type == Map.TILE.wall && m.tiles[cx, cy].wall != Map.WALL.pass;
            }

            if ((aa && ac) || ab)
            {
                animation.position.Y = ((ay + 1) * Constants.TILESIZE - Constants.TILESIZE / 2) + diskRadius;
                if (m.tiles[bx, ay].wall == Map.WALL.bounce)
                {
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_slowhit");

                    if (!Constants.BOUNCETOSLOW)
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        player.released = true;
                    }
                    else
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        stopped = true;
                    }
                }
                else
                {
                    velocity.Y = -velocity.Y;
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_wallhit");
                }
            }
            if ((ca && cc) || cb)
            {
                animation.position.Y = (cy * Constants.TILESIZE - Constants.TILESIZE / 2) - diskRadius;
                if (m.tiles[bx, cy].wall == Map.WALL.bounce)
                {
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_slowhit");

                    if (!Constants.BOUNCETOSLOW)
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        player.released = true;
                    }
                    else
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        stopped = true;
                    }
                }
                else
                {
                    velocity.Y = -velocity.Y;
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_wallhit");
                }
            }
            if ((aa && ca) || ba)
            {
                animation.position.X = ((ax + 1) * Constants.TILESIZE - Constants.TILESIZE / 2) + diskRadius;
                if (m.tiles[ax, by].wall == Map.WALL.bounce)
                {
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_slowhit");

                    if (!Constants.BOUNCETOSLOW)
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        player.released = true;
                    }
                    else
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        stopped = true;
                    }
                }
                else
                {
                    velocity.X = -velocity.X;
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_wallhit");
                }
            }
            if ((ac && cc) || bc)
            {
                animation.position.X = (cx * Constants.TILESIZE - Constants.TILESIZE / 2) - diskRadius;
                if (m.tiles[cx, by].wall == Map.WALL.bounce)
                {
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_slowhit");

                    if (!Constants.BOUNCETOSLOW)
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        player.released = true;
                    }
                    else
                    {
                        velocity.Y = 0;
                        velocity.X = 0;
                        stopped = true;
                    }
                }
                else
                {
                    velocity.X = -velocity.X;
                    if (Math.Abs(velocity.X) > 0.2f || Math.Abs(velocity.Y) > 0.2f)
                        SoundManager.PlaySound("sound/dw_wallhit");
                }
            }

            if (ax >= 0 && ax < Constants.MAPX && ay >= 0 && ay < Constants.MAPY &&
                bx >= 0 && bx < Constants.MAPX && by >= 0 && by < Constants.MAPY &&
                cx >= 0 && cx < Constants.MAPX && cy >= 0 && cy < Constants.MAPY)
            {
                if (m.tiles[ax, ay].wall == Map.WALL.destr && m.tiles[ax, ay].respawn == 0)
                {
                    m.tiles[ax, ay].type = Map.TILE.floor;
                    m.tiles[ax, ay].anim.removeFromRenderingEngine();
                    m.tiles[ax, ay].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[ax, ay].anim.position.X, m.tiles[ax, ay].anim.position.Y), 0.1f);
                    m.tiles[ax, ay].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
                if (m.tiles[ax, by].wall == Map.WALL.destr && m.tiles[ax, by].respawn == 0)
                {
                    m.tiles[ax, by].type = Map.TILE.floor;
                    m.tiles[ax, by].anim.removeFromRenderingEngine();
                    m.tiles[ax, by].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[ax, by].anim.position.X, m.tiles[ax, by].anim.position.Y), 0.1f);
                    m.tiles[ax, by].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
                if (m.tiles[ax, cy].wall == Map.WALL.destr && m.tiles[ax, cy].respawn == 0)
                {
                    m.tiles[ax, cy].type = Map.TILE.floor;
                    m.tiles[ax, cy].anim.removeFromRenderingEngine();
                    m.tiles[ax, cy].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[ax, cy].anim.position.X, m.tiles[ax, cy].anim.position.Y), 0.1f);
                    m.tiles[ax, cy].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }

                if (m.tiles[bx, ay].wall == Map.WALL.destr && m.tiles[bx, ay].respawn == 0)
                {
                    m.tiles[bx, ay].type = Map.TILE.floor;
                    m.tiles[bx, ay].anim.removeFromRenderingEngine();
                    m.tiles[bx, ay].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[bx, ay].anim.position.X, m.tiles[bx, ay].anim.position.Y), 0.1f);
                    m.tiles[bx, ay].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
                if (m.tiles[bx, by].wall == Map.WALL.destr && m.tiles[bx, by].respawn == 0)
                {
                    m.tiles[bx, by].type = Map.TILE.floor;
                    m.tiles[bx, by].anim.removeFromRenderingEngine();
                    m.tiles[bx, by].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[bx, by].anim.position.X, m.tiles[bx, by].anim.position.Y), 0.1f);
                    m.tiles[bx, by].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
                if (m.tiles[bx, cy].wall == Map.WALL.destr && m.tiles[bx, cy].respawn == 0)
                {
                    m.tiles[bx, cy].type = Map.TILE.floor;
                    m.tiles[bx, cy].anim.removeFromRenderingEngine();
                    m.tiles[bx, cy].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[bx, cy].anim.position.X, m.tiles[bx, cy].anim.position.Y), 0.1f);
                    m.tiles[bx, cy].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }

                if (m.tiles[cx, ay].wall == Map.WALL.destr && m.tiles[cx, ay].respawn == 0)
                {
                    m.tiles[cx, ay].type = Map.TILE.floor;
                    m.tiles[cx, ay].anim.removeFromRenderingEngine();
                    m.tiles[cx, ay].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[cx, ay].anim.position.X, m.tiles[cx, ay].anim.position.Y), 0.1f);
                    m.tiles[cx, ay].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
                if (m.tiles[cx, by].wall == Map.WALL.destr && m.tiles[cx, by].respawn == 0)
                {
                    m.tiles[cx, by].type = Map.TILE.floor;
                    m.tiles[cx, by].anim.removeFromRenderingEngine();
                    m.tiles[cx, by].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[cx, by].anim.position.X, m.tiles[cx, by].anim.position.Y), 0.1f);
                    m.tiles[cx, by].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
                if (m.tiles[cx, cy].wall == Map.WALL.destr && m.tiles[cx, cy].respawn == 0)
                {
                    m.tiles[cx, cy].type = Map.TILE.floor;
                    m.tiles[cx, cy].anim.removeFromRenderingEngine();
                    m.tiles[cx, cy].anim = Animation.createSingleFrameAnimation("tiles/breakfloor",
                        new Vector2(m.tiles[cx, cy].anim.position.X, m.tiles[cx, cy].anim.position.Y), 0.1f);
                    m.tiles[cx, cy].respawn = Constants.DESTR_RESPAWN;
                    SoundManager.PlaySound("sound/dw_breakoff");
                }
            }
        }
Example #3
0
        public void collisionDetectionVsMap(Map m)
        {
            if (!alive) return;

            bool aa = false, ab = false, ac = false, ba = false, bc = false, ca = false, cb = false, cc = false;
            int ax = (int)((animation.position.X - Constants.PLAYERRADIUS + Constants.TILESIZE / 2) / Constants.TILESIZE),
                ay = (int)((animation.position.Y - Constants.PLAYERRADIUS + Constants.TILESIZE / 2) / Constants.TILESIZE);
            int bx = (int)((animation.position.X + Constants.TILESIZE / 2) / Constants.TILESIZE),
                by = (int)((animation.position.Y + Constants.TILESIZE / 2) / Constants.TILESIZE);
            int cx = (int)((animation.position.X + Constants.PLAYERRADIUS + Constants.TILESIZE / 2) / Constants.TILESIZE),
                cy = (int)((animation.position.Y + Constants.PLAYERRADIUS + Constants.TILESIZE / 2) / Constants.TILESIZE);

            if (!(bx >= 0 && bx < Constants.MAPX && by >= 0 && by < Constants.MAPY) ||
                (bx >= 0 && bx < Constants.MAPX && by >= 0 && by < Constants.MAPY && m.tiles[bx, by].type == Map.TILE.empty))
            {
                kill();
                return;
            }

            if (ay >= 0 && ay < Constants.MAPY)
            {
                if (ax >= 0 && ax < Constants.MAPX) aa = m.tiles[ax, ay].type == Map.TILE.wall;
                if (bx >= 0 && bx < Constants.MAPX) ab = m.tiles[bx, ay].type == Map.TILE.wall;
                if (cx >= 0 && cx < Constants.MAPX) ac = m.tiles[cx, ay].type == Map.TILE.wall;
            }
            if (by >= 0 && by < Constants.MAPY)
            {
                if (ax >= 0 && ax < Constants.MAPX) ba = m.tiles[ax, by].type == Map.TILE.wall;
                if (cx >= 0 && cx < Constants.MAPX) bc = m.tiles[cx, by].type == Map.TILE.wall;
            }
            if (cy >= 0 && cy < Constants.MAPY)
            {
                if (ax >= 0 && ax < Constants.MAPX) ca = m.tiles[ax, cy].type == Map.TILE.wall;
                if (bx >= 0 && bx < Constants.MAPX) cb = m.tiles[bx, cy].type == Map.TILE.wall;
                if (cx >= 0 && cx < Constants.MAPX) cc = m.tiles[cx, cy].type == Map.TILE.wall;
            }

            if ((aa && ac) || ab)
            {
                animation.position.Y = ((ay + 1) * Constants.TILESIZE - Constants.TILESIZE / 2) + Constants.PLAYERRADIUS;
                velocity.Y = 0;
            }
            if ((ca && cc) || cb)
            {
                animation.position.Y = (cy * Constants.TILESIZE - Constants.TILESIZE / 2) - Constants.PLAYERRADIUS;
                velocity.Y = 0;
            }
            if ((aa && ca) || ba)
            {
                animation.position.X = ((ax + 1) * Constants.TILESIZE - Constants.TILESIZE / 2) + Constants.PLAYERRADIUS;
                velocity.X = 0;
            }
            if ((ac && cc) || bc)
            {
                animation.position.X = (cx * Constants.TILESIZE - Constants.TILESIZE / 2) - Constants.PLAYERRADIUS;
                velocity.X = 0;
            }
        }