Exemple #1
0
 protected override void BeginGame()
 {
     scene = new ARScene(this);
     scene.LoadScene();
     quitter = componentFactory.GraphicsInputFactory.CreateInputComponent();
     quitter.AddKeyDelegate(KeyCodes.Escape, new InputComponent.InputHandler(RequestEndGame));
 }
Exemple #2
0
        public PlayerController(PlayerView playerViewInstance, int _playerID, InputScriptableObject _customInputScheme = null, Material _rewardedMat = null)
        {
            playerModel = new PlayerModel();
            playerModel.SetID(_playerID);
            playerID = playerModel.GetID();

            playerView = playerViewInstance;

            if (_rewardedMat != null)
            {
                SetMaterial(_rewardedMat);
            }

            if (_customInputScheme)
            {
                currentInputComponent = new CustomInputComponent(_customInputScheme, this);
            }
            else
            {
                currentInputComponent = new KeyboardComponent(this);
            }
            playerView.SetPlayerController(this);
            currentStateDictionary.Clear();
            CreateNewPlayerState();

            GameApplication.Instance.GetService <IPlayerService>().UpdatePlayer += UpdateCurrentPlayer;
        }
Exemple #3
0
        protected override void BindInput(InputComponent playerInputComponent)
        {
            base.BindInput(playerInputComponent);

            // Bind the jump action to Character.Jump(), which already has the appropriate delegate signature.
            playerInputComponent.BindAction(InputAction.Jump, InputEventType.Pressed, Jump);
            playerInputComponent.BindAction(InputAction.Jump, InputEventType.Released, StopJumping);

            playerInputComponent.BindAxis(InputAxis.MoveForward, MoveForward);
            playerInputComponent.BindAxis(InputAxis.MoveRight, MoveRight);

            // We have 2 versions of the rotation bindings to handle different kinds of devices differently
            // "turn" handles devices that provide an absolute delta, such as a mouse.
            // "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
            playerInputComponent.BindAxis(InputAxis.Turn, AddControllerYawInput);
            playerInputComponent.BindAxis(InputAxis.TurnRate, (float axisValue) => AddControllerYawInput(axisValue * BaseTurnRate * World.GetWorldDeltaSeconds()));
            playerInputComponent.BindAxis(InputAxis.LookUp, AddControllerPitchInput);
            playerInputComponent.BindAxis(InputAxis.LookUpRate, (float axisValue) => AddControllerPitchInput(axisValue * BaseLookUpRate * World.GetWorldDeltaSeconds()));

            // handle touch devices
            playerInputComponent.BindTouch(InputEventType.Pressed, (fingerIndex, location) => Jump());
            playerInputComponent.BindTouch(InputEventType.Released, (fingerIndex, location) => StopJumping());

            // VR headset functionality
            playerInputComponent.BindAction(InputAction.ResetVR, InputEventType.Pressed, OnResetVR);
        }
    protected override void OnUpdate()
    {
        //Get Player Translation, which was set by the physic system
        var currentPosition = EntityManager.GetComponentData <Translation>(GameVariables.Player.Entity).Value;


        //Calculate Input
        InputComponent input = EntityManager.GetComponentData <InputComponent>(GameVariables.Player.Entity);

        var screenPos = new float2(input.Mouse.x - Screen.width * 0.5f, input.Mouse.y - Screen.height * 0.5f) / 20;
        var distance  = math.clamp(math.distance(0, screenPos), 0.1f, length);
        var oldPos    = math.normalizesafe(screenPos);

        var newDir = float3.zero;
        var cos    = math.cos(offsetRad);
        var sin    = math.sin(offsetRad);

        newDir.x = oldPos.x * cos - oldPos.y * sin;
        newDir.z = oldPos.x * sin + oldPos.y * cos;
        newDir.y = 0;

        GameVariables.MouseToTransform.position = currentPosition + newDir * distance;
        GameVariables.Player.Transform.position = currentPosition;

        //Debug Ray

        /*var playerLocalToWorld = EntityManager.GetComponentData<LocalToWorld>(GameVariables.Player.Entity);
         * var e = GameVariables.Player.PlayerWeaponEntities[GameVariables.Player.CurrentWeaponHeld];
         * var localToWorld = EntityManager.GetComponentData<LocalToWorld>(e);*/
        #if UNITY_EDITOR
        /*Debug.DrawRay(playerLocalToWorld.Position, playerLocalToWorld.Forward * 5, Color.blue);
         * Debug.DrawRay(localToWorld.Position, localToWorld.Forward * 5, Color.yellow);
         * Debug.DrawRay(currentPosition,newDir  * 5, Color.red);*/
        #endif
    }
Exemple #5
0
    private Ray areaCheckRay;       // 현재 캐릭터가 어느 지역에 있는지 확인하는 Ray

    // Start is called before the first frame update
    void Start()
    {
        if (animator == null)
        {
            animator = GetComponent <Animator>();
        }
        if (inputComponent == null)
        {
            inputComponent = GetComponent <InputComponent>();
        }
        if (characterMovement == null)
        {
            characterMovement = GetComponent <CharacterMovement>();
        }
        if (rigidbody == null)
        {
            rigidbody = GetComponent <Rigidbody>();
        }
        if (capsuleCollider == null)
        {
            capsuleCollider         = GetComponent <CapsuleCollider>();
            capsuleCollider.enabled = true;
        }
        maxHp      = 100.0f;
        curHp      = maxHp;
        maxStamina = 100.0f;
        curStamina = 100.0f;
    }
        public RheinwerkGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.IsFullScreen = false;
            // Fenstergrösse festlegen.
            graphics.PreferredBackBufferHeight = 2000;
            graphics.PreferredBackBufferWidth  = 3000;

            // Objektinstanzen erzeugen
            Input             = new InputComponent(this);
            Input.UpdateOrder = 0;

            Scene             = new SceneComponent(this);
            Scene.UpdateOrder = 2;
            Scene.DrawOrder   = 0;

            Simulation             = new SimulationComponent(this);
            Simulation.UpdateOrder = 1;

            // Komponenten hinzufügen
            Components.Add(Input);
            Components.Add(Scene);
            Components.Add(Simulation);

            // Update Order bestimmt in welcher Reihenfolge die Komponenten gemalt werden
            Input.UpdateOrder      = 0;
            Simulation.UpdateOrder = 1;
            Scene.UpdateOrder      = 2;

            Hud             = new HudComponent(this);
            Hud.UpdateOrder = 3;
            Hud.DrawOrder   = 1;
            Components.Add(Hud);
        }
    void setVelocityByInput(Entity entity, InputComponent component)
    {
        Vector2 position = entity.position.pos;
        VelocityComponent velocity = entity.velocity;

        velocity.vel.Set((component.x - position.x) * 5.0f, (component.y - position.y) * 5.0f);
    }
Exemple #8
0
    public void Update(GunComponent gunComponent, InputComponent input, GameobjectComponent gameobjectComponent)
    {
        if (gunComponent == null || gunComponent.enable == false)
        {
            return;
        }

        if (gunComponent.entity.identity.isAIControl == false)
        {
            SetDirection(gunComponent, input, gameobjectComponent.transform);
        }

        gunComponent.laserTimer.Update();
        if (gunComponent.laserTimer.isRunning == false)
        {
            if (InputSystem.GetHoldAction(input, "laser"))
            {
                gunComponent.laserTimer.Enter();
                EmitLaser(gunComponent, gameobjectComponent.transform);
                return;
            }
        }

        gunComponent.fireTimer.Update();
        if (gunComponent.fireTimer.isRunning == false)
        {
            if (InputSystem.GetHoldAction(input, "fire"))
            {
                gunComponent.fireTimer.Enter();
                Fire(gunComponent, gameobjectComponent.transform);
            }
        }
    }
 public PlayerController(GameObject _playerView)
 {
     playerModel    = new PlayerModel();
     playerView     = GameObject.Instantiate(_playerView, Vector3.zero, Quaternion.identity).GetComponent <PlayerView>();
     inputComponent = new InputComponent();
     playerView.SetPlayerController(this);
 }
Exemple #10
0
        public override GameState UpdateState(GameTime gameTime)
        {
            //rotation += (float)gameTime.ElapsedGameTime.TotalSeconds * .5f;
            //car.Speed = ((float)Math.Sin(gameTime.TotalGameTime.TotalSeconds) + 2f) * 1.5f;
            //car.Update();

            InputComponent input = Game.GetService <InputComponent>();
            int            i     = availableColors.FindIndex(0, c => c == diffuseColor);

            if (input.GetKey(Keys.Left))
            {
                i--;
                if (i < 0)
                {
                    i = availableColors.Count - 1;
                }
            }
            else if (input.GetKey(Keys.Right))
            {
                i = (++i % availableColors.Count);
            }

            diffuseColor = availableColors[i];
            GameSettings.Default.CarColor = diffuseColor;

            GameState state = base.UpdateState(gameTime);

            if (state != this.gameState)
            {
                GameSettings.Default.Save();
            }
            return(state);
        }
Exemple #11
0
        private static void HandleAxisMappings(InputComponent inputComponent)
        {
            ResetAxisStates(inputComponent);
            if (inputComponent.InputMapping == null)
            {
                return;
            }

            var axisMappings = inputComponent.InputMapping.AxisMappings;

            foreach (var axisMapping in axisMappings)
            {
                var axisName = axisMapping.AxisName;

                foreach (var hardwareAxis in axisMapping.HardwareAxes)
                {
                    var state       = ComputeState(inputComponent.HardwareInput, hardwareAxis);
                    var scaledState = state * hardwareAxis.Scale;

                    if (inputComponent.AxisStates.ContainsKey(axisName))
                    {
                        inputComponent.AxisStates[axisName] += scaledState;
                    }
                    else
                    {
                        inputComponent.AxisStates[axisName] = scaledState;
                    }
                }

                if (inputComponent.AxisBindings.ContainsKey(axisName))
                {
                    inputComponent.AxisBindings[axisName](inputComponent.GetAxisState(axisName));
                }
            }
        }
Exemple #12
0
    void MoveControl(TankComponent tank, InputComponent input, MoveComponent move, Transform transform, GameobjectComponent gameobjectComponent)
    {
        foreach (var item in TankComponent.moveActionDict)
        {
            if (InputSystem.GetHoldAction(input, item.Key))
            {
                move.moveDirection = item.Value;
            }
        }

        move.needMove = false;
        foreach (var item in TankComponent.moveActionDict)
        {
            if (InputSystem.GetHoldAction(input, item.Key))
            {
                move.needMove = true;

                break;
            }
        }

        if (move.needMove == true)
        {
            //Debug.Log("need move is true");
            gameobjectComponent.animator.SetInteger("state", 1);
            transform.rotation = Quaternion.Euler(0, 0, move.moveDirection * 90);
        }
        else
        {
            move.moveDirection = -1;
            gameobjectComponent.animator.SetInteger("state", 0);
        }
    }
        public void SerializeAndDeserialize_WhenInputMappingIsNotNull()
        {
            // Arrange
            var inputMapping        = new InputMapping();
            var inputMappingAssetId = AssetId.CreateUnique();

            var component = new InputComponent
            {
                InputMapping = inputMapping
            };

            AssetStore.GetAssetId(inputMapping).Returns(inputMappingAssetId);
            AssetStore.GetAsset <InputMapping>(inputMappingAssetId).Returns(inputMapping);

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.InputMapping, Is.EqualTo(inputMapping));
            Assert.That(actual.HardwareInput, Is.EqualTo(HardwareInput.Empty));
            Assert.That(actual.ActionBindings, Is.Empty);
            Assert.That(actual.AxisBindings, Is.Empty);
            Assert.That(actual.ActionStates, Is.Empty);
            Assert.That(actual.AxisStates, Is.Empty);
        }
 public Entity AddInput(int newX, int newY)
 {
     var component = new InputComponent();
     component.x = newX;
     component.y = newY;
     return AddInput(component);
 }
Exemple #15
0
 public static void GOTO_STATE3(AiComponent aicomponent, InputComponent input)
 {
     Debug.Log("GOTO_3");
     clearInputState(aicomponent, input);
     aicomponent.Dir        = 0;
     aicomponent.finishMove = false;
     aicomponent.timeCount  = 0;
     if (aicomponent.MoveState == 0)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 4;
     }
     else if (aicomponent.MoveState == 1)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 2;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd * 5;
     }
     else if (aicomponent.MoveState == 2)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 8;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd * 5;
     }
     else if (aicomponent.MoveState == 5)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed * 4;
     }
     aicomponent.MoveState = 3;
 }
Exemple #16
0
    /*
     * MoveState=0 根据玩家方向选择横向或者纵向持续来回移动并不断扫射 5s 接状态2
     *           1 四方向原地射击 接状态1
     *           2 玩家靠近时变换到战场的四个点其中之一,四方向射击一次
     *           3 玩家坐标越过中线时,对称跳跃到玩家另一侧
     *           4 暴走状态 射速以及移速加快 接状态1或2
     *           5 开始搜寻状态 玩家最后一次miss的方位
     *           6 目标丢失,停顿
     *           状态12重复四次没有状态2时接状态2
     *           血量到1/5时接状态4
     */
    public static void Boss1Shoot(AiComponent aicomponent, InputComponent input)
    {
        aicomponent.MoveState       = aicomponent.bodyworkAIcomponent.MoveState;
        aicomponent.timeCountShoot += Time.deltaTime;


        switch (aicomponent.MoveState)
        {
        case 1:
            skill_MoveShoot(aicomponent, input);
            break;

        case 2:
            skill_Attack(aicomponent, input);
            break;

        case 3:
            skill_QuickMove(aicomponent, input);
            break;

        case 4:
            //暴走状态
            break;

        case 5:
            //搜寻状态
            break;

        default:
            break;
        }
    }
    public override void Initialize(Transform[] objects)
    {
        // list because I don't know size here
        List <Filter> tmpFilters = new List <Filter>();
        int           index      = 0;

        for (int i = 0; i < objects.Length; i++)
        {
            // check performance
            InventoryComponent  invC = objects[i].GetComponent <InventoryComponent>();
            InputComponent      inpC = objects[i].GetComponent <InputComponent>();
            InteractorComponent intC = objects[i].GetComponent <InteractorComponent>();
            MovementComponent   movC = objects[i].GetComponent <MovementComponent>();

            if (invC && inpC && intC && movC)
            {
                tmpFilters.Add(new Filter(index, objects[i].gameObject, invC, inpC, intC, movC));
            }
        }

        filters = tmpFilters.ToArray();

        environmentComponent   = GetComponentInChildren <EnvironmentComponent>();
        transportableComponent = GetComponentInChildren <CartComponent>();
        cartInteractable       = transportableComponent.GetComponent <InteractableComponent>();
        lightComponent         = GetComponentInChildren <LightComponent>();
        //villagerComponent = GetComponentInChildren<VillagerComponent>();
        travelComponent  = GetComponentInChildren <TravelComponent>();
        treeComponents   = GetComponentsInChildren <CollectibleComponent>();
        goapSystem       = GetComponent <GOAPSystem>();
        navMeshComponent = playerGO.GetComponent <NavMeshComponent>();
    }
    //每帧都会调用对应的实体
    public override void Execute(List <BasicEntity> entities)
    {
        foreach (BasicEntity e in entities)
        {
            AttackComponent  attack = e.GetComponent <AttackComponent> ();
            VoxelBlocks      map    = GameObject.Find("Voxel Map").transform.GetComponent <VoxelBlocks> ();
            AbilityComponent ab     = e.GetComponent <AbilityComponent> ();
            InputComponent   input  = e.GetComponent <InputComponent> ();
            StateComponent   ap     = e.GetComponent <StateComponent> ();

            int i = AiToInput.GetAbilityCount(e, M_LinkedType);
            //检测是否按下攻击键

            if (i >= ab.m_temporaryAbility.Count || i != input.currentKey)
            {
                continue;
            }

            //若无攻击对象则获取周围可攻击对象
            if (attack.enemy == null)
            {
                attack.enemy = GetEnemyAround(e);
                if (attack.enemy == null)
                {
                    return;
                }
            }
            List <Vector3> el = new List <Vector3> ();
            foreach (var enemy in attack.enemy)
            {
                el.Add(enemy.GetComponent <BlockInfoComponent> ().m_logicPosition);
            }
            UISimple ui = GameObject.Find("UI").GetComponent <UISimple> ();
            ui.ShowUI(el, 2);

            //左键攻击
            if (input.leftButtonDown)
            {
                BasicEntity enemy = map.GetBlockByLogicPos(input.currentPos).entity;

                //检测当前选中敌人是否处于攻击范围内
                List <BasicEntity> list = GetEnemyAround(e);
                if (list != null && !list.Contains(enemy))
                {
                    attack.enemy = list;
                    return;
                }
                //扣除敌人HP值
                DeadComponent  dead  = enemy.GetComponent <DeadComponent> ();
                StateComponent state = e.GetComponent <StateComponent> ();
                dead.hp             -= attack.STR;
                state.m_actionPoint -= 1;
                state.Invoke("AnimationEnd", 1);
                state.AnimationStart();
                //播放攻击动画
                //播放敌人受击动画
                //减少AP
            }
        }
    }
Exemple #19
0
    public void Start()
    {
        soundManager = SoundManager.instance;
        input        = GetComponent <InputComponent>();

        input.OnInventoryMoveLeft  += ChangeSlotLeft;
        input.OnInventoryMoveRight += ChangeSlotRight;
        input.OnUseInventoryItem   += UseItemSelected;
        input.OnInventoryDropItem  += DropItemSelected;

        slots = new GameObject[numberOfSlots];

        for (int i = 0; i < numberOfSlots; i++)
        {
            slots[i] = slotHolder.transform.GetChild(i).gameObject;

            if (slots[i].GetComponent <Slot>().itemName == "")
            {
                slots[i].GetComponent <Slot>().isEmpty = true;
            }
        }

        // Get each slot in the Inventories assigned Grid
        itemSlots = slotHolder.GetComponentsInChildren <Slot>();
    }
Exemple #20
0
    public override void Tick(float deltaTime)
    {
        for (int i = 0; i < filters.Length; i++)
        {
            // cache variables
            Filter              filter        = filters[i];
            InventoryComponent  inventoryComp = filter.inventoryComponent;
            InputComponent      inputComp     = filter.inputComponent;
            InteractorComponent interactComp  = filter.interactorComponent;


            // ----- logic -----
            if (inputComp.GetKeyDown(KeyCode.E) || inputComp.GetButtonDown("Fire1"))
            {
                isGathering = true;
            }
            else if (inputComp.GetKeyUp(KeyCode.E) || inputComp.GetButtonUp("Fire1") || isGathering == false)
            {
                //stop gather
                interactedTime = 0f;
                isGathering    = false;
                player.uiComponent.gatheringPrompt.ProgressFill(0);
            }

            if (isGathering)
            {
                AttemptWorldInteract(interactComp, player.inventoryComponent, inputComp.worldInteractMask);
                interactComp.SetInteractMode(InteractMode.Object);
            }
        }
    }
Exemple #21
0
        public static void OnBeginPlay()
        {
            Assert.IsFalse(variable.IsBool);
            Assert.IsFalse(variable.IsFloat);
            Assert.IsFalse(variable.IsString);
            Assert.IsTrue(variable.IsInt);
            Assert.IsTrue(variable.GetInt() == variableValue);

            variable.SetOnChangedCallback(VariableEvent);

            ConsoleManager.RegisterCommand(consoleCommand, "Executes a test command", ConsoleCommand);

            Assert.IsTrue(ConsoleManager.IsRegisteredVariable(consoleCommand));

            Engine.AddActionMapping(pauseResumeAction, pauseResumeKey);
            Engine.AddAxisMapping(mouseXAction, mouseXKey);
            Engine.AddAxisMapping(mouseYAction, mouseYKey);

            InputComponent inputComponent = playerController.InputComponent;

            Assert.IsFalse(inputComponent.HasBindings);

            inputComponent.BindAction(pauseResumeAction, InputEvent.Pressed, PauseResume, true);
            inputComponent.BindAxis(mouseXAction, MouseXMessage);
            inputComponent.BindAxis(mouseYAction, MouseYMessage);

            Assert.IsTrue(inputComponent.HasBindings);
        }
Exemple #22
0
    public override void Initialize(Transform[] objects)
    {
        // list because I don't know size here
        List <Filter> tmpFilters = new List <Filter>();
        int           index      = 0;

        for (int i = 0; i < objects.Length; i++)
        {
            // check performance
            LightComponent lc = objects[i].GetComponent <LightComponent>();
            InputComponent ic = objects[i].GetComponent <InputComponent>();

            if (lc && ic)
            {
                tmpFilters.Add(new Filter(index, objects[i].gameObject, ic, lc));
                lightyComp = lc;
            }
        }

        filters = tmpFilters.ToArray();
        player.uiComponent.torchIndicator.SetImageFillAmount(1, 0f);
        player.uiComponent.torchIndicator.SetImageFillAmount(2, 0f);
        player.uiComponent.torchIndicator.SetImageFillAmount(3, 0f);
        gridComp = GetComponentInChildren <GridComponent>();
    }
        public RheinwerkGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.IsFullScreen = false;

            // Objektinstanzen erzeugen
            Input             = new InputComponent(this);
            Input.UpdateOrder = 0;

            Scene             = new SceneComponent(this);
            Scene.UpdateOrder = 2;
            Scene.DrawOrder   = 0;

            Simulation             = new SimulationComponent(this);
            Simulation.UpdateOrder = 1;

            // Komponenten hinzufügen
            Components.Add(Input);
            Components.Add(Scene);
            Components.Add(Simulation);

            // Update Order bestimmt in welcher Reihenfolge die Komponenten gemalt werden
            Input.UpdateOrder      = 0;
            Simulation.UpdateOrder = 1;
            Scene.UpdateOrder      = 2;
        }
Exemple #24
0
 public static void GOTO_STATE2(AiComponent aicomponent, InputComponent input)
 {
     Debug.Log("GOTO_2");
     clearInputState(aicomponent, input);
     aicomponent.Dir        = 0;
     aicomponent.finishMove = false;
     aicomponent.timeCount  = 0;
     if (aicomponent.MoveState == 0)
     {
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd / 5;
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 2;
     }
     else if (aicomponent.MoveState == 1)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 4;
     }
     else if (aicomponent.MoveState == 3)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 8;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd / 5;
     }
     else if (aicomponent.MoveState == 5)
     {
         aicomponent.entity.moveComponent.moveSpeed = aicomponent.entity.moveComponent.moveSpeed / 2;
         aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd = aicomponent.entity.tankComponent.gunEntity.gunComponent.shootCd / 5;
     }
     aicomponent.MoveState         = 2;
     aicomponent.StateChangeCount += 1;
     if (aicomponent.StateChangeCount > 4)
     {
         aicomponent.StateChangeCount = 0;
         GOTO_STATE3(aicomponent, input);
     }
 }
Exemple #25
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            ScreenHeight = graphics.PreferredBackBufferHeight;
            ScreenWidth  = graphics.PreferredBackBufferWidth;

            Input = new InputComponent(this)
            {
                UpdateOrder = 0
            };
            Components.Add(Input);

            Simulation = new SimulationComponent(this)
            {
                UpdateOrder = 1
            };
            Components.Add(Simulation);

            Scene = new SceneComponent(this)
            {
                UpdateOrder = 2, DrawOrder = 0
            };
            Components.Add(Scene);

            graphics.IsFullScreen = true;
        }
    public void Execute()
    {
        Entity         e     = _group.GetSingleEntity();
        InputComponent input = e.input;

        updatePlayer(input);
    }
Exemple #27
0
        protected override void Update()
        {
            base.Update();
            InputComponent inputComponent = (InputComponent)LogicComponent;
            SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>();

            if (inputComponent.value == true)
            {
                if (Selected)
                {
                    spriteRenderer.sprite = SelectedTrueSprite;
                }
                else
                {
                    spriteRenderer.sprite = TrueSprite;
                }
            }
            else
            {
                if (Selected)
                {
                    spriteRenderer.sprite = SelectedFalseSprite;
                }
                else
                {
                    spriteRenderer.sprite = FalseSprite;
                }
            }
        }
Exemple #28
0
        public OctoGame() : base()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            this.Window.Title     = "OctoAwesome";

            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;
            this.IsMouseVisible = true;

            input             = new InputComponent(this);
            input.UpdateOrder = 1;
            Components.Add(input);

            world             = new WorldComponent(this, input);
            world.UpdateOrder = 2;
            Components.Add(world);

            //camera = new CameraComponent(this, world, input);
            //camera.UpdateOrder = 3;
            //Components.Add(camera);

            camera3d             = new Camera3DComponent(this, world);
            camera3d.UpdateOrder = 3;
            Components.Add(camera3d);

            render3d           = new Render3DComponent(this, world, camera3d);
            render3d.DrawOrder = 1;
            Components.Add(render3d);
        }
Exemple #29
0
        /// <summary>
        /// Gets called whenever the player has been initialized.
        /// </summary>
        public override void OnPlayerInitialized( )
        {
            MediaComponent comp = MainWindow.Player.GetComponent <MediaComponent>( );

            comp.OnMediaLoaded += (Sender, Args) =>
            {
                OpenLocalSubs.IsEnabled = true;
                OpenOSSubs.IsEnabled    = true;
            };
            comp.OnMediaFailedToLoad += (Sender, Args) =>
            {
                OpenLocalSubs.IsEnabled = false;
                OpenOSSubs.IsEnabled    = false;
                EnableSubs.IsEnabled    = false;
                EnableSubs.IsChecked    = false;
            };

            InputComponent inputComponent = Player.GetComponent <InputComponent>( );

            inputComponent.OnShowControls += (Sender, Args) => this.Visibility = Visibility.Visible;
            inputComponent.OnHideControls += (Sender, Args) => this.Visibility = Visibility.Collapsed;

            SubtitlesComponent subs = MainWindow.Player.GetComponent <SubtitlesComponent>( );

            subs.OnSubtitlesFailedToLoad += SubsOnOnSubtitlesFailedToLoad;
            subs.OnSubtitlesLoaded       += SubsOnOnSubtitlesLoaded;
        }
Exemple #30
0
            public void AddInputWithSampleMouseAxisMappings(out InputComponent inputComponent, out AxisMapping lookRight, out AxisMapping lookUp)
            {
                lookRight = new AxisMapping {
                    AxisName = nameof(lookRight)
                };
                lookRight.HardwareAxes.Add(new HardwareAxis
                {
                    HardwareInputVariant = HardwareInputVariant.CreateMouseVariant(HardwareInputVariant.MouseVariant.AxisX),
                    Scale = 1.0
                });

                lookUp = new AxisMapping {
                    AxisName = nameof(lookUp)
                };
                lookUp.HardwareAxes.Add(new HardwareAxis
                {
                    HardwareInputVariant = HardwareInputVariant.CreateMouseVariant(HardwareInputVariant.MouseVariant.AxisY),
                    Scale = 1.0
                });

                var inputMapping = new InputMapping();

                inputMapping.AxisMappings.Add(lookUp);
                inputMapping.AxisMappings.Add(lookRight);

                inputComponent = new InputComponent {
                    InputMapping = inputMapping
                };

                var entity = new Entity();

                entity.AddComponent(inputComponent);

                _scene.AddEntity(entity);
            }
Exemple #31
0
        public Player(int x, int y, InputComponent input, PhysicsComponent physics)
        {
            _input   = input;
            _physics = physics;

            Position = new Vector2(x * Tile.Size, y * Tile.Size);
        }
Exemple #32
0
 public ControllerPlayer(ViewPlayer player)
 {
     model          = new ModelPlayer();
     inputComponent = new InputComponent(this);
     view           = GameObject.Instantiate(player.gameObject, model.position, Quaternion.identity, null).GetComponent <ViewPlayer>();
     view.SetController(this);
 }
Exemple #33
0
 public ControllerPlayer(GameObject player, Vector3 spawnPoint, Controls controls)
 {
     this.view  = GameObject.Instantiate(player, spawnPoint, Quaternion.identity, null).GetComponent <ViewPlayer>();
     this.model = new ModelPlayer(controls);
     view.SetController(this);
     inputComponent = new InputComponent(this);
 }
    void setVelocityByInput(Entity entity, InputComponent component)
    {
        Vector2 position = entity.position.pos;
        VelocityComponent velocity = entity.velocity;

        Entity cameraEntity = _camera.GetSingleEntity();
        float velocityOffsetY = cameraEntity.hasVelocity ? cameraEntity.velocity.vel.y : 0.0f;

        velocity.vel.Set((component.x - position.x) * 5.0f, (component.y - position.y) * 5.0f + velocityOffsetY);
    }
Exemple #35
0
 public InputComponent(Game game)
     : base(game)
 {
     Debug.Assert(s_theInput == null, "You cannot construct more than one InputComponent");
     keyCurrent = Keyboard.GetState();
     keyLast = keyCurrent;
     padCurrent = new GamePadState[4];
     padLast = new GamePadState[4];
     s_theInput = this;
 }
 public Entity ReplaceInput(int newX, int newY)
 {
     InputComponent component;
     if (hasInput) {
         WillRemoveComponent(ComponentIds.Input);
         component = input;
     } else {
         component = new InputComponent();
     }
     component.x = newX;
     component.y = newY;
     return ReplaceComponent(ComponentIds.Input, component);
 }
Exemple #37
0
        public TestOldMan(int playerNumber = 0)
        {
            mPlayerNumber = playerNumber;

            mPosition = new PositionComponent(this, 100, 100);
            mRotation = new RotationComponent(this);
            //mRenderable = new RenderableComponent(this);
            mPhysics = new PhysicsComponent(this);
            mAnimated = new AnimatedComponent(this);
            mInput = new InputComponent(this);
            mController = new PlayerControllerComponent(this);

            mHealth = new HealthComponent(this, 100.0f);
        }
Exemple #38
0
 public string GetAnimationId(InputComponent input)
 {
     if (input.Input.HasFlag(InputKey.Left)) {
         return "moveleft";
     }
     if (input.Input.HasFlag(InputKey.Right)) {
         return "moveright";
     }
     if (input.Input.HasFlag(InputKey.Up)) {
         return "moveup";
     }
     if (input.Input.HasFlag(InputKey.Down)) {
         return "movedown";
     }
     return "idle";
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="parent">The parent entity for this Component.</param>
        /// <note>The parent Entity MUST have a PositionComponent in order to construct this Component.</note>
        /// <note>The parent Entity MUST have an InputComponent in order to construct this Component.</note>
        public TheFinaleCameraComponent_cl(Entity_cl parent)
            : base(parent)
        {
            // Asserting here to ensure that the TheFinaleCameraComponent has all the required Components
            // These will be compiled out of the Release build
            Debug.Assert(mParentEntity.GetComponentOfType(typeof(PositionComponent)) != null, "TheFinaleCameraComponent: No PositionComponent exists on parent Entity!");
            Debug.Assert(mParentEntity.GetComponentOfType(typeof(InputComponent)) != null, "TheFinaleCameraComponent: No InputComponent exists on parent Entity!");

            mPositionComponent = (PositionComponent)mParentEntity.GetComponentOfType(typeof(PositionComponent));
            mInputComponent = (InputComponent)mParentEntity.GetComponentOfType(typeof(InputComponent));

            mInputComponent.AddKey("moveN", Keys.W);
            mInputComponent.AddKey("moveW", Keys.A);
            mInputComponent.AddKey("moveS", Keys.S);
            mInputComponent.AddKey("moveE", Keys.D);

            // Items at the same position as the camera should appear at the bottom of the screen, horizontally centered
            mScreenOffsetMatrix = Matrix.CreateTranslation(new Vector3((float)FNA.Game.BaseInstance.WindowWidth * 0.5f, (float)FNA.Game.BaseInstance.WindowHeight, 0));

            RecalculateTransformationMatrix();
        }
Exemple #40
0
        public TestNess(int playerNumber = 0)
        {
            mPlayerNumber = playerNumber;

            mPosition = new PositionComponent(this, 100, 100);
            mRotation = new RotationComponent(this);
            //mRenderable = new RenderableComponent(this);
            mPhysics = new PhysicsComponent(this);
            mAnimated = new AnimatedComponent(this);
            mInput = new InputComponent(this);
            mController = new PlayerControllerComponent(this);

            //switch (mPlayerNumber)
            //{
            //    case 0:
            //        // Player 0 means no human control.
            //        break;

            //    case 1:
            //        mInput.PlayerIndex = PlayerIndex.One;
            //        break;

            //    case 2:
            //        mInput.PlayerIndex = PlayerIndex.Two;
            //        break;

            //    case 3:
            //        mInput.PlayerIndex = PlayerIndex.Three;
            //        break;

            //    case 4:
            //        mInput.PlayerIndex = PlayerIndex.Four;
            //        break;
            //}

            mHealth = new HealthComponent(this, 100.0f);
        }
Exemple #41
0
        protected override void SetUpEnts()
        {
            //FileManager.LoadAllEntities(Path.Combine("..\\", "..\\", "..\\", "..\\", "..\\",
            //                                         "Maps", "Test", "ObjDefs", "Entities"), this.sys);
            //var dir = Directory.GetCurrentDirectory();
            //FileManager.LoadAllEntities(Path.Combine("..\\", "..\\",
            //                                         "Maps", "Test", "ObjDefs", "Entities"), this.sys);
            //FileManager.LoadAllEntities(Path.Combine("..\\", "..\\",
            //                                         "Maps", "Testing", "Entities", "test"), this.sys);
            //EntityEngine.Assets.Scenario scen = new EntityEngine.Assets.Scenario();

            this.LoadMapToCurrent("Testing");
            Asset scen = EntityEngine.FileManagerNS.FileManager.GetAssetsFromHierarchy("test", AssetType.Scenario)[0];
            //var scenario = EntityEngine.FileManagerNS.FileManager.LoadAssetJson<EntityEngine.Assets.Scenario>(scen);
            LoadScenario(scen);

            var menu = this.sys.GetComponentSystem<MenuComponent, MenuSystem>();
            menu.SetActiveGroup("");
            // axis: main

            // ToDo: use this code in Python to load maps
            //this.LoadMapToCurrent("Testing")
            //this.LoadScenario(EntityEngine.FileManagerNS.FileManager.GetAssetsFromHierarchy("test", EntityEngine.AssetType.Scenario)[0])

            var com = new InputComponent();
            com.IsActive = true;
            com.Input = (timeDelta, kbState) =>
            {
                var move = new List<float>() { 0, 0, 0 };
                var rot = new List<float>() { 0, 0, 0 };

                if (kbState["W"])
                    move[2] += 0.2f;
                if (kbState["S"])
                    move[2] += -0.2f;
                if (kbState["A"])
                    move[0] += 0.2f;
                if (kbState["D"])
                    move[0] += -0.2f;
                if (kbState["Q"])
                    move[1] += -0.2f;
                if (kbState["E"])
                    move[1] += 0.2f;

                if (kbState["Left"])
                {
                    float degree = 1;
                    float angle = (float)Math.PI * degree / 180.0f;
                    rot[1] += -angle;
                }
                if (kbState["Right"])
                {
                    float degree = 1;
                    float angle = (float)Math.PI * degree / 180.0f;
                    rot[1] += angle;
                }
                if (kbState["Up"])
                {
                    float degree = 1;
                    float angle = (float)Math.PI * degree / 180.0f;
                    rot[0] += angle;
                }
                if (kbState["Down"])
                {
                    float degree = 1;
                    float angle = (float)Math.PI * degree / 180.0f;
                    rot[0] += -angle;
                }
                if (kbState["C"])
                {
                    float degree = 1;
                    float angle = (float)Math.PI * degree / 180.0f;
                    rot[2] += angle;
                }
                if (kbState["Z"])
                {
                    float degree = 1;
                    float angle = (float)Math.PI * degree / 180.0f;
                    rot[2] += -angle;
                }

                if (move != new List<float>() { 0, 0, 0 })
                    render.Camera.Move(move[0], move[1], move[2]);
                if (rot != new List<float>() { 0, 0, 0 })
                    render.Camera.Rotate(rot[0], rot[1], rot[2]);
                render.Camera.UpdateViewMatrix();
            };
            this.sys.GetComponentSystem<InputComponent, InputSystem>()
                .AddComponent(com);
        }
Exemple #42
0
        public void HandleInput(SGDE.Game game, InputComponent input)
        {
            switch (input.Type)
            {
                case InputType.Keyboard:
                    SGDE.Input.Keyboard keyboard = (SGDE.Input.Keyboard)input;

                    if (keyboard.IsKeyPressed(Keys.Left))
                    {
                        this.Translate(-5, 0);
                    }
                    if (keyboard.IsKeyPressed(Keys.Right))
                    {
                        this.Translate(5, 0);
                    }
                    if (keyboard.IsKeyPressed(Keys.Up))
                    {
                        this.Translate(0, -5);
                    }
                    if (keyboard.IsKeyPressed(Keys.Down))
                    {
                        this.Translate(0, 5);
                    }
                    if (keyboard.IsKeyClicked(Keys.Escape))
                    {
                        game.Exit();
                    }
                    if (keyboard.IsKeyClicked(Keys.C))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    if (keyboard.IsKeyPressed(Keys.A))
                    {
                        this.Rotate(-1.0f);
                    }
                    if (keyboard.IsKeyPressed(Keys.D))
                    {
                        this.Rotate(1.0f);
                    }
                    if (keyboard.IsKeyPressed(Keys.W))
                    {
                        this.Scale(new Vector2(0.01f, 0.01f));
                    }
                    if (keyboard.IsKeyPressed(Keys.X))
                    {
                        this.Scale(new Vector2(-0.01f, -0.01f));
                    }
                    if (keyboard.IsKeyClicked(Keys.Space))
                    {
                        this.ShootProjectile();
                    }

                    break;
                case InputType.GamePad:
                    SGDE.Input.GamePad gamePad = (SGDE.Input.GamePad)input;
                    Vector2 leftThumb = gamePad.GetThumbstickPosition(GamePadComponent.LeftStick);

                    if (leftThumb != Vector2.Zero)
                    {
                        this.Translate(leftThumb.X * 5, leftThumb.Y * -5);
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.Back))
                    {
                        game.Exit();
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.A))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    break;
            }
        }
 public Entity AddInput(InputComponent component)
 {
     return AddComponent(ComponentIds.Input, component);
 }
Exemple #44
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Note: use this.Content to load your game contents here

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Create needed input components
            inputManager = new InputComponent(this, true, true, false, false);

            //Loads all the sprites
            planeSprite = new GameSprite(Content.Load<Texture2D>("plane"), 1, 3, 0, 0.5);

            //Create Game objects
             planeObject = new GameObject(planeSprite, Window.ClientBounds.Width / 2 - planeSprite.Width / 2,
                 Window.ClientBounds.Height - planeSprite.Height);
        }
Exemple #45
0
        public void HandleInput(SGDE.Game game, InputComponent input)
        {
            switch (input.Type)
            {
                case InputType.Keyboard:
                    SGDE.Input.Keyboard keyboard = (SGDE.Input.Keyboard)input;
                    if (keyboard.IsKeyPressed(Keys.Left))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(5, 0));
                        }
                        else
                        {
                            this.Translate(-5, 0);
                        }
                    }
                    else if (keyboard.IsKeyPressed(Keys.Right))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(-5, 0));
                        }
                        else
                        {
                            this.Translate(5, 0);
                        }
                    }
                    if (keyboard.IsKeyPressed(Keys.Up))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(0, 5));
                        }
                        else
                        {
                            this.Translate(0, -5);
                        }
                    }
                    else if (keyboard.IsKeyPressed(Keys.Down))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            game.CameraControl.Translate(new Vector2(0, -5));
                        }
                        else
                        {
                            this.Translate(0, 5);
                        }
                    }

                    if (keyboard.IsKeyPressed(Keys.O))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            this.Scale(0.9f);
                        }
                        else
                        {
                            game.CameraControl.Scale(0.9f);
                        }
                    }
                    else if (keyboard.IsKeyPressed(Keys.I))
                    {
                        if (keyboard.IsKeyPressed(Keys.LeftShift))
                        {
                            this.Scale(1.1f);
                        }
                        else
                        {
                            game.CameraControl.Scale(1.1f);
                        }
                    }
                    if (keyboard.IsKeyPressed(Keys.R))
                    {
                        game.CameraControl.Rotate((float)(Math.PI / 32));
                    }
                    else if (keyboard.IsKeyPressed(Keys.L))
                    {
                        game.CameraControl.Rotate(-(float)(Math.PI / 32));
                    }

                    if (keyboard.IsKeyClicked(Keys.Escape))
                    {
                        game.Exit();
                    }
                    if (keyboard.IsKeyClicked(Keys.C))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    break;
                case InputType.GamePad:
                    SGDE.Input.GamePad gamePad = (SGDE.Input.GamePad)input;
                    Vector2 leftStick = gamePad.GetThumbstickPosition(GamePadComponent.LeftStick);
                    if (leftStick != Vector2.Zero)
                    {
                        this.Translate(leftStick.X * 5, -leftStick.Y * 5);
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.Back))
                    {
                        game.Exit();
                    }
                    if (gamePad.IsButtonClicked(GamePadComponent.A))
                    {
                        ((Game1)game).ToggleCollision();
                    }
                    break;
                case InputType.Mouse:
                    SGDE.Input.Mouse mouse = (SGDE.Input.Mouse)input;
                    Vector2 diff = mouse.PositionDiff;
                    this.Translate(diff.X, diff.Y);
                    break;
            }
        }
 void updatePlayer(InputComponent component)
 {
     bool isDown = component.isDown;
     foreach (Entity player in _players.GetEntities()) {
         if (isDown) {
             setVelocityByInput(player, component);
             setWeapon(player);
             normalGameSpeed();
         }
         else {
             slowGameSpeed();
             slowDown(player);
             removeWeapon(player);
         }
     }
 }
Exemple #47
0
        public void HandleInput(SGDE.Game game, InputComponent input)
        {
            SGDE.Input.Keyboard keyboard = (SGDE.Input.Keyboard)input;

            if (!staggered)
            {
                if (keyboard.IsKeyPressed(Keys.Left))
                {
                    this.Translate(-5, 0);
                    if (dir != PlayerDirection.Left)
                    {
                        if (!knockBack)
                            this.SpriteImage.SetAnimation("WalkLeft");
                        else
                            this.SpriteImage.SetAnimation("KnockBackLeft");
                        dir = PlayerDirection.Left;
                    }
                }
                else if (keyboard.IsKeyPressed(Keys.Right))
                {
                    this.Translate(5, 0);
                    if (dir != PlayerDirection.Right)
                    {
                        if (!knockBack)
                            this.SpriteImage.SetAnimation("WalkRight");
                        else
                            this.SpriteImage.SetAnimation("KnockBackRight");
                        dir = PlayerDirection.Right;
                    }
                }
                else
                {
                    this.SetVelocity(0, this.GetVelocity().Y);
                    switch (dir)
                    {
                        case PlayerDirection.Right:
                            if (!knockBack)
                                this.SpriteImage.SetAnimation("StandRight");
                            else
                                this.SpriteImage.SetAnimation("KnockBackRight");
                            dir = PlayerDirection.StandingRight;
                            break;
                        case PlayerDirection.Left:
                            if (!knockBack)
                                this.SpriteImage.SetAnimation("StandLeft");
                            else
                                this.SpriteImage.SetAnimation("KnockBackLeft");
                            dir = PlayerDirection.StandingLeft;
                            break;
                    }
                }

                if (keyboard.IsKeyPressed(Keys.Up))
                {
                    if (onGround && this.GetCollisionUnit().HasCollisions())
                    {
                        this.SetVelocity(this.GetVelocity().X, -10.0f);
                        onGround = false;
                    }
                }

                if (keyboard.IsKeyPressed(Keys.Z) && Game1.superJumpActive)
                {
                    if (onGround && this.GetCollisionUnit().HasCollisions())
                    {
                        this.SetVelocity(this.GetVelocity().X, -13.0f);
                        onGround = false;
                    }
                }
            }
            if (keyboard.IsKeyPressed(Keys.Escape))
                game.Exit();
        }