IEnumerator CheckSleep() { if (screenFader.isRunning || isForceSleeping) { yield return(null); } else { int hour = clock.GetHours((long)clock.currentGameTime); if (hour >= 3 && hour < 6 && !isForceSleeping) { isForceSleeping = true; yield return(StartCoroutine(screenFader.FadeToColor(Constants.Colors.FADE, .5f))); Action action = gameManager.GetActionWithTag(Constants.Actions.SLEEP_NIGHT); UpdateStats(action); SavePlayerData(); playerOrientation = PlayerOrientation.Down; walking = false; UpdatePlayerAnimation(playerOrientation, walking); SceneManager.LoadScene(Constants.Levels.LEVEL_1); isForceSleeping = false; } } }
protected void SetOrientation(PlayerOrientation _orientation = PlayerOrientation.UP) { orientation = _orientation; Debug.Log("orientation set to " + orientation); float _z = 0; switch (orientation) { case PlayerOrientation.LEFT: _z = 90; break; case PlayerOrientation.RIGHT: _z = -90; break; case PlayerOrientation.DOWN: _z = 180; break; } transform.rotation = Quaternion.Euler(0, 0, _z); rigidbody.position = new Vector3(Mathf.Floor(transform.position.x), Mathf.Floor(transform.position.y), Mathf.Floor(transform.position.z)) + Vector3.one * 0.5f; animator.TryChangeState(PlayerState.TURN, asOverlay: true); }
private void UpdatePlayerAnimation(PlayerOrientation playerOrientation, bool walking) { animator.SetBool("up", playerOrientation == PlayerOrientation.Up); animator.SetBool("down", playerOrientation == PlayerOrientation.Down); animator.SetBool("left", playerOrientation == PlayerOrientation.Left); animator.SetBool("right", playerOrientation == PlayerOrientation.Right); animator.SetBool("walking", walking); }
void Start() { startTime = Time.time; hitObjectText = GameObject.Find("Timer").GetComponent(typeof(Text)) as Text; timer = GameObject.Find("Timer").GetComponent(typeof(CountdownTimer)) as CountdownTimer; walk = GameObject.Find("Player").GetComponent(typeof(PlayerWalk)) as PlayerWalk; cameraSwitcher = GameObject.Find("floor").GetComponent(typeof(PlayerOrientation)) as PlayerOrientation; }
void Jump(Vector2 direction) { rb.AddForce(direction, ForceMode2D.Force); rb.velocity = (direction.normalized * JumpCharge); transform.localScale = new Vector3(Mathf.Sign(rb.velocity.x), 1, 1); BatteryController.Instance.followOffset = new Vector3(BatteryController.Instance.followOffset.x - Mathf.Sign(rb.velocity.x) * BatteryController.Instance.followOffset.x, 0, 0); orientationState = PlayerOrientation.Vertical; }
public override void Input() { IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap; foreach (PulseAbility pa in WatchedComponents.Where(c => c is PulseAbility)) { ButtonInput pulseButton = inputMap.Pulse; if (pa.Owner.GetComponent <Health>() is Health health && health.CurrentHealth <= 0) { continue; } if (pa.EnergyMeter >= pa.PulseCost) { if (pulseButton.Consume()) { double strength = (pa.PulseStrength * Math.Sqrt(pa.EnergyMeter / pa.MaxEnergy)); if (pa.Owner.Components.Has <Physical>() && pa.Owner.Components.Has <PlayerOrientation>()) { pa.Owner.Components.Get <Physical>().Velocity = pa.Owner.Components.Get <PlayerOrientation>().Unit * -strength; ISoundEffect sound_low = Woofer.Controller.AudioUnit["pulse_low"]; sound_low.Pitch = (float)(strength / 256) - 1; ISoundEffect sound_mid = Woofer.Controller.AudioUnit["pulse_mid"]; sound_mid.Pitch = sound_low.Pitch; ISoundEffect sound_high = Woofer.Controller.AudioUnit["pulse_high"]; sound_high.Pitch = sound_low.Pitch; sound_low.Volume = 0.6f; sound_low.Play(); sound_mid.Play(); sound_high.Play(); } pa.EnergyMeter -= pa.PulseCost; if (pa.Owner.Components.Has <Spatial>()) { Spatial sp = pa.Owner.Components.Get <Spatial>(); if (sp == null) { continue; } PlayerOrientation po = pa.Owner.Components.Get <PlayerOrientation>(); Owner.Events.InvokeEvent(new PulseEvent(pa, sp.Position + pa.Offset, po != null ? po.Unit : new Vector2D(), strength, pa.MaxRange)); } } } } }
public override void Update() { foreach (PlayerAnimation player in WatchedComponents) { Physical physical = player.Owner.Components.Get <Physical>(); PlayerMovementComponent movement = player.Owner.Components.Get <PlayerMovementComponent>(); PlayerOrientation orientation = player.Owner.Components.Get <PlayerOrientation>(); PulseAbility pulse = player.Owner.Components.Get <PulseAbility>(); if (physical == null || movement == null || orientation == null) { continue; } if (pulse != null && pulse.EnergyMeter == 0) { player.WooferBlinkingTime += Owner.DeltaTime; if (player.WooferBlinkingTime >= 0.75) { player.WooferBlinkingTime -= 0.75; } } else { player.WooferBlinkingTime = 0; } if (!movement.OnGround || Math.Abs(physical.Velocity.X) <= 1e-2) { player.WalkAnimationProgress = 0; } else if (Math.Abs(physical.Velocity.X) > 1e-2) { //Console.WriteLine("frames: " + ((int)(Owner.DeltaTime/Owner.FixedDeltaTime))); if (orientation.Unit.X == 0 || orientation.Unit.X / Math.Abs(orientation.Unit.X) == physical.Velocity.X / Math.Abs(physical.Velocity.X)) { player.WalkAnimationProgress++; } else { player.WalkAnimationProgress--; } int frameDuration = 8; int animationFrames = 6; if (player.WalkAnimationProgress >= animationFrames * frameDuration) { player.WalkAnimationProgress = 0; } else if (player.WalkAnimationProgress <= 0) { player.WalkAnimationProgress = animationFrames * frameDuration - 1; } } } }
private void OnTriggerEnter(Collider other) { if (!other.CompareTag("Player")) { return; } PlayerOrientation po = other.gameObject.GetComponent <PlayerOrientation>(); po.hasFlashlight = true; other.gameObject.transform.GetChild(0).gameObject.SetActive(true); Destroy(this.gameObject); }
void Awake() { startingPosition = transform.position; daysRemaining = GameObject.Find("RemainingDays").GetComponent <DayCounterScript>(); eventSystem = GameObject.Find("EventSystem"); mplayer = GameObject.Find("PersistentDataObject").GetComponent <MusicPlayer>(); clock = GameObject.Find("Clock").GetComponent <ClockManager>(); pointer = GetComponent <SliderController>(); animator = GetComponent <Animator>(); gameManager = FindObjectOfType <GameManager>(); dialogController.gameObject.SetActive(true); playerOrientation = PlayerOrientation.Down; screenFader = GameObject.Find("Fader").GetComponent <ScreenFader>(); isForceSleeping = (PlayerPrefs.GetInt(Constants.Prefs.FORCE_SLEEPING, Constants.Prefs.Defaults.FORCE_SLEEPING) == 1); bool hasSavedGame = (PlayerPrefs.GetFloat(Constants.Prefs.GAME_TIME, Constants.Prefs.Defaults.GAME_TIME) > 0); if (hasSavedGame) { LoadPlayerData(); } bool hasChangedFloor = PlayerPrefs.GetInt(Constants.Prefs.CHANGING_FLOOR, Constants.Prefs.Defaults.CHANGING_FLOOR) == 1; if (isForceSleeping) { gameManager.Reset(); daysRemaining.ShowRemainingDays(); StartCoroutine(DisplayDailyMessage()); isForceSleeping = false; PlayerPrefs.SetInt(Constants.Prefs.FORCE_SLEEPING, Constants.Prefs.Defaults.FORCE_SLEEPING); SavePlayerData(); } else if (hasChangedFloor) { mplayer.StopLoopedFootsteps(); transform.position = new Vector3(-0.86f, 3.88f, 0f); playerOrientation = PlayerOrientation.Right; PlayerPrefs.SetInt(Constants.Prefs.CHANGING_FLOOR, Constants.Prefs.Defaults.CHANGING_FLOOR); SavePlayerData(); } UpdatePlayerAnimation(playerOrientation, false); }
public override void Input() { IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap; foreach (PulseAbility pa in WatchedComponents.Where(c => c is PulseAbility)) { ButtonState pulseButton = inputMap.Pulse; if (pulseButton.IsPressed()) { pa.Pulse.RegisterPressed(); } else { pa.Pulse.RegisterUnpressed(); } if (pa.EnergyMeter >= pa.PulseCost) { if (pulseButton.IsPressed() && pa.Pulse.Execute()) { double strength = (pa.PulseStrength * Math.Sqrt(pa.EnergyMeter / pa.MaxEnergy)); if (pa.Owner.Components.Has <Physical>() && pa.Owner.Components.Has <PlayerOrientation>()) { pa.Owner.Components.Get <Physical>().Velocity = pa.Owner.Components.Get <PlayerOrientation>().Unit * -strength; } pa.EnergyMeter -= pa.PulseCost; if (pa.Owner.Components.Has <Spatial>()) { Spatial sp = pa.Owner.Components.Get <Spatial>(); if (sp == null) { continue; } PlayerOrientation po = pa.Owner.Components.Get <PlayerOrientation>(); Owner.Events.InvokeEvent(new PulseEvent(pa, sp.Position, po != null ? po.Unit : new Vector2D(), strength, pa.MaxRange)); } } } } }
public void LoadPlayerData() { clock.use24hour = PlayerPrefs.GetInt(Constants.Prefs.USE_24_HOUR_CLOCK, Constants.Prefs.Defaults.USE_24_HOUR_CLOCK) == 1; clock.currentGameTime = PlayerPrefs.GetFloat(Constants.Prefs.GAME_TIME, Constants.Prefs.Defaults.GAME_TIME); pointer.value = PlayerPrefs.GetFloat(Constants.Prefs.PLAYER_STATUS, Constants.Prefs.Defaults.PLAYER_STATUS); if (!isForceSleeping) { Vector2 newPosition = Vector2.zero; newPosition.x = PlayerPrefs.GetFloat(Constants.Prefs.LAST_POSITION_X, Constants.Prefs.Defaults.LAST_POSITION_X); newPosition.y = PlayerPrefs.GetFloat(Constants.Prefs.LAST_POSITION_Y, Constants.Prefs.Defaults.LAST_POSITION_Y); transform.position = newPosition; playerOrientation = (PlayerOrientation)PlayerPrefs.GetInt(Constants.Prefs.LAST_ORIENTATION, Constants.Prefs.Defaults.LAST_ORIENTATION); } UpdatePlayerAnimation(playerOrientation, false); }
public void LoadPlayerData() { clock.use24hour = PlayerPrefs.GetInt(Constants.Prefs.USE_24_HOUR_CLOCK, Constants.Prefs.Defaults.USE_24_HOUR_CLOCK) == 1; clock.currentGameTime = PlayerPrefs.GetFloat(Constants.Prefs.GAME_TIME, Constants.Prefs.Defaults.GAME_TIME); pointer.value = PlayerPrefs.GetFloat(Constants.Prefs.PLAYER_STATUS, Constants.Prefs.Defaults.PLAYER_STATUS); if(!isForceSleeping) { Vector2 newPosition = Vector2.zero; newPosition.x = PlayerPrefs.GetFloat(Constants.Prefs.LAST_POSITION_X, Constants.Prefs.Defaults.LAST_POSITION_X); newPosition.y = PlayerPrefs.GetFloat(Constants.Prefs.LAST_POSITION_Y, Constants.Prefs.Defaults.LAST_POSITION_Y); transform.position = newPosition; playerOrientation = (PlayerOrientation) PlayerPrefs.GetInt(Constants.Prefs.LAST_ORIENTATION, Constants.Prefs.Defaults.LAST_ORIENTATION); } UpdatePlayerAnimation(playerOrientation, false); }
public static Vector3 ToVector(this PlayerOrientation orientation) { switch (orientation) { case PlayerOrientation.UP: return(Vector3.up); case PlayerOrientation.RIGHT: return(Vector3.right); case PlayerOrientation.DOWN: return(Vector3.down); case PlayerOrientation.LEFT: return(Vector3.left); } return(Vector3.zero); }
void ProcessInput() { walking = false; if (!isPaused) { if (Input.GetButton("MoveUp")) { walking = true; playerOrientation = PlayerOrientation.Up; } if (Input.GetButton("MoveDown")) { walking = true; playerOrientation = PlayerOrientation.Down; } if (Input.GetButton("MoveLeft")) { walking = true; playerOrientation = PlayerOrientation.Left; } if (Input.GetButton("MoveRight")) { walking = true; playerOrientation = PlayerOrientation.Right; } if (Input.GetButtonDown("Action") && interactiveObject != null && !interacting) { StartCoroutine(Interact()); } } if (Input.GetButtonDown("Pause") && !screenFader.isRunning) { TogglePause(); } }
public static PlayerOrientation ToOpposite(this PlayerOrientation orientation) { return((PlayerOrientation)((int)(orientation + 2) % 4)); }
IEnumerator Interact() { Action action = dialogController.currentAction; if(action != null && action.active && action.interactable) { interacting = true; mplayer.PlayInteraction(); walking = false; animator.SetBool("walking", walking); if(action.tag == Constants.Actions.SUBMIT_THESIS) { yield return GameObject.FindObjectOfType<GameManager>().EndGame(true); } else if(action.tag == Constants.Actions.READ_LETTER) { interacting = false; action.active = false; Action letterAction = gameManager.GetActionWithTag(Constants.Actions.OPENED_LETTER); letterAction.text = Constants.Strings.LETTER_MESSAGE; letterAction.active = true; interactiveObject = null; dialogController.background.rectTransform.sizeDelta += new Vector2(200, 200); dialogController.dialogText.rectTransform.sizeDelta += new Vector2(200, 200); } else { if(gameManager.CanExecuteAction(action)) { if(action.tag == Constants.Actions.SLEEP_NIGHT) { yield return screenFader.FadeToColor(Constants.Colors.FADE, 0.25f); interactiveObject = null; dialogController.Hide(); transform.position = startingPosition; playerOrientation = PlayerOrientation.Down; UpdatePlayerAnimation(playerOrientation, false); UpdateSpriteZOrder(); UpdateStats(action); daysRemaining.ShowRemainingDays(); StartCoroutine(DisplayDailyMessage()); } else { yield return screenFader.FadeToColor(Constants.Colors.FADE, 0.25f); UpdateStats(action); yield return screenFader.FadeToColor(Color.clear, 0.25f); } } else { interacting = false; dialogController.currentAction = null; lastActionInteractable = action.interactable; lastActionText = action.text; action.interactable = false; action.text = Constants.Strings.WAIT_MESSAGE; } } } interacting = false; yield return null; }
IEnumerator Interact() { Action action = dialogController.currentAction; if (action != null && action.active && action.interactable) { interacting = true; mplayer.PlayInteraction(); walking = false; animator.SetBool("walking", walking); if (action.tag == Constants.Actions.SUBMIT_THESIS) { yield return(GameObject.FindObjectOfType <GameManager>().EndGame(true)); } else if (action.tag == Constants.Actions.READ_LETTER) { interacting = false; action.active = false; Action letterAction = gameManager.GetActionWithTag(Constants.Actions.OPENED_LETTER); letterAction.text = Constants.Strings.LETTER_MESSAGE; letterAction.active = true; interactiveObject = null; dialogController.background.rectTransform.sizeDelta += new Vector2(200, 200); dialogController.dialogText.rectTransform.sizeDelta += new Vector2(200, 200); } else { if (gameManager.CanExecuteAction(action)) { if (action.tag == Constants.Actions.SLEEP_NIGHT) { yield return(screenFader.FadeToColor(Constants.Colors.FADE, 0.25f)); interactiveObject = null; dialogController.Hide(); transform.position = startingPosition; playerOrientation = PlayerOrientation.Down; UpdatePlayerAnimation(playerOrientation, false); UpdateSpriteZOrder(); UpdateStats(action); daysRemaining.ShowRemainingDays(); StartCoroutine(DisplayDailyMessage()); } else { yield return(screenFader.FadeToColor(Constants.Colors.FADE, 0.25f)); UpdateStats(action); yield return(screenFader.FadeToColor(Color.clear, 0.25f)); } } else { interacting = false; dialogController.currentAction = null; lastActionInteractable = action.interactable; lastActionText = action.text; action.interactable = false; action.text = Constants.Strings.WAIT_MESSAGE; } } } interacting = false; yield return(null); }
public override void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r) { foreach (PlayerAnimation player in WatchedComponents) { Renderable renderable = player.Owner.Components.Get <Renderable>(); Vector2D[] offsets = new Vector2D[4]; offsets[Head] = new Vector2D(0, Origins[Head]); offsets[Legs] = new Vector2D(0, Origins[Legs]); offsets[Woofer] = new Vector2D(0, Origins[Woofer]); offsets[Arms] = new Vector2D(0, Origins[Arms]); if (!player.Initialized) { renderable.Sprites = new Sprite[] { new Sprite(player.SpritesheetName, Destination, new Rectangle(offsets[Head], 32, 32)), new Sprite(player.SpritesheetName, Destination, new Rectangle(offsets[Legs], 32, 32)), new Sprite(player.SpritesheetName, Destination, new Rectangle(offsets[Woofer], 32, 32)), new Sprite(player.SpritesheetName, Destination, new Rectangle(offsets[Arms], 32, 32)) }; player.Initialized = true; } Physical physical = player.Owner.Components.Get <Physical>(); PlayerOrientation orientation = player.Owner.Components.Get <PlayerOrientation>(); PulseAbility pulse = player.Owner.Components.Get <PulseAbility>(); if (orientation.Unit.X > 0 || player.LastLookedRight) { for (int i = Head; i <= Arms; i++) { offsets[i] += OrientationOffset; } } if (orientation.Unit.Y >= Math.Sin(Math.PI / 6)) { offsets[Head].X += 32; } else if (orientation.Unit.Y <= Math.Sin(-Math.PI / 6)) { offsets[Head].X += 64; } if (orientation.Unit.X != 0) { player.LastLookedRight = orientation.Unit.X > 0; } if (pulse != null) { offsets[Woofer].Y += 32 * 5 * (1 - (pulse.EnergyMeter / pulse.MaxEnergy)); } for (int i = Head; i <= Arms; i++) { renderable.Sprites[i].Source = new Rectangle(offsets[i], 32, 32); } } }
IEnumerator CheckSleep() { if (screenFader.isRunning || isForceSleeping) { yield return null; } else { int hour = clock.GetHours((long) clock.currentGameTime); if(hour >= 3 && hour < 6 && !isForceSleeping) { isForceSleeping = true; yield return StartCoroutine(screenFader.FadeToColor(Constants.Colors.FADE, .5f)); Action action = gameManager.GetActionWithTag(Constants.Actions.SLEEP_NIGHT); UpdateStats(action); SavePlayerData(); playerOrientation = PlayerOrientation.Down; walking = false; UpdatePlayerAnimation(playerOrientation, walking); SceneManager.LoadScene(Constants.Levels.LEVEL_1); isForceSleeping = false; } } }
private void UpdateLocalMap(float fElapsedTime) { m_script.ProcessCommands(fElapsedTime); // måste ha högst prioritet // proj knull // Erase and delete redundant projectiles // m_vecProjectiles.erase(remove_if(m_vecProjectiles.begin(), m_vecProjectiles.end(), [](const cDynamic* d) { return ((cDynamic_Projectile*)d)->bRedundant; }), m_vecProjectiles.end()); if (m_vecProjectiles != null && m_vecProjectiles.Any()) { if (m_vecProjectiles.Exists(x => x.Redundant == true)) { var tempList = m_vecProjectiles.Where(x => x.Redundant == false).ToList(); if (tempList.Any()) { m_vecProjectiles = tempList; } else { m_vecProjectiles = new List <DynamicObj>(); } } } // end proj knull if (m_script.UserControlEnabled) { // tillåt check för input, egentligen // borde innefatta "// Handle Input" fast det går ju sönder då, vet i fasiken hur han gjorde det. } else { if (m_bShowDialog) { if (GetKey(Key.Space).Released || GetKey(Key.T).Released) { m_bShowDialog = false; m_script.CompletedCommand(); } } } SlimDx.timer_Tick(); IIP = SlimDx.IIP; // Krabb för projektil bool firstInList = true; bool bWorkingWithProjectiles = false; List <List <DynamicObj> > krabbMedProjektiler = new List <List <DynamicObj> >(); krabbMedProjektiler.Add(listDynamics); if (m_vecProjectiles != null) { krabbMedProjektiler.Add(m_vecProjectiles); } foreach (var myObjectList in krabbMedProjektiler) // galet jäkla knulleri { foreach (var myObject in myObjectList) //foreach (var myObject in listDynamics) // TODO: känns som det blir betdligt bättre respnse om man flyttar lopen så inte allt körs i denna, men då tycks andra objekt förlora förmågan till gravitation och dylikt, kolla på det. { // Handle Input if (Focus && firstInList && m_script.UserControlEnabled) { playerTimer += fElapsedTime; if (playerTimer <= 0.1f) { GraphicsCounter = 0; } else if (playerTimer <= 0.2f) { GraphicsCounter = 1; } else if (playerTimer <= 0.3f) { GraphicsCounter = 2; } else if (playerTimer <= 0.4f) { GraphicsCounter = 3; } else if (playerTimer <= 0.5f) { GraphicsCounter = 4; //playerTimer -= 1.0f; playerTimer = 0.0f; } else { GraphicsCounter = 0; playerTimer = 0.0f; } //Test Gamepad if (!IIP.idle) { if (IIP.right) { } if (IIP.left) { } if (IIP.jump) { } if (IIP.otherButton) { } if (IIP.start) { } if (IIP.select) { } } //End test Gamepad //if (GetKey(VK_UP).bHeld) if (GetKey(Key.Up).Down) { //fPlayerVelY = -6.0f; m_pPlayer.vy = -6.0f; } //if (GetKey(VK_DOWN).bHeld) if (GetKey(Key.Down).Down) { //fPlayerVelY = 6.0f; m_pPlayer.vy = 6.0f; } //if (GetKey(VK_RIGHT).bHeld) if (GetKey(Key.Right).Down || IIP.right) { PlayerOrientation = PlayerOrientation.Right; // fPlayerVelX += (bPlayerOnGround ? 25.0f : 15.0f) * fElapsedTime; m_pPlayer.vx += (bPlayerOnGround ? 25.0f : 15.0f) * fElapsedTime; // Okså hastigheten //if (bPlayerOnGround) //{ // nDirModY = 0; // nDirModX = GraphicsCounter; //} //else //{ // nDirModY = PlayerOrientation == PlayerOrientation.Right ? 2 : 3; // nDirModX = 0; //} } //if (GetKey(VK_LEFT).bHeld) if (GetKey(Key.Left).Down || IIP.left) { PlayerOrientation = PlayerOrientation.Left; //fPlayerVelX += (bPlayerOnGround ? -25.0f : -15.0f) * fElapsedTime; m_pPlayer.vx += (bPlayerOnGround ? -25.0f : -15.0f) * fElapsedTime; // Okså hastigheten //if (bPlayerOnGround) //{ // nDirModY = 1; // nDirModX = GraphicsCounter; //} //else //{ // nDirModY = PlayerOrientation == PlayerOrientation.Right ? 2 : 3; // nDirModX = 0; //} } //if (GetKey(VK_SPACE).bPressed) // Har ingen hoppa i rpg if (GetKey(Key.Space).Pressed || IIP.jump) { if (myObject.vy == 0) { myObject.vy = -12.0f; //// nDirModX = 1; //nDirModX = 0; //// nDirModY = 2; // 2 Eller 3 beroended på vilket håll gubbe vänd mot //nDirModY = PlayerOrientation == PlayerOrientation.Right ? 2 : 3; } } // Testa script : scriptProcessor. if (GetKey(Key.Z).Released) { // spelaren går i en tiangel //m_script.AddCommand(new CommandMoveTo(m_pPlayer, 10, 10, 3.0f)); //m_script.AddCommand(new CommandMoveTo(m_pPlayer, 15, 10, 3.0f)); //m_script.AddCommand(new CommandMoveTo(m_pPlayer, 15, 15, 3.0f)); //m_script.AddCommand(new CommandMoveTo(m_pPlayer, 10, 10, 3.0f)); //m_script.AddCommand(new CommandMoveTo(listDynamics[1], 15, 5, 2.0f)); //m_script.AddCommand(new CommandMoveTo(listDynamics[1], 8, 5, 2.0f)); m_script.AddCommand(new CommandMoveTo(listDynamics[2], 8, 5, 2.0f)); m_script.AddCommand(new CommandMoveTo(listDynamics[2], 15, 5, 2.0f)); m_script.AddCommand(new CommandShowDialog(new List <string>() { "Grr" })); m_script.AddCommand(new CommandShowDialog(new List <string>() { "Jag ar ett monster" })); } // Testa interact // // Interaction requested if (GetKey(Key.I).Released) { // Grab a point from the direction the player is facing and check for interactions float fTestX = 0; float fTestY = 0; if (m_pPlayer.GetFacingDirection() == 0) // South { fTestX = m_pPlayer.px + 0.5f; fTestY = m_pPlayer.py + 1.5f; } if (m_pPlayer.GetFacingDirection() == 1) // West { fTestX = m_pPlayer.px - 0.5f; fTestY = m_pPlayer.py + 0.5f; } if (m_pPlayer.GetFacingDirection() == 2) // North { fTestX = m_pPlayer.px + 0.5f; fTestY = m_pPlayer.py - 0.5f; } if (m_pPlayer.GetFacingDirection() == 3) // East { fTestX = m_pPlayer.px + 1.5f; fTestY = m_pPlayer.py + 0.5f; } // Check if test point has hit a dynamic object bool bHitSomething = false; foreach (var dyns in listDynamics) { // Här vill jag nog har nåt snarlikt för att hoppa på fiende if (fTestX > dyns.px && fTestX < (dyns.px + 1.0f) && fTestY > dyns.py && fTestY < (dyns.py + 1.0f)) { if (dyns.Friendly) { bHitSomething = true; // Iterate through quest stack until something responds, the base quests should capture // interactions that are not specfied in other quests foreach (var quest in m_listQuests) { if (quest.OnInteraction(listDynamics, dyns, NATURE.TALK)) { bHitSomething = true; break; } } // Some objects just do stuff when you interact with them //dyns.OnInteract(m_pPlayer); // Then check if it is map related m_pCurrentMap.OnInteraction(listDynamics, dyns, NATURE.TALK); } else { // Interaction was with something not friendly - only enemies // are not friendly, so perfrom attack m_pPlayer.PerformAttack(); } } } if (!bHitSomething) // Default action is attack { m_pPlayer.PerformAttack(); } } if (GetKey(Key.M).Released) { m_nGameMode = (int)Mode.MODE_INVENTORY; } firstInList = false; } // Gravity myObject.vy += 20.0f * fElapsedTime; // Drag if (bPlayerOnGround) { myObject.vx += -3.0f * myObject.vx * fElapsedTime; if (Math.Abs(myObject.vx) < 0.01f) { myObject.vx = 0.0f; } } // Clamp velocities if (myObject.vx > 10.0f) { myObject.vx = 10.0f; } if (myObject.vx < -10.0f) { myObject.vx = -10.0f; } if (myObject.vy > 100.0f) { myObject.vy = 100.0f; } if (myObject.vy < -100.0f) { myObject.vy = -100.0f; } // hade väl räckt med att köra loopen från här, kanske? // DynamicObj myObject = m_pPlayer; float fNewObjectPosX = myObject.px + myObject.vx * fElapsedTime; float fNewObjectPosY = myObject.py + myObject.vy * fElapsedTime; // Collision float fBorder = 0.1f; // Hårdkoda hitbox (bevara för rpg!!) //projektil bool bCollisionWithMap = false; if (myObject.vx <= 0) // Moving Left { //(bevara för rpg!!) if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + 0.0f), (int)(myObject.py + 0.0f)) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + 0.0f), (int)(myObject.py + 0.9f))) //if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + fBorder), (int)(myObject.py + fBorder + 0.0f)) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + fBorder), (int)(myObject.py + (1.0f - fBorder)))) { fNewObjectPosX = (int)fNewObjectPosX + 1; //fPlayerVelX = 0; myObject.vx = 0; //projektil bCollisionWithMap = true; } } else // Moving Right { //(bevara för rpg!!) if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + (1.0f - fBorder)), (int)(myObject.py + fBorder + 0.0f)) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + (1.0f - fBorder)), (int)(myObject.py + (1.0f - fBorder)))) //if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + fBorder + 0.0f), (int)(fNewObjectPosY + fBorder)) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + (1.0f - fBorder)), (int)(fNewObjectPosY + fBorder))) { fNewObjectPosX = (int)fNewObjectPosX; //fPlayerVelX = 0; myObject.vx = 0; //projektil bCollisionWithMap = true; } } bPlayerOnGround = false; //if (fPlayerVelY <= 0) // Moving Up if (myObject.vy <= 0) { //(bevara för rpg!!) if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + 0.0f), (int)fNewObjectPosY) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + 0.9f), (int)fNewObjectPosY)) //if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + fBorder + 0.0f), (int)(fNewObjectPosY + fBorder)) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + (1.0f - fBorder)), (int)(fNewObjectPosY + fBorder))) { fNewObjectPosY = (int)fNewObjectPosY + 1; //fPlayerVelY = 0; myObject.vy = 0; //projektil bCollisionWithMap = true; } HasMovedUp = true; } else // Moving Down { //(bevara för rpg!!) if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + 0.0f), (int)(fNewObjectPosY + 1.0f)) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + 0.9f), (int)(fNewObjectPosY + 1.0f))) // if (m_pCurrentMap.GetSolid((int)(fNewObjectPosX + fBorder + 0.0f), (int)(fNewObjectPosY + (1.0f - fBorder))) || m_pCurrentMap.GetSolid((int)(fNewObjectPosX + (1.0f - fBorder)), (int)(fNewObjectPosY + (1.0f - fBorder)))) { fNewObjectPosY = (int)fNewObjectPosY; //fPlayerVelY = 0; myObject.vy = 0; bPlayerOnGround = true; //projektil bCollisionWithMap = true; } } // gjorde ta bort projektil väldigt snabb.. tror det har med min loop att göra //if (myObject.IsProjectile && bCollisionWithMap) //{ // myObject.Redundant = true; //} var didJustHitGround = HasMovedUp && bPlayerOnGround; if (didJustHitGround) { HasMovedUp = false; //nDirModX = 0; //nDirModY = PlayerOrientation == PlayerOrientation.Right ? 0 : 1; } //Collision dynamiska objekt float fDynamicObjectPosX = fNewObjectPosX; float fDynamicObjectPosY = fNewObjectPosY; foreach (var dyn in listDynamics) { if (dyn != myObject) { // if the object is solid then the player must not overlapp if (dyn.SolidVsDynamic && myObject.SolidVsDynamic) { // Check if bounding rectangles overlap if (fDynamicObjectPosX < (dyn.px + 1.0f) && (fDynamicObjectPosX + 1.0f) > dyn.px && myObject.py < (dyn.py + 1.0f) && (myObject.py + 1.0f) > dyn.py) { // First Check Horizontally - Check Left if (myObject.vx <= 0) { fDynamicObjectPosX = dyn.px + 1.0f; } else { fDynamicObjectPosX = dyn.px - 1.0f; } } if (fDynamicObjectPosX < (dyn.px + 1.0f) && (fDynamicObjectPosX + 1.0f) > dyn.px && fDynamicObjectPosY < (dyn.py + 1.0f) && (fDynamicObjectPosY + 1.0f) > dyn.py) { // First Check Vertically - Check Left if (myObject.vy <= 0) { fDynamicObjectPosY = dyn.py + 1.0f; } else { fDynamicObjectPosY = dyn.py - 1.0f; } } } else { if (myObject == listDynamics[0]) { // Object is player and can interact with things if (fDynamicObjectPosX < (dyn.px + 1.0f) && (fDynamicObjectPosX + 1.0f) > dyn.px && myObject.py < (dyn.py + 1.0f) && (myObject.py + 1.0f) > dyn.py) { // First check if object is part of a quest foreach (var quest in m_listQuests) { if (quest.OnInteraction(listDynamics, dyn, NATURE.WALK)) { break; } } // Then check if it is map related m_pCurrentMap.OnInteraction(listDynamics, dyn, NATURE.WALK); // Finally just check the object dyn.OnInteract(myObject); } } else { if (bWorkingWithProjectiles) { if (fDynamicObjectPosX < (dyn.px + 1.0f) && (fDynamicObjectPosX + 1.0f) > dyn.px && fDynamicObjectPosY < (dyn.py + 1.0f) && (fDynamicObjectPosY + 1.0f) > dyn.py) { if (dyn.Friendly != myObject.Friendly) { // We know object is a projectile, so dyn is something // opposite that it has overlapped with if (dyn.IsAttackable) { // Dynamic object is a creature Damage((cDynamic_Projectile)myObject, (Creature)dyn); } } } } } } } } // Apply new position //fPlayerPosX = fNewObjectPosX; //myObject.px = fNewObjectPosX; //fPlayerPosY = fNewObjectrPosY; //myObject.py = fNewObjectPosY; myObject.px = fDynamicObjectPosX; myObject.py = fDynamicObjectPosY; //Uppdatera Objektet! myObject.Update(fElapsedTime, m_pPlayer); // PART 3 time: 47:21 han har lagt loopen annorlunda här. KAnske kan vara bra för nåt, men jag fortsätter så här just nu } bWorkingWithProjectiles = true; } // Jag gissar lite här på vad det är han försöker åstadkomma var switchList = new List <Quest.Quest>(); foreach (var q in m_listQuests) { if (!q.bCompleted) { switchList.Add(q); } } m_listQuests = switchList; //// Link camera to player position fCameraPosX = m_pPlayer.px; // Ganska bra om det finns direkt tillgång till spelar obj, även om det kommer finnas massa olika obj, för kameran vill alltid följa spelaren. fCameraPosY = m_pPlayer.py; // Draw Levels int nTileWidth = 16; int nTileHeight = 16; //int nVisibleTilesX = ScreenWidth() / nTileWidth; int nVisibleTilesX = ScreenWidth / nTileWidth; //int nVisibleTilesY = ScreenHeight() / nTileHeight; int nVisibleTilesY = ScreenHeight / nTileHeight; // Calculate Top-Leftmost visible tile float fOffsetX = fCameraPosX - (float)nVisibleTilesX / 2.0f; float fOffsetY = fCameraPosY - (float)nVisibleTilesY / 2.0f; // Clamp camera to game boundaries if (fOffsetX < 0) { fOffsetX = 0; } if (fOffsetY < 0) { fOffsetY = 0; } // v1 //if (fOffsetX > nLevelWidth - nVisibleTilesX) fOffsetX = nLevelWidth - nVisibleTilesX; //if (fOffsetY > nLevelHeight - nVisibleTilesY) fOffsetY = nLevelHeight - nVisibleTilesY; if (fOffsetX > m_pCurrentMap.nWidth - nVisibleTilesX) { fOffsetX = m_pCurrentMap.nWidth - nVisibleTilesX; } if (fOffsetY > m_pCurrentMap.nHeight - nVisibleTilesY) { fOffsetY = m_pCurrentMap.nHeight - nVisibleTilesY; } // Get offsets for smooth movement float fTileOffsetX = (fOffsetX - (int)fOffsetX) * nTileWidth; float fTileOffsetY = (fOffsetY - (int)fOffsetY) * nTileHeight; // Draw visible tile map for (int x = -1; x < nVisibleTilesX + 1; x++) { for (int y = -1; y < nVisibleTilesY + 1; y++) { PixelEngine.Point firstMagicalParam = new Point(); PixelEngine.Point secondMagicalParam = new Point(); // m_pCurrentMap[0] int idx = m_pCurrentMap.GetIndex((int)(x + fOffsetX), (int)(y + fOffsetY)); //int sx = idx % 10; //column that the sprite is on // TODO: hårt nummer && tror det 'r antal tiles som finns i spriten //int sy = idx / 10; // row that the tile is on // TODO: hårt nummer int sx = idx % 5; //column that the sprite is on // TODO: hårt nummer && tror det 'r antal tiles som finns i spriten int sy = idx / 5; // row that the tile is on // TODO: hårt nummer var firstMagicalPlayerParamNew = new Point((int)(x * nTileWidth - fTileOffsetX), (int)(y * nTileHeight - fTileOffsetY)); var secondMagicalPlayerParamNew = new Point((int)(sx * nTileWidth), (int)(sy * nTileWidth)); DrawPartialSprite(firstMagicalPlayerParamNew, m_pCurrentMap.pSprite, secondMagicalPlayerParamNew, nTileWidth, nTileHeight); } } // Draw all objekts bool firstInDraw = true; foreach (var VARIABLE in krabbMedProjektiler)// Knulleriet fortsätter { foreach (var myObject in VARIABLE) //foreach (var myObject in listDynamics) { if (firstInDraw) { firstInDraw = false; } else { myObject.DrawSelf(this, fOffsetX, fOffsetY); } } } // hac tills vidare för att rita spelare längst fram. det är en lista och det sista som ritas är det som syns högst upp m_pPlayer.DrawSelf(this, fOffsetX, fOffsetY); // hyffsat obra, fixa loopen ist. // Draw health to screen string sHealth = "HP: " + m_pPlayer.Health.ToString() + "/" + m_pPlayer.MaxHealth.ToString(); DisplayDialog(new List <string>() { sHealth }, 160, 10); if (m_bShowDialog) { DisplayDialog(m_vecDialogToShow, 20, 20); } //DrawBigText("Hello everybody "+idxBig,30,30 ); //idxBig++; }
public override void Render <TSurface, TSource>(ScreenRenderer <TSurface, TSource> r) { foreach (PlayerAnimation player in WatchedComponents) { Renderable renderable = player.Owner.Components.Get <Renderable>(); Vector2D[] srcOffsets = new Vector2D[5]; srcOffsets[Legs] = new Vector2D(0, Origins[Legs]); srcOffsets[Torso] = new Vector2D(0, Origins[Torso]); srcOffsets[Head] = new Vector2D(0, Origins[Head]); srcOffsets[Woofer] = new Vector2D(0, Origins[Woofer]); srcOffsets[Arms] = new Vector2D(0, Origins[Arms]); Vector2D[] destOffsets = new Vector2D[5]; destOffsets[Legs] = destOffsets[Torso] = destOffsets[Head] = destOffsets[Woofer] = destOffsets[Arms] = Vector2D.Empty; if (!player.Initialized) { renderable.Sprites = new List <Sprite>() { new Sprite(player.SpritesheetName, Destination, new Rectangle(srcOffsets[Legs], 32, 32)), new Sprite(player.SpritesheetName, Destination, new Rectangle(srcOffsets[Torso], 32, 32)), new Sprite(player.SpritesheetName, Destination, new Rectangle(srcOffsets[Head], 32, 32)), new Sprite("woofer", Destination, new Rectangle(srcOffsets[Woofer], 0, 0)), new Sprite(player.SpritesheetName, Destination, new Rectangle(srcOffsets[Arms], 32, 32)) }; player.Initialized = true; } Physical physical = player.Owner.Components.Get <Physical>(); PlayerMovementComponent movement = player.Owner.Components.Get <PlayerMovementComponent>(); PlayerOrientation orientation = player.Owner.Components.Get <PlayerOrientation>(); if (physical == null || movement == null || orientation == null) { continue; } PulseAbility pulse = player.Owner.Components.Get <PulseAbility>(); bool handsFree = pulse == null; if (orientation.Unit.X > 0 || player.LastLookedRight) { for (int i = Legs; i <= Arms; i++) { srcOffsets[i] += OrientationOffset; } } bool forceLook = handsFree && !movement.OnGround; if (orientation.Unit.Y >= Math.Sin(Math.PI / 9)) { if (!forceLook) { srcOffsets[Head].X += 32; } srcOffsets[Woofer].X += 32; if (!handsFree) { srcOffsets[Arms].X += 32; } if (orientation.Unit.Y >= Math.Sin(2 * Math.PI / 6)) { srcOffsets[Woofer].X += 32; if (!handsFree) { srcOffsets[Arms].X += 32; } } } else if (orientation.Unit.Y <= Math.Sin(-Math.PI / 9)) { if (!forceLook) { srcOffsets[Head].X += 64; } srcOffsets[Woofer].X += 96; if (!handsFree) { srcOffsets[Arms].X += 96; } if (orientation.Unit.Y <= Math.Sin(-2 * Math.PI / 6)) { srcOffsets[Woofer].X += 32; destOffsets[Woofer] += new Vector2D(0, -3); //Offset woofer down since it goes out of the spritesheet grid if (!handsFree) { srcOffsets[Arms].X += 32; } } } if (forceLook) { srcOffsets[Head].X += physical.Velocity.Y <= 0 ? 64 : 32; } if (orientation.Unit.X != 0) { player.LastLookedRight = orientation.Unit.X > 0; } if (pulse != null) { srcOffsets[Woofer].Y = 256; srcOffsets[Woofer].Y -= 32 * Math.Round(pulse.EnergyMeter / 20); if (pulse.EnergyMeter == 0 && player.WooferBlinkingTime >= 0.375) { srcOffsets[Woofer].Y += 32; } } if (handsFree) { srcOffsets[Arms].Y += 32; } if (!movement.OnGround || Math.Abs(physical.Velocity.X) <= 1e-2) /*player.WalkAnimationProgress = 0;*/ } {
private void FixedUpdate() { float xInput = Input.GetAxis("Horizontal"); float yInput = Input.GetAxis("Vertical"); rigidbody.velocity = transform.right * xInput * moveVelocity; bool duck = Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow); if (xInput < 0) { spriteRenderer.flipX = true; } if (xInput > 0) { spriteRenderer.flipX = false; } if (xInput == 0) { rigidbody.velocity = Vector3.zero; if (duck) { animator.TryChangeState(PlayerState.DUCKPARK); } else { animator.TryChangeState(PlayerState.PARK); } return; } else { if (duck) { animator.TryChangeState(PlayerState.DUCKDRIVE); } else { animator.TryChangeState(PlayerState.DRIVE); } } PlayerOrientation direction = InputToOrientation(xInput); Vector3 downleft = (GetOrientation().ToOpposite().ToVector() + direction.ToOpposite().ToVector()) / 2; bool infront = IsGroundInDirection(transform.position + direction.ToVector() / 2, direction.ToVector(), 0.1f); bool below = IsGroundInDirection(transform.position + downleft, (GetOrientation().ToOpposite().ToVector()), 0.1f); bool backleft = IsGroundInDirection(transform.position + downleft, downleft, 0.5f); if (!backleft && !infront && !below) { return; } if (infront) { SetOrientation(direction.ToOpposite()); rigidbody.velocity = InputToOrientation(xInput).ToVector() * rigidbody.velocity.magnitude; } else if (!below) { SetOrientation(direction); //rigidbody.velocity = Quaternion.Euler(0, 0, 90) * rigidbody.velocity; rigidbody.velocity = InputToOrientation(xInput).ToVector() * rigidbody.velocity.magnitude; } }
void Awake() { startingPosition = transform.position; daysRemaining = GameObject.Find("RemainingDays").GetComponent<DayCounterScript>(); eventSystem = GameObject.Find("EventSystem"); mplayer = GameObject.Find("PersistentDataObject").GetComponent<MusicPlayer>(); clock = GameObject.Find("Clock").GetComponent<ClockManager>(); pointer = GetComponent<SliderController>(); animator = GetComponent<Animator>(); gameManager = FindObjectOfType<GameManager>(); dialogController.gameObject.SetActive(true); playerOrientation = PlayerOrientation.Down; screenFader = GameObject.Find("Fader").GetComponent<ScreenFader>(); isForceSleeping = (PlayerPrefs.GetInt(Constants.Prefs.FORCE_SLEEPING, Constants.Prefs.Defaults.FORCE_SLEEPING) == 1); bool hasSavedGame = (PlayerPrefs.GetFloat(Constants.Prefs.GAME_TIME, Constants.Prefs.Defaults.GAME_TIME) > 0); if(hasSavedGame) { LoadPlayerData(); } bool hasChangedFloor = PlayerPrefs.GetInt(Constants.Prefs.CHANGING_FLOOR, Constants.Prefs.Defaults.CHANGING_FLOOR) == 1; if(isForceSleeping) { gameManager.Reset(); daysRemaining.ShowRemainingDays(); StartCoroutine(DisplayDailyMessage()); isForceSleeping = false; PlayerPrefs.SetInt(Constants.Prefs.FORCE_SLEEPING, Constants.Prefs.Defaults.FORCE_SLEEPING); SavePlayerData(); } else if (hasChangedFloor) { mplayer.StopLoopedFootsteps(); transform.position = new Vector3(-0.86f, 3.88f, 0f); playerOrientation = PlayerOrientation.Right; PlayerPrefs.SetInt(Constants.Prefs.CHANGING_FLOOR, Constants.Prefs.Defaults.CHANGING_FLOOR); SavePlayerData(); } UpdatePlayerAnimation(playerOrientation, false); }