示例#1
0
        private void Post_OnCollision(object sender, PhysicsBodyComponent e)
        {
            ServerMPPlayer player = e.GameObject as ServerMPPlayer;

            if (player != null)
            {
                CommandPost post = ((PhysicsBodyComponent)sender).GameObject as CommandPost;
                if (post.Team == player.Team)
                {
                    player.Refresh();

                    if (player.HasIntel)
                    {
                        CaptureIntel(player, player.Intel);
                    }
                }
            }
            else if (e.GameObject is Intel intel)
            {
                if (intel.Holder == null)
                {
                    CommandPost post = ((PhysicsBodyComponent)sender).GameObject as CommandPost;
                    if (post.Team != intel.Team)
                    {
                        CaptureIntel(intel.LastHolder as ServerMPPlayer, intel);
                    }
                }
            }
        }
示例#2
0
        protected override void Update(float dt)
        {
            base.Update(dt);

            PhysicsBodyComponent p = e.GetComponent <PhysicsBodyComponent> ();
            AABBComponent        c = e.GetComponent <AABBComponent> ();

            if (Input.IsKeyHeld(Keys.D))
            {
                p.Velocity.X = 100;
            }
            else if (Input.IsKeyHeld(Keys.A))
            {
                p.Velocity.X = -100;
            }
            else
            {
                p.Velocity.X = 0;
            }

            if (Input.IsKeyHeld(Keys.S))
            {
                p.Velocity.Y = 100;
            }
            else if (Input.IsKeyHeld(Keys.W))
            {
                p.Velocity.Y = -100;
            }
            else
            {
                p.Velocity.Y = 0;
            }
        }
        private void PhysicsBody_OnCollision(object sender, PhysicsBodyComponent e)
        {
            if (!IsDed && (e.GameObject is PhysicsBlock || (owner != null && e.GameObject is Player player && owner.Team != player.Team)))
            {
                physicsBody.OnCollision -= PhysicsBody_OnCollision;
                IsDed = true;
                world.Explode(new Explosion(owner, Transform.Position, 55, 70, 200, 0.15f, "Melon"));

                if (!GlobalNetwork.IsServer)
                {
                    AudioBuffer explodeBuffer = AssetManager.LoadSound("Weapons/Grenade/Explode.wav");

                    if (explodeBuffer != null)
                    {
                        AudioSource explodeAudioSource = new AudioSource(explodeBuffer);
                        explodeAudioSource.MaxDistance = 1000;
                        explodeAudioSource.Position    = Transform.Position;
                        explodeAudioSource.Pitch       = 0.5f;

                        world.PlayWorldAudio(new WorldAudioSource(explodeAudioSource));
                    }
                }

                Dispose();
            }
        }
示例#4
0
 private void PhysicsBody_OnCollision(object sender, PhysicsBodyComponent e)
 {
     if (Math.Abs(PhysicsBody.Velocity.Y) > 1f)
     {
         bounceAudioSource?.Play();
     }
 }
        public MelonEntity(Player owner, Vector3 position, Vector3 velocity, World world)
            : base(position)
        {
            this.owner = owner;
            this.world = world;

            // Setup physics
            physicsBody = new PhysicsBodyComponent(new Vector3(2f), 0.0001f);
            AddComponent(physicsBody);

            physicsBody.Velocity = velocity * 400;

            physicsBody.CanCollideWithSoft  = true;
            physicsBody.CanBePushedBySoft   = false;
            physicsBody.IsAffectedByGravity = true;

            physicsBody.OnCollision += PhysicsBody_OnCollision;

            // Setup renderer
            if (GlobalNetwork.IsClient)
            {
                renderer = new VoxelRenderComponent();
                AddComponent(renderer);

                renderer.VoxelObject = AssetManager.LoadVoxelObject("Models/melon.aosm", BufferUsageHint.StaticDraw);
            }
        }
        private void CharacterController_OnCollision(object sender, PhysicsBodyComponent e)
        {
            if (this.intel == null)
            {
                Intel intel = e.GameObject as Intel;

                if (intel != null)
                {
                    if (intel.RequestOwnership(this))
                    {
                        DashCMD.WriteLine("[SPPlayer] Picked up the intel", ConsoleColor.Green);
                        this.intel          = intel;
                        intel.IsIconVisible = false;
                    }
                }
            }

            CommandPost commandPost = e.GameObject as CommandPost;

            if (commandPost != null)
            {
                if (commandPost.Team == Team)
                {
                    Refresh();

                    if (intel != null)
                    {
                        intel.Return();
                        intel.IsIconVisible = true;
                        intel = null;
                    }
                }
            }
        }
示例#7
0
        internal protected override void Update(float dt)
        {
            base.Update(dt);

            foreach (Entity e in Entities)
            {
                PhysicsBodyComponent pbody = e.GetComponent <PhysicsBodyComponent> ();
                if (pbody == null)
                {
                    continue;
                }

                TransformComponent transform = e.GetComponent <TransformComponent> ();
                AABBComponent      collider  = e.GetComponent <AABBComponent> ();

                if (pbody.Velocity.X != 0)
                {
                    transform.Position = new Vector2(transform.Position.X + pbody.Velocity.X * dt, transform.Position.Y);
                    HandleHorizontalCollision(e, transform, collider, pbody);
                }

                if (pbody.Velocity.Y != 0)
                {
                    transform.Position = new Vector2(transform.Position.X, transform.Position.Y + pbody.Velocity.Y * dt);
                    HandleVerticalCollision(e, transform, collider, pbody);
                }
            }
        }
        internal Intersection(PhysicsBodyComponent object1, PhysicsBodyComponent object2, AABBCollisionResolver resolver,
                              float deltaTime, IntersectionType type)
        {
            Object1        = object1;
            Object2        = object2;
            Resolver       = resolver;
            this.deltaTime = deltaTime;
            Type           = type;

            Object1EntryTime = Resolver.Sweep(Object1.GetCollider(), Object2.GetCollider(), Object1.Velocity * deltaTime, out Object2Normal);
            Object2EntryTime = Resolver.Sweep(Object2.GetCollider(), Object1.GetCollider(), Object2.Velocity * deltaTime, out Object1Normal);
        }
示例#9
0
        private void Post_OnCollision(object sender, PhysicsBodyComponent e)
        {
            ServerMPPlayer player = e.GameObject as ServerMPPlayer;

            if (player != null)
            {
                CommandPost post = ((PhysicsBodyComponent)sender).GameObject as CommandPost;
                if (post.Team == player.Team)
                {
                    player.Refresh();
                }
            }
        }
示例#10
0
        public PhysicsBlock(Block block, Vector3 position, IndexPosition ipos, Chunk chunk)
            : base(position)
        {
            PhysicsBodyComponent physicsBody = new PhysicsBodyComponent(Block.CUBE_3D_SIZE);

            AddComponent(physicsBody);

            Block                = block;
            BlockPos             = ipos;
            Chunk                = chunk;
            physicsBody.IsStatic = true;
            physicsBody.CanCollideWithTerrain = false;
        }
示例#11
0
 private void CharacterController_OnCollision(object sender, PhysicsBodyComponent e)
 {
     if (Intel == null)
     {
         if (e.GameObject is Intel intel)
         {
             if (intel.RequestOwnership(this))
             {
                 DashCMD.WriteLine("[ServerMPPlayer] Intel has been picked up!", ConsoleColor.Green);
                 Intel = intel;
             }
         }
     }
 }
示例#12
0
        public PlayerRaycastResult RaycastPlayer(Vector3 origin, Player player, float maxDist = 2000f)
        {
            Vector3 dir = (player.Transform.Position - origin).Normalize();
            Ray     ray = new Ray(origin, dir);

            TerrainRaycastResult tResult = TerrainPhysics.Raycast(ray, true, maxDist);
            float?dist;
            PhysicsBodyComponent playerPhysics = player.GetComponent <PhysicsBodyComponent>();
            bool hitPlayer = ray.Intersects(playerPhysics.GetCollider(), out dist);

            if (hitPlayer && dist.Value <= maxDist && (!tResult.Intersects || dist.Value < tResult.IntersectionDistance.Value))
            {
                return(new PlayerRaycastResult(ray, true, ray.Origin + ray.Direction * dist.Value, dist, player));
            }
            else
            {
                return(new PlayerRaycastResult(ray));
            }
        }
示例#13
0
        public GrenadeEntity(Player owner, Vector3 position, Vector3 velocity, World world, float throwPower)
            : base(position - new Vector3(0.75f))
        {
            this.owner = owner;
            this.world = world;

            // Setup physics
            PhysicsBody = new PhysicsBodyComponent(new Vector3(1.5f), 0.0001f);
            AddComponent(PhysicsBody);

            PhysicsBody.Velocity = velocity * throwPower;

            PhysicsBody.CanCollideWithSoft        = false;
            PhysicsBody.BounceOnWallCollision     = true;
            PhysicsBody.BounceOnVerticalCollision = true;
            PhysicsBody.VerticalBounceFalloff     = 0.8f;
            PhysicsBody.HorizontalBounceFalloff   = 0.7f;
            PhysicsBody.Friction = 0.2f;

            // Setup renderer
            if (GlobalNetwork.IsClient)
            {
                renderer = new VoxelRenderComponent();
                AddComponent(renderer);

                renderer.VoxelObject = AssetManager.LoadVoxelObject("Models/grenade.aosm", BufferUsageHint.StaticDraw);

                AudioBuffer bounceAudioBuffer = AssetManager.LoadSound("Weapons/Grenade/Bounce.wav");

                if (bounceAudioBuffer != null)
                {
                    bounceAudioSource             = new AudioSource(bounceAudioBuffer);
                    bounceAudioSource.MaxDistance = 200;
                    bounceAudioSource.Gain        = 0.25f;
                }

                PhysicsBody.OnCollision += PhysicsBody_OnCollision;
            }
        }
示例#14
0
        public BlockItem(ItemManager itemManager, MasterRenderer renderer)
            : base(itemManager, ItemType.BlockItem)
        {
            this.renderer = renderer;

            ModelOffset            = new Vector3(-1.75f, -1.75f, 2.5f);
            ownerPlayerPhysicsBody = OwnerPlayer.GetComponent <PhysicsBodyComponent>();

            if (!GlobalNetwork.IsServer)
            {
                entRenderer = renderer.GetRenderer3D <EntityRenderer>();

                cube = new DebugCube(Color4.White, 1.5f);
                Renderer.VoxelObject = cube.VoxelObject;

                if (cursorCube == null)
                {
                    cursorCube = new DebugCube(Color4.White, Block.CUBE_SIZE);
                    cursorCube.RenderAsWireframe = true;
                    cursorCube.ApplyNoLighting   = true;
                    cursorCube.OnlyRenderFor     = RenderPass.Normal;
                }

                Colors = new Color[PaletteHeight, PaletteWidth];

                for (int y = 0; y < PaletteHeight; y++)
                {
                    for (int x = 0; x < PaletteWidth; x++)
                    {
                        if (y == 0)
                        {
                            Colors[y, x] = Maths.HSVToRGB(0, 0, Math.Max(x / (float)PaletteWidth, 0.05f));
                        }
                        else
                        {
                            int halfPalette = PaletteWidth / 2;
                            if (x > halfPalette)
                            {
                                Colors[y, x] = Maths.HSVToRGB(
                                    (y - 1) / ((float)PaletteHeight - 1) * 360,
                                    1f - Math.Max((x - halfPalette) / (float)halfPalette, 0.05f),
                                    1f);
                            }
                            else
                            {
                                Colors[y, x] = Maths.HSVToRGB(
                                    (y - 1) / ((float)PaletteHeight - 1) * 360,
                                    1f,
                                    Math.Max(x / (float)halfPalette, 0.05f));
                            }
                        }
                    }
                }

                BlockColor = Colors[ColorY, ColorX];

                if (!itemManager.IsReplicated)
                {
                    AudioBuffer buildAudioBuffer = AssetManager.LoadSound("Weapons/Block/build.wav");

                    if (buildAudioBuffer != null)
                    {
                        buildAudioSource = new AudioSource(buildAudioBuffer);
                        buildAudioSource.IsSourceRelative = true;
                        buildAudioSource.Gain             = 0.5f;
                    }
                }
            }
        }
        public IEnumerable <PhysicsBodyComponent> GetBroadphaseIntersections(AxisAlignedBoundingBox broad)
        {
            _terrainBlockCache.Clear();

            // Convert the broad AABB to an IndexPosition AABB
            IndexPosition min = new IndexPosition(
                Maths.NegativeRound(broad.Min.X / Block.CUBE_SIZE),
                Maths.NegativeRound(broad.Min.Y / Block.CUBE_SIZE),
                Maths.NegativeRound(broad.Min.Z / Block.CUBE_SIZE));

            IndexPosition max = new IndexPosition(
                (int)Math.Ceiling(broad.Max.X / Block.CUBE_SIZE),
                (int)Math.Ceiling(broad.Max.Y / Block.CUBE_SIZE),
                (int)Math.Ceiling(broad.Max.Z / Block.CUBE_SIZE));

            // Calculate the chunk index to use as reference
            IndexPosition chunkIndex = Terrain.WorldToChunkCoords(broad.Center);

            // Try each block
            for (int x = min.X; x <= max.X; x++)
            {
                for (int y = min.Y; y <= max.Y; y++)
                {
                    for (int z = min.Z; z <= max.Z; z++)
                    {
                        // Calculate the index positions for the current block
                        IndexPosition blockIndexWorld = new IndexPosition(x, y, z);
                        IndexPosition blockChunkIndex = Chunk.BlockToChunkBlockCoords(chunkIndex, blockIndexWorld);

                        // Find the block
                        Chunk chunk;
                        int   fx, fy, fz;
                        Block block = Terrain.FindBlock(chunkIndex, blockChunkIndex.X, blockChunkIndex.Y, blockChunkIndex.Z,
                                                        out fx, out fy, out fz, out chunk);

                        // If this block has collision, process it
                        if (block.HasCollision())
                        {
                            IndexPosition blockIPos = new IndexPosition(fx, fy, fz);
                            // Calculate the blocks world position and create a PhyicsBlock from it
                            Vector3      blockWorldPosition = Chunk.ChunkBlockToWorldCoords(chunk.Position, blockIPos);
                            PhysicsBlock physBlock          = GetNewPhysicsBlock(block, blockWorldPosition, blockIPos, chunk);

                            // Grab its collider
                            PhysicsBodyComponent   physicsBody       = physBlock.GetComponent <PhysicsBodyComponent>();
                            AxisAlignedBoundingBox physBlockCollider = physicsBody.GetCollider();
                            //DebugAABBs.Add(physBlockCollider as AABoundingBox);

                            // Check if the block intersects the broad,
                            // if it does this block is valid for collision response
                            // TODO: Might be able to remove the intersect check
                            if (broad.Intersects(physBlockCollider))
                            {
                                _terrainBlockStorage.Add(physBlock);
                                _terrainBlockCache.Add(physicsBody);
                            }
                            else
                            {
                                unusedPhysBlocks.Enqueue(physBlock);
                            }
                        }
                    }
                }
            }

            return(_terrainBlockCache);
        }
示例#16
0
 public FakeServerPlayer(Vector3 position, Vector3 size, float mass)
     : base(position)
 {
     PhysicsBody = new PhysicsBodyComponent(size, mass);
     AddComponent(PhysicsBody);
 }
示例#17
0
        private void HandleVerticalCollision(Entity e, TransformComponent t, AABBComponent c, PhysicsBodyComponent p)
        {
            foreach (Entity o in Entities)
            {
                if (e == o)
                {
                    continue;
                }

                TransformComponent ot = o.GetComponent <TransformComponent> ();
                AABBComponent      oc = o.GetComponent <AABBComponent> ();

                Rectangle r  = new Rectangle((int)t.Position.X + c.OffsetX, (int)t.Position.Y + c.OffsetY, c.Width, c.Height);
                Rectangle or = new Rectangle((int)ot.Position.X + oc.OffsetX, (int)ot.Position.Y + oc.OffsetY, oc.Width, oc.Height);

                if (r.Intersects(or))
                {
                    float d = r.GetIntersectionDepth(or).Y * -1;

                    t.Position = new Vector2(t.Position.X, (float)Math.Floor(t.Position.Y - d));
                }
            }
        }