/// <summary> /// Default Constructor public AttributeBoard(Game game, Texture2D background, ContentManager Content) : base(game) { centerX = game.GraphicsDevice.Viewport.TitleSafeArea.Center.X; centerY = game.GraphicsDevice.Viewport.TitleSafeArea.Center.Y + 50; this.Content = Content; Components.Add(new ImageComponent(game, background, ImageComponent.DrawMode.Stretch)); // Get the current spritebatch spriteBatch = (SpriteBatch)Game.Services.GetService( typeof(SpriteBatch)); // Get the audio library audio = (AudioLibrary) Game.Services.GetService(typeof(AudioLibrary)); // for the mouse or touch cursor = new Cursor(game, spriteBatch); cursor.targetToLock = null; //Components.Add(cursor); UnassignedPtsBar = Content.Load<Texture2D>("Image/AttributeBoardTextures/UnassignedPtsBarNew"); statsFont = IngamePresentation.statsFont; menuLarge = IngamePresentation.largeFont; speedTexture = Content.Load<Texture2D>("Image/AttributeBoardTextures/speed"); hitpointTexture = Content.Load<Texture2D>("Image/AttributeBoardTextures/hit_point"); shootrateTexture = Content.Load<Texture2D>("Image/AttributeBoardTextures/shooting_rate"); bulletStrengthTexture = Content.Load<Texture2D>("Image/AttributeBoardTextures/strength"); this.game = game; }
public SelectLoadingLevelScene(Game game, SpriteFont font, Texture2D background, Texture2D teamLogo, GraphicsDevice graphicDevice) : base(game) { this.teamLogo = teamLogo; this.font = font; this.graphicsDevice = graphicDevice; Components.Add(new ImageComponent(game, background, ImageComponent.DrawMode.Stretch)); // Get the current spritebatch spriteBatch = (SpriteBatch)Game.Services.GetService( typeof(SpriteBatch)); menu = new TextMenuComponent(game, font, font); Components.Add(menu); cursor = new Cursor(game, spriteBatch); }
public CreditScene(Game game, Texture2D textureBack, Texture2D[] creditForgroundTextures, Texture2D textureNextButton, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice) : base(game) { this.spriteBatch = spriteBatch; backgroundTexture = textureBack; this.textureNextButton = textureNextButton; this.graphicsDevice = graphicsDevice; // Get the audio library audio = (AudioLibrary) Game.Services.GetService(typeof(AudioLibrary)); cursor = new Cursor(game, spriteBatch); this.creditForgroundTextures = creditForgroundTextures; int creditSceneWidth = (int)(graphicsDevice.Viewport.TitleSafeArea.Width * 0.65); int creditSceneHeight = (int)(graphicsDevice.Viewport.TitleSafeArea.Height * 0.75); textureFrontRectangle = new Rectangle(graphicsDevice.Viewport.TitleSafeArea.Center.X - creditSceneWidth/2, graphicsDevice.Viewport.TitleSafeArea.Center.Y - creditSceneHeight/2, creditSceneWidth, creditSceneHeight); int nextRectangleWidth = (int)(graphicsDevice.Viewport.TitleSafeArea.Width * 0.05); int nextRectangleHeight = (int)(graphicsDevice.Viewport.TitleSafeArea.Height * 0.0875); nextRectangle = new Rectangle(textureFrontRectangle.Center.X - nextRectangleWidth/2, textureFrontRectangle.Bottom - nextRectangleHeight, nextRectangleWidth, nextRectangleHeight); nextPressed = false; }
public static bool MouseOnResearchFacility(Cursor cursor, Camera gameCamera, ResearchFacility researchFacility) { if (researchFacility == null) return false; BoundingSphere researchFacilityRealSphere; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); researchFacilityRealSphere = researchFacility.BoundingSphere; researchFacilityRealSphere.Center.Y = researchFacility.Position.Y; researchFacilityRealSphere.Radius *= 1; if (RayIntersectsBoundingSphere(cursorRay, researchFacilityRealSphere)) { return true; } else return false; }
public static bool MouseOnObject(Cursor cursor, BoundingSphere boundingSphere, Vector3 center, Camera gameCamera) { Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); BoundingSphere boundingSphiro; boundingSphiro = boundingSphere; boundingSphiro.Center = center; if (CursorManager.RayIntersectsBoundingSphere(cursorRay, boundingSphiro)) return true; return false; }
public static bool MouseOnFish(Cursor cursor, Camera gameCamera, Fish[] fish, int fishAmount) { BoundingSphere sphere; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); for (int i = 0; i < fishAmount; i++) { sphere = fish[i].BoundingSphere; sphere.Radius *= GameConstants.EasyAimScale; if (RayIntersectsBoundingSphere(cursorRay, sphere)) { cursor.SetOnFishMouseImage(); return true; } } cursor.SetNormalMouseImage(); return false; }
public static ShipWreck MouseOnWhichShipWreck(Cursor cursor, Camera gameCamera, List<ShipWreck> shipWrecks) { if (shipWrecks == null) return null; BoundingSphere shipRealSphere; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (ShipWreck shipWreck in shipWrecks) { shipRealSphere = shipWreck.BoundingSphere; shipRealSphere.Center.Y = shipWreck.Position.Y; shipRealSphere.Radius *= 1; if (RayIntersectsBoundingSphere(cursorRay, shipRealSphere)) { return shipWreck; } } //cursor.SetNormalMouseImage(); return null; }
public static void MouseOnWhichPowerPack(Cursor cursor, Camera gameCamera, List<Powerpack> powerPacks, ref Powerpack cursorOnPowerPack, ref Powerpack botOnPowerPack, HydroBot hydroBot) { bool foundBotOnPowerpack = false, foundCursorOnPowerpack = false; if (hydroBot == null) foundBotOnPowerpack = true; if (cursor == null) foundCursorOnPowerpack = true; BoundingSphere botPowerPackBoundingSphere = new BoundingSphere(); if (!foundBotOnPowerpack) botPowerPackBoundingSphere = new BoundingSphere(hydroBot.BoundingSphere.Center, 5); if (powerPacks == null) return; Ray cursorRay = new Ray(); if (cursor != null) cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Powerpack powerPack in powerPacks) { if (!foundBotOnPowerpack) { if (powerPack.BoundingSphere.Intersects(botPowerPackBoundingSphere)) { foundBotOnPowerpack = true; botOnPowerPack = powerPack; } } if (!foundCursorOnPowerpack) { if (RayIntersectsBoundingSphere(cursorRay, powerPack.BoundingSphere)) { foundCursorOnPowerpack = true; cursorOnPowerPack = powerPack; } } if (foundBotOnPowerpack && foundCursorOnPowerpack) return; } }
public static Factory MouseOnWhichFactory(Cursor cursor, Camera gameCamera, List<Factory> factories) { if (factories == null) return null; BoundingSphere factoryRealSphere; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Factory factory in factories) { factoryRealSphere = factory.BoundingSphere; factoryRealSphere.Center.Y = factory.Position.Y; factoryRealSphere.Radius *= 1; if (RayIntersectsBoundingSphere(cursorRay, factoryRealSphere)) { return factory; } } return null; }
public void CalculateCameraRestriction(Cursor cursor) { Vector2 oldPosition = cursor.Position; cursor.SetPosition(new Vector2(PoseidonGame.graphics.PreferredBackBufferWidth, PoseidonGame.graphics.PreferredBackBufferHeight)); Vector3 pointIntersect = CursorManager.IntersectPointWithPlane(cursor, this, gameFloatHeight); HalfScreenX = Math.Abs(pointIntersect.X); HalfScreenZ = Math.Abs(pointIntersect.Z); cameraRestrictionCanculated = true; cursor.SetPosition(oldPosition); }
public void Update(float avatarYaw, Vector3 position, float aspectRatio, GameTime gameTime, Cursor cursor) { if (gameMode != GameMode.ShipWreck) { if (position.X >= MaxRangeX - HalfScreenX) position.X = MaxRangeX - HalfScreenX; else if (position.X <= -MaxRangeX + HalfScreenX) position.X = -MaxRangeX + HalfScreenX; if (position.Z >= MaxRangeZ - HalfScreenZ) position.Z = MaxRangeZ - HalfScreenZ; else if (position.Z <= -MaxRangeZ + HalfScreenZ) position.Z = -MaxRangeZ + HalfScreenZ; } // If we're shaking... if (shaking) { // Move our timer ahead based on the elapsed time shakeTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; // If we're at the max duration, we're not going to be shaking anymore if (shakeTimer >= shakeDuration) { shaking = false; shakeTimer = shakeDuration; } // Compute our progress in a [0, 1] range float progress = shakeTimer / shakeDuration; // Compute our magnitude based on our maximum value and our progress. This causes // the shake to reduce in magnitude as time moves on, giving us a smooth transition // back to being stationary. We use progress * progress to have a non-linear fall // off of our magnitude. We could switch that with just progress if we want a linear // fall off. float magnitude = shakeMagnitude * (1f - (progress * progress)); // Generate a new offset vector with three random values and our magnitude shakeOffset = new Vector3(NextFloat(), NextFloat(), NextFloat()) * magnitude; } Matrix rotationMatrix = Matrix.CreateRotationY(avatarYaw); Vector3 transformedheadOffset = Vector3.Transform(AvatarHeadOffset, rotationMatrix); Vector3 transformedReference = Vector3.Transform(TargetOffset, rotationMatrix); Vector3 cameraPosition = position + transformedheadOffset; Vector3 cameraTarget = position + transformedReference; Vector3 camRot = Vector3.Transform(Vector3.UnitZ, rotationMatrix); // If we're shaking, add our offset to our position and target if (shaking) { cameraPosition += shakeOffset; cameraTarget += shakeOffset; } //Calculate the camera's view and projection // matrices based on current values. ViewMatrix = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.UnitZ); ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(GameConstants.ViewAngle), aspectRatio, GameConstants.NearClip, GameConstants.FarClip); if (!cameraRestrictionCanculated) CalculateCameraRestriction(cursor); }
public SurvivalGameScene(Game game, GraphicsDeviceManager graphic, ContentManager content, GraphicsDevice GraphicsDevice, SpriteBatch spriteBatch, Vector2 pausePosition, Rectangle pauseRect, Texture2D actionTexture, CutSceneDialog cutSceneDialog, Radar radar, Texture2D stunnedTexture) : base(game) { graphics = graphic; Content = content; GraphicDevice = GraphicsDevice; this.spriteBatch = spriteBatch; this.pausePosition = pausePosition; this.pauseRect = pauseRect; this.actionTexture = actionTexture; this.game = game; this.radar = radar; this.stunnedIconTexture = stunnedTexture; roundTime = TimeSpan.FromSeconds(2592000); random = new Random(); gameCamera = new Camera(GameMode.SurvivalMode); boundingSphere = new GameObject(); hydroBot = new HydroBot(GameConstants.MainGameMaxRangeX, GameConstants.MainGameMaxRangeZ, GameConstants.MainGameFloatHeight, GameMode.SurvivalMode); if (File.Exists("SurvivalMode")) { ObjectsToSerialize objectsToSerialize = new ObjectsToSerialize(); Serializer serializer = new Serializer(); string SavedFile = "SurvivalMode"; objectsToSerialize = serializer.DeSerializeObjects(SavedFile); hydroBot = objectsToSerialize.hydrobot; } //stop spinning the bar IngamePresentation.StopSpinning(); HydroBot.gamePlusLevel = 0; HydroBot.gameMode = GameMode.SurvivalMode; for (int index = 0; index < GameConstants.numberOfSkills; index++) { HydroBot.skills[index] = true; } skillTextures = new Texture2D[GameConstants.numberOfSkills]; bulletTypeTextures = new Texture2D[GameConstants.numBulletTypes]; // for the mouse or touch cursor = new Cursor(game, spriteBatch); //Components.Add(cursor); bubbles = new List<Bubble>(); points = new List<Point>(); //loading winning, losing textures winningTexture = IngamePresentation.winningTexture; losingTexture = IngamePresentation.losingTexture; scaredIconTexture = IngamePresentation.scaredIconTexture; isAncientKilled = false; // Instantiate the factory Button float buttonScale = 1.0f; if (game.Window.ClientBounds.Width <= 900) { buttonScale = 0.8f; // scale the factory panel icons a bit smaller in small window mode } factoryButtonPanel = new ButtonPanel(4, buttonScale); this.Load(); gameBoundary = new GameBoundary(); gameBoundary.LoadGraphicsContent(GraphicDevice); }
public StartScene(Game game, SpriteFont smallFont, SpriteFont largeFont, Texture2D background, Texture2D elements, Texture2D teamLogo, GraphicsDevice graphicDevice) : base(game) { this.elements = elements; this.teamLogo = teamLogo; this.game = game; this.graphicsDevice = graphicDevice; widthScale = (float)game.Window.ClientBounds.Width / 1440; heightScale = (float)game.Window.ClientBounds.Height / 900; //textScale = widthScale * heightScale; //if (textScale > 1) textScale = 1; GameConstants.generalTextScaleFactor = (float)Math.Sqrt((double)widthScale * (double)heightScale); if (GameConstants.generalTextScaleFactor > 1) GameConstants.generalTextScaleFactor = 1; titleLine1SrcRect = new Rectangle(0, 0, 588, 126);//Hydrobot (0,0, 588, 126) titleLine2SrcRect = new Rectangle(90, 169, 620, 126); //Adventure (90, 169, 620, 126) Components.Add(new ImageComponent(game, background, ImageComponent.DrawMode.Stretch)); // Create the Menu if (File.Exists("SurvivalMode")) { string[] items = { "New Game", "New Game Plus", "Load Saved Level", "Guardian Mode", "Config", "Help", "Credits", "Quit" }; menuItems = items; } else { string[] items = { "New Game", "Load Saved Level", "Config", "Help", "Credits", "Quit" }; menuItems = items; } menu = new TextMenuComponent(game, smallFont, largeFont); //starting values resetMenuStartPosition(); menu.Position = new Vector2((game.Window.ClientBounds.Width / 2) , titleLine2DestRect.Bottom); menu.SetMenuItems(menuItems); Components.Add(menu); // Get the current spritebatch spriteBatch = (SpriteBatch)Game.Services.GetService( typeof(SpriteBatch)); // Get the audio library audio = (AudioLibrary) Game.Services.GetService(typeof(AudioLibrary)); cursor = new Cursor(game, spriteBatch); }
public static void deleteSmallerThanZero(SwimmingObject[] objs, ref int size, BoundingFrustum cameraFrustum, GameMode gameMode, Cursor cursor, ParticleSystem explosionParticles) { for (int i = 0; i < size; i++) { if (objs[i].health <= 0 && objs[i].gaveExp == false) { // Delete code is below this // This snippet does not include deleting if (objs[i] is SeaCow) { HydroBot.hasSeaCow = false; HydroBot.seaCowPower = 0; HydroBot.iconActivated[IngamePresentation.seaCowIcon] = false; } if (objs[i] is SeaTurtle) { HydroBot.hasTurtle = false; HydroBot.turtlePower = 0; HydroBot.iconActivated[IngamePresentation.turtleIcon] = false; } if (objs[i] is SeaDolphin) { HydroBot.hasDolphin = false; HydroBot.dolphinPower = 0; HydroBot.iconActivated[IngamePresentation.dolphinIcon] = false; } if (objs[i].isBigBoss == true) { if (gameMode == GameMode.MainGame || gameMode == GameMode.ShipWreck) { PlayGameScene.isBossKilled = true; PlayGameScene.numBossKills += 1; } else if (gameMode == GameMode.SurvivalMode && objs[i] is Fish) SurvivalGameScene.isAncientKilled = true; } else { if (gameMode == GameMode.MainGame || gameMode == GameMode.ShipWreck) { PlayGameScene.numNormalKills += 1; } } if (objs[i] is BaseEnemy) { HydroBot.currentExperiencePts += objs[i].basicExperienceReward; objs[i].gaveExp = true; if (gameMode == GameMode.SurvivalMode) SurvivalGameScene.score += objs[i].basicExperienceReward / 2; if (objs[i].BoundingSphere.Intersects(cameraFrustum)) { Point point = new Point(); String point_string = "+" + objs[i].basicExperienceReward.ToString() + "EXP"; point.LoadContent(PoseidonGame.contentManager, point_string, objs[i].Position, Color.LawnGreen); if (gameMode == GameMode.ShipWreck) ShipWreckScene.points.Add(point); else if (gameMode == GameMode.MainGame) PlayGameScene.points.Add(point); else if (gameMode == GameMode.SurvivalMode) SurvivalGameScene.points.Add(point); } if (!objs[i].isBigBoss) { if (objs[i].BoundingSphere.Intersects(cameraFrustum)) { if (objs[i] is GhostPirate) PoseidonGame.audio.skeletonDie.Play(); else PoseidonGame.audio.hunterYell.Play(); } } else { if (objs[i] is MutantShark) PoseidonGame.audio.mutantSharkYell.Play(); else if (objs[i] is Terminator) PoseidonGame.audio.terminatorYell.Play(); else if (objs[i] is Submarine) { PoseidonGame.audio.Explosion.Play(); if (explosionParticles != null) { for (int k = 0; k < GameConstants.numExplosionParticles; k++) explosionParticles.AddParticle(objs[i].Position, Vector3.Zero); } } } } if (objs[i] is Fish) { int envLoss; envLoss = GameConstants.envLossForFishDeath; HydroBot.currentEnvPoint -= envLoss; if (objs[i].BoundingSphere.Intersects(cameraFrustum)) { Point point = new Point(); String point_string = "-" + envLoss.ToString() + "ENV"; point.LoadContent(PoseidonGame.contentManager, point_string, objs[i].Position, Color.Red); if (gameMode == GameMode.ShipWreck) ShipWreckScene.points.Add(point); else if (gameMode == GameMode.MainGame) PlayGameScene.points.Add(point); else if (gameMode == GameMode.SurvivalMode) SurvivalGameScene.points.Add(point); } } if (objs[i] == cursor.targetToLock) { cursor.targetToLock = null; //objs[i] = null; } //if we are playing the survival mode //revive the dead enemy instead if (gameMode != GameMode.SurvivalMode || objs[i] is Fish || (objs[i].releasedFromSubmarine)) { objs[i] = null; for (int k = i; k < size - 1; k++) { objs[k] = objs[k + 1]; } objs[--size] = null; } } } }
public ConfigScene(Game game, SpriteFont smallFont, SpriteFont largeFont, SpriteFont numberFont, Texture2D background, Texture2D configTitle, Texture2D unselectedCheckbox, Texture2D selectedCheckBox, Texture2D slidebar, Texture2D dragbutton, Texture2D okButton, GraphicsDevice graphicDevice) : base(game) { this.game = game; this.graphicsDevice = graphicDevice; regularFont = smallFont; selectedFont = largeFont; //widthScale = (float)game.Window.ClientBounds.Width / 1280; //heightScale = (float)game.Window.ClientBounds.Height / 800; textScale = GameConstants.generalTextScaleFactor;//(float)Math.Sqrt((double)(widthScale * heightScale)); uncheckedBox = unselectedCheckbox; checkedBox = selectedCheckBox; this.okButton = okButton; this.slideBar = slidebar; this.dragButton = dragbutton; this.numberFont = numberFont; Components.Add(new ImageComponent(game, background, ImageComponent.DrawMode.Stretch)); this.configTitle = configTitle; int titleWidth = (int)(330 * widthScale); int titleHeight = (int)(80 * heightScale); titleRect = new Rectangle(game.Window.ClientBounds.Center.X - titleWidth / 2, game.Window.ClientBounds.Top + titleHeight/3, titleWidth, titleHeight); string[] items = { "Music Volume", "Sound Volume", "Live Tutorial", "Special Effect", "Particle Level", "Fish School Size", "Difficulty" }; menuItems = items; itemRectList = new List<Rectangle>(menuItems.Length); iconRectList = new List<Rectangle>(menuItems.Length); int x, y, width, height, maxItemWidth; maxItemWidth = findMaxWidth(); x = game.Window.ClientBounds.Center.X - (int)( maxItemWidth * 0.7); y = titleRect.Bottom+titleHeight/4; height = (int)((regularFont.MeasureString(menuItems[0]).Y) * textScale); foreach (string menu in menuItems) { width = (int)(regularFont.MeasureString(menu).X * textScale); Rectangle itemRectangle = new Rectangle(x, y, width, height); itemRectList.Add(itemRectangle); y += (int)(regularFont.LineSpacing*1.2*textScale); } int iconPositionX = x + maxItemWidth + (int)(10 * widthScale); int barheight = (int)(20*heightScale), barwidth = (int)(200*widthScale); int checkBoxheight = (int)(30*heightScale) , checkboxWidth = (int)(30*widthScale); musicVolumeRect = new Rectangle(iconPositionX, itemRectList[0].Center.Y - barheight / 2, barwidth, barheight); iconRectList.Add(musicVolumeRect); soundVolumeRect = new Rectangle(iconPositionX, itemRectList[1].Center.Y - barheight / 2, barwidth, barheight); iconRectList.Add(soundVolumeRect); showLiveTipRect = new Rectangle(iconPositionX+ barwidth/2, itemRectList[2].Center.Y - checkBoxheight/2, checkboxWidth, checkBoxheight); iconRectList.Add(showLiveTipRect); specialEffectRect = new Rectangle(iconPositionX + barwidth/2, itemRectList[3].Center.Y - checkBoxheight / 2, checkboxWidth, checkBoxheight); iconRectList.Add(specialEffectRect); numParticleRect = new Rectangle(iconPositionX, itemRectList[4].Center.Y - barheight / 2, barwidth, barheight); iconRectList.Add(numParticleRect); schoolFishRect = new Rectangle(iconPositionX, itemRectList[5].Center.Y - barheight / 2, barwidth, barheight); iconRectList.Add(schoolFishRect); easyRect = new Rectangle(iconPositionX, itemRectList[6].Center.Y - checkBoxheight / 2, checkboxWidth, checkBoxheight); iconRectList.Add(easyRect); mediumRect = new Rectangle(iconPositionX + checkboxWidth * 3, itemRectList[6].Center.Y - checkBoxheight / 2, checkboxWidth, checkBoxheight); iconRectList.Add(mediumRect); hardRect = new Rectangle(iconPositionX + checkboxWidth * 6, itemRectList[6].Center.Y - checkBoxheight / 2, checkboxWidth, checkBoxheight); iconRectList.Add(hardRect); width = titleWidth/2; height = (int)(titleHeight*0.75); okBox = new Rectangle(game.Window.ClientBounds.Center.X - width / 2, game.Window.ClientBounds.Bottom - (int)(height * 1.5), width, height); // Get the current spritebatch spriteBatch = (SpriteBatch)Game.Services.GetService( typeof(SpriteBatch)); // Get the audio library audio = (AudioLibrary) Game.Services.GetService(typeof(AudioLibrary)); cursor = new Cursor(game, spriteBatch); selectedIndex = -1; }
public static TreasureChest MouseOnWhichChest(Cursor cursor, Camera gameCamera, List<TreasureChest> treasureChests) { if (treasureChests == null) return null; BoundingSphere treasureChestRealSphere; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (TreasureChest treasureChest in treasureChests) { treasureChestRealSphere = treasureChest.BoundingSphere; treasureChestRealSphere.Center.Y = treasureChest.Position.Y; treasureChestRealSphere.Radius *= 1; if (RayIntersectsBoundingSphere(cursorRay, treasureChestRealSphere)) { return treasureChest; } } return null; }
public static BaseEnemy MouseOnWhichEnemy(Cursor cursor, Camera gameCamera, BaseEnemy[] enemies, int enemiesAmount) { if (enemies == null) return null; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); BoundingSphere sphere; for (int i = 0; i < enemiesAmount; i++) { //making it easier to aim sphere = enemies[i].BoundingSphere; sphere.Radius *= GameConstants.EasyAimScale; if (RayIntersectsBoundingSphere(cursorRay, sphere)) { //cursor.SetShootingMouseImage(); return enemies[i]; } } //cursor.SetNormalMouseImage(); return null; }
public static bool InShootingRange(HydroBot hydroBot, Cursor cursor, Camera gameCamera, float planeHeight) { Vector3 pointIntersect = IntersectPointWithPlane(cursor, gameCamera, planeHeight); Vector3 mouseDif = pointIntersect - hydroBot.Position; float distanceFromTank = mouseDif.Length(); if (distanceFromTank < GameConstants.BotShootingRange) return true; else return false; }
public static Fish MouseOnWhichFish(Cursor cursor, Camera gameCamera, Fish[] fish, int fishAmount) { if (fish == null) return null; BoundingSphere sphere; Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); for (int i = 0; i < fishAmount; i++) { sphere = fish[i].BoundingSphere; sphere.Radius *= GameConstants.EasyAimScale; if (RayIntersectsBoundingSphere(cursorRay, sphere)) { return fish[i]; } } //cursor.SetNormalMouseImage(); return null; }
public static Vector3 IntersectPointWithPlane(Cursor cursor, Camera gameCamera, float planeHeight) { Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); float t = (planeHeight - cursorRay.Position.Y) / cursorRay.Direction.Y; float x = cursorRay.Position.X + cursorRay.Direction.X * t; float z = cursorRay.Position.Z + cursorRay.Direction.Z * t; return new Vector3(x, planeHeight, z); }
public static void MouseOnWhichResource(Cursor cursor, Camera gameCamera, List<Resource> resources, ref Resource cursorOnResource, ref Resource botOnResource, HydroBot hydroBot) { bool foundBotOnResource = false, foundCursorOnResource = false; if (hydroBot == null) foundBotOnResource = true; if (cursor == null) foundCursorOnResource = true; BoundingSphere botPowerPackBoundingSphere = new BoundingSphere(); if (!foundBotOnResource) botPowerPackBoundingSphere = new BoundingSphere(hydroBot.BoundingSphere.Center, 5); if (resources == null) return; Ray cursorRay = new Ray(); if (cursor != null) cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Resource resource in resources) { if (!foundBotOnResource) { if (resource.BoundingSphere.Intersects(botPowerPackBoundingSphere)) { foundBotOnResource = true; botOnResource = resource; } } if (!foundCursorOnResource) { if (RayIntersectsBoundingSphere(cursorRay, resource.BoundingSphere)) { foundCursorOnResource = true; cursorOnResource = resource; } } if (foundBotOnResource && foundCursorOnResource) return; } }
public static bool MouseOnEnemy(Cursor cursor, Camera gameCamera, BaseEnemy[] enemies, int enemiesAmount) { Ray cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); BoundingSphere sphere; for (int i = 0; i < enemiesAmount; i++) { //making it easier to aim sphere = enemies[i].BoundingSphere; //boss is already big if (!enemies[i].isBigBoss) sphere.Radius *= GameConstants.EasyAimScale; if (RayIntersectsBoundingSphere(cursorRay, sphere)) { cursor.SetShootingMouseImage(); return true; } } cursor.SetNormalMouseImage(); return false; }
public static void MouseOnWhichTrash(Cursor cursor, Camera gameCamera, List<Trash> trashes,ref Trash cursorOnTrash,ref Trash botOnTrash, HydroBot hydroBot) { bool foundBotOnTrash = false, foundCursorOnTrash = false; if (hydroBot == null) foundBotOnTrash = true; BoundingSphere botTrashBoundingSphere = new BoundingSphere(); if (!foundBotOnTrash) botTrashBoundingSphere = new BoundingSphere(hydroBot.BoundingSphere.Center, 20); if (trashes == null) return; BoundingSphere trashRealSphere; Ray cursorRay = new Ray(); if (cursor != null) cursorRay = cursor.CalculateCursorRay(gameCamera.ProjectionMatrix, gameCamera.ViewMatrix); foreach (Trash trash in trashes) { trashRealSphere = trash.BoundingSphere; trashRealSphere.Center.Y = trash.Position.Y; trashRealSphere.Radius *= 5; if (!foundBotOnTrash) { if (trash.BoundingSphere.Intersects(botTrashBoundingSphere)) { foundBotOnTrash = true; botOnTrash = trash; } } if (!foundCursorOnTrash) { if (RayIntersectsBoundingSphere(cursorRay, trashRealSphere)) { foundCursorOnTrash = true; cursorOnTrash = trash; } } if (foundBotOnTrash && foundCursorOnTrash) return; } }
public static void UseSkill(bool mouseOnLivingObject, Vector3 pointIntersect, Cursor cursor, Camera gameCamera, GameMode gameMode, HydroBot hydroBot, GameScene gameScene, ContentManager Content, SpriteBatch spriteBatch, GameTime gameTime, List<DamageBullet> myBullet, BaseEnemy[] enemies, ref int enemiesAmount, Fish[] fish, ref int fishAmount, ref bool isCastingSkill) { if (isCastingSkill) { if (!hydroBot.clipPlayer.inRange(75, 95)) hydroBot.clipPlayer.switchRange(75, 95); //animation done playing, cast the skill now if (hydroBot.clipPlayer.donePlayingAnimation) { int healthToLose = 0; isCastingSkill = false; if (shootHammer) { ShootHammer(hydroBot, Content, myBullet, gameMode); HydroBot.skillPrevUsed[0] = PoseidonGame.playTime.TotalSeconds; HydroBot.skillPrevUsed[1] = PoseidonGame.playTime.TotalSeconds; HydroBot.firstUse[0] = false; HydroBot.firstUse[1] = false; shootHammer = false; } if (shootPiercingArrow) { ShootPiercingArrow(hydroBot, Content, spriteBatch, myBullet, gameMode); HydroBot.skillPrevUsed[0] = PoseidonGame.playTime.TotalSeconds; HydroBot.skillPrevUsed[3] = PoseidonGame.playTime.TotalSeconds; HydroBot.firstUse[0] = false; HydroBot.firstUse[3] = false; shootPiercingArrow = false; } if (shootHerculesArrow) { HydroBot.firstUse[0] = false; HydroBot.skillPrevUsed[0] = PoseidonGame.playTime.TotalSeconds; //audio.Explosion.Play(); CastSkill.UseHerculesBow(hydroBot, Content, spriteBatch, myBullet, gameMode); shootHerculesArrow = false; } if (useThorHammer) { HydroBot.firstUse[1] = false; HydroBot.skillPrevUsed[1] = PoseidonGame.playTime.TotalSeconds; PoseidonGame.audio.Explo1.Play(); gameCamera.Shake(25f, .4f); CastSkill.UseThorHammer(hydroBot.Position, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, enemies, ref enemiesAmount, fish, fishAmount, HydroBot.gameMode, false); useThorHammer = false; } if (castInvincible) { HydroBot.firstUse[2] = false; HydroBot.invincibleMode = true; HydroBot.skillPrevUsed[2] = PoseidonGame.playTime.TotalSeconds; castInvincible = false; PoseidonGame.audio.armorSound.Play(); } if (castAutoExplode) { HydroBot.invincibleMode = true; HydroBot.autoExplodeMode = true; HydroBot.skillPrevUsed[2] = PoseidonGame.playTime.TotalSeconds; HydroBot.skillPrevUsed[1] = PoseidonGame.playTime.TotalSeconds; HydroBot.firstUse[2] = false; HydroBot.firstUse[1] = false; castAutoExplode = false; PoseidonGame.audio.armorSound.Play(); } if (castAutoHipno) { HydroBot.invincibleMode = true; HydroBot.autoHipnotizeMode = true; HydroBot.skillPrevUsed[2] = PoseidonGame.playTime.TotalSeconds; HydroBot.skillPrevUsed[4] = PoseidonGame.playTime.TotalSeconds; HydroBot.firstUse[2] = false; HydroBot.firstUse[4] = false; castAutoHipno = false; PoseidonGame.audio.armorSound.Play(); } if (castSonic) { HydroBot.firstUse[3] = false; HydroBot.skillPrevUsed[3] = PoseidonGame.playTime.TotalSeconds; HydroBot.supersonicMode = true; castSonic = false; PoseidonGame.audio.hermesSound.Play(); } if (castSonicHipno) { HydroBot.sonicHipnotiseMode = true; HydroBot.supersonicMode = true; HydroBot.skillPrevUsed[4] = PoseidonGame.playTime.TotalSeconds; HydroBot.skillPrevUsed[3] = PoseidonGame.playTime.TotalSeconds; HydroBot.firstUse[4] = false; HydroBot.firstUse[3] = false; castSonicHipno = false; PoseidonGame.audio.hermesSound.Play(); } if (castHipno) { HydroBot.firstUse[4] = false; PoseidonGame.audio.hipnotizeSound.Play(); useHypnotise(enemyToHipNo); HydroBot.skillPrevUsed[4] = PoseidonGame.playTime.TotalSeconds; castHipno = false; enemyToHipNo = null; } //lose health after using skill if (HydroBot.skillComboActivated && HydroBot.secondSkillID != -1 && HydroBot.secondSkillID != HydroBot.activeSkillID) healthToLose = (int)(2 * GameConstants.EnergyLostPerSkill);//GameConstants.skillHealthLoss; else healthToLose = (int)(GameConstants.EnergyLostPerSkill); //display HP loss //HydroBot.currentHitPoint -= healthToLose; //we now lose energy instead of health int energyLost = healthToLose; HydroBot.currentEnergy -= energyLost; Point point = new Point(); String point_string = "-" + energyLost.ToString() + "Energy"; point.LoadContent(PoseidonGame.contentManager, point_string, hydroBot.Position, Color.Red); if (gameMode == GameMode.ShipWreck) ShipWreckScene.points.Add(point); else if (gameMode == GameMode.MainGame) PlayGameScene.points.Add(point); else if (gameMode == GameMode.SurvivalMode) SurvivalGameScene.points.Add(point); if (!hydroBot.clipPlayer.inRange(50, 74)) hydroBot.clipPlayer.switchRange(50, 74); } return; } else //skill casting may have been aborted { shootHammer = shootPiercingArrow = shootHerculesArrow = useThorHammer = castInvincible = castAutoExplode = castAutoHipno = castSonic = castSonicHipno = castHipno = false; } bool skillUsed = false; int floatHeight; if (gameMode == GameMode.ShipWreck) floatHeight = GameConstants.ShipWreckFloatHeight; else floatHeight = GameConstants.MainGameFloatHeight; pointIntersect = CursorManager.IntersectPointWithPlane(cursor, gameCamera, floatHeight); hydroBot.ForwardDirection = CursorManager.CalculateAngle(pointIntersect, hydroBot.Position); // Hercules' Bow!!! if (HydroBot.activeSkillID == 0)// && mouseOnLivingObject) { //use skill combo if activated //cooldowns for both skills must be cleared if ((HydroBot.skillComboActivated && HydroBot.secondSkillID == 1) && //cooldowns check ((HydroBot.firstUse[0] == true && HydroBot.firstUse[1] == true)|| (PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[0] > GameConstants.coolDownForHerculesBow && PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[1] > GameConstants.coolDownForThorHammer))) { //ShootHammer(hydroBot, Content, myBullet, gameMode); //HydroBot.skillPrevUsed[0] = PoseidonGame.playTime.TotalSeconds; //HydroBot.skillPrevUsed[1] = PoseidonGame.playTime.TotalSeconds; //HydroBot.firstUse[0] = false; //HydroBot.firstUse[1] = false; shootHammer = true; skillUsed = true; } else if ((HydroBot.skillComboActivated && HydroBot.secondSkillID == 3) && ((HydroBot.firstUse[3] == true && HydroBot.firstUse[0] == true) || (PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[0] > GameConstants.coolDownForHerculesBow && PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[3] > GameConstants.coolDownForHermesSandal))) { //ShootPiercingArrow(hydroBot, Content, spriteBatch, myBullet, gameMode); //HydroBot.skillPrevUsed[0] = PoseidonGame.playTime.TotalSeconds; //HydroBot.skillPrevUsed[3] = PoseidonGame.playTime.TotalSeconds; //HydroBot.firstUse[0] = false; //HydroBot.firstUse[3] = false; shootPiercingArrow = true; skillUsed = true; } //or else use single skill //if the skill has cooled down //or this is the 1st time the user uses it else if ((PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[0] > GameConstants.coolDownForHerculesBow) || HydroBot.firstUse[0] == true) { //HydroBot.firstUse[0] = false; //HydroBot.skillPrevUsed[0] = PoseidonGame.playTime.TotalSeconds; ////audio.Explosion.Play(); //CastSkill.UseHerculesBow(hydroBot, Content, spriteBatch, myBullet, gameMode); shootHerculesArrow = true; skillUsed = true; } } //Thor's Hammer!!! if (HydroBot.activeSkillID == 1) { if ((PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[1] > GameConstants.coolDownForThorHammer) || HydroBot.firstUse[1] == true) { //HydroBot.firstUse[1] = false; //HydroBot.skillPrevUsed[1] = PoseidonGame.playTime.TotalSeconds; //PoseidonGame.audio.Explo1.Play(); //gameCamera.Shake(25f, .4f); //CastSkill.UseThorHammer(hydroBot.Position, hydroBot.MaxRangeX, hydroBot.MaxRangeZ, enemies, ref enemiesAmount, fish, fishAmount, HydroBot.gameMode, false); useThorHammer = true; skillUsed = true; } } // Achilles' Armor!!! if (HydroBot.activeSkillID == 2) { if ((HydroBot.skillComboActivated && HydroBot.secondSkillID == 4) && //cooldowns check ((HydroBot.firstUse[2] == true && HydroBot.firstUse[4] == true) || (PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[2] > GameConstants.coolDownForArchillesArmor && PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[4] > GameConstants.coolDownForHypnotise))) { //HydroBot.invincibleMode = true; //HydroBot.autoHipnotizeMode = true; //HydroBot.skillPrevUsed[2] = PoseidonGame.playTime.TotalSeconds; //HydroBot.skillPrevUsed[4] = PoseidonGame.playTime.TotalSeconds; //HydroBot.firstUse[2] = false; //HydroBot.firstUse[4] = false; castAutoHipno = true; skillUsed = true; } else if ((HydroBot.skillComboActivated && HydroBot.secondSkillID == 1) && //cooldowns check ((HydroBot.firstUse[2] == true && HydroBot.firstUse[1] == true) || (PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[2] > GameConstants.coolDownForArchillesArmor && PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[1] > GameConstants.coolDownForThorHammer))) { //HydroBot.invincibleMode = true; //HydroBot.autoExplodeMode = true; //HydroBot.skillPrevUsed[2] = PoseidonGame.playTime.TotalSeconds; //HydroBot.skillPrevUsed[1] = PoseidonGame.playTime.TotalSeconds; //HydroBot.firstUse[2] = false; //HydroBot.firstUse[1] = false; castAutoExplode = true; skillUsed = true; } else if ((PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[2] > GameConstants.coolDownForArchillesArmor) || HydroBot.firstUse[2] == true) { //HydroBot.firstUse[2] = false; //HydroBot.invincibleMode = true; //HydroBot.skillPrevUsed[2] = PoseidonGame.playTime.TotalSeconds; castInvincible = true; skillUsed = true; } //if (skillUsed) PoseidonGame.audio.armorSound.Play(); } //Hermes' Winged Sandal!!! if (HydroBot.activeSkillID == 3) { if ((HydroBot.skillComboActivated && HydroBot.secondSkillID == 4) && ((HydroBot.firstUse[3] == true && HydroBot.firstUse[4] == true) || (PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[4] > GameConstants.coolDownForHypnotise && PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[3] > GameConstants.coolDownForHermesSandal))) { //HydroBot.sonicHipnotiseMode = true; //HydroBot.supersonicMode = true; //HydroBot.skillPrevUsed[4] = PoseidonGame.playTime.TotalSeconds; //HydroBot.skillPrevUsed[3] = PoseidonGame.playTime.TotalSeconds; //HydroBot.firstUse[4] = false; //HydroBot.firstUse[3] = false; castSonicHipno = true; skillUsed = true; } else if ((PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[3] > GameConstants.coolDownForHermesSandal) || HydroBot.firstUse[3] == true) { //HydroBot.firstUse[3] = false; //HydroBot.skillPrevUsed[3] = PoseidonGame.playTime.TotalSeconds; //HydroBot.supersonicMode = true; castSonic = true; skillUsed = true; } //if (skillUsed) PoseidonGame.audio.hermesSound.Play(); } // Hypnotise skill if (HydroBot.activeSkillID == 4) { BaseEnemy enemy = CursorManager.MouseOnWhichEnemy(cursor, gameCamera, enemies, enemiesAmount); //can't hipnotize a submarine if (enemy != null && !(enemy is Submarine) && (HydroBot.firstUse[4] == true || PoseidonGame.playTime.TotalSeconds - HydroBot.skillPrevUsed[4] > GameConstants.coolDownForHypnotise)) { //HydroBot.firstUse[4] = false; //PoseidonGame.audio.hipnotizeSound.Play(); //useHypnotise(enemy); //HydroBot.skillPrevUsed[4] = PoseidonGame.playTime.TotalSeconds; castHipno = true; skillUsed = true; enemyToHipNo = enemy; } } if (skillUsed) { isCastingSkill = true; } //stop moving whether or not the skill has been casted hydroBot.reachDestination = true; pointIntersect = Vector3.Zero; }