public bool isInsideGap(SpriteBase sprite) { Bounds2 spriteBounds = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref spriteBounds); return(pipeGap.Overlaps(spriteBounds)); }
public new bool HasCollidedWithPlayer(SpriteUV player) //Check if the a sprite has hit a part of the maze { if (tileIndex > 5 && tileIndex < 15) { laserOn = true; } else { laserOn = false; } Bounds2 playerBounds = player.GetlContentLocalBounds(); player.GetContentWorldBounds(ref playerBounds); //Get sprite bounds (player bounds) Bounds2 laserBounds = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref laserBounds); //Get all of the maze bounds laserBounds.Max = laserBounds.Max - 15.0f; laserBounds.Min = laserBounds.Min + 15.0f; if (playerBounds.Overlaps(laserBounds) && laserOn) { return(true); } return(false); }
public void CheckInput() { var touches = Touch.GetData(0); var touchPos = Input2.Touch00.Pos; Bounds2 touchBox = new Bounds2(); touchBox.Min.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Max.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Min.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); touchBox.Max.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); if (touchBox.Overlaps(restartBox) && touches.Count != 0) { restart = true; } if (Input2.GamePad0.Square.Release) { restart = true; } if (touches.Count > 0) { restart = true; } }
/* * Simple collision check between two entities * */ public static bool checkCollisionBetweenEntities(GameEntity ge1, GameEntity ge2) { Bounds2 tempBounds1 = new Bounds2(ge1.Position + ge1.bounds.Min, ge1.Position + ge1.bounds.Max); Bounds2 tempBounds2 = new Bounds2(ge2.Position + ge2.bounds.Min, ge2.Position + ge2.bounds.Max); return(tempBounds1.Overlaps(tempBounds2)); }
public bool HasCollidedWith(SpriteUV sprite) { //beam1 bounds Bounds2 beam1 = spinSprite[0].GetlContentLocalBounds(); spinSprite[0].GetContentWorldBounds(ref beam1); //beam2 bounds Bounds2 beam2 = spinSprite[1].GetlContentLocalBounds(); spinSprite[1].GetContentWorldBounds(ref beam2); //beam3 bounds Bounds2 beam3 = spinSprite[2].GetlContentLocalBounds(); spinSprite[2].GetContentWorldBounds(ref beam3); //player bounds Bounds2 player = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref player); if (player.Overlaps(beam1)) { return(true); } if (player.Overlaps(beam2)) { return(true); } if (player.Overlaps(beam3)) { return(true); } else { return(false); } }
public bool HasCollidedWithPlayer(Bounds2 player) //Check if the a sprite has hit a part of the maze { foreach (SpriteUV spri in sprites) { Bounds2 mazeTile = spri.GetlContentLocalBounds(); spri.GetContentWorldBounds(ref mazeTile); //Get all of the maze bounds if (player.Overlaps(mazeTile)) //Return true if the player overlaps with the maze { return(true); } } return(false); }
public bool HasHitSide(Bounds2 player, int gravity) //Checks if the player has hit the side of the maze and not the floor { foreach (SpriteUV spri in sprites) { Bounds2 mazeTile = spri.GetlContentLocalBounds(); spri.GetContentWorldBounds(ref mazeTile); //Get all of the maze bounds if (player.Overlaps(mazeTile)) //Return true if the player overlaps with the maze { if (checkSides(player, spri, gravity)) //Return true if the player has come into contact with a side { return(true); } } } return(false); }
public bool isCollidingWith(SpriteBase sprite) { Bounds2 topRect = sprites[0].GetlContentLocalBounds(); sprites[0].GetContentWorldBounds(ref topRect); Bounds2 botRect = sprites[1].GetlContentLocalBounds(); sprites[1].GetContentWorldBounds(ref botRect); Bounds2 spriteRect = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref spriteRect); bool isTopCollision = topRect.Overlaps(spriteRect); bool isBottomCollision = botRect.Overlaps(spriteRect); return(isTopCollision || isBottomCollision); }
public void Update(float Offset) { if (Engine.GetKeyDown(Key.F)) { GenerateTerrain(); } for (int y = 0; y < Terrain.Count; y++) { for (int x = 0; x < Terrain[y].Count; x++) { int type = Terrain[y][x]; Bounds2 bounds = new Bounds2(((x - LEVELONEWIDTH / 2) * TILESIZE) - Offset, y * TILESIZE, TILESIZE, TILESIZE); if (screen.Overlaps(bounds)) { switch (type) { case GameScreen.AIR: Engine.DrawRectSolid(bounds, new Color(38, 198, 235)); //Engine.DrawRectEmpty(tileBounds, Color.Black); break; case GameScreen.DIRT: Engine.DrawRectSolid(bounds, Color.Brown); break; case GameScreen.GRASS: Engine.DrawRectSolid(bounds, Color.Green); break; } } } } for (int x = 0; x < Flowers.Length; x++) { if (Flowers[x] == true) { Engine.DrawTexture(Flower, new Vector2(((x - LEVELONEWIDTH / 2) * TILESIZE) - Offset, Heights[x] * TILESIZE - TILESIZE)); } } //clouds.Update(Offset); }
public bool HasCollidedWithPlayer(SpriteUV player) //Check if the a sprite has hit a part of the maze { if (collected == false) { Bounds2 playerBounds = player.GetlContentLocalBounds(); player.GetContentWorldBounds(ref playerBounds); //Get sprite bounds (player bounds) Bounds2 spriteBounds = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref spriteBounds); //Get all of the maze bounds if (playerBounds.Overlaps(spriteBounds)) { return(true); } } return(false); }
public new bool HasCollidedWithPlayer(SpriteUV player) //Check if the a sprite has hit a part of the maze { Bounds2 playerBounds = player.GetlContentLocalBounds(); player.GetContentWorldBounds(ref playerBounds); //Get sprite bounds (player bounds) Bounds2 holeBounds = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref holeBounds); //Get all of the maze bounds holeBounds.Max = holeBounds.Max - 15.0f; holeBounds.Min = holeBounds.Min + 15.0f; if (playerBounds.Overlaps(holeBounds)) { return(true); } return(false); }
public void CheckInput() { var touches = Touch.GetData(0); var touchPos = Input2.Touch00.Pos; Bounds2 touchBox = new Bounds2(); touchBox.Min.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Max.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Min.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); touchBox.Max.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); if (touchBox.Overlaps(muteBox) && touches.Count != 0) { Hide(); } }
/* * checks collisions with AmmoPacks * shit method, fix to use a QuadTree instead, otherwise creates a performance hit * */ public static bool checkAmmoPackCollisions(GameEntity ge, List <AmmoItem> list, out AmmoItem ai) { //temp bounds Bounds2 tempBounds1 = new Bounds2(ge.Position + ge.bounds.Min, ge.Position + ge.bounds.Max); foreach (AmmoItem a in list) { //for the ammo pack Bounds2 tempBounds2 = new Bounds2(a.Position + a.bounds.Min, a.Position + a.bounds.Max); if (tempBounds1.Overlaps(tempBounds2)) { ai = a; return(true); } } ai = null; return(false); }
/* * Checks collisions of enemies together * DEPRACATED - use efficientCollisionsCheck instead * */ public static bool checkEnemiesCollisions(GameEntity ge, List <Enemy> list, Vector2 proposedChange, out Enemy oe) { //temp bounds Bounds2 tempBounds1 = new Bounds2(ge.Position + proposedChange + ge.bounds.Min, ge.Position + proposedChange + ge.bounds.Max); foreach (Enemy e in list) { if (ge.GetType() == typeof(BasicEnemy) && e.Equals(ge)) { continue; } //also making the enemy bound box bigger Bounds2 tempBounds2 = new Bounds2(e.Position + e.bounds.Min * 2.0f, e.Position + e.bounds.Max * 2.0f); if (tempBounds1.Overlaps(tempBounds2)) { oe = e; return(true); } } oe = null; return(false); }
public static void Update() { if (screenManager.IsTransitioning()) { screenManager.Update(gameScene); // Transition Finished, load relevant data if (!screenManager.IsTransitioning()) { if (screenManager.GetScreen() == Screens.Game) { SetupGame(); soundManager.PlayBGM(); } else if (screenManager.GetScreen() == Screens.GameOver) { gameScene.Camera2D.SetViewY(new Vector2(0.0f, Director.Instance.GL.Context.GetViewport().Height *0.5f), new Vector2((Director.Instance.GL.Context.GetViewport().Width *0.5f), Director.Instance.GL.Context.GetViewport().Height *0.5f)); } } } else { UpdateTouchData(); switch (screenManager.GetScreen()) { case Screens.Splash: screenManager.ChangeScreenTo(Screens.Menu); break; case Screens.Game: if (!tutorialManager.HasPopUp()) { GameUpdate(); } else { UpdateTouchData(); } break; case Screens.GameOver: Vector2 touchPos = Input2.Touch00.Pos; if (touchPos.X >= 0) { touchPos = new Vector2((touchPos.X * 450) + 450, (touchPos.Y * 272) + 272); } else { touchPos = new Vector2(((touchPos.X + 1) * 450), ((touchPos.Y + 1) * 272)); } Bounds2 touchBox = new Bounds2(touchPos, touchPos); if (touchBox.Overlaps(rSprite.GetlContentLocalBounds())) { screenManager.ChangeScreenTo(Screens.Menu); gameScene.RemoveChild(rSprite, false); } break; } } }
public void CheckInput() { var touches = Touch.GetData(0); var touchPos = Input2.Touch00.Pos; Bounds2 touchBox = new Bounds2(); touchBox.Min.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Max.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Min.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); touchBox.Max.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); if (!options) { if (touchBox.Overlaps(playBox) && touches.Count != 0) { play = true; RemoveAll(); } if (touchBox.Overlaps(controlsBox) && touches.Count != 0) { //options = true; //optionScreen.Show(); dialog.Show(); options = true; } if (Input2.GamePad0.Cross.Release && playSprite.TextureInfo == playSelectTexture) { play = true; RemoveAll(); } if (Input2.GamePad0.Down.Release) { playSprite.TextureInfo = playTexture; controlSprite.TextureInfo = controlTexture; } if (Input2.GamePad0.Right.Release) { controlSprite.TextureInfo = controlSelectTexture; playSprite.TextureInfo = playTexture; } if (Input2.GamePad0.Left.Release) { controlSprite.TextureInfo = controlTexture; playSprite.TextureInfo = playTexture; } if (Input2.GamePad0.Up.Release) { controlSprite.TextureInfo = controlTexture; playSprite.TextureInfo = playSelectTexture; } } else { //if (!optionScreen.CheckOptions()) // options = false; } }
public void Input(List <List <int> > tiles) { if (Engine.GetKeyHeld(Key.A)) { WalkState = WSTATE.LEFT; } else if (Engine.GetKeyHeld(Key.D)) { WalkState = WSTATE.RIGHT; } else { WalkState = WSTATE.STANDING; } if (Engine.GetKeyHeld(Key.W) && JumpState == JSTATE.STANDING) { JumpState = JSTATE.JUMPING; } Velocities(); bool cx = false; bool cy = false; //Collision for (int y = 0; y < tiles.Count; y++) { for (int x = 0; x < tiles[y].Count; x++) { Bounds2 tBounds; if (tiles[y][x] != GameScreen.AIR) { tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset + VelocityX), y * GrassBiome.TILESIZE, GrassBiome.TILESIZE, GrassBiome.TILESIZE); if (GetBounds().Overlaps(tBounds)) { cx = true; } tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset), (y * GrassBiome.TILESIZE), GrassBiome.TILESIZE, GrassBiome.TILESIZE); Bounds2 pBounds = new Bounds2(ScreenX + 7, ScreenY + VelocityY, Width, Height); if (pBounds.Overlaps(tBounds)) { cy = true; } tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset), y * GrassBiome.TILESIZE, GrassBiome.TILESIZE, GrassBiome.TILESIZE); float dx = VelocityX / Math.Abs(VelocityX); float dy = VelocityY / Math.Abs(VelocityY); if (GetBounds().Overlaps(tBounds)) { tBounds = new Bounds2(((x - GrassBiome.LEVELONEWIDTH / 2) * GrassBiome.TILESIZE) - (Offset), y * GrassBiome.TILESIZE, GrassBiome.TILESIZE, GrassBiome.TILESIZE); while (GetBounds().Overlaps(tBounds)) { ScreenY -= 1; } } } } } if (cx) { VelocityX = 0; WalkState = WSTATE.STANDING; Current = Standing; } if (cy) { Current = Standing; VelocityY = 0; JumpState = JSTATE.STANDING; } else if (JumpState == JSTATE.STANDING) { JumpState = JSTATE.FALLING; } }