Esempio n. 1
0
        public void Initialize(GraphicsDevice GraphicsDevice, ContentManager Content)
        {
            cameraMatrix = Matrix.CreateTranslation(400 - Tile.Size * 11, Tile.Size, 0);

            Tile.InitTextures(GraphicsDevice, BiomeData.GetBiome(1));

            // load maze
            int MapId = 0;

            maze = Cell.ParseData(MapData.GetMap(MapId));

            // load graphic stuff
            pixel = Content.Load <Texture2D>("pixel");
            Pj.ColliderTexture = Content.Load <Texture2D>("pj");
            Pj.IdleTexture     = Content.Load <Texture2D>("pj_idle");
            Pj.RunningTexture  = Content.Load <Texture2D>("pj_running");
            Pj.PaletteTexture  = Content.Load <Texture2D>("pj_palette");
            Pj.effect          = Content.Load <Effect>("pj_shader");
            Pj.effect.Parameters["u_lut"].SetValue(Pj.PaletteTexture);


            this.Pjs   = new Dictionary <string, Pj>();
            this.aiPjs = new List <AiPj>();

            //Pjs.Add("Player", new TestPj("Player", PlayerControllerIndex.Keyboard, 18.5f * Tile.Size, 2.5f * Tile.Size, 1));
            AiPj aipj = new AiPj("AI", Tile.Size * 2.5f, Tile.Size * 2.5f, 2);

            Pjs.Add("AI", aipj);
            aiPjs.Add(aipj);
        }
Esempio n. 2
0
        private void PrepareToStartGame()
        {
            peersNotReadyToStartYet = new List <NetPeer>();
            peersNotReadyToStartYet.AddRange(server.GetPeers());

            int mapId = random.Next(MapData.MapsCount);

            world = new GameWorld {
                maze = Cell.ParseData(MapData.GetMap(mapId))
            };
            int biomeId = random.Next(BiomeData.BiomesCount);

            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.PrepareToStartGame);
            writer.Put(players.Count);
            writer.Put(mapId);
            writer.Put(biomeId);
            server.SendToAll(writer, SendOptions.ReliableOrdered);

            // instantiate characters
            foreach (KeyValuePair <NetPeer, List <string> > entry in playersPerClient)
            {
                NetPeer peer = entry.Key;
                foreach (string id in entry.Value)
                {
                    LobbyPlayer character = players[id];

                    ServerPj serverPj = new ServerPj(id);
                    serverPj.SpawnInAnEmptyPosition(world.maze);
                    world.Pjs.Add(id, serverPj);

                    float x = serverPj.x;
                    float y = serverPj.y;

                    NetDataWriter localCharacterWriter = new NetDataWriter();
                    localCharacterWriter.Put((int)NetMessage.InstantiateCharacter);
                    localCharacterWriter.Put(id);
                    localCharacterWriter.Put((int)character.PlayerControllerIndex);
                    localCharacterWriter.Put((int)Pj.Type.Local);
                    localCharacterWriter.Put(x);
                    localCharacterWriter.Put(y);
                    peer.Send(localCharacterWriter, SendOptions.ReliableOrdered);

                    NetDataWriter remoteCharacterWriter = new NetDataWriter();
                    remoteCharacterWriter.Put((int)NetMessage.InstantiateCharacter);
                    remoteCharacterWriter.Put(id);
                    remoteCharacterWriter.Put((int)character.PlayerControllerIndex);
                    remoteCharacterWriter.Put((int)Pj.Type.Remote);
                    remoteCharacterWriter.Put(x);
                    remoteCharacterWriter.Put(y);
                    server.SendToAll(remoteCharacterWriter, SendOptions.ReliableOrdered, peer);
                }
            }
        }
Esempio n. 3
0
        public void Initialize(GraphicsDevice GraphicsDevice, ContentManager Content)
        {
            BiomeData.Biome biome = BiomeData.GetBiome(3);
            int mapId = 0;

            pixel = Content.Load<Texture2D>("pixel");
            Tile.InitTextures(GraphicsDevice, biome);
            world = new GameWorld();
            world.maze = Cell.ParseData(MapData.GetMap(mapId));

            renderTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            renderTargetRectangle = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
            cameraMatrix = Matrix.CreateTranslation(GraphicsDevice.PresentationParameters.BackBufferWidth / 2 - Tile.Size * 11, Tile.Size, 0);
            floorRectangle = new Rectangle(0, 0, world.maze.GetLength(1) * Tile.Size, world.maze.GetLength(0) * Tile.Size);


            this.biome = new Biome
            {
                BackgroundColor = biome.BackgroundColor,
                FloorColor = biome.GroundColor,
                WallColor = biome.WallColor,
                WallTopColor = biome.WallTopColor,

                BackgroundOverlayTexture = null,
                FloorOverlayTexture = Content.Load<Texture2D>("gravelOverlay"),
                WallOverlayTexture = Content.Load<Texture2D>("gravelOverlay"),
                WallTopOverlayTexture = Content.Load<Texture2D>("iceOverlay"),

                BackgroundBlendingMode = Biome.BlendingMode.Normal,
                FloorBlendingMode = Biome.BlendingMode.Reflect,
                WallBlendingMode = Biome.BlendingMode.Reflect,
                WallTopBlendingMode = Biome.BlendingMode.Reflect,
            };

            biomeBackgroundEffect = Content.Load<Effect>("floor_shader");
            biomeEffect = Content.Load<Effect>("walls_shader");
            biomeEffect.Parameters["u_wallBlendingMode"]?.SetValue((int)this.biome.WallBlendingMode);
            biomeEffect.Parameters["u_wallColor"]?.SetValue(this.biome.WallColor.ToVector3());
            biomeEffect.Parameters["u_wallOverlayTexture"]?.SetValue(this.biome.WallOverlayTexture);
            biomeEffect.Parameters["u_wallOverlayTextureSize"]?.SetValue(new Vector2(this.biome.WallOverlayTexture.Width, this.biome.WallOverlayTexture.Height));
            biomeEffect.Parameters["u_wallTopBlendingMode"]?.SetValue((int)this.biome.WallTopBlendingMode);
            biomeEffect.Parameters["u_wallTopColor"]?.SetValue(this.biome.WallTopColor.ToVector3());
            biomeEffect.Parameters["u_wallTopOverlayTexture"]?.SetValue(this.biome.WallTopOverlayTexture);
            biomeEffect.Parameters["u_wallTopOverlayTextureSize"]?.SetValue(new Vector2(this.biome.WallTopOverlayTexture.Width, this.biome.WallTopOverlayTexture.Height));
            biomeEffect.Parameters["u_screenSize"]?.SetValue(new Vector2(GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight));
        }
Esempio n. 4
0
        public void Initialize(GraphicsDevice GraphicsDevice, ContentManager Content)
        {
            System.Diagnostics.Debug.WriteLine("Loading...");
            charactersToInstantiate = new List <LobbyPlayerEventArgs>();

            // Tile.Init has to be called on the main thread
            Tile.InitTextures(GraphicsDevice, biome);

            Thread t = new Thread(() =>
            {
                // load maze
                gameScreen.world.maze = Cell.ParseData(MapData.GetMap(MapId));

                // load graphic stuff
                gameScreen.pixel      = Content.Load <Texture2D>("pixel");
                Pj.ColliderTexture    = Content.Load <Texture2D>("pj");
                Pj.IdleTexture        = Content.Load <Texture2D>("pj_idle");
                Pj.RunningTexture     = Content.Load <Texture2D>("pj_running");
                Pj.StunnedTexture     = Content.Load <Texture2D>("stunned");
                Pj.TeleportingTexture = Content.Load <Texture2D>("teleporting");
                Pj.TestTexture        = Content.Load <Texture2D>("t");
                Pj.PaletteTexture     = Content.Load <Texture2D>("pj_palette");
                Pj.effect             = Content.Load <Effect>("pj_shader");
                Pj.effect.Parameters["u_lut"].SetValue(Pj.PaletteTexture);
                SprintPowerUp.pixel          = Content.Load <Texture2D>("pixel");
                SprintPowerUp.Icon           = Content.Load <Texture2D>("sprint");
                TraverseWallsPowerUp.Icon    = Content.Load <Texture2D>("traverseWalls");
                SprintBuff.texture           = Content.Load <Texture2D>("circle");
                TraverseWallsBuff.texture    = Content.Load <Texture2D>("circle");
                SurpriseBoxDrop.modelTexture = Content.Load <Texture2D>("surpriseBox");
                BananaPowerUp.Icon           = Content.Load <Texture2D>("bananaIcon");
                BananaDrop.modelTexture      = Content.Load <Texture2D>("bananaDrop");
                InvisiblePowerUp.Icon        = Content.Load <Texture2D>("invisible");
                TintaPowerUp.Icon            = Content.Load <Texture2D>("tinta");
                TintaSplash.Texture          = Content.Load <Texture2D>("tinta_splash");
                ImmunePowerUp.Icon           = Content.Load <Texture2D>("immune");
                RandomTeleportPowerUp.Icon   = Content.Load <Texture2D>("randomTeleport");
                RelojPowerUp.Icon            = Content.Load <Texture2D>("reloj");

                // Initialize rendering stuff
                gameScreen.renderTarget          = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
                gameScreen.renderTargetRectangle = new Rectangle(0, 0, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
                gameScreen.cameraMatrix          = Matrix.CreateTranslation(GraphicsDevice.PresentationParameters.BackBufferWidth / 2 - Tile.Size * 11, Tile.Size, 0);
                gameScreen.floorRectangle        = new Rectangle(0, 0, gameScreen.world.maze.GetLength(1) * Tile.Size, gameScreen.world.maze.GetLength(0) * Tile.Size);
                gameScreen.floorColor            = biome.GroundColor;
                gameScreen.backgroundColor       = biome.BackgroundColor;
                gameScreen.biomeTintColor        = biome.TintColor;

                // instantiate the characters
                while (gameScreen.world.Pjs.Count < ExpectedPlayers)
                {
                    lock (locker)
                    {
                        foreach (LobbyPlayerEventArgs args in charactersToInstantiate)
                        {
                            switch (args.Type)
                            {
                            case Pj.Type.Local:
                                LocalPj pj = new LocalPj(args.PlayerID, args.ControllerIndex, args.X, args.Y, 1);
                                gameScreen.world.Pjs.Add(args.PlayerID, pj);
                                gameScreen.LocalPlayers.Add(pj);
                                break;

                            case Pj.Type.Remote:
                                gameScreen.world.Pjs.Add(args.PlayerID, new RemotePj(args.PlayerID, args.X, args.Y, 1));
                                break;

                            default:
                                throw new System.ComponentModel.InvalidEnumArgumentException();
                            }
                        }

                        charactersToInstantiate.Clear();
                    }
                }

                Thread.Sleep(500);
                hasFinishedLoading = true;
            });

            t.Start();
        }