/// <summary> /// Update /// </summary> public override void Update() { base.Update(); float c0 = Mathf.Sin(Time.time * 2) + 1.0f; c0 /= 2.0f; c0 = (c0 * (255 - 125)) + 125; if (!TransitionDone()) { return; } if (RB.ButtonPressed(RB.BTN_ABXY, RB.PLAYER_ANY) || RB.ButtonPressed(RB.BTN_POINTER_ANY, RB.PLAYER_ANY)) { SceneGame scene = new SceneGame(); scene.Initialize(); SuperFlagRun game = (SuperFlagRun)RB.Game; game.SwitchScene(scene); RB.SoundPlay(SuperFlagRun.SOUND_START_GAME); } mFlagOne.Update(); mFlagTwo.Update(); }
/// <summary> /// Update /// </summary> public override void Update() { base.Update(); mPlayerOne.Update(); mPlayerTwo.Update(); mFlagOne.Update(); mFlagTwo.Update(); if (mWinningPlayer != 0) { if (mTimeoutUntilReset > 0) { mTimeoutUntilReset -= Time.deltaTime; if (mTimeoutUntilReset <= 0) { SceneTitle scene = new SceneTitle(); scene.Initialize(); SuperFlagRun game = (SuperFlagRun)RB.Game; game.SwitchScene(scene); } } } }
/// <summary> /// Update velocity /// </summary> protected override void UpdateVelocity() { float movementSpeed = 0.01f; Vector2 movementForce = new Vector2(); SuperFlagRun game = (SuperFlagRun)RB.Game; SceneGame scene = (SceneGame)game.CurrentScene; if (scene.GetWinner() == 0) { if (RB.ButtonDown(RB.BTN_LEFT, mPlayerNum)) { movementForce.x -= movementSpeed; mDirX = -1; } else if (RB.ButtonDown(RB.BTN_RIGHT, mPlayerNum)) { mDirX = 1; movementForce.x += movementSpeed; } if (RB.ButtonDown(RB.BTN_ABXY, mPlayerNum)) { if (!mJumpKeyDown && mPhysics.IsOnGround) { mPhysics.Jump(); mJumpKeyDown = true; } } if (!RB.ButtonDown(RB.BTN_ABXY, mPlayerNum)) { mJumpKeyDown = false; } } if (!mJumpKeyDown) { mPhysics.Velocity = new Vector2(mPhysics.Velocity.x, Mathf.Max(-1, mPhysics.Velocity.y)); } mPhysics.AddForce(new Vector2(0, PlatformPhysics.GRAVITY)); mPhysics.AddMovementForce(movementForce * mPhysics.MoveAccel); }
private void DrawScrollingClouds() { SuperFlagRun game = (SuperFlagRun)RB.Game; if (game.GameMap == null) { return; } int totalMapWidth = game.GameMapSize.width * RB.SpriteSize().width; int offset = (int)(Time.time * 25) % totalMapWidth; RB.CameraSet(new Vector2i(offset, 0)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_CLOUDS); RB.CameraSet(new Vector2i(offset - totalMapWidth, 0)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_CLOUDS); }
private Vector2 GetCameraOffset(EntityPlayer player) { // Clip the camera, note we clip first and last column of tiles out because they are special invisible tiles that // block movement, they're not meant to be shown int cameraX = (int)player.Pos.x - (RB.DisplaySize.width / 2) + (RB.SpriteSize().width / 2); if (cameraX < RB.SpriteSize().width) { cameraX = RB.SpriteSize().width; } if (cameraX > (RB.SpriteSize().width *LEVEL_WIDTH) - RB.DisplaySize.width - RB.SpriteSize().width) { cameraX = (RB.SpriteSize().width *LEVEL_WIDTH) - RB.DisplaySize.width - RB.SpriteSize().width; } int cameraY = (int)player.Pos.y - (int)(RB.SpriteSize().height * 2.5f); if (cameraY < RB.SpriteSize().height) { cameraY = RB.SpriteSize().height; } SuperFlagRun game = (SuperFlagRun)RB.Game; if (game.GameMap == null) { return(Vector2.zero); } if (cameraY > (RB.SpriteSize().height *game.GameMapSize.height) - (RB.DisplaySize.height / 2) - RB.SpriteSize().height) { cameraY = (RB.SpriteSize().height *game.GameMapSize.height) - (RB.DisplaySize.height / 2) - RB.SpriteSize().height; } return(new Vector2(cameraX, cameraY)); }
/// <summary> /// Update /// </summary> public override void Update() { base.Update(); if (Mathf.Abs(mPhysics.Velocity.x) > 0) { mFrameIndex += Mathf.Abs(mPhysics.Velocity.x) * mRunAnimSpeed; if (mFrameIndex >= mRunFrames.Length) { mFrameIndex = 0; } } else { mFrameIndex = 0; } if (!mPhysics.IsOnGround) { mFrameIndex = 0; } int newFrameIndex = (int)mFrameIndex; if (mLastFrameIndex != newFrameIndex && (newFrameIndex == 1 || newFrameIndex == 3)) { RB.SoundPlay(SuperFlagRun.SOUND_FOOT_STEP, 0.35f, Random.Range(0.7f, 1.3f)); } mLastFrameIndex = newFrameIndex; SuperFlagRun game = (SuperFlagRun)RB.Game; SceneGame scene = (SceneGame)game.CurrentScene; if (mCarriedFlag == null && scene.GetWinner() == 0) { EntityFlag flag = scene.GetEnemyFlag(mPlayerNum); if (flag.ColliderInfo.Rect.Offset(new Vector2i((int)flag.Pos.x, (int)flag.Pos.y)).Intersects(ColliderInfo.Rect.Offset(new Vector2i((int)Pos.x, (int)Pos.y)))) { mCarriedFlag = flag; RB.SoundPlay(SuperFlagRun.SOUND_PICKUP_FLAG); } } else if (mCarriedFlag != null) { if ((int)mFrameIndex == 1 || (int)mFrameIndex == 2) { mCarriedFlag.Pos = new Vector2(Pos.x, Pos.y - 10); } else { mCarriedFlag.Pos = new Vector2(Pos.x, Pos.y - 11); } if (scene.GetWinner() == 0) { EntityFlagSlot flagSlot = scene.GetFlagSlot(mPlayerNum); if (flagSlot.ColliderInfo.Rect.Offset(new Vector2i((int)flagSlot.Pos.x, (int)flagSlot.Pos.y)).Intersects(ColliderInfo.Rect.Offset(new Vector2i((int)Pos.x, (int)Pos.y)))) { RB.SoundPlay(SuperFlagRun.SOUND_DROP_FLAG); scene.SetWinner(mPlayerNum); mCarriedFlag.Pos = flagSlot.Pos; mCarriedFlag = null; } } } }
/// <summary> /// Render /// </summary> public override void Render() { RB.Clear(new Color32(127, 213, 221, 255)); RB.CameraReset(); SuperFlagRun game = (SuperFlagRun)RB.Game; if (game.TitleMap == null) { RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load title TMX map.\nPlease try re-importing the map Demos/SuperFlagRun/TitleMap.tmx in Unity"); return; } RB.CameraSet(new Vector2i(RB.SpriteSize().width, 0)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_SKY); DrawScrollingClouds(); RB.CameraSet(new Vector2i(RB.SpriteSize().width, RB.SpriteSize().height * 12)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_DECO); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TITLE_TERRAIN); RB.CameraSet(new Vector2i(RB.SpriteSize().width, -RB.SpriteSize().height * 7)); // Draw Flags mFlagOne.Render(); mFlagTwo.Render(); // Draw Players int x = (RB.SpriteSize().width * 3) + 8; int y = RB.SpriteSize().height * 3; RB.DrawSprite(RB.SpriteIndex(0, 2), new Vector2i(x, y), 0); RB.DrawSprite(RB.SpriteIndex(0, 3), new Vector2i(x, y + RB.SpriteSize().height), 0); x = RB.DisplaySize.width - (RB.SpriteSize().width * 2) - 8; RB.DrawSprite(RB.SpriteIndex(5, 2), new Vector2i(x, y), RB.FLIP_H); RB.DrawSprite(RB.SpriteIndex(5, 3), new Vector2i(x, y + RB.SpriteSize().height), RB.FLIP_H); // Draw Castles RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(RB.SpriteSize().width * 2, RB.SpriteSize().height * 4)); RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i(RB.DisplaySize.width - (RB.SpriteSize().width * 3), RB.SpriteSize().height * 4), 0); // Draw Title RB.CameraReset(); RB.SpriteSheetSet(SuperFlagRun.SPRITESHEET_TITLE); byte tint = (byte)((Mathf.Sin(Time.time * 2) * 60) + 196); RB.TintColorSet(new Color32(tint, tint, tint, 255)); RB.DrawCopy(new Rect2i(0, 0, 323, 103), new Vector2i((RB.DisplaySize.width / 2) - (323 / 2), (int)(Mathf.Sin(Time.time * 2) * 6) + 15)); RB.TintColorSet(Color.white); RB.SpriteSheetSet(SuperFlagRun.SPRITESHEET_SPRITES); // Draw Press Any Button string str = "PRESS ANY BUTTON"; Vector2i textSize = RB.PrintMeasure(SuperFlagRun.GAME_FONT, str); RB.Print(SuperFlagRun.GAME_FONT, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2), (int)(RB.DisplaySize.height * 0.55f)), Color.white, str); RB.Print(new Vector2i(2, RB.DisplaySize.height - 9), Color.black, "RetroBlit technical demo game"); // Let base render last so it can overlay the scene base.Render(); }
/// <summary> /// Render /// </summary> public override void Render() { RB.Clear(new Color32(127, 213, 221, 255)); SuperFlagRun game = (SuperFlagRun)RB.Game; if (game.GameMap == null) { RB.Print(new Vector2i(2, 2), DemoUtil.IndexToRGB(14), "Failed to load game TMX map.\nPlease try re-importing the map Demos/SuperFlagRun/GameMap.tmx in Unity"); return; } // Draw Player One view RB.CameraReset(); Vector2i cameraOffset; if (!game.SinglePlayer) { RB.ClipSet(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height / 2)); cameraOffset = GetCameraOffset(mPlayerOne); } else { cameraOffset = GetCameraOffset(mPlayerOne); cameraOffset.y -= RB.DisplaySize.height / 2; } RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_SKY); DrawScrollingClouds((int)cameraOffset.x, (int)cameraOffset.y); RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y)); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_BACKGROUND); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TERRAIN); if (mWinningPlayer == 0) { mFlagOneSlot.Render(); } mFlagOne.Render(); mFlagTwo.Render(); mPlayerTwo.Render(); mPlayerOne.Render(); // Draw Castles RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(16, RB.SpriteSize().height * 26)); RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i((RB.SpriteSize().width *LEVEL_WIDTH) - 64, RB.SpriteSize().height * 26), 0); if (!game.SinglePlayer) { // Draw Player Two view RB.ClipSet(new Rect2i(0, RB.DisplaySize.height / 2, RB.DisplaySize.width, RB.DisplaySize.height / 2)); cameraOffset = GetCameraOffset(mPlayerTwo); RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2))); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_SKY); DrawScrollingClouds((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2)); cameraOffset = GetCameraOffset(mPlayerTwo); RB.CameraSet(new Vector2i((int)cameraOffset.x, (int)cameraOffset.y - (RB.DisplaySize.height / 2))); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_BACKGROUND); RB.DrawMapLayer(SuperFlagRun.MAP_LAYER_TERRAIN); if (mWinningPlayer == 0) { mFlagTwoSlot.Render(); } mFlagOne.Render(); mFlagTwo.Render(); mPlayerOne.Render(); mPlayerTwo.Render(); // Draw Castles RB.DrawCopy(new Rect2i(0, 64, 48, 64), new Vector2i(16, RB.SpriteSize().height * 26)); RB.DrawCopy(new Rect2i(80, 64, 48, 64), new Vector2i((RB.SpriteSize().width *LEVEL_WIDTH) - 64, RB.SpriteSize().height * 26), 0); RB.ClipReset(); RB.CameraReset(); // Draw divider for (int x = 0; x < RB.DisplaySize.width; x += 16) { RB.DrawSprite(RB.SpriteIndex(0, 0), new Vector2i(x, (RB.DisplaySize.height / 2) - 4)); } } RB.ClipReset(); RB.CameraReset(); if (mWinningPlayer != 0) { string playerOneStr = "LOSER"; string playerTwoStr = "WINNER"; if (mWinningPlayer == RB.PLAYER_ONE) { playerOneStr = "WINNER"; playerTwoStr = "LOSER"; } int textOffsetX = (int)(Mathf.Cos(Time.time * 6.0f) * 8); int textOffsetY = (int)(Mathf.Sin(Time.time * 6.0f) * 5); Vector2i textSize; string text = playerOneStr; textSize = RB.PrintMeasure(SuperFlagRun.GAME_FONT, text); RB.Print(SuperFlagRun.GAME_FONT, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2) + textOffsetX, (RB.DisplaySize.height / 4) - (textSize.height / 2) + textOffsetY), Color.white, text); text = playerTwoStr; textSize = RB.PrintMeasure(SuperFlagRun.GAME_FONT, text); RB.Print(SuperFlagRun.GAME_FONT, new Vector2i((RB.DisplaySize.width / 2) - (textSize.width / 2) + textOffsetX, (RB.DisplaySize.height / 4 * 3) - (textSize.height / 2) + textOffsetY), Color.white, text); } // Let base render last so it can overlay the scene base.Render(); }