public List <Tuple <Double, Double> > process(int threshold) { Threshold = threshold; centerOfSubRegionsList = new List <Tuple <Double, Double> >(); subRegionsList = new List <SubRegion>(); // creating the array with same size // to keep the processing status for each cell InputRegionProcessedFlags = new bool[yDimentionSize, xDimentionSize]; for (int y = 0; y < InputRegion.GetLength(0); y++) { for (int x = 0; x < InputRegion.GetLength(1); x++) { if (!InputRegionProcessedFlags[y, x]) { matchCellToRegion(x, y); } } } foreach (var subRegion in subRegionsList) { centerOfSubRegionsList.Add(subRegion.CenterOfMass()); //foreach (var t in subRegion) // Console.Write("\n\t{0}", t.ToString()); } return(centerOfSubRegionsList); }
/// <summary> /// Returns true if this action can be performed with the given input. /// </summary> private bool CanPerform(Action action, InputType inputType, InputRegion inputRegion, SwipeDirection swipeDirection) { // Tests whether the input corresponds to the action's properties bool validInputRegion = Equals(action.inputRegion, inputRegion); bool validInputType = action.inputType == inputType; bool validSwipeDirection = (action.inputType == InputType.Swipe)? Equals(action.swipeDirection, swipeDirection):true; // Return true if all of the given input matches the action's required input return(validInputRegion && validInputType && validSwipeDirection); }
public override void Reset() { base.Reset(); IsVirusUp = false; IsRedScreenOfDeathUp = false; ProgressBarCount = 0; _timeUntilCountUp = 0; _retirementTime = RETIREMENT_START_TIME; cancelButton = null; warningIconVisible = false; }
public void StartVirus() { Reset(); IsVirusUp = true; float x = Rand.Next((int)MIN_WINDOW_OFFSET.X, (int)MAX_WINDOW_OFFSET.X); float y = Rand.Next((int)MIN_WINDOW_OFFSET.Y, (int)MAX_WINDOW_OFFSET.Y); CurrentWindowOffset = new Vector2(x, y); cancelButton = new InputRegion(CurrentWindowOffset + CANCEL_BUTTON_HITBOX_OFFSET, CANCEL_BUTTON_HITBOX_SIZE, true, (n) => { Reset(); }); Manager.soundPopup.Play(); }
/// <summary> /// Returns true if the two input regions are equivalent. That is, they both correspond to the same region /// </summary> public bool Equals(InputRegion r1, InputRegion r2) { if (r1 == r2) { return(true); } if (r1 == InputRegion.Any || r2 == InputRegion.Any) { return(true); } // If this statement is reached, the two input regions are not equivalent. Thus, return false return(false); }
/// <summary> /// Create an Action and copy all the values from the given template /// </summary> public Action(Action template) { // Copy the values from the given template name = template.name; animationSequences = ArrayUtils.Copy <AnimationSequence>(template.animationSequences); hitBoxes = ArrayUtils.DeepCopy(template.hitBoxes); forces = ArrayUtils.DeepCopy(template.forces); onStartEvents = ArrayUtils.DeepCopy(template.onStartEvents); linkableCombatActionScriptableObjects = ArrayUtils.Copy <ActionScriptableObject>(template.linkableCombatActionScriptableObjects); listensToInput = template.listensToInput; inputType = template.inputType; inputRegion = template.inputRegion; swipeDirection = template.swipeDirection; startSounds = ArrayUtils.Copy <AudioClip>(template.startSounds); impactSounds = ArrayUtils.Copy <AudioClip>(template.impactSounds); cancelable = template.cancelable; overrideCancelable = template.overrideCancelable; }
public void SetState(UIState state) { UIState prev = State; State = state; if (State == UIState.MainMenu) { inputRegions.Clear(); inputRegions.Add(new InputRegion(HARDBOILED_INPUTBOX, true, (i) => { if (!Main.HasWon) { return; } if (Rand.Next(RARE_SCREEN_RARITY) == 0) { SetStateNextFrame(UIState.RareStartup); } else { SetStateNextFrame(UIState.Survive); } Main.Level.IsHardBoiled = true; })); inputRegions.Add(new InputRegion(STARTGAME_INPUTBOX, true, (i) => { if (Rand.Next(RARE_SCREEN_RARITY) == 0) { SetStateNextFrame(UIState.RareStartup); } else { SetStateNextFrame(UIState.Survive); } Main.Level.IsHardBoiled = false; })); inputRegions.Add(new InputRegion(FULLSCREEN_INPUTBOX, true, (i) => { Main.MainGame.ToggleFullscreen(); })); InputRegion volumeInput = new InputRegion(VOLUME_INPUTBOX); volumeInput.MouseDown += _volume_MouseDown; inputRegions.Add(volumeInput); menuMusic.Play(); } else { menuMusic.Stop(); } if (State == UIState.RareStartup) { inputRegions.Clear(); RareStartupIndex = Rand.Next(0, RARE_SCREEN_COUNT) + 1; timer = new HelperTimer(TimeSpan.FromSeconds(RARE_STARTUP_TIME), "RareStartupEnd", () => { SetStateNextFrame(UIState.Survive); }); } if (State == UIState.Survive) { inputRegions.Clear(); _staticScreensLeft = STATIC_SCREEN_LENGTH; timer = new HelperTimer(TimeSpan.FromSeconds(SURVIVE_DELAY), "SurviveDelay", () => { timer = new HelperTimer(TimeSpan.FromSeconds(SURVIVE_FADETIME), "SurviveFade", () => { SetStateNextFrame(UIState.Office); }); }); Main.Level.Laptop.soundCameraChange.Play(); } if (State == UIState.YouDied) { inputRegions.Clear(); inputRegions.Add(new InputRegion(Vector2.Zero, WindowSize, true, (i) => { SetStateNextFrame(UIState.MainMenu); })); } if (State == UIState.Static) { inputRegions.Clear(); timer = new HelperTimer(TimeSpan.FromSeconds(DEATH_STATIC_TIME), "DeathStaticEnd", () => { SetState(UIState.YouDied); }); soundStatic.Play(); Main.Level.Office.musicClassicalish.Stop(); } else { soundStatic.Stop(); } if (State == UIState.SixAM) { inputRegions.Clear(); _spamOffset = SPAM_SIZE.Y; timer = new HelperTimer(TimeSpan.FromSeconds(SPAM_DELAY), "SpamBegin", () => { _doingSpam = true; timer = new HelperTimer(TimeSpan.FromSeconds(SPAM_TIME), "SpamEnd", () => { _doingSpam = false; if (Main.Level.IsHardBoiled) { SetState(UIState.Newspaper); } else { SetState(UIState.TheEggnd); } }); }); Main.Level.Office.musicClassicalish.Stop(); } if (State == UIState.TheEggnd) { inputRegions.Clear(); timer = new HelperTimer(TimeSpan.FromSeconds(THE_EGGND_TIME), "TheEggndTime", () => { SetState(UIState.MainMenu); }); Main.Level.spamMusic.Stop(); theEggndMusic.Play(); } else { theEggndMusic.Stop(); } if (State == UIState.Newspaper) { inputRegions.Clear(); timer = new HelperTimer(TimeSpan.FromSeconds(NEWSPAPER_FADEIN_TIME), "NewspaperIn", () => { inputRegions.Add(new InputRegion(Vector2.Zero, WindowSize, true, (n) => { timer = new HelperTimer(TimeSpan.FromSeconds(NEWSPAPER_FADEOUT_TIME), "NewspaperOut", () => { SetStateNextFrame(UIState.MainMenu); newspaperMusic.Stop(); }); })); }); newspaperMusic.Play(); } if (State == UIState.Office) { inputRegions.Clear(); if (prev != UIState.Laptop) { Main.Level.Reset(); } else { Main.Level.Laptop.Hide(); Main.Level.Office.Show(); } } else { Main.Level.Hide(); } if (State == UIState.Laptop) { inputRegions.Clear(); if (prev != UIState.Office) { Main.Level.Reset(); // should never happen } else { Main.Level.Office.Hide(); Main.Level.Laptop.Show(); } } }
/// <summary> /// Returns an action from this move set that can performed from the given /// input /// </summary> public Action GetActionFromInput(InputType inputType, InputRegion inputRegion, SwipeDirection swipeDirection) { Debug.Log("Touch: " + inputType + ", " + inputRegion + ", " + swipeDirection); // Stores the action this character is currently performing Action currentAction = character.CharacterControl.CurrentAction; // If this character is currently performing an action, the action's linkable moves have priority over other moves if (currentAction != null) { Debug.Log("Current Action: " + currentAction.name + " Linkable moves : " + currentAction.linkableCombatActions.Length); // Cycle through each combat move that the character can link to from the current move for (int i = 0; i < currentAction.linkableCombatActions.Length; i++) { // Stores the action that can be linked from the character's current action Action linkableAction = currentAction.linkableCombatActions[i]; Debug.Log("Test linkable action: " + linkableAction.name); // If the action which can be linked from the current action listens to input and can be performed if (linkableAction.listensToInput && CanPerform(linkableAction, inputType, inputRegion, swipeDirection)) { // Return this linkable action, since it can be performed given the input, and given the current action // the character is performing return(linkableAction); } } } // Cycle through each combat action present in this action set for (int i = 0; i < combatActions.Length; i++) { // Cache the attack move being cycled through Action action = combatActions[i]; // If the action can be performed through user input, check if the given input satisfies the action's requirements if (action.listensToInput) { //Debug.Log("Move to test: " + action.name + " " + action.inputType + ", " + action.inputRegion + ", " + action.swipeDirection // + " = " + CanPerform(action, inputType, inputRegion, swipeDirection)); // If the given touch information satisfies the action's required input if (CanPerform(action, inputType, inputRegion, swipeDirection)) { // Return this attack move, since it can be performed given the input return(action); } } } // Cycle through each basic action present in this action set for (int i = 0; i < basicActions.actions.Length; i++) { // Cache the basic move being cycled through Action action = basicActions.actions[i]; // If the action listens to user input to be performed, check if the given input satisfies the action's requirements if (action.listensToInput) { Debug.Log("Action to test: " + action.name + ": " + action.inputType + ", " + action.inputRegion + ", " + action.swipeDirection + "... Can perform? " + CanPerform(action, inputType, inputRegion, swipeDirection)); // If the given touch information satisfies the action's required input if (CanPerform(action, inputType, inputRegion, swipeDirection)) { // Return this basic action, since it can be performed given the input return(action); } } } // If this statement is reached, no move can be performed from the given input return(null); }
/// <summary> /// Called when the user performs a touch that is interpreted /// as being performed by this character. Depending on the input /// and the character's action set, an appropriate action will be /// performed /// </summary> public void OnTouch(TouchInfo touch, InputType inputType, GameObject pressedObject, SwipeDirection swipeDirection) { // If the character is dead, return from this method. The character cannot perform actions whilst dead. if (character.CharacterStats.IsDead()) { return; } // Stores the region which was pressed by this touch InputRegion inputRegion = InputRegion.EmptySpace; // If the touch did not press a GameObject if (pressedObject == null) { // Inform the touch it has pressed empty space inputRegion = InputRegion.EmptySpace; } // Else, if the touch did not press any object else if (pressedObject != null) { // If the touch pressed the same GameObject that received this event if (pressedObject == gameObject) { // The GameObject touched itself inputRegion = InputRegion.Self; } // Else, if the touch pressed an enemy else if (pressedObject.layer == Layer.Enemy) { // Inform the touch that it pressed an enemy inputRegion = InputRegion.Enemy; } } // Retrieve an action that can be performed from the given touch Action validAction = actionSet.GetActionFromInput(inputType, inputRegion, swipeDirection); // If the given input can perform an action if (validAction != null) { // If the character is not performing a action // OR if the current action can be cancelled midway // OR if the action to perform can cancel any action if (currentAction == null || currentAction.cancelable || validAction.overrideCancelable) { // The action's target object is the same object that was pressed when this action was performed validAction.targetObject = pressedObject; // The action's target position is the last position that was pressed by the touch that performed this action validAction.targetPosition = touch.finalWorldPosition; // Update the target object/position of the events stored in the action. Ensures that the events target the right Transform/position. validAction.UpdateEvents(); // Perform the action which corresponds to the user's input PerformAction(validAction); } // Else, if the character is already performing an action that can't be canceled else { // Queue the given action. It will be performed when the current action is done being performed. QueueAction(validAction); } } }
public Office(Level level) { Level = level; CameraOffset = new Vector2(MAX_CAMERA_OFFSET / 2.0f, 0); lightswitchInput = new InputRegion(LIGHTSWITCH_INPUTBOX, false, (i) => { IsLightOn = !IsLightOn; if (IsLightOn) { soundLightOn.Play(); if (!Level.IsHardBoiled) { musicClassicalish.Play(); } } else { soundLightOff.Play(); Level.Monsters.GoldenFlumpty.Shoo(); if (!Level.IsHardBoiled) // Don't pause music in hard boiled mode { musicClassicalish.Pause(); } } }); buttonLeftInput = new InputRegion(BUTTON_LEFT_OFFSET + CameraOffset, BUTTON_SIZE, true, (i) => { if (Vent != VentState.Left) { Vent = VentState.Left; _ventMoving = true; soundVent.Stop(); soundVent.Play(); } }); buttonRightInput = new InputRegion(BUTTON_RIGHT_OFFSET + CameraOffset, BUTTON_SIZE, false, (i) => { if (Vent != VentState.Right) { Vent = VentState.Right; _ventMoving = true; soundVent.Stop(); soundVent.Play(); } }); rawrInput = new InputRegion(RAWR_HITBOX_OFFSET + CameraOffset, RAWR_HITBOX_SIZE, true, (i) => { soundRawr.Stop(); soundRawr.Play(); // spammable }); muteIntroInput = new InputRegion(MUTE_INTRO_INPUTBOX, false, (i) => { musicIntro.Stop(); showMuteButton = false; muteButtonTimer.Stop(); if (Level.IsHardBoiled) { musicToreador.Play(); } else { musicClassicalish.Play(); } }); Vent = VentState.Left; }