示例#1
0
        // Forces all the clients to teleport the pj to the same position as it is in the server
        public void TeleportPj(Pj pj)
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.Teleport);
            writer.Put(pj.ID);
            writer.Put(pj.x);
            writer.Put(pj.y);
            server.SendToAll(writer, SendOptions.ReliableUnordered);
        }
示例#2
0
        public void RemovePowerUp(Pj pj)
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.RemovePowerUp);
            writer.Put(pj.ID);
            server.SendToAll(writer, SendOptions.ReliableUnordered);

            world.OnPowerUpRemoved(this, new GameplayPowerUpEventArgs()
            {
                PlayerId = pj.ID
            });
        }
示例#3
0
        public void AddPowerUp(int type, Pj pj)
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.AddPowerUp);
            writer.Put(pj.ID);
            writer.Put(type);
            server.SendToAll(writer, SendOptions.ReliableUnordered);

            world.OnPowerUpAdded(this, new GameplayPowerUpEventArgs()
            {
                PlayerId = pj.ID, Type = type
            });
        }
示例#4
0
        public void RemoveBuff(Pj pj, int buffId)
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.RemoveBuff);
            writer.Put(pj.ID);
            writer.Put(buffId);
            server.SendToAll(writer, SendOptions.ReliableUnordered);

            world.OnBuffRemoved(this, new GameplayBuffEventArgs()
            {
                PlayerId = pj.ID, BuffId = buffId
            });
        }
示例#5
0
        public void AddBuff(int type, Pj pj)
        {
            int buffId = ((ServerPj)pj).LastBuff++;

            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)NetMessage.AddBuff);
            writer.Put(type);
            writer.Put(pj.ID);
            writer.Put(buffId);
            server.SendToAll(writer, SendOptions.ReliableUnordered);

            world.OnBuffAdded(this, new GameplayBuffEventArgs()
            {
                BuffType = type, PlayerId = pj.ID, BuffId = buffId
            });
        }
示例#6
0
        public void Update(float dt)
        {
            foreach (Pj pj in Pjs.Values)
            {
                pj.Update(dt);
            }

            foreach (AiPj pj in aiPjs)
            {
                if (pj.NeedsToRecalculatePath)
                {
                    pj.NeedsToRecalculatePath = false;
                    Pj      player = Pjs["Player"];
                    Vector2 to     = new Vector2(player.x, player.y);
                    Vector2 from   = new Vector2(pj.x, pj.y);
                    pj.path = Pathfinder.CalculatePath(nodes, horizontalNodes, verticalNodes, from, to, maze);
                }
            }
        }
示例#7
0
        public void Draw(SpriteBatch spritebatch)
        {
            List <IDrawable> SortDrawables()
            {
                List <IDrawable> drawables = new List <IDrawable>();

                List <Pj> pjsToInsert = new List <Pj>();

                pjsToInsert.AddRange(Pjs.Values);
                pjsToInsert.Sort((a, b) => b.y.CompareTo(a.y));

                int mazeW = maze.GetLength(1);
                int mazeH = maze.GetLength(0);

                for (int y = 0; y < mazeH; y++)
                {
                    for (int i = pjsToInsert.Count - 1; i >= 0; i--)
                    {
                        Pj pj = pjsToInsert[i];

                        Cell leftCell  = maze[y, (int)((pj.x - pj.hw) / Tile.Size)];
                        Cell rightCell = maze[y, (int)((pj.x + pj.hw) / Tile.Size)];

                        if (pj.y < leftCell.GetSortY() && pj.y < rightCell.GetSortY())
                        {
                            drawables.Add(pj);
                            pjsToInsert.RemoveAt(i);
                        }
                    }

                    for (int x = 0; x < mazeW; x++)
                    {
                        drawables.Add(maze[y, x]);
                    }
                }

                return(drawables);
            }

            spritebatch.GraphicsDevice.Clear(new Color(77f / 255, 174f / 255, 183f / 255));

            spritebatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, cameraMatrix);
            spritebatch.Draw(pixel, new Rectangle(0, 0, maze.GetLength(1) * Tile.Size, maze.GetLength(0) * Tile.Size), new Color(182f / 255, 186f / 255, 159f / 255));

            foreach (AiPj pj in aiPjs)
            {
                Pathfinder.DrawPath(spritebatch, pixel, pj.path);
            }

            foreach (IDrawable drawable in SortDrawables())
            {
                drawable.Draw(spritebatch, cameraMatrix);
            }

            /*foreach (PathfindingNode node in nodes)
             * {
             *  node.DrawNavigationPosition(spritebatch, pixel);
             * }*/

            spritebatch.End();
        }