/// <summary> /// Updates the animation. /// </summary> /// <param name="dt"></param> public void Update(float dt) { if (IsPlaying && SMH.TimePassed(_lastFrameChange, 1f / FPS)) { if ((_goingBackwards && _activeFrame == 0) || (!_goingBackwards && _activeFrame == _sprites.Count - 1)) { if (PingPong) { _goingBackwards = !_goingBackwards; } if (!Loop) { IsPlaying = false; } } if (IsPlaying) { if (_goingBackwards) { _activeFrame = _activeFrame == 0 ? _sprites.Count - 1 : _activeFrame - 1; } else { _activeFrame = _activeFrame == _sprites.Count - 1 ? 0 : _activeFrame + 1; } _lastFrameChange = SMH.Now; } } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (SMH game = new SMH()) { #if windows ((form)form.fromhandle(game.window.handle)).icon = new icon("game.ico"); #endif game.Run(); } }
/// <summary> /// Plays the switch sound effect originating from point (gridX, gridY). The sound will only be played if /// alwaysPlaySound is true or the sound is originating from a point close to Smiley. /// This method can be called as much as you want but it will only play a sound at maximum every SWITCH_SOUND_DELAY /// seconds to avoid it sounding like the dickens if a ton of switches are toggled at once. /// </summary> /// <param name="gridX"></param> /// <param name="gridY"></param> /// <param name="alwaysPlaySound"></param> public void PlaySwitchSound(int gridX, int gridY, bool alwaysPlaySound) { if (SMH.TimePassed(_lastSwitchTime, SwitchSoundDelay)) { bool inRange = Math.Abs(gridX - SMH.Player.Tile.X) <= 8 && Math.Abs(gridY - SMH.Player.Tile.Y) <= 6; if (alwaysPlaySound || inRange) { _lastSwitchTime = SMH.Now; PlaySound(Sound.Switch); } } }
private void UpdateTransition(float dt) { _timeInTransition += dt; _transitionScale += 2f * dt; if (_timeInTransition > 1.5f) { SMH.Sound.PlayMusic(Music.Town); SMH.StartGame(true); //TODO:smh->resources->Purge(ResourceGroups::Cinematic); } }
public bool Update(float dt) { int controlCount = 0; foreach (ControlInfo info in _controls) { if (_currentAction == ControlAction.CascadingMove) { if (!info.Started && SMH.TimePassed(_timeStartedAction, (float)controlCount * 0.15f)) { info.Started = true; info.TimeStarted = SMH.Now; } if (info.Started && !info.Finished) { info.Control.X += (_xDist / _duration) * dt; info.Control.Y += (_yDist / _duration) * dt; //Make sure that when the controls are coming up from off the screen they don't go past their //intended end point. This can happen sometimes when returning to the menu because the game is //processing a bunch of shit in one frame if (_yDist < 0 && info.Control.Y < info.StartY + _yDist) { info.Control.Y = info.StartY + _yDist; } if (SMH.TimePassed(info.TimeStarted, _duration)) { info.Finished = true; info.Control.X = info.StartX + _xDist; info.Control.Y = info.StartY + _yDist; if (controlCount == _controls.Count - 1) { //If the last control is finished, then return true because the action is finished. return(true); } } } } controlCount++; } return(false); }
/// <summary> /// Plays a sound unless the same sound was already played in the last specified amount of time. /// </summary> /// <param name="sound"></param> /// <param name="delay"></param> public void PlaySound(Sound sound, float delay) { float lastPlayed; bool playSound = true; if (_lastPlayedTimes.TryGetValue(sound, out lastPlayed)) { playSound = SMH.TimePassed(lastPlayed, delay); } else { _lastPlayedTimes[sound] = SMH.Now; } if (playSound) { SoundEffect sfx = _contentManager.Load <SoundEffect>(sound.GetDescription()); sfx.Play((float)SoundVolume / 100f, 0, 0); } }
public override bool Update(float dt) { //Update buttons foreach (ButtonInfo bi in _buttons) { bi.Button.Update(dt); if (bi.Button.IsClicked()) { switch (bi.Type) { case MiniMenuButton.Cancel: return(false); case MiniMenuButton.Quit: SMH.WindowManager.OpenMiniMenu(MiniMenuMode.ExitPrompt); return(true); case MiniMenuButton.Save: SMH.SaveManager.Save(); SMH.PopupMessageManager.ShowSaveConfirmation(); return(false); case MiniMenuButton.Options: SMH.WindowManager.OpenOptionsWindow(); return(true); case MiniMenuButton.Yes: SMH.ShowMenu(); return(false); case MiniMenuButton.No: SMH.WindowManager.OpenMiniMenu(MiniMenuMode.Exit); return(true); } } } return(true); }
/// <summary> /// Draws any currently active messages. /// </summary> public void Draw() { if (!SMH.GameTimePassed(_timeMessageStarted, _messageDuration)) { //Determine text alpha - fade out near the end if (SMH.GameTimePassed(_timeMessageStarted, _messageDuration * 0.75f)) { _messageAlpha -= 255f * (1f / (_messageDuration * 0.25f)) * SMH.DT; if (_messageAlpha < 0.0) { _messageAlpha = 0f; _adviceManMessageActive = false; } } SMH.Graphics.DrawString(SmileyFont.AbilityTitle, _message, 512, 710, Enums.TextAlignment.Center, Color.FromNonPremultiplied(255, 255, 255, (int)_messageAlpha), 0.9f); if (_adviceManMessageActive) { SMH.Graphics.DrawSprite(Sprites.AdviceManDown, 80, 725, Color.FromNonPremultiplied(255, 255, 255, (int)_messageAlpha), 0f, 0.8f); } } }
public override void Update(float dt) { if (_inTransition) { UpdateTransition(dt); } if (SMH.Input.IsDown(Keys.F2)) { EnterScene(FinalScene); return; } _timeInSceneState += dt; //Fade in before doing anything if (_backgroundAlpha < 255f) { _backgroundAlpha = Math.Min(255f, _backgroundAlpha + 255f * dt); if (_backgroundAlpha == 255f) { EnterScene(1); _timeCinematicStarted = SMH.Now; } else { return; } } if (SMH.Now - _timeCinematicStarted > SceneOneMusicLength && !_musicTransitionedYet) { //Music transition SMH.Sound.StopMusic(); _musicTransitionedYet = true; } if (!_musicFadeoutYet && _scene == FinalScene && _sceneState == SceneState.Wait && _timeInSceneState > 3.5) { //Start fading out the music near the end of the final _scene SMH.Sound.FadeOutMusic(); _musicFadeoutYet = true; } if (_sceneState == SceneState.ShowPicture) { _pictureOffset += 300f * dt; if (_pictureOffset >= 0) { _pictureOffset = 0f; EnterSceneState(SceneState.ShowText); } } else if (_sceneState == SceneState.ShowText) { _textAlpha += 320 * dt; if (_textAlpha >= 255f) { _textAlpha = 255f; EnterSceneState(SceneState.Wait); } } else if (_sceneState == SceneState.Wait) { if (_timeInSceneState > _sceneDuration) { EnterSceneState(SceneState.FadeText); } } else if (_sceneState == SceneState.FadeText) { _textAlpha -= 320 * dt; if (_textAlpha <= 0f) { _textAlpha = 0f; EnterSceneState(SceneState.FadePicture); } } else if (_sceneState == SceneState.FadePicture) { _pictureOffset -= 300f * dt; if (_pictureOffset <= MaxPictureOffset) { _pictureOffset = MaxPictureOffset; EnterScene(_scene + 1); } } if (SMH.Input.IsPressed(Keys.Enter)) { //TODO:smh->resources->Purge(ResourceGroups::Cinematic); SMH.StartGame(true); } }
/// <summary> /// Updates the NPC. /// </summary> /// <param name="dt"></param> public override void Update(float dt) { //Update collision box CollisionBox = new Rect(X - 32f, Y - 32f, 64, 64); //Exit conversation if (!SMH.WindowManager.IsTextBoxOpen) { InConversation = false; } //If in conversation, stand still and face the player if (InConversation) { if (SMH.Player.X > X + 32) { _facing = Direction.Right; } else if (SMH.Player.X < X - 32) { _facing = Direction.Left; } else if (SMH.Player.Y > Y + 32) { _facing = Direction.Down; } else if (SMH.Player.Y < Y - 32) { _facing = Direction.Up; } return; } else { _facing = _walkDirection; } if (_stage == NPCStage.Rest) { DX = DY = 0; } else if (_stage == NPCStage.Walk) { if (_walkDirection == Direction.Left) { DX = -Speed; DY = 0; } else if (_walkDirection == Direction.Right) { DX = Speed; DY = 0; } else if (_walkDirection == Direction.Up) { DX = 0; DY = -Speed; } else if (_walkDirection == Direction.Down) { DX = 0; DY = Speed; } } //Switch stage when the current one is finished if (SMH.GameTimePassed(_timeEnteredStage, _stageLength)) { ChangeStage(); } //Move _futureCollisionBox = new Rect(X + DX * dt * 3f - 32f, Y + DY * dt * 3f - 32f, 64, 64); _futureCollisionBox2 = new Rect(X + DX * dt * 3f - 32f, Y + DY * dt * 3f - 32f, 64, 64); if (SMH.Player.CollisionCircle.Intersects(_futureCollisionBox2)) { //If colliding with the player, enter rest mode _stage = NPCStage.Rest; } else if (!SMH.Environment.TestCollision(_futureCollisionBox, CanPass) && !SMH.NPCManager.TestCollision(this)) { X += DX * dt; Y += DY * dt; } else { ChangeDirection(); } }
public override void Update(float dt) { if (_difficultyPrompt.IsVisible) { Difficulty?result = _difficultyPrompt.Update(dt); if (result == null) { return; } SMH.SaveManager.CurrentSave.Difficulty = result.Value; } if (State == MenuState.EnteringScreen) { SetWindowPosition(_windowX, _windowY + 1800f * dt); if (_windowY > 138f) { EnterState(MenuState.InScreen); SetWindowPosition(_windowX, 138f); } } else if (State == MenuState.ExitingScreen) { SetWindowPosition(_windowX, _windowY - 1800f * dt); if (_windowY <= -512f) { //Done exiting screen - perform action based on what button was clicked. switch (_clickedButton) { case SelectFileButton.Back: MainMenu.ShowScreen <TitleScreen>(); break; case SelectFileButton.Start: if (SMH.SaveManager.CurrentSave.IsEmpty) { SMH.Environment.LoadLevelAsynch(Level.FOUNTAIN_AREA); MainMenu.ShowScreen <CinematicScreen>(); } else { SMH.StartGame(false); } break; } } } //Set "start" button text based on whether or not an empty file is selected. _buttons[SelectFileButton.Start].Text = SMH.SaveManager.Saves[_selectedSlot].IsEmpty ? "Start" : "Continue"; //Update buttons foreach (KeyValuePair <SelectFileButton, Button> kvp in _buttons) { kvp.Value.Update(dt); if (kvp.Value.IsClicked() && kvp.Key != SelectFileButton.Delete) { _clickedButton = kvp.Key; SMH.SaveManager.CurrentSave = SMH.SaveManager.Saves[_selectedSlot]; EnterState(MenuState.ExitingScreen); if (kvp.Key == SelectFileButton.Start && SMH.SaveManager.Saves[_selectedSlot].IsEmpty) { _difficultyPrompt.IsVisible = true; } } } //Click delete button if (_buttons[SelectFileButton.Delete].IsClicked()) { if (!SMH.SaveManager.Saves[_selectedSlot].IsEmpty) { _deletePromptActive = true; } } //Update save box selections if (!_deletePromptActive) { foreach (KeyValuePair <SaveSlot, SaveBox> kvp in _saveBoxes) { if (SMH.Input.IsDown(Input.Attack) && kvp.Value.CollisionBox.Contains(SMH.Input.Cursor)) { _selectedSlot = kvp.Key; } } } //Listen for response to delete prompt if (_deletePromptActive) { SaveBox box = _saveBoxes[_selectedSlot]; _yesDeleteBox = new Rect(box.X + 100f, box.Y + 60f, 50f, 35f); _noDeleteBox = new Rect(box.X + 180f, box.Y + 60f, 50f, 35f); _mouseOverYes = _yesDeleteBox.Contains(SMH.Input.Cursor); _mouseOverNo = _noDeleteBox.Contains(SMH.Input.Cursor); if (SMH.Input.IsDown(Input.Attack)) { if (_mouseOverYes) { SMH.SaveManager.Delete(_selectedSlot); _deletePromptActive = false; } else if (_mouseOverNo) { _deletePromptActive = false; } } } //Move the Smiley selector towards the selected file. if (_smileyY > _saveBoxes[_selectedSlot].Y + 45f) { _smileyY -= 750f * dt; if (_smileyY < _saveBoxes[_selectedSlot].Y + 45f) { _smileyY = _saveBoxes[_selectedSlot].Y + 45f; } } else if (_smileyY < _saveBoxes[_selectedSlot].Y + 45f) { _smileyY += 750f * dt; if (_smileyY > _saveBoxes[_selectedSlot].Y + 45f) { _smileyY = _saveBoxes[_selectedSlot].Y + 45f; } } }
/// <summary> /// Updates the DebugConsole. /// </summary> /// <param name="dt"></param> public void Update(float dt) { if (SMH.Input.IsPressed(Keys.OemTilde)) { IsActive = !IsActive; } if (!IsActive || SMH.State != GameState.Game) { return; } //Teleport to warp zone if (SMH.Input.IsPressed(Keys.F1) && SMH.SaveManager.CurrentSave.Level != Level.DEBUG_AREA) { if (!SMH.AreaChanger.IsChangingAreas) { SMH.AreaChanger.ChangeArea(1, 1, Level.DEBUG_AREA); } } if (SMH.Input.IsPressed(Keys.F2)) { foreach (Ability ability in Enum.GetValues(typeof(Ability))) { SMH.SaveManager.CurrentSave.HasAbility[ability] = true; } } if (SMH.Input.IsPressed(Keys.F3)) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 4; j++) { SMH.SaveManager.CurrentSave.NumKeys[i, j] += 5; } } } if (SMH.Input.IsPressed(Keys.F4)) { SMH.SaveManager.CurrentSave.Money += 10; } if (SMH.Input.IsPressed(Keys.F5)) { SMH.Player.Health = SMH.Player.MaxHealth; SMH.Player.Mana = SMH.Player.MaxMana; } //Toggle invincibility if (SMH.Input.IsPressed(Keys.F6)) { SMH.Player.IsInvincible = !SMH.Player.IsInvincible; } //Toggle uber-ness (really fast, a shitload of damage) if (SMH.Input.IsPressed(Keys.F7)) { SMH.Player.IsUber = !SMH.Player.IsUber; } //Move smiley with num pad int xMove = 0; int yMove = 0; Keys upKey = Keys.NumPad8; Keys downKey = Keys.NumPad5; Keys leftKey = Keys.NumPad4; Keys rightKey = Keys.NumPad6; if (SMH.Input.IsDown(upKey) || SMH.Input.IsDown(downKey) || SMH.Input.IsDown(leftKey) || SMH.Input.IsDown(rightKey)) { if (!_debugMovePressed) { _debugMovePressed = true; _lastDebugMoveTime = SMH.GameTime; } if (SMH.Input.IsPressed(upKey) || (SMH.GameTimePassed(_lastDebugMoveTime, 0.5f) && SMH.Input.IsDown(upKey))) { yMove = -1; } if (SMH.Input.IsPressed(downKey) || (SMH.GameTimePassed(_lastDebugMoveTime, 0.5f) && SMH.Input.IsDown(downKey))) { yMove = 1; } if (SMH.Input.IsPressed(leftKey) || (SMH.GameTimePassed(_lastDebugMoveTime, 0.5f) && SMH.Input.IsDown(leftKey))) { xMove = -1; } if (SMH.Input.IsPressed(rightKey) || (SMH.GameTimePassed(_lastDebugMoveTime, 0.5f) && SMH.Input.IsDown(rightKey))) { xMove = 1; } } else { _debugMovePressed = false; } if (xMove != 0 || yMove != 0) { SMH.Player.MoveTo(SMH.Player.Tile.X + xMove, SMH.Player.Tile.Y + yMove); } }