public void TestIterationChanged() { var ent0 = new StationaryShape(0.0f, 0.0f, 0.0f, 0.0f); var ent1 = new StationaryShape(1.0f, 1.0f, 1.0f, 1.0f); var ent2 = new StationaryShape(2.0f, 2.0f, 2.0f, 2.0f); var ent3 = new StationaryShape(3.0f, 3.0f, 3.0f, 3.0f); var ent4 = new StationaryShape(4.0f, 4.0f, 4.0f, 4.0f); var ent5 = new StationaryShape(5.0f, 5.0f, 5.0f, 5.0f); var ents = new EntityContainer(); foreach (var shp in new[] { ent0, ent1, ent2, ent3, ent4, ent5 }) { ents.AddStationaryEntity(shp, null); } ents.Iterate(entity => { entity.Shape.Position.X *= -1.0f; entity.Shape.Position.Y *= -1.0f; }); foreach (Entity ent in ents) { Assert.LessOrEqual(ent.Shape.Position.X, 0.0f); Assert.LessOrEqual(ent.Shape.Position.Y, 0.0f); } }
public void AddEntity(StationaryShape shape, IBaseImage image) { // add to entities GameObjectEntities.AddStationaryEntity(shape, image); // update the Platform bounding box if (shape.Position.X < BoundingBox.Position.X) { BoundingBox.Position.X = shape.Position.X; } if (shape.Position.Y < BoundingBox.Position.Y) { BoundingBox.Position.Y = shape.Position.Y; } if (shape.Position.X + shape.Extent.X > BoundingBox.Position.X + BoundingBox.Extent.X) { BoundingBox.Extent.X = (shape.Position.X + shape.Extent.X) - BoundingBox.Position.X; } if (shape.Position.Y + shape.Extent.Y > BoundingBox.Position.Y + BoundingBox.Extent.Y) { BoundingBox.Extent.Y = (shape.Position.Y + shape.Extent.Y) - BoundingBox.Position.Y; } }
[Test] // Testing too much speed collision with platform results in death. public void CollisionWithPlatformDeathTest() { _testCollisionObstacle = new EntityContainer(); _testCollisionPlatform = new EntityContainer(); _testSpecifiedPlatform = new List <Dictionary <char, List <Entity> > >(); _testPassengerList = new List <Passenger>(); var stationaryShape = new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 0.5f)); var image = new Image(Path.Combine("Assets", "Images", "Taxi_Thrust_None.png")); _testPlayer = new Player(); _testPlayer.SetPosition(0.5f, 0.6f); _testPlayer.GetsShape().Direction.Y = -0.005f; _testCollisionPlatform.AddStationaryEntity(stationaryShape, image); CollisionChecker collisionTest = new CollisionChecker(_testCollisionObstacle, _testCollisionPlatform, _testPlayer, _testPassengerList, _testSpecifiedPlatform); while (!collisionTest.GetGameOverChecker()) { _testPlayer.PlayerMove(); collisionTest.CheckCollsion(); } Assert.AreEqual(collisionTest.GetGameOverChecker(), true); }
public Text(string text, Vec2F pos, Vec2F extent) { this.text = text; shape = new StationaryShape(pos, extent); color = Color.Black; fontSize = 50; // create a texture id textureId = GL.GenTexture(); // bind this new texture id BindTexture(); // set texture properties, filters, blending functions, etc. GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Lequal); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.AlphaTest); GL.AlphaFunc(AlphaFunction.Gequal, 0.5f); // unbind this new texture UnbindTexture(); // create a texture CreateBitmapTexture(); }
/// <summary> /// Constructor takes a string[] and gives data to fields /// </summary> /// <param name="lst"></param> public Customer(string[] lst) { name = lst[1]; SpawnTime = int.Parse(lst[2]); StartPlatform = char.Parse(lst[3]); if (lst[4].Length > 1) { var dop = lst[4].Split('^')[1]; DropOffPlatform = char.Parse(dop); } else { DropOffPlatform = char.Parse(lst[4]); } dropOffTime = int.Parse(lst[5]); dropOffPoints = int.Parse(lst[6]); Shape = new StationaryShape(new Vec2F(), new Vec2F(0.05F, 0.05F)); Image = new Image(Utils.GetImageFilePath("CustomerStandRight.png")); Entity = new Entity(Shape, Image); IsRendered = false; IsDroppedOff = false; StopRenderTime = 0; }
public void TestIterationUnchanged() { var ent0 = new StationaryShape(0.0f, 0.0f, 0.0f, 0.0f); var ent1 = new StationaryShape(1.0f, 1.0f, 1.0f, 1.0f); var ent2 = new StationaryShape(2.0f, 2.0f, 2.0f, 2.0f); var ent3 = new StationaryShape(3.0f, 3.0f, 3.0f, 3.0f); var ent4 = new StationaryShape(4.0f, 4.0f, 4.0f, 4.0f); var ent5 = new StationaryShape(5.0f, 5.0f, 5.0f, 5.0f); var ents = new EntityContainer(); foreach (var shp in new[] { ent0, ent1, ent2, ent3, ent4, ent5 }) { ents.AddStationaryEntity(shp, null); } foreach (Entity ent in ents) { ent.Shape.Position.X *= -1.0f; ent.Shape.Position.Y *= -1.0f; } foreach (Entity ent in ents) { // TODO: Ask Boris for advice on safe pointers in ReadOnlyCollections //Assert.GreaterOrEqual(ent.Shape.Position.X, 0.0f); //Assert.GreaterOrEqual(ent.Shape.Position.Y, 0.0f); } }
public TestAabbCollision() { solidBlockLeft = new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(0.1f, 1.0f)); solidBlockRight = new StationaryShape(new Vec2F(1.0f, 0.0f), new Vec2F(0.1f, 1.0f)); solidBlockUp = new StationaryShape(new Vec2F(0.0f, 1.0f), new Vec2F(1.0f, 0.1f)); solidBlockDown = new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 0.1f)); actorVelocity = 0.05f; }
public void TestCollisionMultiplicationFactorCloseness() { var wall = new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 1.0f)); var move = new DynamicShape(new Vec2F(2.0f, 0.0f), new Vec2F(1.0f, 1.0f), new Vec2F(-1.0f, 0.0f)); var data = CollisionDetection.Aabb(move, wall); Assert.IsFalse(data.Collision); }
public void TestCollisionMultiplicationFactorExactness() { var wall = new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 1.0f)); var move = new DynamicShape(new Vec2F(2.0f, 0.0f), new Vec2F(1.0f, 1.0f), new Vec2F(-2.0f, 0.0f)); var data = CollisionDetection.Aabb(move, wall); Assert.AreEqual(data.DirectionFactor.X, 0.5f); }
public void CreateEnemies(List <Image> enemyStrides) { for (int i = 1; i < 9; i++) { var shape = new StationaryShape(new Vec2F(i * 0.1f, 0.9f), new Vec2F(0.1f, 0.1f)); Enemies.AddDynamicEntity(new Enemy(shape, new ImageStride(80, enemyStrides))); } }
public void StudentCheck() { // Copied in the exact parameters from assignment 9 debug run where it first fails StationaryShape s = new StationaryShape(new Vec2F(0.9f, 0.739130437f), new Vec2F(0.025f, 0.0434782617f)); DynamicShape a = new DynamicShape(new Vec2F(0.744843602f, 0.783036947f), new Vec2F(0.065f, 0.05f), new Vec2F(-0.00157072174f, -0.00205000024f)); Assert.IsFalse(CollisionDetection.Aabb(a, s).Collision); }
/// <summary> /// If collision happens with obstacle or hits the platform to hard /// explosion happends. /// </summary> /// <param name="player">Player</param> public static void CreateExplosion(Entities.Player.Player player) { ObstacleCollision.explsionShape = new StationaryShape(new Vec2F(player.GetsShape().Position.X, player.GetsShape().Position.Y), new Vec2F(player.GetsShape().Extent.X, player.GetsShape().Extent.Y)); ObstacleCollision.explosionStrides = ImageStride.CreateStrides(8, Path.Combine("Assets", "Images", "Explosion.png")); ObstacleCollision.EXPLOSION.AddAnimation(ObstacleCollision.explsionShape, 500, new ImageStride(500 / 8, ObstacleCollision.explosionStrides)); }
/// <summary> /// Translates the ASCII map with a set of keys. /// </summary> private void AsciiToLevel(IEnumerable <string> text, Dictionary <char, Platform> platformKeys, Dictionary <char, Image> keyLegend) { // map is 23 x 40, calculate size of each levelSprite float height = 1f / 23f; float width = 1f / 40f; // translate from ascii to game level, each char represents an entity var textArr = text.ToArray(); for (int i = 0; i < 23; i++) { for (int j = 0; j < 40; j++) { char _char = textArr[22 - i][j]; // ^ is the ascii symbol for the exit if (_char == '^') { var exitStrides = ImageStride.CreateStrides(4, Path.Combine("Assets", "Images", "aspargus-passage.png")); var shape = new StationaryShape( new Vec2F(width * j, i * height), new Vec2F(width, height)); var e = new Exit(); e.PropSprites.AddStationaryEntity( shape, new ImageStride(30, exitStrides)); Props.Add(e); // > is the ascii symbol for the player, set player position } else if (_char == '>') { Player.Entity.Shape.Position = new Vec2F(width * j - width, i * height - height / 2); } else if (_char != ' ') { // add the char as an Entity to the appropriate container EntityContainer container; if (platformKeys.ContainsKey(_char)) { container = platformKeys[_char].PropSprites; } else { container = LevelSprites; } container.AddStationaryEntity( new StationaryShape( new Vec2F(width * j, i * height), new Vec2F(width, height)), keyLegend[_char]); } } } }
public void AddingPlatformToBoundingBoxGivesExpectedBoundingBoxPosition(float x, float y) { var shape = new StationaryShape(x, y, 0, 0); testPlatform.AddPlatform(shape, null); var deltaX = Math.Abs(testPlatform.GetBoundingBox().Position.X) - Math.Abs(x); var deltaY = Math.Abs(testPlatform.GetBoundingBox().Position.Y) - Math.Abs(y); Assert.IsTrue(deltaX < acceptableDeviance && deltaY < acceptableDeviance); }
public void IncreaseBoundingBoxExtentInGivenDirectionGivesExpectedBoundingBox( float x, float y) { var shape = new StationaryShape(0, 0, x, y); testPlatform.AddPlatform(shape, null); var deltaX = Math.Abs(testPlatform.GetBoundingBox().Extent.X) - Math.Abs(x); var deltaY = Math.Abs(testPlatform.GetBoundingBox().Extent.Y) - Math.Abs(y); Assert.IsTrue(deltaX < acceptableDeviance && deltaY < acceptableDeviance); }
public DynamicCamera(StationaryShape worldShape) { Offset = new Vec2F(0.0f, 0.0f); Scale = 1f; WorldShape = worldShape; innerBounds = new DynamicShape(0.25f, 0.25f, 0.5f, 0.5f); //innerBounds.ScaleFromCenter(0.5f); displacement = innerBounds.Position; overlay = new Entity(innerBounds, new Image(Path.Combine("Assets", "Images", "Overlay.png"))); System.Console.WriteLine("Offset is: {0}", Offset); System.Console.WriteLine("inner is: {0}", innerBounds.Position); }
public ChaseCamera(StationaryShape worldShape) { cameraShape = new DynamicShape(0.5f, 0.5f, 0.0f, 0.0f); Offset = baseOffset - cameraShape.Position;//new Vec2F(0f, 0f); Scale = 1f; WorldShape = worldShape; // Initialize the queue and fill it with 0-vectors to make the camera lag behind by CAMERA_DELAY seconds directionQueue = new Queue <Vec2F>(CAMERA_DELAY); for (int i = 0; i < CAMERA_DELAY; i++) { directionQueue.Enqueue(new Vec2F(0f, 0f)); } }
public void TestMoveLeft() { var obstacleLeft = new StationaryShape(new Vec2F(0.0f, 0.6f), new Vec2F(1.0f, 0.4f)); var obstacleRight = new StationaryShape(new Vec2F(0.0f, 0.0f), new Vec2F(1.0f, 0.4f)); var obstacles = new List <StationaryShape>() { obstacleLeft, obstacleRight }; var actor = new DynamicShape(new Vec2F(0.0f, 0.45f), new Vec2F(0.1f, 0.1f)); actor.Direction.X = 0.001f; actor.Direction.Y = 0.0f; Assert.IsFalse(CheckActorMove(actor, obstacles, 1000)); }
public PlayerLife(StationaryShape shape, int placement) : base(shape, PlayerLife.stride) { switch (placement) { case (1): shape.SetPosition(new Vec2F(0.01f, 0.89f)); break; case (2): shape.SetPosition(new Vec2F(0.06f, 0.89f)); break; case (3): shape.SetPosition(new Vec2F(0.11f, 0.89f)); break; default: throw new ArgumentException( "The PlayerLife could not be placed correctly."); } }
public void ExitObstacleCollisionTest() { var shape = new StationaryShape(new Vec2F(0.0F, 0.5F), new Vec2F(1F, 0.5F)); var file = Path.Combine(Utils.GetImageFilePath("obstacle.png")); player = new Player(); player.SpawnPos(new Vec2F(0.5F, 0.4F)); entityContainer = new EntityContainer(); entityContainer.AddStationaryEntity(shape, new Image(file)); bool col = false; while (player.Shape.Position.Y < 0.55F && col == false) { player.MoveUp = true; player.Move(); col = Collision.ExitCollision(player, entityContainer); Console.WriteLine(col); } Assert.True(col); }
public static void MainFunction() { var win = new Window("TestAnimations", 500, AspectRatio.R1X1); Animation anim = new Animation() { Duration = 0 }; StationaryShape shape = new StationaryShape(0.5f, 0.5f, 0.5f, 0.5f); var strides = ImageStride.CreateStrides(4, "PuffOfSmoke.png"); win.AddKeyPressEventHandler(delegate(KeyboardKeyEventArgs keyArgs) { switch (keyArgs.Key) { case Key.Escape: win.CloseWindow(); break; case Key.Space: // do something to test animations anim = new Animation() { Duration = 1000, Shape = shape }; anim.Stride = new ImageStride(30, strides); break; } }); while (win.IsRunning()) { win.PollEvents(); win.Clear(); if (anim.IsActive()) { anim.RenderAnimation(); } win.SwapBuffers(); } }
public void PlatformCollisionTest() { var shape = new StationaryShape(new Vec2F(0.0F, 0.0F), new Vec2F(1F, 0.5F)); var file = Path.Combine(Utils.GetImageFilePath("obstacle.png")); player = new Player(); player.SpawnPos(new Vec2F(0.5F, 0.6F)); Platforms = new List <Platform>(); Platforms.Add(new Platform(shape, new Image(file), 'i')); bool col = false; char returnVal2 = 'e'; while (player.Shape.Position.Y > 0.45F && col == false) { player.Move(); col = Collision.PlatformCollision(player, Platforms).Item1; returnVal2 = Collision.PlatformCollision(player, Platforms).Item2; Console.WriteLine(col); } Assert.True(col); Assert.True(returnVal2 == 'i'); }
/// <summary> /// Add a new entity to the instance's platEntity EntityContainer. Also updates the /// boundingBox shape if the position and dimensions of the new shape exceed the ones of /// boundingBox. Also re-centers the platform's text label to the new center of the /// bounding box /// </summary> /// <param name="shape"></param> /// <param name="image"></param> public void AddPlatform(StationaryShape shape, IBaseImage image) { if (platEntity.CountEntities() < 1) { boundingBox.Position = shape.Position.Copy(); boundingBox.Extent = shape.Extent.Copy(); } platEntity.AddStationaryEntity(shape, image); if (shape.Position.X < boundingBox.Position.X) { boundingBox.Position.X = shape.Position.X; } if (shape.Position.Y < boundingBox.Position.Y) { boundingBox.Position.Y = boundingBox.Position.Y; } if (shape.Position.X + shape.Extent.X > boundingBox.Position.X + boundingBox.Extent.X) { boundingBox.Extent.X = (shape.Position.X + shape.Extent.X) - boundingBox.Position.X; } if (shape.Position.Y + shape.Extent.Y > boundingBox.Position.Y + boundingBox.Extent.Y) { boundingBox.Extent.Y = (shape.Position.Y + shape.Extent.Y) - boundingBox.Position.Y; } text.GetShape().Position = new Vec2F( boundingBox.Position.X + boundingBox.Extent.X / 2 - Constants.EXTENT_X / 2, boundingBox.Position.Y); }
/// <summary> /// Builds a level object from the given level file path. /// </summary> /// <param name="filepath"></param> /// <returns></returns> public Level GetLevelFromFile(string filepath) { var levelContent = levelLoader.ReadFileContents(filepath); //parsing map var levelMap = levelContent[Constants.MAP]; if (levelMap.Count != 23 || levelMap[0].Length != 40) { throw new Exception( "Error building level. Level must be 40 lines x 23 characters."); } var platformIds = levelParser.ParsePlatformChars(levelContent[Constants.PLATFORMS]); if (platformIds.Count < 1) { throw new Exception("Error building level. Level must contain platforms."); } var levelImages = levelParser.ParseImages(levelContent[Constants.IMAGES]); if (levelImages.Count < 1) { throw new Exception("Error building level. Level must contain image mapping."); } Dictionary <char, Platform> platformDictionary = new Dictionary <char, Platform>(); foreach (char platformChar in platformIds) { platformDictionary.Add(platformChar, new Platform(platformChar)); } EntityContainer <Obstacle> obstacles = new EntityContainer <Obstacle>(); EntityContainer portals = new EntityContainer(); Vec2F extent = new Vec2F(Constants.EXTENT_X, Constants.EXTENT_Y); Vec2F playerStartingPosition = null; Player player = new Player(null, null); //parsing level map int i = 0; foreach (string mapString in levelMap) { for (int j = 0; j < mapString.Length; j++) { char mapChar = mapString[j]; Vec2F position = new Vec2F( j * Constants.EXTENT_X, 1 - i * Constants.EXTENT_Y - Constants.EXTENT_Y ); StationaryShape shape = new StationaryShape(position, extent); if (mapChar == ' ') { continue; } //checking the individual map chars if (platformIds.Contains(mapString[j])) { platformDictionary[mapChar].AddPlatform( shape, imageContainer.GetImageByName(levelImages[mapChar])); } else if (mapChar == '^') { portals.AddStationaryEntity(shape, null); } else if (mapChar == '<' || mapChar == '>') { playerStartingPosition = new Vec2F(j * Constants.EXTENT_X, 1 - i * Constants.EXTENT_Y); player.Shape.Position = playerStartingPosition; } else { var newObstacle = new Obstacle(shape, null) { Image = imageContainer.GetImageByName(levelImages[mapChar]) }; obstacles.AddStationaryEntity(newObstacle); } } i++; } if (playerStartingPosition == null) { throw new Exception( "Error building level. Level map must contain a starting position for player."); } if (portals.CountEntities() < 1) { throw new Exception( "Error building level. Level map must contain portal entities."); } var levelCustomers = levelParser.ParseCustomerStrings(levelContent[Constants.CUSTOMERS]); var name = levelParser.ParseLevelName(levelContent[Constants.NAME]); return(new Level( name, portals, obstacles, platformDictionary, levelCustomers, player, playerStartingPosition)); }
/// <summary> /// Takes the list of chars the reader has read and add the map entities /// to the corresponding entity containers, goes top-left to bottom-right /// </summary> /// <param name="map"></param> public void MapCreator(List <char> map) { const float width = 0.025F; const float height = 0.04347F; const float xMin = 0; const float yMin = 0; const float xMax = 1 - width; const float yMax = 1 - height; Vec2F imageExtent = new Vec2F(width, height); var x = xMin; var y = yMax; var index = 0; while (y > yMin) { while (x < xMax) { // Increment index variable when coordinate is empty if (map[index].ToString() == " ") { index += 1; } else { if (reader.LegendData.ContainsKey(map[index]) && !reader.MetaData.ContainsKey(map[index])) { var shape = new StationaryShape(new Vec2F(x, y), imageExtent); var file = Path.Combine(Utils.GetImageFilePath(reader.LegendData[map[index]])); Obstacles.AddStationaryEntity(shape, new Image(file)); } if (reader.MetaData.ContainsKey(map[index])) { var shape = new StationaryShape(new Vec2F(x, y), imageExtent); var file = Path.Combine((Utils.GetImageFilePath(reader.MetaData[map[index]]))); Platforms.Add(new Platform(shape, new Image(file), map[index])); } if (map[index] == '^') { var shape = new StationaryShape(new Vec2F(x, y), imageExtent); var file = Path.Combine(Utils.GetImageFilePath("aspargus-passage.png")); Exits.AddStationaryEntity(shape, new Image(file)); } if (map[index] == '>') { playerpos = new Vec2F(x, y); } index += 1; } x += width; } x = 0; y -= height; } }
public Enemy(StationaryShape shape, IBaseImage image) : this(shape, image, 10, 10) { }
public Enemy(StationaryShape shape, IBaseImage image, int health, int damage) : base(shape, image) { Health = health; Damage = damage; StartPos = shape.Position.Copy(); }
public Platform(StationaryShape shape, Image img, char plat) : base(shape, img) { PlatformType = plat; }
public Enemy(StationaryShape shape, IBaseImage image) : base(shape, image) { Position = shape.Position.Copy(); }
public Obstacle(StationaryShape shape, IBaseImage image) : base(shape, image) { }