/// <summary> /// This method will handle the logic of the options menu. It will only be called when an options menu exists, and all logic will skip when it is inactive. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { double t; switch (activationState) { case ActivationState.activating: //When this is in the middle of activating activationState = ActivationState.active; break; case ActivationState.active: //When this is active if (pack.controller.confirm()) { switch (selectedIndex) { case 0: pack.state.removeOptions(pack); break; } } break; case ActivationState.deactivating: //When this is in the middle of deactivating break; case ActivationState.inactive: //When this has successfully deactivated break; } }
/// <summary> /// This handles the logic of the elevatorbot each update. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { if (isActive) //If this has been released { if (!isElevating) //If this has not yet found a surface { if (isRight) //If this is facing right velocity.X = SPEED_PIXELS_PER_UPDATE; else velocity.X = -SPEED_PIXELS_PER_UPDATE; doPhysics(pack); detectCollisions(pack); } else //If this has found a surface { if (!animatorSet) animator = pack.time.TotalGameTime.TotalMilliseconds; float t = (float)(animator / time); //Calculate t if (isRight) //Set the position { position.X = attachedSurface.StartX + ((attachedSurface.EndX - attachedSurface.StartX) / t); position.Y = attachedSurface.StartY + ((attachedSurface.EndY - attachedSurface.StartY) / t); } else { position.X = attachedSurface.EndX - ((attachedSurface.EndX - attachedSurface.StartX) / t); position.Y = attachedSurface.EndY - ((attachedSurface.EndY - attachedSurface.StartY) / t); } } } }
/// <summary> /// This calls the selection logic and handles the logic for when an item is selected. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { base.doThis(pack); //Handle selected index if(pack.controller.confirm()) //If selected, handle that. { switch(selectedIndex) { case 0: pack.state.loadState(new HubScreenState()); break; case 1: pack.state.loadState(new CreditsState()); break; case 2: pack.state.pause(pack); pack.state.displayOptions(pack); break; case 3: pack.state.exitGame = true; break; case 4: pack.state.loadState(new LevelEditState()); break; } } }
/// <summary> /// Standard splash state logic is to wait for any button press and then call nextState. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { if (pack.controller.confirm()) { nextState(pack); } }
/// <summary> /// This method will apply gravity if acceleration is enabled. /// </summary> /// <param name="pack">see doPacket</param> public virtual void doPhysics(doPacket pack) { if (accelerationEnabled) { acceleration.Y = GRAVITY; acceleration.X = 0; } }
/// <summary> /// The do method of a level state should propagate the do chain throughout all objects the level contains. /// Additionally, any logic which is above the object level but below the master level should be conducted here. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { foreach (LevelBlock l in walls) l.doThis(pack, player); foreach (HitBoxInteractable i in interactables) i.doThis(pack); foreach (GameObject o in objects) o.doThis(pack); }
/// <summary> /// This method will check for collisions. If a collision is detected, then check to see if this is being activated. If it is, affect the player. /// </summary> /// <param name="pack"></param> /// <param name="p"></param> public override Boolean effectPlayer(doPacket pack, Player p) { //This needs to activate only on collision if (pack.controller.use() || p.type == InteractorType.toolbot) target.DynamicInvoke(); if (p.type == InteractorType.toolbot) { int x = 0; //Toolbot interaction animation wot wot } return false; }
/// <summary> /// Typical menu state do method will only handle the logic of selecting and changing menu items. /// Method calls will probably be used to perform the menu item logic itself. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { if (pack.controller.up()) { selectedIndex--; if (selectedIndex < 0) selectedIndex = totalItems - 1; } if (pack.controller.down()) { selectedIndex++; if (selectedIndex == totalItems) selectedIndex = 0; } }
SpriteBatch sb; //The sprite batch, used to draw things. #endregion Fields #region Constructors /// <summary> /// Constructor. /// </summary> /// <param name="sb">The sprite batch</param> /// <param name="c">The content manager</param> public GameState(SpriteBatch sb, ContentManager c) { GameTime time = new GameTime(); controller = new Controller(); doPack = new doPacket(this, time, controller); drawPack = new drawPacket(this, time, sb); content = c; gameWorld = new RenderTarget2D(sb.GraphicsDevice, 1280, 720); effects = new RenderTarget2D(sb.GraphicsDevice, 1280, 720); UI = new RenderTarget2D(sb.GraphicsDevice, 1280, 720); pauseBG = new RenderTarget2D(sb.GraphicsDevice, 1280, 720); exitGame = false; playerPosition = new CollisionPoint(); cameraPosition = new Point(); paused = false; frameCaptured = false; }
public override void doThis(doPacket pack) { base.doThis(pack); if (pack.state.playerPosition.X - pack.state.cameraPosition.X < 400) //This will keep the camera on the player, but inside the level. pack.state.cameraPosition.X = (int)pack.state.playerPosition.X - 400; if (pack.state.playerPosition.X - pack.state.cameraPosition.X > 870) pack.state.cameraPosition.X = (int)pack.state.playerPosition.X - 870; if (pack.state.playerPosition.Y - pack.state.cameraPosition.Y < 360) pack.state.cameraPosition.Y = (int)pack.state.playerPosition.Y - 360; if (pack.state.playerPosition.Y - pack.state.cameraPosition.Y > 620) pack.state.cameraPosition.Y = (int)pack.state.playerPosition.Y - 620; if (pack.state.cameraPosition.X < 0) pack.state.cameraPosition.X = 0; if (pack.state.cameraPosition.Y < 0) pack.state.cameraPosition.Y = 0; if (pack.state.cameraPosition.X > levelSize.X - 1280) pack.state.cameraPosition.X = (int)levelSize.X - 1280; if (pack.state.cameraPosition.Y > levelSize.Y - 720) pack.state.cameraPosition.Y = (int)levelSize.Y - 720; }
/// <summary> /// This handles the logic of detecting and making sure the elements on the hub screen are animated. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { base.doThis(pack); //Handle the selection logic if (pack.controller.confirm()) //If selected, find the index and apply logic. { switch (selectedIndex) { case 0: pack.state.loadState(new Level1State()); break; case 1: pack.state.loadState(new DatabaseState()); break; case 2: pack.state.pause(pack); pack.state.displayOptions(pack); break; case 3: pack.state.exitGame = true; break; } } }
/// <summary> /// This method will handle the logic of the options menu. It will only be called when an options menu exists, and all logic will skip when it is inactive. /// </summary> /// <param name="pack">see doPacket</param> public void doThis(doPacket pack) { double t; switch (activationState) { case ActivationState.activating: //When this is in the middle of activating animator += pack.time.ElapsedGameTime.TotalMilliseconds; //Animation stuff if (animator < 250) { t = (animator / (double)250); if (t > 1) t = 1; drawRect.X = 640; drawRect.Y = 360 - (int)(5 * t); drawRect.Width = 1; drawRect.Height = (int)(10 * t); } else if (animator < 650) { t = ((animator - 250) / (double)100); if (t > 1) t = 1; drawRect.X = 640 - (int)((float)620 * t); drawRect.Y = 355; drawRect.Width = (int)((float)1240 * t); drawRect.Height = 10; } break; case ActivationState.active: //When this is active break; case ActivationState.deactivating: //When this is in the middle of deactivating break; case ActivationState.inactive: //When this has successfully deactivated break; } }
/// <summary> /// This method will deactivate the options menu. It should be called just before unpausing. /// </summary> /// <param name="pack">see doPacket</param> public void deactivate(doPacket pack) { //Stuff }
/// <summary> /// This method will activate the options menu. It should be called after the game has been paused. /// </summary> /// <param name="s">The state to return to once options are completed.</param> /// <param name="pack">see doPacket</param> public void activate(State s, doPacket pack) { activationState = ActivationState.activating; returnState = s; animator = 0; }
/// <summary> /// This method only applies its logic if this is disappearing. If it is, it will handle that logic. /// </summary> /// <param name="pack">see doPacket</param> /// <param name="player">The current player</param> public override void doThis(doPacket pack, Player player) { if (disappearing) { disappearTime += pack.time.ElapsedGameTime.TotalMilliseconds; //Increments the timer by the number of milliseconds since the last update. if (disappearTime >= disappearLength) //IF: The timer is up { //NOTE: This should probably be changed to DEACTIVATE it instead of removing it, otherwise we'll probably have trouble when we have to load the same level more than once per session. level.walls.Remove(this); //Remove this from the level } } }
/// <summary> /// This method will unpause the state. /// </summary> /// <param name="pack">see doPacket</param> public virtual void unpause(doPacket pack) { }
/// <summary> /// This method will check to see if a collision has occurred. If one has, then it will call its delegate method. /// </summary> /// <param name="pack">see doPacket</param> /// <param name="p">The object interacting with this.</param> public override Boolean effectPlayer(doPacket pack, Player p) { //METHOD CALL TO DETECT COLLISIONS HERE target.DynamicInvoke(); return false; }
/// <summary> /// This method will display a pause menu over the current screen during pause. /// </summary> /// <param name="pack">see doPacket</param> public void displayPause(doPacket pack) { //FILL ME UP }
/// <summary> /// This method will update the position of the moving hanging ledge. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { if (!pack.state.paused) //If the game is not paused { //STUFF } }
/// <summary> /// This method will display an options menu over the current screen during pause. /// </summary> /// <param name="pack">see doPacket</param> public void displayOptions(doPacket pack) { tempState = new OptionsMenuState(); tempState.loadState(this, content); }
/// <summary> /// This method will do nothing, since this doodad is not animated. /// </summary> /// <param name="pack">see doPacket</param> public virtual void doThis(doPacket pack) { }
/// <summary> /// This method will fire when the player has collided with this object. It will catch them on the hanging point and send the player into hanging mode. /// Hanging mode is not handled by this object. /// </summary> /// <param name="pack">see doPacket</param> /// <param name="p">The player</param> /// <returns>True if the player has been effected. Otherwise false.</returns> public override Boolean effectPlayer(doPacket pack, Player p) { if (detectCollision(p.hitBox)) { p.hang(pack, this, isRight); return true; } return false; }
/// <summary> /// No internal logic is required for this. This method can probably be removed. /// </summary> /// <param name="pack"></param> public override void doThis(doPacket pack) { }
/// <summary> /// This method will keep track of the current frame. /// </summary> /// <param name="pack">see doPacket</param> public void doThis(doPacket pack) { animator += pack.time.ElapsedGameTime.TotalMilliseconds; if (animator >= milliseconds) { if (isComplete) { currentFrame = 0; isComplete = false; } else if (++currentFrame == frames - 1) isComplete = true; animator -= milliseconds; } }
/// <summary> /// This will handle the do logic of the game world. All do's should be conditional, since null elements will be common. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { updateMouse(); float xDif = 0; float yDif = 0; if (mNew.LeftButton == ButtonState.Released) //If the mouse button is released, the selected object clears. selectedObject = null; if (mOld.LeftButton == ButtonState.Released && mNew.LeftButton == ButtonState.Pressed) //Whenever the mouse button is clicked... { while(true) { bool found = false; Vector3 mouseNow = new Vector3(mNew.X, mNew.Y, 0); //Capture its position mouseNow.X += pack.state.cameraPosition.X; mouseNow.Y += pack.state.cameraPosition.Y; foreach (LevelBlock w in walls) //Crawl each collection to find if there is an object being clicked on { if (w.Dimensions.Contains(mouseNow) == ContainmentType.Contains) { selectedObject = w; found = true; break; } } if (found) break; foreach (Doodad d in doodads) { if (d.hitBox.Contains(mouseNow) == ContainmentType.Contains) { selectedObject = d; found = true; break; } } if (found) break; foreach (GameObject o in objects) { if (o.hitBox.Contains(mouseNow) == ContainmentType.Contains) { selectedObject = o; found = true; break; } } if (found) break; foreach (HitBoxInteractable i in interactables) { if (i.HitBox.Contains(mouseNow) == ContainmentType.Contains) { selectedObject = i; found = true; break; } } if (found) break; foreach (Doodad d in background) { if (d.hitBox.Contains(mouseNow) == ContainmentType.Contains) { selectedObject = d; found = true; break; } } if (found) break; selectedObject = null; //If no object is being clicked on, then set selected object to null break; } } if ((mOld.LeftButton == ButtonState.Pressed && mNew.LeftButton == ButtonState.Pressed) || (mOld.RightButton == ButtonState.Pressed && mNew.RightButton == ButtonState.Pressed)) //If the mouse remains clicked, capture the mouse position difference { xDif = mNew.X - mOld.X; yDif = mNew.Y - mOld.Y; xDif /= state.cameraScale; yDif /= state.cameraScale; } else //Otherwise, dif = 0 { xDif = 0; yDif = 0; } if (selectedObject == null && pack.state.drawPack.sb.GraphicsDevice.Viewport.X <= mOld.X && pack.state.drawPack.sb.GraphicsDevice.Viewport.Y <= mOld.Y && mOld.X <= pack.state.drawPack.sb.GraphicsDevice.Viewport.X + pack.state.drawPack.sb.GraphicsDevice.Viewport.Width && mOld.Y <= pack.state.drawPack.sb.GraphicsDevice.Viewport.Y + pack.state.drawPack.sb.GraphicsDevice.Viewport.Height) //If no object underneath the mouse, and the mouse is over the window, move the level. { pack.state.cameraPosition.X -= (int)xDif; pack.state.cameraPosition.Y -= (int)yDif; } else //Else, find the object underneath the mouse and move its position, drag and drop stype { foreach (Doodad d in background) { if (selectedObject == d) { d.moveThis(new Vector2(xDif,yDif)); form.updateProperties(); } } foreach (LevelBlock w in walls) { if (selectedObject == w) { w.moveThis(new Vector2(xDif, yDif)); form.updateProperties(); } } foreach (Doodad d in doodads) { if (selectedObject == d) { d.moveThis(new Vector2(xDif, yDif)); form.updateProperties(); } } foreach (GameObject o in objects) { if (selectedObject == o) { o.moveThis(new Vector2(xDif, yDif)); form.updateProperties(); } } foreach (HitBoxInteractable i in interactables) { if (selectedObject == i) { i.moveThis(new Vector2(xDif, yDif)); form.updateProperties(); } } } foreach (LevelBlock w in walls) w.doThis(pack, nullPlayer); foreach (Doodad d in doodads) d.doThis(pack); foreach (HitBoxInteractable i in interactables) i.doThis(pack); foreach (GameObject o in objects) o.doThis(pack); }
public override void nextState(doPacket pack) { pack.state.loadState(new TitleMenuState()); }
/// <summary> /// This method will animate the animation. /// </summary> /// <param name="pack">see doPacket</param> public override void doThis(doPacket pack) { animation.doThis(pack); }
public override void nextState(doPacket pack) { pack.state.loadState(new LogoSplashState()); }
/// <summary> /// This method handles the movement of the moving platform. /// </summary> /// <param name="pack">see doPacket</param> /// <param name="player">The current player</param> public override void doThis(doPacket pack, Player player) { if (!pack.state.paused) //If the game is not paused { if (setAnimator) //If the animator needs to be reset... { animator = 0; //...reset it. setAnimator = false; } animator += pack.time.ElapsedGameTime.TotalMilliseconds; //Increment animator t = (float)(animator) / (secondsPerCycle * 1000); //Calculate t (0-1) //Set the position of the moving platform. float width = _Width; float height = _Height; if (isRight) dimensions.Min.X = begin.X + ((end.X - begin.X) * t); else dimensions.Min.X = end.X - ((end.X - begin.X) * t); if (isDown) dimensions.Min.Y = begin.Y + ((end.Y - begin.Y) * t); else dimensions.Min.Y = end.Y - ((end.Y - begin.Y) * t); dimensions.Max.X = dimensions.Min.X + width; dimensions.Max.Y = dimensions.Min.Y + height; if (t > 1) //If the cycle is finished... { setAnimator = true; //...reverse the platform. isRight = !isRight; isDown = !isDown; calculateSpeed(); } } }
/// <summary> /// Must be overridden. This method will load the next state into the master game state. /// </summary> /// <param name="pack">see doPacket</param> public virtual void nextState(doPacket pack) { }