public void Spawn(Touching dir, Red_Boss parent) { if (dir.HasFlag(Touching.UP)) { Position = parent.Position + new Vector2(16 * t_index - 14, -13); } else if (dir.HasFlag(Touching.LEFT)) { Position = parent.Position + new Vector2(-14, 16 * t_index - 16); } else if (dir.HasFlag(Touching.RIGHT)) { Position = parent.Position + new Vector2(parent.width + 2, 16 * t_index - 16); } else if (dir.HasFlag(Touching.DOWN)) { Position = parent.Position + new Vector2(16 * t_index - 14, parent.height + 2); } else { //player isn't close in any direction, so random locations Vector2 ul = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid); Position.X = ul.X + 16 + 12 * (1 + t_index) + GlobalState.RNG.Next(-5, 6); Position.Y = ul.Y + 16 * GlobalState.RNG.Next(1, 4) + GlobalState.RNG.Next(-5, 6) + tentacle.height - height; } tentacle.Position = Position + Vector2.UnitY * (height - 3 - tentacle.height); tentacle.y_push = tentacle.height; Flicker(0.7f + (float)GlobalState.RNG.NextDouble()); state = StateLogic(); }
public IntersectResult LineContains(CoordinateRectangle line) { var iLeftTop = PointContains(line.LeftTop) != IntersectResult.None; var iRightBottom = PointContains(line.RightBottom) != IntersectResult.None; if (iLeftTop && iRightBottom) { return(IntersectResult.Contains); } if (iLeftTop || iRightBottom) { return(IntersectResult.Intersects); } if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Right, Top), line)) { return(IntersectResult.Intersects); } if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Right, Top, Right, Bottom), line)) { return(IntersectResult.Intersects); } if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Bottom, Right, Bottom), line)) { return(IntersectResult.Intersects); } if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Left, Bottom), line)) { return(IntersectResult.Intersects); } return(IntersectResult.None); }
public override void Update() { base.Update(); if (_preset.Alive) { if (touching != Touching.NONE) { walk_t = 0; } Vector2 grid = MapUtilities.GetInGridPosition(Position); if ((grid.X < 5 && velocity.X < 0) || (grid.X + width > 155 && velocity.X > 0) || (grid.Y < 5 && velocity.Y < 0) || (grid.Y + height > 155 && velocity.Y > 0)) { walk_t = 0; } walk_t -= GameTimes.DeltaTime; if (walk_t <= 0) { (velocity.X, velocity.Y) = (velocity.Y, -velocity.X); FaceTowards(Position + velocity); PlayFacing("walk"); walk_t = walk_t_max; } } else if (_curAnim.Finished && !blood.exists) { SpawnBlood(); } }
public virtual void Draw() { if (exists) { if (visible) { Rectangle srect = sprite.GetRect(_curAnim.Frame); srect.Height -= (int)y_push; SpriteDrawer.DrawSprite(sprite.Tex, MathUtilities.CreateRectangle(Position.X - offset.X * scale, Position.Y - offset.Y * scale + (int)y_push, srect.Width * scale, srect.Height * scale), srect, color * opacity, rotation, _flip, DrawingUtilities.GetDrawingZ(layer, MapUtilities.GetInGridPosition(Position).Y + height)); } if (shadow != null) { shadow.Draw(); } if (GlobalState.draw_hitboxes && HasVisibleHitbox) { SpriteDrawer.DrawSprite(ResourceManager.GetTexture("hitbox"), Hitbox, color: Color.Red, Z: DrawingUtilities.GetDrawingZ(DrawOrder.HITBOX, 0)); } } }
public void Spawn() { Vector2 tl = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid); Position = tl + new Vector2(GlobalState.RNG.Next(0, 160 - 24), GlobalState.RNG.Next(0, 32)); Play("explode"); }
public override IHoverData GetHoverData(MapGraphics graphics) { if (graphics.view.mode == MapView.ViewMode.TopDown) { foreach (var tri in GetTrianglesWithinDist()) { var dat = MapUtilities.Get2DWallDataFromTri(tri); if (dat != null) { bool zProjection = !dat.Value.xProjection; float v = zProjection ? graphics.mapCursorPosition.X : graphics.mapCursorPosition.Z; float vOther = zProjection ? graphics.mapCursorPosition.Z : graphics.mapCursorPosition.X; float one = zProjection ? dat.Value.x1 : dat.Value.z1; float two = zProjection ? dat.Value.x2 : dat.Value.z2; float min = Math.Min(one, two); float max = Math.Max(one, two); float otherOne = zProjection ? dat.Value.z1 : dat.Value.x1; float otherTwo = zProjection ? dat.Value.z2 : dat.Value.x2; float interpolatedOther = otherOne + ((v - one) / (two - one)) * (otherTwo - otherOne); var angle = MoreMath.AngleTo_Radians(dat.Value.x1, dat.Value.z1, dat.Value.x2, dat.Value.z2); float projectionDist = Size / (float)Math.Abs(!zProjection ? Math.Cos(angle) : Math.Sin(angle)); if (v >= min && v <= max && Math.Abs(vOther - interpolatedOther) < projectionDist) { hoverData.triangle = tri; return(hoverData); } } } } return(null); }
public static Bitmap DownloadImageFromTile(TileBlock block, bool getBitmap) { try { var oRequest = MapUtilities.CreateTileWebRequest(block); var oResponse = (HttpWebResponse)oRequest.GetResponse(); var bmpStream = new MemoryStream(); var oStream = oResponse.GetResponseStream(); if (oStream != null) { oStream.CopyTo(bmpStream); } oResponse.Close(); if (bmpStream.Length > 0) { WriteImageToFile(block, bmpStream); return(getBitmap ? (Bitmap)Image.FromStream(bmpStream) : null); } } catch (Exception ex) { //do nothing System.Diagnostics.Trace.WriteLine(ex.Message); } return(null); }
IEnumerator CutSceneState() { while (!GlobalState.LastDialogueFinished) { yield return("wait"); } GlobalState.disable_menu = true; _player.BeIdle(); _player.state = PlayerState.INTERACT; velocity = -Vector2.UnitY * 40; Play("walk_u"); while (MapUtilities.GetInGridPosition(Position).Y > 6 * 16) { yield return("move up"); } velocity = Vector2.UnitX * 40; Play("walk_r"); while (MapUtilities.GetInGridPosition(Position).X > 10) //wraps around when on next screen { yield return("move right"); } exists = false; GlobalState.disable_menu = false; _player.state = PlayerState.GROUND; yield break; }
//Note: Removed most refrences to "rooms". May cause bugs. //Credit goes to http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels //for algorithm. Read it if you want to understand. public void GenCave(int sizeX, int sizeY, float initialWallProb) { this.sizeX = sizeX; this.sizeY = sizeY; if (sizeX < 10 || sizeY < 10) { Debug.Log("Error! Map for GenCave is too small"); } int attempts = 0; bool good = false; while (!good) { attempts++; mapData = createFilledMapArray(eTile.Filler); caveInitWalls(initialWallProb); caveRunSmoothAutomata(3); caveRunFillGapsAutomata(2); //caveConnectRegions(); caveMakeSpawn(); caveMakeGoal(); good = MapUtilities.isGoodMap(mapData); MakeWalls(); } if (attempts > 2) { Debug.Log("Took " + attempts + " to generate caves"); } }
private ScreenCoordinate GetRightBottom(int screenWidth, int screenHeight, int level) { return(new ScreenCoordinate( MapUtilities.GetX(this, level) + ((screenWidth - 1) / 2 + 1), MapUtilities.GetY(this, level) + ((screenHeight - 1) / 2 + 1), level)); }
private ScreenCoordinate GetLeftTop(int screenWidth, int screenHeight, int level) { return(new ScreenCoordinate( MapUtilities.GetX(this, level) - ((screenWidth + 1) / 2 - 1), MapUtilities.GetY(this, level) - ((screenHeight + 1) / 2 - 1), level)); }
public ArthurDanger(EntityPreset preset, Player p) : base(preset.Position, "arthur", 16, 16, Drawing.DrawOrder.ENTITIES) { _preset = preset; AddAnimation("walk_d", CreateAnimFrameArray(0, 1), 8); AddAnimation("walk_l", CreateAnimFrameArray(4, 5), 8); AddAnimation("walk_u", CreateAnimFrameArray(2, 3), 8); AddAnimation("walk_r", CreateAnimFrameArray(4, 5), 8); AddAnimation("roll", CreateAnimFrameArray(6), 6); // For flying through the air AddAnimation("stunned", CreateAnimFrameArray(8, 9), 6); AddAnimation("wobble", CreateAnimFrameArray(16, 17), 8); AddAnimation("fall_1", CreateAnimFrameArray(10), 8); AddAnimation("fall", CreateAnimFrameArray(10, 11, 12, 13, 14, 15, 6), 2, false); // Should end on an empty frame _parabola = new Parabola_Thing(this, 32, 1); shadow = new Shadow(this, new Vector2(0, -2), ShadowType.Normal); Play("wobble"); Position.Y -= 32; offset.Y = 5 * 16; _initPos = Position; _dustPillow = new Dust(MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid) + new Vector2(46, 16), p); _stateLogic = StateLogic(); }
public Rock(EntityPreset preset, Player p) : base(preset.Position, 16, 16, DrawOrder.ENTITIES) { immovable = true; scene = preset.Frame == 17 ? "melos" : "marina"; string texName = "note_rock"; int f = 0; if (GlobalState.CURRENT_MAP_NAME == "SPACE") { texName = "space_npcs"; f = MapUtilities.GetRoomCoordinate(Position).X > 5 ? 31 : 30; } else if (GlobalState.CURRENT_MAP_NAME == "TRAIN") { f = 1; } SetTexture(texName); SetFrame(f); scene = MathUtilities.IntToString(preset.Frame + 1); }
IEnumerator <string> StateLogic() { while (MapUtilities.GetInGridPosition(_p.Position).X > 80) { volume.Update(); yield return("Waiting"); } Sounds.SoundManager.StopSong(); var sound = Sounds.SoundManager.PlaySoundEffect("red_cave_rise"); GlobalState.Dialogue = Dialogue.DialogueManager.GetDialogue("happy_npc", "briar"); while (!GlobalState.LastDialogueFinished || sound.State == Microsoft.Xna.Framework.Audio.SoundState.Playing) { GlobalState.screenShake.Shake(0.02f, 0.1f); _p.dontMove = true; yield return("Dialogue"); } _p.dontMove = false; GlobalState.events.IncEvent("HappyStarted"); GlobalState.flash.Flash(1f, Color.Red, () => { ((Map)GlobalState.Map).ReloadSettings(_p); GlobalState.darkness.ForceAlpha(1); }); yield break; }
public void DoCollision(Map map, bool ignore_player_map_collision) { foreach (Entity e in _mapColliders.Where(e => e.exists)) { Touching t = e.allowCollisions; if (ignore_player_map_collision && e is Player) { e.Solid = false; //during transition no collision with map, but do have tile effects take an effect } map.Collide(e); foreach (Entity m in _mapEntities.Where(m => m.Solid && m.exists && m.Hitbox.Intersects(e.Hitbox))) { m.Collided(e); } e.allowCollisions = t; } //map-entity collision sets per-frame state values that are checked in entity-entity collisions(player+dust->raft) foreach (Group g in _groups.Values) { foreach (Entity collider in g.colliders.Where(e => e.exists)) { foreach (Entity target in g.targets.Where(e => e.exists && !ReferenceEquals(e, collider))) { if (collider.Hitbox.Intersects(target.Hitbox)) { collider.Collided(target); } } } } Vector2 roomUpLeft = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid); Vector2 roomBottomRight = roomUpLeft + Vector2.One * GameConstants.SCREEN_WIDTH_IN_PIXELS; foreach (Entity e in _keepOnScreen.Where(e => e.exists)) { if (e.Hitbox.Left < roomUpLeft.X) { e.Position.X = roomUpLeft.X; e.touching |= Touching.LEFT; } else if (e.Hitbox.Right > roomBottomRight.X) { e.Position.X = roomBottomRight.X - e.width; e.touching |= Touching.RIGHT; } if (e.Hitbox.Top < roomUpLeft.Y) { e.Position.Y = roomUpLeft.Y; e.touching |= Touching.UP; } else if (e.Hitbox.Bottom > roomBottomRight.Y) { e.Position.Y = roomBottomRight.Y - e.height; e.touching |= Touching.DOWN; } } }
public PlayerDieDummy(Vector2 pos, string textureName) : base(MapUtilities.GetInGridPosition(pos), textureName, 16, 16, DrawOrder.PLAYER_DIE_DUMMY) { Position.Y += 20; AddAnimation("die", CreateAnimFrameArray(25, 26, 27, 24, 25, 26, 27, 24, 25, 26, 27, 32), 12, false); Play("die"); }
public Laser() : base(Vector2.Zero, "wallboss_laser", 64, 10, Drawing.DrawOrder.BG_ENTITIES) { AddAnimation("charge", CreateAnimFrameArray(0)); AddAnimation("attack", CreateAnimFrameArray(1, 2), 12); exists = false; visible = false; start_loc = Position = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid) + new Vector2(48, 32 + 11); }
/// <summary> /// Highlights the specified feature using the color specified by the ArcFM Properties. /// </summary> /// <param name="source">The source.</param> /// <returns> /// Returns a <see cref="IElement" /> representing the graphic element that was highlighted. /// </returns> public static IElement Highlight(this IFeature source) { if (source == null) { return(null); } return(MapUtilities.HighlightFeature(source)); }
/// <summary> /// Pans the map to the feature. /// </summary> /// <param name="source">The source.</param> public static void Pan(this IFeature source) { if (source == null) { return; } MapUtilities.PanFeature(source); }
/// <summary> /// Flashes the feature for the specified interval (in milliseconds) a set number of times using the color specified by /// the ArcFM Properties. /// </summary> /// <param name="source">The source that will be flashed.</param> public static void Flash(this IFeature source) { if (source == null) { return; } MapUtilities.FlashFeature(source, 500, 1); }
/// <summary> /// Flashes the feature for the specified interval (in milliseconds) a set number of times using the color specified by /// the ArcFM Properties. /// </summary> /// <param name="source">The source that will be flashed.</param> /// <param name="interval">The interval in milliseconds.</param> /// <param name="flashTimes">Number of times to flash the feature.</param> public static void Flash(this IFeature source, int interval, int flashTimes) { if (source == null) { return; } MapUtilities.FlashFeature(source, interval, flashTimes); }
/// <summary> /// Zooms the map to the specified feature. /// </summary> /// <param name="source">The source.</param> public static void Zoom(this IFeature source) { if (source == null) { return; } MapUtilities.ZoomFeature(source); }
public SkittishSecret(EntityPreset preset, Player p) : base(preset.Position, "forest_npcs", 16, 16, Drawing.DrawOrder.ENTITIES) { AddAnimation("walk_r", CreateAnimFrameArray(32, 33), 4, true); Play("walk_r"); Position.X = initial_pos = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid).X; player = p; }
public IntersectResult RectangleContains(CoordinateRectangle rectangle) { var iLeftTop = PointContains(rectangle.LeftTop) != IntersectResult.None; var iRightBottom = PointContains(rectangle.RightBottom) != IntersectResult.None; if (iLeftTop && iRightBottom) { return(IntersectResult.Contains); } if (iLeftTop || iRightBottom) { return(IntersectResult.Intersects); } if (PointContains(rectangle.LeftBottom) != IntersectResult.None) { return(IntersectResult.Intersects); } if (PointContains(rectangle.RightTop) != IntersectResult.None) { return(IntersectResult.Intersects); } iLeftTop = rectangle.PointContains(LeftTop) != IntersectResult.None; iRightBottom = rectangle.PointContains(RightBottom) != IntersectResult.None; if (iLeftTop && iRightBottom) { return(IntersectResult.Supersets); } if (iLeftTop || iRightBottom) { return(IntersectResult.Intersects); } if (rectangle.PointContains(LeftBottom) != IntersectResult.None) { return(IntersectResult.Intersects); } if (rectangle.PointContains(RightTop) != IntersectResult.None) { return(IntersectResult.Intersects); } if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Left, Bottom), new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Top))) { return(IntersectResult.Intersects); } if (MapUtilities.CheckLinesIntersection(new CoordinateRectangle(Left, Top, Right, Top), new CoordinateRectangle(rectangle.Left, rectangle.Top, rectangle.Left, rectangle.Bottom))) { return(IntersectResult.Intersects); } return(IntersectResult.None); }
private void OnOpenMapClicked() { if (!TryGetGpsLocation(out var manualLocation)) { PopupHelper.ErrorDialog(this, Resource.String.EditPoi_WrongFormat); return; } MapUtilities.OpenMap(double.Parse(_editTextLatitude.Text, CultureInfo.InvariantCulture), double.Parse(_editTextLongitude.Text, CultureInfo.InvariantCulture)); }
private void OnOpenMapClicked() { if (!TryGetGpsLocation(out var manualLocation, false)) { PopupHelper.ErrorDialog(this, Resource.String.PhotoParameters_SetCameraLocationFirst); return; } MapUtilities.OpenMap(double.Parse(_editTextLatitude.Text, CultureInfo.InvariantCulture), double.Parse(_editTextLongitude.Text, CultureInfo.InvariantCulture)); }
public SmallWave(Red_Boss parent) : base(Vector2.Zero, "red_boss_small_wave", 16, 64, Drawing.DrawOrder.BG_ENTITIES) { spawn_point = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid) + new Vector2(96, 48); AddAnimation("move", CreateAnimFrameArray(0, 1), 8); AddAnimation("rise", CreateAnimFrameArray(2, 3), 8); AddAnimation("fall", CreateAnimFrameArray(1, 2, 3, 4), 8, false); exists = false; immovable = true; }
private void TriggerPathFindingOnUnitWithTarget(Entity entity, FractionalHex pos, ActionTarget target, RuntimeMap map, ref RefreshPathTimer refreshPathTimer) { Hex dest; MapUtilities.TryFindClosestOpenAndReachableHex(out dest, (FractionalHex)target.OccupyingHex, pos, map.MovementMapValues); PostUpdateCommands.AddComponent(entity, new TriggerPathfinding() { Destination = dest }); refreshPathTimer.TurnsWithoutRefresh = 0; }
public DeathPlace(EntityPreset preset, Player p) : base(preset.Position, DrawOrder.ENTITIES) { exists = GlobalState.InDeathRoom; immovable = true; visible = false; gridToCheck = MapUtilities.GetRoomUpperLeftPos(GlobalState.CurrentMapGrid + new Point(0, 1)); _player = p; }
public void CompatibleHeightLevelWorkAsIntended() { MapHeight l0_1 = MapHeight.l0 | MapHeight.l1; MapHeight l0 = MapHeight.l0; MapHeight l1 = MapHeight.l1; Assert.IsTrue(MapUtilities.CompatibleHeightLevel(l0_1, l0)); Assert.IsTrue(MapUtilities.CompatibleHeightLevel(l0_1, l1)); Assert.IsFalse(MapUtilities.CompatibleHeightLevel(l1, l0)); }
public void CycleMoveRepositionsOnHeadLocation(double positionX, double positionZ, double velocityX, double velocityZ, double headRow, double headColumn, double rotation, string direction) { var position = new Vector3(positionX, gameConfig.CycleConfig.Y_OFFSET, positionZ); var map = new Map(gameConfig.MapConfig); var velocity = new Vector3(velocityX, 0, velocityZ); var movementController = new CycleMovementController(position, velocity, rotation, map, gameConfig); movementController.HeadLocation = new MapLocation(headRow, headColumn); var movementFlag = (MovementFlag)Enum.Parse(typeof(MovementFlag), direction); var mapUtilities = new MapUtilities(gameConfig.MapConfig.MAP_SIZE, gameConfig.MapConfig.FLOOR_TILE_SIZE); movementController.Move(movementFlag); Assert.True(movementController.Position.SameAs(mapUtilities.ToPosition(new MapLocation(headRow, headColumn),gameConfig.CycleConfig.Y_OFFSET))); }