Exemplo n.º 1
0
        public static void AddDefault(ObstacleShape shape)
        {
            switch (shape)
            {
            case ObstacleShape.Box:
                Add(new Obstacle(Primitives.Cube(0.5f, 0.5f, 0.5f, _defaultMaterial),
                                 PhysicsHandler.CreateKinematicCollider(new BoxShape(0.5f, 0.5f, 0.5f))));
                break;

            case ObstacleShape.Sphere:
                Add(new Obstacle(Primitives.Sphere(0.5f, 50, 50, _defaultMaterial),
                                 PhysicsHandler.CreateKinematicCollider(new SphereShape(0.5f))));
                break;

            case ObstacleShape.Cylinder:
                Add(new Obstacle(new Model(new Mesh[]
                {
                    Primitives.Cylinder(0.25f, 1f, 1f, 50, _defaultMaterial)
                }), PhysicsHandler.CreateKinematicCollider(new CylinderShape(0.25f, 1f, 0.25f))));
                break;

            case ObstacleShape.Cone:
                Add(new Obstacle(new Model(new Mesh[]
                {
                    Primitives.Cone(0.5f, 2, 50, _defaultMaterial)
                }), PhysicsHandler.CreateKinematicCollider(new ConeShape(0.5f, 2))));      // TODO: cone's rigid body center is not the circle center, but the center of mass; fix
                break;

            default:
                throw new ArgumentException("The given obstacle shape is not implemented yet.", "shape");
            }
        }
 public override void onAddedToEntity()
 {
     _circleCollider = entity.getComponent <CircleCollider>();
     _mover          = entity.getComponent <Mover>();
     _physicsHandler = entity.getComponent <PhysicsHandler>();
     _mapComponent   = entity.scene.findEntity("tiled-map").getComponent <TiledMapComponent>();
 }
Exemplo n.º 3
0
    private void Awake()
    {
        var collider2D = GetComponent <Collider2D>();

        Debug.Assert(collider2D);
        Debug.Assert(collider2D.isTrigger);
        _physicsHandler = GameObject.FindWithTag("Player").GetComponent <PhysicsHandler>();
    }
Exemplo n.º 4
0
 private void Awake()
 {
     UpdateParameters();
     _physicsHandler = GetComponent <PhysicsHandler>();
     Debug.Assert(_physicsHandler, "You must add a PhysicsHandler !");
     groundDetector = GetComponentInChildren <GroundDetection>();
     Debug.Assert(groundDetector, "You must add a GroundDetector !");
 }
Exemplo n.º 5
0
        public override void onAddedToEntity()
        {
            base.onAddedToEntity();
            loadContent();

            _boxCollider    = entity.getComponent <BoxCollider>();
            _mover          = entity.getComponent <TiledMapMover>();
            _physicsHandler = entity.getComponent <PhysicsHandler>();
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        public Engine(AutoUpdateable gameLogic)
        {
            {
                // Init window
                renderForm            = new RenderForm("RaymarchEngine");
                renderForm.AutoSize   = false;
                renderForm.ClientSize = new Size(
                    Screen.PrimaryScreen.WorkingArea.Width,
                    Screen.PrimaryScreen.WorkingArea.Height
                    );
                renderForm.AllowUserResizing = false;
                renderForm.IsFullscreen      = isFullscreen;
                renderForm.StartPosition     = FormStartPosition.Manual;
                renderForm.Location          = new Point(0, 0);
                renderForm.WindowState       = FormWindowState.Maximized;
                renderForm.MinimizeBox       = false;
                renderForm.Show();
            }

            this.gameLogic = gameLogic;

            RaymarchRenderer.Init();

            // Create main scene
            Scene.CurrentScene = new Scene();

            // Start physics library
            physics = new PhysicsHandler(PhysicsReady);

            // Init input device
            InputDevice.Init(renderForm);

            int unixTime = Util.ConvertToUnixTimestamp(DateTime.Now);

            // Execute all start methods
            StaticUpdater.ExecuteStartActions(unixTime);

            // Execute each scene object's components' Start method
            foreach (GameObject gameObject in Scene.CurrentScene.GameObjects)
            {
                foreach (IComponent component in gameObject.Components)
                {
                    component.Start(unixTime);
                }
            }

            // It's important that render device is created after scene and game logic start
            renderDevice = new RenderDevice(renderForm, new Resolution(2560, 1440));

            // Start stopwatch for deltaTime
            stopwatch = new Stopwatch();
            stopwatch.Start();
        }
Exemplo n.º 7
0
        public GameManager()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            Template = new Template();

            // Systems
            systems.Add(renderer              = new Renderer());
            systems.Add(collisionHandler      = new CollisionHandler());
            systems.Add(physicsHandler        = new PhysicsHandler());
            systems.Add(animationHandler      = new AnimationHandler(Content));
            systems.Add(stateHandler          = new StateHandler());
            systems.Add(particleSystemHandler = new ParticleSystemHandler());
            systems.Add(parallaxHandler       = new ParallaxHandler());
        }
Exemplo n.º 8
0
        public Player(Scene scene, Vector2 SpawnPos)
        {
            position  = SpawnPos;
            offset    = new Vector2(6, 16);
            position += offset;
            id        = 1;

            this.scene  = scene;
            tempTexture = scene.game.textureHandler.redTexture;

            maxVelocity  = 3f;
            acceleration = 0.2f;

            inputHandler     = new PlayerInputHandler();
            physicsHandler   = new PhysicsHandler();
            collisionHandler = new CollisionHandler(scene);
            animationHandler = new PlayerAnimationHandler(scene.game, scene.game.textureHandler.player_idle, 20, null, scene.game.textureHandler.player_moveX, null, scene.game.textureHandler.player_moveUp, null);
        }
Exemplo n.º 9
0
        public Player(Main game)
        {
            this.map  = game.map;
            this.game = game;

            inputHandler     = new InputHandler();
            physicsHandler   = new PhysicsHandler();
            collisionHandler = new CollisionHandler(this.map);

            Color[] az = Enumerable.Range(0, 1).Select(i => Color.Red).ToArray();
            collisionBoxTexture = game.textureHandler.colorTexture;
            collisionBoxTexture.SetData(az);

            position = new Vector2(166, 80);
            prevPos  = position;

            this.texture       = game.textureHandler.playerTexture;
            this.movingTexture = game.textureHandler.playerWalk;
        }
Exemplo n.º 10
0
        public GameManager(GameLayout game, string contentDirectory)
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = contentDirectory;

            Template = new Template();
            penumbra = new PenumbraComponent(this);

            Services.AddService(penumbra);

            gameLayout = game;

            // Systems
            systems.Add(renderer         = new Renderer());
            systems.Add(collisionHandler = new CollisionHandler());
            systems.Add(physicsHandler   = new PhysicsHandler());
            systems.Add(animationHandler = new AnimationHandler(Content));
            systems.Add(lightHandler     = new LightHandler(penumbra));
        }
Exemplo n.º 11
0
        private static void PollSelection(GameWindow window, MouseState mouseState, KeyboardState keyboardState)  // TODO: raycast is performed wrong on shapes' edges; check!
        {
            var startWorld = RaycastResult.StartWorld.ToBullet3();
            var endWorld   = RaycastResult.EndWorld.ToBullet3();

            using (var raycastCallback = new ClosestRayResultCallback(ref startWorld, ref endWorld))
            {
                PhysicsHandler.RayTestRef(ref startWorld, ref endWorld, raycastCallback);
                if (/*window.IsMouseButtonPressed(MouseButton.Right)*/ mouseState.IsButtonDown(MouseButton.Right) && _lastState.IsButtonUp(MouseButton.Right))  // TODO: perhaps use Window built-in method?
                {
                    if (raycastCallback.HasHit)
                    {
                        if (!keyboardState.IsKeyDown(Key.ControlLeft) && SelectedObjects.Find(x => x != raycastCallback.CollisionObject) != null)
                        {
                            // Control is not pressed and other objects are already selected ---> clear selection and add the new object to the selection
                            ClearAndAddSelection(raycastCallback.CollisionObject);
                        }
                        else
                        {
                            // add the object to the selection if it's not there yet
                            if (!SelectedObjects.Contains(raycastCallback.CollisionObject))
                            {
                                AddSelection(raycastCallback.CollisionObject);
                            }
                            else
                            {
                                RemoveSelection(raycastCallback.CollisionObject);
                            }
                        }
                    }
                    else
                    {
                        // no object is selected ---> clear selection
                        ClearSelection();
                    }
                }
            }
        }
Exemplo n.º 12
0
        public Entity createProjectile(string name, ProjectileController controller, Vector2 pos, ref Sprite sprite)
        {
            // Entity entity = createEntity("Entity");
            ProjectileEntity waveProjectile = new ProjectileEntity(name, controller, ProjectileType.WAVE);

            //Hardcoding position adjustments
            //pos.X += 16;
            waveProjectile.position = pos;

            //Attach Sprite
            sprite.setRenderLayer(1);
            waveProjectile.addComponent <Sprite>(sprite);

            //Attack physics
            PhysicsHandler physicsHandler = new PhysicsHandler(controller.collisionResult);

            physicsHandler.isProjectile = true;
            physicsHandler.applyGravity = false;
            waveProjectile.addComponent <PhysicsHandler>(physicsHandler);

            //Attach hit detection
            CircleCollider circleCollider = new CircleCollider(sprite.width);

            waveProjectile.addComponent <CircleCollider>(circleCollider);
            Flags.setFlagExclusive(ref circleCollider.collidesWithLayers, 0); //Prevent collisions on layer 0
            Flags.setFlagExclusive(ref circleCollider.physicsLayer, 2);       //

            //Attack mover
            Mover mover = new Mover();

            waveProjectile.addComponent <Mover>(mover);

            entity.scene.addEntity <ProjectileEntity>(waveProjectile);

            return(waveProjectile);
        }
Exemplo n.º 13
0
        public Human(Vector2 spawnPosition, Texture2D texture, List <Entity> obstacles, int team)
        {
            animationFactory = new AnimationFactory();
            Position         = spawnPosition;
            Texture          = texture;
            Team             = team;
            Scale            = 1f;
            Input            = new AIInput();
            _PhysicsHandler  = new PhysicsHandler();
            List <ICollision> collidableList = new List <ICollision>();

            foreach (var obstacle in obstacles)
            {
                if (obstacle._collision != null)
                {
                    collidableList.Add(obstacle._collision);
                }
            }
            _collision                = new HumanCollision(spawnPosition, collidableList);
            _collision.Parent         = this;
            healthBar                 = new HealthBar();
            healthBar.ParentTransform = this;
            healthBar.Health          = this;
        }
Exemplo n.º 14
0
        public static Manipulator CreateDefaultManipulator()
        {
            // set links' parameters
            var links = new LinkData[_defaultLinksNumber];

            links.Fill(new LinkData
            {
                Length = _defaultLinksLength
            });

            // define model and collider for each link
            for (int i = 0; i < links.Length; i++)
            {
                links[i].Model    = _defaultLinkModel.DeepCopy();
                links[i].Collider = PhysicsHandler.CreateKinematicCollider(new CylinderShape(0.15f, 0.5f, 0.15f));
            }

            // set joints' parameters
            var joints = new JointData[_defaultLinksNumber + 1];

            joints.Fill(_defaultJoint);
            joints[joints.Length - 1] = _defaultGripper;

            // define model and collider for each joint
            for (int i = 0; i < joints.Length - 1; i++)
            {
                joints[i].Model    = _defaultJointModel.DeepCopy();
                joints[i].Collider = PhysicsHandler.CreateKinematicCollider(new SphereShape(0.2f));
            }

            // TODO: gripper collider is not affected by the initial transform; fix!
            joints[_defaultLinksNumber].Model    = _defaultGripperModel.DeepCopy();
            joints[_defaultLinksNumber].Collider = PhysicsHandler.CreateKinematicCollider(new SphereShape(0.1f));

            // set joints' axes
            var jointAxes = new Vector3[_defaultLinksNumber + 1];

            jointAxes[0] = jointAxes[jointAxes.Length - 1] = Vector3.UnitY;
            for (int i = 1; i < _defaultLinksNumber; i++)
            {
                jointAxes[i] = /*Vector3.UnitX;*/ i % 2 == 0 ? Vector3.UnitZ : Vector3.UnitX;
            }

            // set joints' positions
            var jointPositions = new Vector3[_defaultLinksNumber + 1];

            jointPositions[0] = Vector3.Zero;
            for (int i = 1; i < _defaultLinksNumber + 1; i++)
            {
                jointPositions[i] = jointPositions[i - 1] + ((joints[i - 1].Length + joints[i].Length) / 2 + links[i - 1].Length) * Vector3.UnitY;
            }

            // create a default manipulator
            var manipulator = new Manipulator(new ManipData
            {
                N              = _defaultLinksNumber,
                Links          = links,
                Joints         = joints,
                JointAxes      = jointAxes,
                JointPositions = jointPositions,
                Goal           = _defaultGoal,
                ShowTree       = true
            });

            var solver     = DampedLeastSquares.Default();
            var planner    = GeneticAlgorithm.Default(); /*ARRT.Default(manipulator);*/
            var controller = MotionController.Default();

            manipulator.Controller = new Controller(manipulator, planner, solver, controller);

            // add manipulator to the list
            Add(manipulator);

            return(manipulator);
        }
Exemplo n.º 15
0
 public void UpdatePhysics()
 {
     PhysicsHandler.Update(this);
 }