Example #1
0
        /// <summary>
        /// Draws the Target vox for the player
        /// </summary>
        /// <param name="cam">Camera MAtrices class</param>
        /// <param name="currentPlayerforViewport">The current player for the viewport</param>
        public void drawSuroundingBox(SpriteBatch b, Camera.CameraMatrices cam, playerObject currentPlayerforViewport)
        {
            //if its the current player dont draw it
            if (this is playerObject)
            {
                if (((playerObject)this).getViewport.Equals(Game.GraphicsDevice.Viewport))
                {
                    return;
                }
            }

            if (this is Objects.Bullet || this is Objects.Planets.Planet || this is Objects.Asteroid) // dont draw for bullets
            {
                return;
            }

            if ((cam.Position - Position).Length() > 800) // depth culling
            {
                return;
            }

            if (IsVisible(cam))
            {
                Vector2 screenViewport = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

                if (setVertexCoords(b, cam, screenViewport, currentPlayerforViewport))
                {
                    drawBox(screenViewport);
                }
            }
        }
Example #2
0
    private void OnReceivedClientInitialStats(ulong guid)
    {
        playerObject tempObj = clients[guid];

        tempObj.name       = m_NetworkReader.ReadString();
        tempObj.m_x        = m_NetworkReader.ReadFloat();
        tempObj.m_y        = m_NetworkReader.ReadFloat();
        tempObj.m_z        = m_NetworkReader.ReadFloat();
        tempObj.rotation_x = m_NetworkReader.ReadFloat();
        tempObj.rotation_y = m_NetworkReader.ReadFloat();
        tempObj.rotation_z = m_NetworkReader.ReadFloat();

        clients[guid] = tempObj;

        if (m_NetworkWriter.StartWritting())
        {
            m_NetworkWriter.WritePacketID((byte)Packets_ID.ID_NEWPLAYER);
            m_NetworkWriter.Write(tempObj.id);
            m_NetworkWriter.Write(tempObj.name);
            m_NetworkWriter.Write(tempObj.m_x);
            m_NetworkWriter.Write(tempObj.m_y);
            m_NetworkWriter.Write(tempObj.m_z);
            m_NetworkWriter.Write(tempObj.rotation_x);
            m_NetworkWriter.Write(tempObj.rotation_y);
            m_NetworkWriter.Write(tempObj.rotation_z);
            m_NetworkWriter.Write(tempObj.playerNum);

            SendToAll(guid, m_NetworkWriter, true);
            // peer.SendBroadcast(Peer.Priority.Immediate, Peer.Reliability.Reliable, 0);
        }
    }
Example #3
0
    private void OnReceivedClientMovementData(ulong guid)
    {
        playerObject tempObj = clients[guid];

        tempObj.m_x        = m_NetworkReader.ReadFloat();
        tempObj.m_y        = m_NetworkReader.ReadFloat();
        tempObj.m_z        = m_NetworkReader.ReadFloat();
        tempObj.rotation_x = m_NetworkReader.ReadFloat();
        tempObj.rotation_y = m_NetworkReader.ReadFloat();
        tempObj.rotation_z = m_NetworkReader.ReadFloat();
        tempObj.velocity_X = m_NetworkReader.ReadFloat();
        tempObj.velocity_Y = m_NetworkReader.ReadFloat();
        tempObj.velocity_Z = m_NetworkReader.ReadFloat();

        clients[guid] = tempObj;

        if (m_NetworkWriter.StartWritting())
        {
            m_NetworkWriter.WritePacketID((byte)Packets_ID.ID_MOVEMENT);
            m_NetworkWriter.Write(tempObj.id);
            m_NetworkWriter.Write(tempObj.m_x);
            m_NetworkWriter.Write(tempObj.m_y);
            m_NetworkWriter.Write(tempObj.m_z);
            m_NetworkWriter.Write(tempObj.rotation_x);
            m_NetworkWriter.Write(tempObj.rotation_y);
            m_NetworkWriter.Write(tempObj.rotation_z);
            m_NetworkWriter.Write(tempObj.velocity_X);
            m_NetworkWriter.Write(tempObj.velocity_Y);
            m_NetworkWriter.Write(tempObj.velocity_Z);

            SendToAll(guid, m_NetworkWriter, true);
        }
    }
Example #4
0
        /// <summary>
        /// Constructor for Team Information
        /// </summary>
        /// <param name="teamId">Instance of Team class, indicating the identifier for the TeamInformation instance (red/blue)</param>
        /// <param name="fullyAIControlled">Indicates whether the team is human controlled or not</param>
        /// <param name="ownedTurrets">Owned turrets at the start of the game</param>
        /// <param name="teamStartingCredits">Initial credits</param>
        /// <param name="teamPlayer">Team player object</param>
        /// <param name="ownedNodes">Team's patrol nodes</param>
        /// <param name="ownedSpawnPoints">Team's owned spawn points</param>
        /// <param name="maxFighters">Maximum number of fighters</param>
        /// <param name="maxDestroyers">Maximum number of destroyers</param>
        /// <param name="teamHomeBase">Team base instance</param>
        /// <param name="playerSpawnPt">Team's player's spawn point</param>
        public TeamInformation(Team teamId, bool fullyAIControlled, List <Turret> ownedTurrets,
                               int teamStartingCredits, playerObject teamPlayer, List <Node> ownedNodes, List <SpawnPoint> ownedSpawnPoints,
                               uint maxFighters, uint maxDestroyers, Base teamHomeBase, PlayerSpawnPoint playerSpawnPt)
        {
            this.teamId            = teamId;
            this.fullyAIControlled = fullyAIControlled;
            this.ownedTurrets      = ownedTurrets;
            this.teamCredits       = teamStartingCredits;
            this.teamPlayer        = teamPlayer;
            this.teamOwnedNodes    = ownedNodes;
            this.teamSpawnPoints   = ownedSpawnPoints;
            this.maxDestroyers     = maxDestroyers;
            this.maxFighters       = maxFighters;
            this.teamFighters      = new List <Fighter>((int)maxFighters);
            this.teamDestroyers    = new List <Destroyer>((int)maxDestroyers);
            this.teamBase          = teamHomeBase;

            scrambleQueue       = new PowerDataStructures.PriorityQueue <int, StaticObject>(true);
            fighterBattleList   = new Dictionary <Fighter, StaticObject>();
            destroyerBattleList = new Dictionary <Destroyer, StaticObject>();
            turretBattleList    = new Dictionary <Turret, StaticObject>();
            gunsCoolDown        = new Dictionary <StaticObject, int>();
            spawnQueue          = new List <DynamicObject>(ownedSpawnPoints.Count);
            playerTarget        = null;
            playerObjective     = null;
        }
Example #5
0
    void proc_createChar(System.UInt64 _Index, byte _charType, string _nickName, Vector3 _Position, Quaternion _transformForward, bool _controlType, int _Level, int _maxHP, int _currentHP)
    {
        GameObject   newPlayer = Instantiate(Instance.prefabsArry[_charType], _Position, _transformForward);
        playerObject player    = new playerObject();

        GameObject nameObj = Instantiate(Resources.Load("NameObject")) as GameObject;

        nameObj.transform.parent = newPlayer.transform;
        playerName name = nameObj.AddComponent <playerName>();

        name.setPlayer(newPlayer, _nickName);

        GameObject hpBar = Instantiate(Resources.Load("HPBar")) as GameObject;

        hpBar.transform.parent = Instance.HPCanvas.transform;

        hpController hpCntler = newPlayer.AddComponent <hpController>();

        if (!_controlType)
        {
            Destroy(newPlayer.GetComponent <Gamekit3D.PlayerController>());
            Destroy(newPlayer.GetComponent <PlayerInput>());
            player.Controller = newPlayer.AddComponent <otherEllenController>();
            player.Controller.setIndex(_Index);
            player.Player = newPlayer;
            player.Controller.setPlayerData(_Level, _maxHP, _currentHP, hpCntler, hpBar.GetComponent <Slider>());
            Instance.playerDic.Add(_Index, player);
            Instance.hpDic.Add(_Index, hpBar);
        }
        else
        {
            newPlayer.GetComponent <PlayerInput>().enabled = true;
            Instance.Controller = newPlayer.GetComponent <Gamekit3D.PlayerController>();
            Player         = newPlayer;
            Instance.Index = _Index;
            Instance.Controller.setPlayerData(_Level, _maxHP, _currentHP, hpCntler, hpBar.GetComponent <Slider>());
            Instance.StartCoroutine(Gamekit3D.ScreenFader.FadeSceneIn());
        }
    }
 public playerClient(playerObject newPlayerObject, playerEffectsObject newPlayerEffectsObject, playerUIObject newPlayerUIObject)
 {
     playerObject = newPlayerObject;
     playerEffectsObject = newPlayerEffectsObject;
     playerUIObject = newPlayerUIObject;
 }
Example #7
0
        /// <summary>
        /// Sets up the viewport of the object
        /// </summary>
        /// <param name="cam">The camera MAtrices</param>
        /// <param name="screenViewport">The Screen viewport dimensions</param>
        /// <param name="player">The player for the current viewport</param>
        /// <returns></returns>
        private Boolean setVertexCoords(SpriteBatch b, Camera.CameraMatrices cam, Vector2 screenViewport, playerObject player)
        {
            Color col;

            if (this is Objects.Turret)
            {
                col = ((Objects.Turret) this).Repairing ? Color.Aqua : this.Equals(player.Target) ? Color.Red : this.team.Equals(Team.neutral) ? Color.Yellow :
                      this.Team.Equals(player.team) ? Color.Green : Color.Orange;
            }
            else
            {
                col = this.Equals(player.Target) ? Color.Red : this.team.Equals(Team.neutral) ? Color.Yellow :
                      this.Team.Equals(player.team) ? Color.Green : Color.Orange;
            }

            float radiusOfObject;

            radiusOfObject = greatestLength * 5f;                // sets the greatest size of the object

            float distance = (Position - cam.Position).Length(); // distance the object is from the camera
            float radius   = (greatestLength / 2);               // a variable for checking distances away from camera

            //Check if the objectis further away from the camera than its actual size.
            if (distance > radius)
            {
                float angularSize = (float)Math.Tan(radius / distance);                                              // calculate the size differance due to distance away
                radiusOfObject = angularSize * GraphicsDevice.Viewport.Height / MathHelper.ToRadians(cam.viewAngle); // change the size of the object in accordance to the viewing angle
            }

            // The view and projection matrices together
            Matrix  viewProj  = cam.View * cam.Projection;
            Vector4 screenPos = Vector4.Transform(Position, viewProj);                 // the position the screen is at according to the matrices

            float halfScreenY = screenViewport.Y / 2.0f;                               // half the size of the screen
            float halfScreenX = screenViewport.X / 2.0f;                               // half the size of the screen

            float screenY = ((screenPos.Y / screenPos.W) * halfScreenY) + halfScreenY; // the position of the object in 2d space y
            float screenX = ((screenPos.X / screenPos.W) * halfScreenX) + halfScreenX; // the position of the object in 2d space x

            // set positions for lines to draw
            setVertexPosition(screenX, screenY, radiusOfObject, col);

            // set the y back to the non depth version
            screenY = halfScreenY - ((screenPos.Y / screenPos.W) * halfScreenY);
            float distanceToPlayer = (cam.Position - Position).Length();

            drawData(b, distanceToPlayer, screenX, screenY, radiusOfObject, col, player); // draw the distances to the object

            // set the variable to the new position vectors
            targetBoxVB.SetData <VertexPositionColor>(targetBoxVertices);
            return(true);
        }
Example #8
0
    private void OnReceivedClientNetInfo(ulong guid)
    {
        Debug.Log("server received data");
        Connection connection = FindConnection(guid);

        if (clients.Count == MAX_PLAYERS)
        {
            return;
        }

        if (connection != null)
        {
            if (connection.Info == null)
            {
                connection.Info                = new ClientNetInfo();
                connection.Info.net_id         = guid;
                connection.Info.name           = m_NetworkReader.ReadString();
                connection.Info.local_id       = m_NetworkReader.ReadPackedUInt64();
                connection.Info.client_hwid    = m_NetworkReader.ReadString();
                connection.Info.client_version = m_NetworkReader.ReadString();
                ++playerID;

                Debug.Log("Sent");

                if (m_NetworkWriter.StartWritting())
                {
                    m_NetworkWriter.WritePacketID((byte)Packets_ID.ID_WELCOME);
                    m_NetworkWriter.Write(playerID);
                    m_NetworkWriter.Write(clients.Count);

                    foreach (playerObject playerObj in clients.Values)
                    {
                        m_NetworkWriter.Write(playerObj.id);
                        m_NetworkWriter.Write(playerObj.m_x);
                        m_NetworkWriter.Write(playerObj.m_y);
                        m_NetworkWriter.Write(playerObj.m_z);
                        m_NetworkWriter.Write(playerObj.rotation_x);
                        m_NetworkWriter.Write(playerObj.rotation_y);
                        m_NetworkWriter.Write(playerObj.rotation_z);
                        m_NetworkWriter.Write(playerObj.playerNum);
                        m_NetworkWriter.Write(playerObj.name);
                        //m_NetworkWriter.Write
                    }
                    peer.SendData(guid, Peer.Reliability.Reliable, 0, m_NetworkWriter);
                    //  m_NetworkWriter.Send//sending
                    //m_NetworkWriter.Reset();

                    playerObject newObj = new playerObject(playerID);
                    newObj.playerNum = m_NetworkReader.ReadInt32();
                    clients.Add(guid, newObj);

                    Debug.Log("Added new guy : " + newObj.id);
                }
                //peer.SendPacket(connection, Packets_ID.NET_LOGIN, Reliability.Reliable, m_NetworkWriter);
            }
            else
            {
                peer.SendPacket(connection, Packets_ID.CL_FAKE, Reliability.Reliable, m_NetworkWriter);
                peer.Kick(connection, 1);
            }
        }
    }