コード例 #1
0
 public void getBoxWithSpeed(GamePoint3D d1, GamePoint3D d2, GamePoint3D spd, out GamePoint3D o1, out GamePoint3D o2)
 {
     o1 = d1.Min(d2);
     o2 = d2.Max(d1);
     if (spd.X > 0)
     {
         o2.X += spd.X;
     }
     else
     {
         o1.X += spd.X;
     }
     if (spd.Y > 0)
     {
         o2.Y += spd.Y;
     }
     else
     {
         o1.Y += spd.Y;
     }
     if (spd.Z > 0)
     {
         o2.Z += spd.Z;
     }
     else
     {
         o1.Z += spd.Z;
     }
 }
コード例 #2
0
        public GameEntity(GamePoint3D Position, GamePoint2D Size, int Id, GameWorld gameWorld)
        {
            pos          = Position;
            id           = Id;
            spd          = new GamePoint3D();
            frc          = new GamePoint3D(1.2d, 1.2d, 1.01d); //friction system needs to be changed to support different areas, like just going through air
            base_spd     = new GamePoint3D(1d, 0.5d, 0.75d);   //    or walking on something, which have different frictions
            spd_deadzone = new GamePoint3D(0.2d, 0.2d, 0.3d);
            direction    = 0f;
            pitch        = 0f;
            size         = Size;
            precision    = 0.2f; //higher number = chunkier collision checks (faster but crappier)

            BufferStream buff = new BufferStream(1024, 1);

            buff.Write((ushort)4);
            buff.Write(id);
            buff.Write(pos.X);
            buff.Write(pos.Y);
            buff.Write(pos.Z);
            buff.Write(size.X);
            buff.Write(size.Y);
            buff.Write(direction);
            buff.Write(pitch);
            gameWorld.sendToAllClients(buff);
            buff.Deallocate();
        }
コード例 #3
0
        public static bool point_in_cube(GamePoint3D p, GamePoint3D d1, GamePoint3D d2)
        {
            GamePoint3D a1 = d1.Min(d2);
            GamePoint3D a2 = d2.Max(d1);

            return(p.X >= a1.X && p.X <= a2.X && p.Y >= a1.Y && p.Y <= a2.Y && p.Z >= a1.Z && p.Z <= a2.Z);
        }
コード例 #4
0
        public static double point_distance(GamePoint3D a, GamePoint3D b)
        {
            double xx = b.X - a.X;
            double yy = b.Y - a.Y;
            double zz = b.Z - a.Z;

            return(Math.Sqrt((xx * xx) + (yy * yy) + (zz * zz)));
        }
コード例 #5
0
 public void update(GameWorld gameWorld)
 {
     if (gameWorld.entityMap.ContainsKey(entityId))
     {
         if (clientHandler.Connected)
         {
             GameEntity ent_ = gameWorld.entityMap[entityId];
             float      dir  = ent_.direction;
             if (inputMap.getInput("left") == 1f) //strafe left
             {
                 ent_.spd.Add(GameGeometry.lengthdir(Convert.ToSingle(ent_.base_spd.Y), dir - 90));
             }
             if (inputMap.getInput("right") == 1f) //strafe right
             {
                 ent_.spd.Add(GameGeometry.lengthdir(Convert.ToSingle(ent_.base_spd.Y), dir + 90));
             }
             if (inputMap.getInput("forward") == 1f) //forward
             {
                 ent_.spd.Add(GameGeometry.lengthdir(Convert.ToSingle(ent_.base_spd.X), dir));
             }
             if (inputMap.getInput("backward") == 1f) //backward
             {
                 ent_.spd.Add(GameGeometry.lengthdir(Convert.ToSingle(ent_.base_spd.Z), dir + 180));
             }
             if (inputMap.getInput("up") == 1f) //jump
             {
                 GamePoint3D d1 = ent_.pos + new GamePoint3D(-ent_.size.X, -ent_.size.X, -1),
                             d2 = ent_.pos + new GamePoint3D(ent_.size.X, ent_.size.X, ent_.size.Y - 1);
                 if (gameWorld.checkCollision(d1, d2))
                 {
                     ent_.spd.Z += 8d;
                 }
             }
             if (inputMap.getInput("down") == 1f) //crouch
             {
                 ent_.spd.Z -= 1d;                //currently just makes the player fall faster?
             }
             ent_.direction = inputMap.getInput("view_x");
             ent_.pitch     = inputMap.getInput("view_y");
         }
         else
         {
             gameWorld.removeEntity(entityId);
             gameWorld.removeClient(gameWorld.getPlayer(clientHandler.Socket));
         }
         ulong tmpStep = mainProgram.gameSteps;
         uint  pos_    = 1;
         foreach (int thing in priorityList)
         {
             if (tmpStep % pos_ == 0 && !updatedQueue.Contains(thing))
             {
                 updatedQueue.Enqueue(thing);
             }
             pos_++;
         }
     }
 }
コード例 #6
0
        public GamePoint3D Max(GamePoint2D a)
        {
            GamePoint3D tmp = Max(this, a);

            X = tmp.X;
            Y = tmp.Y;
            Z = tmp.Z;
            return(this);
        }
コード例 #7
0
        public GamePoint3D Divide(GamePoint2D a)
        {
            GamePoint3D tmp = Divide(this, a);

            X = tmp.X;
            Y = tmp.Y;
            Z = tmp.Z;
            return(this);
        }
コード例 #8
0
        public GamePoint3D Multiply(GamePoint2D a)
        {
            GamePoint3D tmp = Multiply(this, a);

            X = tmp.X;
            Y = tmp.Y;
            Z = tmp.Z;
            return(this);
        }
コード例 #9
0
        public GamePoint3D Subtract(GamePoint2D a)
        {
            GamePoint3D tmp = Subtract(this, a);

            X = tmp.X;
            Y = tmp.Y;
            Z = tmp.Z;
            return(this);
        }
コード例 #10
0
        public GamePoint3D Add(GamePoint2D a)
        {
            GamePoint3D tmp = Add(this, a);

            X = tmp.X;
            Y = tmp.Y;
            Z = tmp.Z;
            return(this);
        }
コード例 #11
0
        public static bool cube_in_cube(GamePoint3D s1, GamePoint3D s2, GamePoint3D d1, GamePoint3D d2)
        {
            GamePoint3D a1 = s1.Min(s2); //the switching isn't required, but it might smooth processing function in the long run
            GamePoint3D a2 = s2.Max(s1);
            GamePoint3D b1 = d1.Min(d2);
            GamePoint3D b2 = d2.Max(d1);

            return(a1.X < b2.X && a2.Y > b1.Y && a1.Y < b2.Y && a2.Y > b1.Y &&
                   a1.X < b2.X && a2.X > b1.X && a1.Z < b2.Z && a2.Z > b1.Z &&
                   a1.Y < b2.Y && a2.Y > b1.Y && a1.Z < b2.Z && a2.Z > b1.Z);
        }
コード例 #12
0
        public void updatePriorities(Dictionary <int, GameEntity> entityMap)
        {
            tmpmap = entityMap;
            List <int> newList = new List <int>();

            tmppos = entityMap[entityId].pos;
            foreach (KeyValuePair <int, GameEntity> pair in entityMap)
            {
                newList.Add(pair.Key);
            }
            newList.Sort(comparePriority);
            priorityList = newList;
        }
コード例 #13
0
 public bool createObject(GamePoint3D position, GamePoint3D size)
 {
     if (objectMap.Count < maxObjects)
     {
         for (int i = 0; i < maxObjects; i += 1)
         {
             if (!objectMap.ContainsKey(i))
             {
                 objectMap.Add(i, new GameObject(position, size, i, this));
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #14
0
 public bool createEntity(GamePoint3D position, GamePoint2D size)
 {
     //returns if successful
     if (entityMap.Count < maxEntities)
     {
         for (int i = 0; i < maxEntities; i += 1)
         {
             if (!entityMap.ContainsKey(i))
             {
                 entityMap.Add(i, new GameEntity(position, size, i, this));
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #15
0
        public int createPlayer(GamePoint3D position, GamePoint2D size, TcpClientHandler client)
        {
            //this will ignore the max entity limit, however cannot ignore the max connection limit
            //returns if successful
            int i = 0;

            if (clientMap.Count < gameServer.MaxConnections)
            {
                while (entityMap.ContainsKey(i)) //looks to find the lowest open slot to make an entity
                {
                    i += 1;
                }
                entityMap.Add(i, new GameEntity(position, size, i, this));
                clientMap.Add(i, new GameClient(client, i, this));
            }
            return(i);
        }
コード例 #16
0
        public GameObject(GamePoint3D Position, GamePoint3D Size, int Id, GameWorld gameWorld)
        {
            position = Position;
            size     = Size;
            id       = Id;

            BufferStream buff = new BufferStream(64, 1);

            buff.Write((ushort)1);
            buff.Write((uint)id);
            buff.Write(position.X);
            buff.Write(position.Y);
            buff.Write(position.Z);
            buff.Write(size.X);
            buff.Write(size.Y);
            buff.Write(size.Z);
            gameWorld.sendToAllClients(buff);
            buff.Deallocate();
        }
コード例 #17
0
 public bool checkCollision(GamePoint3D d1, GamePoint3D d2)
 {
     try
     {
         foreach (KeyValuePair <int, GameObject> pair in objectMap)
         {
             GamePoint3D p1 = pair.Value.position,
                                                 p2 = pair.Value.position + pair.Value.size;
             if (GameGeometry.cube_in_cube(d1, d2, p1, p2))
             {
                 return(true);
             }
         }
     }
     catch (InvalidOperationException)
     {
         //needs to try again since the objectMap was altered
         return(checkCollision(d1, d2));
     }
     return(false);
 }
コード例 #18
0
 public static GamePoint3D operator -(GamePoint3D left, GamePoint2D right)
 {
     return(GamePoint3D.Subtract(left, right));
 }
コード例 #19
0
 public static GamePoint3D Add(GamePoint3D a, GamePoint2D b)
 {
     return(new GamePoint3D(a.X + b.X, a.Y + b.Y, a.Z));
 }
コード例 #20
0
 public static GamePoint3D Subtract(GamePoint3D a, GamePoint2D b)
 {
     return(new GamePoint3D(a.X - b.X, a.Y - b.Y, a.Z));
 }
コード例 #21
0
 public static GamePoint3D Multiply(GamePoint3D a, GamePoint2D b)
 {
     return(new GamePoint3D(a.X * b.X, a.Y * b.Y, a.Z));
 }
コード例 #22
0
 public static GamePoint3D Divide(GamePoint3D a, GamePoint2D b)
 {
     return(new GamePoint3D(a.X / b.X, a.Y / b.Y, a.Z));
 }
コード例 #23
0
        public bool update(GameWorld gameWorld)
        {
            spd.Z -= 0.5;

            GamePoint3D sz3_ = new GamePoint3D(size.X, size.X, -size.Y);
            GamePoint3D d1   = pos + new GamePoint2D(-size.X, -size.X),
                        d2   = pos + new GamePoint3D(size.X, size.X, size.Y);

            if (spd.X != 0d)
            {
                GamePoint3D t_ = new GamePoint3D(spd.X, 0d, 0d);
                while (gameWorld.checkCollision(d1 + t_, d2 + t_))
                {
                    if (Math.Abs(spd.X) > precision)
                    {
                        spd.X = 0;
                        break;
                    }
                    spd.X -= precision * Math.Sign(spd.X);
                    t_.X   = spd.X;
                }
            }
            if (spd.Y != 0d)
            {
                GamePoint3D t_ = new GamePoint3D(0d, spd.Y, 0d);
                while (gameWorld.checkCollision(d1 + t_, d2 + t_))
                {
                    if (Math.Abs(spd.Y) > precision)
                    {
                        spd.Y = 0;
                        break;
                    }
                    spd.Y -= precision * Math.Sign(spd.Y);
                    t_.Y   = spd.Y;
                }
            }
            if (spd.Z != 0d)
            {
                GamePoint3D t_ = new GamePoint3D(0d, 0d, spd.Z);
                while (gameWorld.checkCollision(d1 + t_, d2 + t_))
                {
                    if (Math.Abs(spd.Z) > precision)
                    {
                        spd.Z = 0;
                        break;
                    }
                    spd.Z -= precision * Math.Sign(spd.Z);
                    t_.Z   = spd.Z;
                }
            }
            if (Math.Abs(spd.X) <= spd_deadzone.X)
            {
                spd.X = 0;
            }
            if (Math.Abs(spd.Y) <= spd_deadzone.Y)
            {
                spd.Y = 0;
            }
            if (Math.Abs(spd.Z) <= spd_deadzone.Z)
            {
                spd.Z = 0;
            }

            pos      += spd;
            spd       = spd.Divide(frc);
            direction = direction % 360f;
            pitch     = GameGeometry.clamp(pitch, -89f, 89f);
            bool updateSelf = false;

            if (pos != previous_pos || previous_direction != direction || previous_pitch != pitch)
            {
                updateSelf = true;
            }

            previous_pos = pos;

            return(updateSelf);
        }
コード例 #24
0
 public static GamePoint3D Min(GamePoint3D a, GamePoint3D b)
 {
     return(new GamePoint3D((a.X > b.X) ? b.X : a.X, (a.Y > b.Y) ? b.Y : a.Y, (a.Z > b.Z) ? b.Z : a.Z));
 }
コード例 #25
0
 public static GamePoint3D Max(GamePoint3D a, GamePoint2D b)
 {
     return(new GamePoint3D((a.X < b.X) ? b.X : a.X, (a.Y < b.Y) ? b.Y : a.Y, a.Z));
 }
コード例 #26
0
 public bool createEntity(GamePoint3D position)
 {
     return(createEntity(position, new GamePoint2D(16d, 64d)));
 }
コード例 #27
0
 public static GamePoint3D operator +(GamePoint3D left, GamePoint2D right)
 {
     return(GamePoint3D.Add(left, right));
 }
コード例 #28
0
 public int createPlayer(GamePoint3D position, TcpClientHandler client)
 {
     return(createPlayer(position, new GamePoint2D(16d, 64d), client));
 }
コード例 #29
0
 public static GamePoint3D operator /(GamePoint3D left, GamePoint2D right)
 {
     return(GamePoint3D.Divide(left, right));
 }
コード例 #30
0
 public static GamePoint3D operator *(GamePoint3D left, GamePoint2D right)
 {
     return(GamePoint3D.Multiply(left, right));
 }