public virtual bool Intersects(FoldingTile tile, out float collisionY) { float bottomMidpoint; if (tile.SlantDepth) { bottomMidpoint = (Z - tile.Z) + (Width / 2); } else { bottomMidpoint = (X - tile.X) + (Width / 2); } if (Left <= tile.Right && Right >= tile.Left && Top <= tile.Bottom && Bottom >= tile.Top && Front >= tile.Front && Back <= tile.Back) { if (tile.SlantOpposite) { collisionY = tile.Y - (bottomMidpoint * tile.Scale); } else { collisionY = tile.Y + (bottomMidpoint * tile.Scale); } return(true); } collisionY = -1; return(false); }
public static void DrawFoldingTileTop(FoldingTile foldingTile, Color color) { Vector2[] vectors = new Vector2[4] { new Vector2(foldingTile.matrixPoint[0].X, foldingTile.matrixPoint[0].Z), new Vector2(foldingTile.matrixPoint[1].X, foldingTile.matrixPoint[1].Z), new Vector2(foldingTile.matrixPoint[2].X, foldingTile.matrixPoint[2].Z), new Vector2(foldingTile.matrixPoint[3].X, foldingTile.matrixPoint[3].Z) }; GL.Begin(PrimitiveType.Quads); GL.Color3(color); for (int x = 0; x < 4; x++) { vectors[x].X *= foldingTile.Size.X; vectors[x].Y *= foldingTile.Size.Y; vectors[x] += new Vector2(foldingTile.position.X, foldingTile.position.Z); GL.Vertex2(vectors[x]); } GL.End(); }
public void Update(double gameTime, FoldingTile[] staticEnvironment, double rotationArgs) { rotation = rotationArgs; position.Y += velocityY; if (Input.KeyDown(OpenTK.Input.Key.Space)) position.Y += 1; if (Input.KeyDown(OpenTK.Input.Key.ControlLeft)) position.Y -= 1; if (onGround) { jumped = false; velocityY = 0; } else velocityY -= (float)(9.8 * gameTime); onGround = false; foreach (FoldingTile foldingTile in staticEnvironment) { float collisionY; if (Intersects(foldingTile, out collisionY)) { onGround = true; if (jumped == false) { position = new Vector3d(position.X, collisionY, position.Z); } } } }
public virtual bool Intersects(FoldingTile tile, out float collisionY) { float bottomMidpoint; if (tile.SlantDepth) bottomMidpoint = (Z - tile.Z) + (Width / 2); else bottomMidpoint = (X - tile.X) + (Width / 2); if (Left <= tile.Right && Right >= tile.Left && Top <= tile.Bottom && Bottom >= tile.Top && Front >= tile.Front && Back <= tile.Back) { if (tile.SlantOpposite) collisionY = tile.Y - (bottomMidpoint * tile.Scale); else collisionY = tile.Y + (bottomMidpoint * tile.Scale); return true; } collisionY = -1; return false; }
public static void DrawFoldingTileFront(FoldingTile foldingTile, Color color) { Vector3[] vectors = new Vector3[4] { new Vector3(foldingTile.matrixPoint[0].X, foldingTile.matrixPoint[0].Y, foldingTile.matrixPoint[0].Z), new Vector3(foldingTile.matrixPoint[1].X, foldingTile.matrixPoint[1].Y, foldingTile.matrixPoint[1].Z), new Vector3(foldingTile.matrixPoint[2].X, foldingTile.matrixPoint[2].Y, foldingTile.matrixPoint[2].Z), new Vector3(foldingTile.matrixPoint[3].X, foldingTile.matrixPoint[3].Y, foldingTile.matrixPoint[3].Z) }; for (int x = 0; x < 4; x++) { vectors[x].X *= foldingTile.Size.X; vectors[x].Z *= foldingTile.Size.Y; if (foldingTile.SlantDepth) { vectors[x].Y *= foldingTile.Size.Y; } else { vectors[x].Y *= foldingTile.Size.X; } vectors[x] += foldingTile.position; } float minX = vectors[0].X, minY = vectors[0].Y; float maxX = vectors[0].X, maxY = vectors[0].Y; for (int x = 0; x < vectors.Length; x++) { if (vectors[x].X < minX) { minX = vectors[x].X; } if (vectors[x].Y < minY) { minY = vectors[x].Y; } if (vectors[x].X > maxX) { maxX = vectors[x].X; } if (vectors[x].Y > maxY) { maxY = vectors[x].Y; } } if (foldingTile.SlantDepth == true) { GL.Color3(color); GL.Begin(PrimitiveType.Quads); GL.Vertex2(minX, minY); GL.Vertex2(minX, -maxY); GL.Vertex2(maxX, -maxY); GL.Vertex2(maxX, minY); GL.End(); } else { GL.LineWidth(1.0f); GL.Color3(color); GL.Begin(PrimitiveType.Lines); GL.Vertex2(minX, -minY); GL.Vertex2(maxX, -maxY); GL.End(); } }