public virtual async Task LoadAsync() { MapSpriteSheet = await MapSheetLoader.LoadAsync(TilesetName); DrawnMap = new MapTile[MapGrid.Count, MapGrid[0].Length]; // These offsets account for the fact that tiles are drawn based // on their center, so a 32x32 tile drawn at (0, 0) will have its // Center at (0, 0), and its Top Left at (-16, -16) without these // adjustments. int tileXOffset = TileWidth / 2; int tileYOffset = TileWidth / 2; for (int rowNum = 0; rowNum < MapGrid.Count; rowNum++) { for (int colNum = 0; colNum < MapGrid[0].Length; colNum++) { Vector2 coords = ModelToWorld(rowNum, colNum); DrawnMap[rowNum, colNum] = new MapTile { BoundingBoxOrigin = MapSpriteSheet.Sprite(CharToTile[MapGrid[rowNum][colNum]]).Origin, BoundingBox = new Rectangle((int)coords.X + tileXOffset, (int)coords.Y + tileYOffset, TileWidth, TileHeight), Position = new Vector2(coords.X + tileXOffset, coords.Y + tileYOffset), ModelChar = MapGrid[rowNum][colNum], IsCollidable = CollisionTiles.Contains(MapGrid[rowNum][colNum]) }; } } }
//hitboxen #region Hitbox private void Collision(CollisionTiles item, Camera camera) { if (hitboxUp.Intersects(item.Rectangle)) { if (item.Id == 1) { goingUp = false; } else { goingUp = true; } } if (hitboxDown.Intersects(item.Rectangle)) { if (item.Id == 1) { goingDown = false; } else { goingDown = true; } } if (hitboxLeft.Intersects(item.Rectangle)) { if (item.Id == 1) { goingLeft = false; } else { goingLeft = true; } } if (hitboxRight.Intersects(item.Rectangle)) { if (item.Id == 1) { goingRight = false; } else { goingRight = true; } } if (Hitbox.Intersects(item.Rectangle)) { //protoyp för att test battle mod //används inte /* * if (item.Id == 3) * { * // Zoom in effekt * camera.Zoom += 0.5f; * camera.Rotation += 0.5f; * * //stoppar spelaren movement med en enkle metod * PlayerStop(); * * // * if (camera.Zoom >= 30) * { * * item.Id = 2; * Game1.gamestate = Gamestate.battle; * * } * * } */ } #endregion }
public override void SerializeImpl(SerializerObject s) { NamePointer = s.SerializePointer(NamePointer, name: nameof(NamePointer)); MapWidth = s.Serialize <ushort>(MapWidth, name: nameof(MapWidth)); MapHeight = s.Serialize <ushort>(MapHeight, name: nameof(MapHeight)); TileSetCount_Total = s.Serialize <ushort>(TileSetCount_Total, name: nameof(TileSetCount_Total)); TileSetCount_4bpp = s.Serialize <ushort>(TileSetCount_4bpp, name: nameof(TileSetCount_4bpp)); TileSetPointer = s.SerializePointer(TileSetPointer, name: nameof(TileSetPointer)); MapTilesPointer = s.SerializePointer(MapTilesPointer, name: nameof(MapTilesPointer)); MapLayerPointers = s.SerializePointerArray(MapLayerPointers, 4, name: nameof(MapLayerPointers)); TilePalettePointer = s.SerializePointer(TilePalettePointer, name: nameof(TilePalettePointer)); CollisionWidth = s.Serialize <ushort>(CollisionWidth, name: nameof(CollisionWidth)); CollisionHeight = s.Serialize <ushort>(CollisionHeight, name: nameof(CollisionHeight)); CollisionMapPointer = s.SerializePointer(CollisionMapPointer, name: nameof(CollisionMapPointer)); CollisionTilesPointer = s.SerializePointer(CollisionTilesPointer, name: nameof(CollisionTilesPointer)); CollisionTypePointers = s.SerializePointer(CollisionTypePointers, name: nameof(CollisionTypePointers)); Pointer_38 = s.SerializePointer(Pointer_38, name: nameof(Pointer_38)); Pointer_3C = s.SerializePointer(Pointer_3C, name: nameof(Pointer_3C)); Pointer_40 = s.SerializePointer(Pointer_40, name: nameof(Pointer_40)); Pointer_44 = s.SerializePointer(Pointer_44, name: nameof(Pointer_44)); Pointer_48 = s.SerializePointer(Pointer_48, name: nameof(Pointer_48)); Pointer_4C = s.SerializePointer(Pointer_4C, name: nameof(Pointer_4C)); XPosition = s.SerializeObject <FixedPointInt>(XPosition, name: nameof(XPosition)); YPosition = s.SerializeObject <FixedPointInt>(YPosition, name: nameof(YPosition)); Name = s.DoAt(NamePointer, () => s.SerializeString(Name, name: nameof(Name))); if (!SerializeData) { return; } TileSet = s.DoAt(TileSetPointer, () => s.SerializeObject <GBAVV_Isometric_TileSet>(TileSet, x => { x.TileSetCount_Total = TileSetCount_Total; x.TileSetCount_4bpp = TileSetCount_4bpp; }, name: nameof(TileSet))); if (MapLayers == null) { MapLayers = new GBAVV_Isometric_MapLayer[MapLayerPointers.Length]; } for (int i = 0; i < MapLayers.Length; i++) { MapLayers[i] = s.DoAt(MapLayerPointers[i], () => s.SerializeObject <GBAVV_Isometric_MapLayer>(MapLayers[i], name: $"{nameof(MapLayers)}[{i}]")); } var mapTilesLength = MapLayers.SelectMany(x => x.TileMapRows).SelectMany(x => x.Commands).Select(x => x.Params?.Max() ?? x.Param).Max() + 1; MapTiles = s.DoAt(MapTilesPointer, () => s.SerializeObjectArray <MapTile>(MapTiles, mapTilesLength * 4, x => x.Is8Bpp = true, name: nameof(MapTiles))); TilePalette = s.DoAt(TilePalettePointer, () => s.SerializeObjectArray <RGBA5551Color>(TilePalette, 256, name: nameof(TilePalette))); CollisionMap = s.DoAt(CollisionMapPointer, () => s.SerializeArray <ushort>(CollisionMap, CollisionWidth * CollisionHeight, name: nameof(CollisionMap))); CollisionTiles = s.DoAt(CollisionTilesPointer, () => s.SerializeObjectArray <GBAVV_Isometric_CollisionTile>(CollisionTiles, CollisionMap.Max() + 1, name: nameof(CollisionTiles))); CollisionTypes = s.DoAt(CollisionTypePointers, () => s.SerializeObjectArray <GBAVV_Isometric_CollisionType>(CollisionTypes, CollisionTiles.Max(x => x.TypeIndex) + 1, name: nameof(CollisionTypes))); s.DoAt(Pointer_4C, () => { if (Pointer_4C_Structs == null) { var objects = new List <GBAVV_Isometric_UnkStruct_0>(); var index = 0; while (true) { var obj = s.SerializeObject <GBAVV_Isometric_UnkStruct_0>(default, name: $"{nameof(Pointer_4C_Structs)}[{index++}]");
//När nån av rectanlarna intersektar med en av collisionTilesen (går alltid) public void PlayerHitdetection(CollisionTiles item, Camera camera) { Collision(item, camera); }