Exemplo n.º 1
0
        public void SetupLevel()
        {
            Color[] color1D = new Color[levelDataTexture.Width * levelDataTexture.Height];
            levelDataTexture.GetData(color1D);
            Color[,] colorData = new Color[levelDataTexture.Width, levelDataTexture.Height];
            for (int x = 0; x < levelDataTexture.Width; x++)
                for (int y = 0; y < levelDataTexture.Height; y++)
                    colorData[x, y] = color1D[x + y * levelDataTexture.Width];

            levelWidth = levelDataTexture.Width * collisionSize;
            levelHeight = levelDataTexture.Height * collisionSize;
            deathHeight = levelHeight;
            levelGridSize = new Point(levelDataTexture.Width, levelDataTexture.Height);
            environmentData = new EnvironmentData[levelDataTexture.Width, levelDataTexture.Height];
            for (int x = 0; x < levelDataTexture.Width; x++)
            {
                for (int y = 0; y < levelDataTexture.Height; y++)
                {
                    if (colorData[x, y] == Color.Black)
                    {
                        environmentData[x, y] = new EnvironmentData(true);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tile"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                            gsPlay.AddGroundTile(GridToPosition(new Point(x, y)) + new Vector2(16, 16));
                        }
                    }
                    else if (colorData[x, y] == new Color(0, 0, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(FrictionType.Ice);
                        SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tile"), GridToPosition(new Point(x, y)));
                        tile.origin = Vector2.Zero;
                        tile.color = new Color(0, 0, 255);
                        gsPlay.backFGList.Add(tile);
                    }
                    else if (colorData[x, y] == new Color(0, 255, 0))
                    {
                        environmentData[x, y] = new EnvironmentData(new Vector2(0, -1f));
                        gsPlay.AddWindEmitter(GridToPosition(x, y) + new Vector2(8, 32), new Vector2(0, -2));
                        //SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/airCurrentUp"), GridToPosition(new Point(x, y)));
                        //tile.origin = Vector2.Zero;
                        //tile.alpha = 128;
                        //gsPlay.backFGList.Add(tile);
                    }
                    else if (colorData[x, y] == new Color(255, 0, 0))
                    {
                        environmentData[x, y] = new EnvironmentData(new Vector2(0, 1f));
                        gsPlay.AddWindEmitter(GridToPosition(x, y) + new Vector2(16, -16), new Vector2(0, 2));
                        //SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/airCurrentDown"), GridToPosition(new Point(x, y)));
                        //tile.origin = Vector2.Zero;
                        //tile.scale = new Vector2(2);
                        //tile.alpha = 128;
                        //gsPlay.backFGList.Add(tile);
                    }
                    else if (colorData[x, y] == new Color(255, 255, 0))
                    {
                        environmentData[x, y] = new EnvironmentData(new Vector2(4, 0));
                        gsPlay.AddWindEmitter(GridToPosition(x, y) + new Vector2(-16, 16), new Vector2(2, 0));
                        //SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/airCurrentRight"), GridToPosition(new Point(x, y)));
                        //tile.origin = Vector2.Zero;
                        //tile.alpha = 128;
                        //tile.scale = new Vector2(2);
                        //gsPlay.frontFGList.Add(tile);
                    }
                    else if (colorData[x, y] == new Color(0, 255, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(new Vector2(-4, 0));
                        gsPlay.AddWindEmitter(GridToPosition(x, y) + new Vector2(48, 16), new Vector2(-2, 0));
                        //SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/airCurrentLeft"), GridToPosition(new Point(x, y)));
                        //tile.origin = Vector2.Zero;
                        //tile.alpha = 128;
                        //tile.scale = new Vector2(2);
                        //gsPlay.frontFGList.Add(tile);
                    }
                    else if (colorData[x, y] == new Color(255, 255, 150))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.ThreeTileRight1, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineThreeRight1"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(255, 255, 100))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.ThreeTileRight2, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineThreeRight2"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(255, 255, 50))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.ThreeTileRight3, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineThreeRight3"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(50, 255, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.ThreeTileLeft1, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineThreeLeft1"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(100, 255, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.ThreeTileLeft2, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineThreeLeft2"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(150, 255, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.ThreeTileLeft3, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineThreeLeft3"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(64, 255, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.TwoTileLeft1, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineTwoLeft1"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(128, 255, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.TwoTileLeft2, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineTwoLeft2"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(255, 255, 128))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.TwoTileRight1, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineTwoRight1"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(255, 255, 64))
                    {
                        environmentData[x, y] = new EnvironmentData(InclineType.TwoTileRight2, FrictionType.Normal);
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/tileInclineTwoRight2"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(50, 50, 50))
                    {
                        environmentData[x, y] = new EnvironmentData(true);
                        environmentData[x, y].oneWayPlatform = true;
                        if (renderCollision)
                        {
                            SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/jumpThru"), GridToPosition(new Point(x, y)));
                            tile.origin = Vector2.Zero;
                            gsPlay.backFGList.Add(tile);
                        }
                    }
                    else if (colorData[x, y] == new Color(255, 128, 255))
                    {
                        environmentData[x, y] = new EnvironmentData(false);
                        environmentData[x, y].checkpoint = true;
                        SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/checkpoint"), GridToCenterPosition(new Point(x, y)));
                        tile.scale = new Vector2(1.5f);
                        gsPlay.backFGList.Add(tile);
                    }
                    else if (colorData[x, y] == new Color(255, 128, 0))
                    {
                        environmentData[x, y] = new EnvironmentData(false);
                        environmentData[x, y].killZone = true;
                        //SpriteIMG tile = new SpriteIMG(gsPlay.LoadTexture("TestSprites/killZone"), GridToPosition(new Point(x, y)));
                        //tile.origin = Vector2.Zero;
                        //gsPlay.backFGList.Add(tile);
                        //gsPlay.AddFireParticle(GridToCenterPosition(x, y));
                    }
                    else if (colorData[x, y] == new Color(255, 128, 1))
                    {
                        environmentData[x, y] = new EnvironmentData(false);
                        environmentData[x, y].killZone = true;
                        gsPlay.AddFireParticle(GridToCenterPosition(x, y));
                    }
                    else if (colorData[x, y] == new Color(255, 128, 2))
                    {
                        environmentData[x, y] = new EnvironmentData(false);
                        environmentData[x, y].killZone = true;
                        gsPlay.AddSpinningFireParticle(GridToCenterPosition(x, y));
                    }
                    else
                    {
                        environmentData[x, y] = new EnvironmentData(false);
                    }
                }
            }

            gsPlay.player1 = new Player(gsPlay, PlayerObjectMode.One, gsPlay.LoadTexture("player1"), player1Pos);
            gsPlay.player1.SetAnimationStuff(1, 1, 8, 8, 256, 256, 64, 5);
            gsPlay.player1.SetCollisionBox(48, 96, Vector2.Zero);
            gsPlay.player2 = new Player(gsPlay, PlayerObjectMode.Two, gsPlay.LoadTexture("player2"), player2Pos);
            gsPlay.player2.SetAnimationStuff(1, 1, 8, 8, 256, 256, 64, 5);
            gsPlay.player2.SetCollisionBox(48, 96, Vector2.Zero);

            player1Checkpoint = gsPlay.AddBGParticle(gsPlay.LoadTexture("TestSprites/checkpointWarm"), new Vector2(-64, -64));
            player1Checkpoint.SetPlayerMode(PlayerObjectMode.One);
            player1Checkpoint.scale = new Vector2(1.5f);
            player1Checkpoint.canDie = false;
            player1Checkpoint.illuminatingAllTheTime = true;
            player2Checkpoint = gsPlay.AddBGParticle(gsPlay.LoadTexture("TestSprites/checkpointCool"), new Vector2(-64, -64));
            player2Checkpoint.SetPlayerMode(PlayerObjectMode.Two);
            player2Checkpoint.scale = new Vector2(1.5f);
            player2Checkpoint.canDie = false;
            player2Checkpoint.illuminatingAllTheTime = true;

            if (hasPortal)
            {
                glados = gsPlay.AddPortal(new EventTrigger(this, 0), gsPlay.LoadTexture("TestSprites/portal"), portalPos);
                glados.SetAnimationStuff(2, 1, 2, 8, 96, 192, 8, 5);
                PortalItem goody = new PortalItem(new EventTrigger(this, glados), gsPlay.LoadTexture("TestSprites/Cursor"), pItemPos);
                gsPlay.areaList.Add(goody);
                goody.SetCollisionBox(32, 32, Vector2.Zero);
                goody.visible = false;
                GlyphEmitter ge = new GlyphEmitter(gsPlay, Art.portalItem1, pItemPos);
                ge.AddTexture(Art.portalItem2);
                ge.AddTexture(Art.portalItem3);
                ge.AddTexture(Art.portalItem4);
                ge.AddTexture(Art.portalItem5);
                ge.selfIlluminated = true;
                ge.startAlpha = 0;
                ge.endAlpha = 255;
                ge.fadeInOut = true;
                ge.startScale = .75f;
                ge.endScale = 1.25f;
                ge.spawnRate = 10;
                ge.life = 40;
                //ge.randomDisplacement = new Vector2(8, 8);
                ge.randomSpeedX = new Vector2(-.75f, .75f);
                ge.randomSpeedY = new Vector2(-.75f, .75f);
                gsPlay.emitterList.Add(ge);
                goody.emitter = ge;

                AnimatedSprite pulseSprite = new AnimatedSprite(Art.portalPulse);
                ParticleEmitter pulse = gsPlay.AddEmitter(pulseSprite, glados.position);
                pulse.bgParticles = true;
                pulse.color = new Color(128, 0, 0);
                pulse.startScale = 1;
                pulse.endScale = 2;
                pulse.startAlpha = 255;
                pulse.endAlpha = 0;
                pulse.randomRotation = false;
                pulse.rotationSpeed = 0;
                pulse.spawnRate = 30;
                pulse.life = 60;
                glados.pulse = pulse;

                LightningChain portalLightning = gsPlay.AddLightning(glados.position + new Vector2(0, -48), glados.position + new Vector2(20, -27), Color.Red);
                portalLightning.AddVertex(glados.position + new Vector2(20, 27));
                portalLightning.AddVertex(glados.position + new Vector2(0, 48));
                portalLightning.AddVertex(glados.position + new Vector2(-20, 27));
                portalLightning.AddVertex(glados.position + new Vector2(-20, -27));
                portalLightning.AddVertex(glados.position + new Vector2(0, -48));
                portalLightning.SetActive(true);
                portalLightning.defaultActive = true;
                goody.AddEvent(new EventTrigger(this, portalLightning));
                //40x55

                List<Particle> particleList = new List<Particle>();
                for (int i = 1; i <= 6; i++)
                {
                    Particle p = gsPlay.AddParticle(Art.sparkle, Vector2.Zero);
                    p.canDie = false;
                    if (i % 2 == 0) p.color = new Color(246, 133, 23);
                    else p.color = new Color(145, 127, 185);
                    p.alpha = 128;
                    particleList.Add(p);
                }
                PortalParticles pp = new PortalParticles(gsPlay, particleList);
                pp.AddVertex(glados.position + new Vector2(0, -53));
                pp.AddVertex(glados.position + new Vector2(25, -27));
                pp.AddVertex(glados.position + new Vector2(25, 27));
                pp.AddVertex(glados.position + new Vector2(0, 53));
                pp.AddVertex(glados.position + new Vector2(-25, 27));
                pp.AddVertex(glados.position + new Vector2(-25, -27));
                pp.SetUpParticles();
                pp.Deactivate();
                gsPlay.ppList.Add(pp);
                goody.AddEvent(new EventTrigger(this, pp));

            }

            gsPlay.cameraPlayer1 = new Camera(gsPlay.player1, gsPlay.player2, Vector2.Zero);
            gsPlay.cameraPlayer2 = new Camera(gsPlay.player2, gsPlay.player1, Vector2.Zero);

            if (glados != null)
            {
                gsPlay.cameraPlayer1.AddTarget(glados);
                gsPlay.cameraPlayer2.AddTarget(glados);
            }
        }
Exemplo n.º 2
0
 public static float GetFriction(PhysObj obj, EnvironmentData data)
 {
     switch (data.frictionType)
     {
         case FrictionType.Normal:
             return EnvironmentData.NORMAL;
         case FrictionType.Ice:
             return EnvironmentData.ICE;
     }
     return 1;
 }