private void OnEnable() { //Debug.Log ("OnEnable"); //Debug.Log ("IsTappable: " + IsTappable); if (IsTappable) { GetComponent <TapGesture>().Tapped += TappedHandler; } //Debug.Log ("IsFlickable: " + IsFlickable); if (IsFlickable) { foreach (var flick in GetComponents <FlickGesture>()) { flick.Flicked += FlickedHandler; } } tileEngine = (TileEngine)FindObjectOfType(typeof(TileEngine)); //Debug.Log ("TileEngine was found: " + (tileEngine != null)); }
public override void Draw(SpriteBatch spriteBatch) { if (!DrawMe) { return; } foreach (var t in Tiles) { var texture = TileEngine.GetTexture(t.ID); if (t.ID == GameConstants.TILE_EMPTY) { continue; } Color dColor = WorldTimer.GetWorldColorTint(); if (t.HasCollision) { dColor = Color.Red; } var player = GameScreen.GetPlayer(); if (player != null) { if (t.IDInt >= GameConstants.TILE_ROOF_LEFT_TOP_CORNER && t.IDInt <= GameConstants.TILE_ROOF_RIGHT_TOP_CORNER) { if (player.ObjectRectangle.Intersects(t.ObjectRectangle)) { dColor.A = 1; } } } spriteBatch.Draw(texture.Texture, new Rectangle((int)(t.Position.X * BaseTileOffsetX), (int)(t.Position.Y * BaseTileOffsetY), Tile.DEFAULT_WIDTH, Tile.DEFAULT_HEIGHT), texture.SourceRectangle, dColor, 0f, Vector2.Zero, SpriteEffects.None, t.Depth); } }
void DrawBorder(Vector2 position, int width, int height) { TileIndex borderTiles = new TileIndex(0, 1); for (int j = 0; j < height; j++) { int row; if (j == 0) row = 0; else if (j == height - 1) row = 2; else row = 1; for (int i = 0; i < width; i++) { int column; if (i == 0) column = 0; else if (i == width - 1) column = 2; else column = 1; TileIndex tile = borderTiles + new TileIndex(column, row); TileEngine.DrawTile(Assets.UITiles, tile, position + new Vector2(i, j) * Assets.CellSize); } } }
public override void TappedHandler(object sender, System.EventArgs e) { TileEngine.TappedCollectible(gameObject, Type); }
public DrawableSheet(string path, ContentManager contentManager, TileEngine tileEngine) : base(path) { texture = contentManager.Load <Texture2D>(path); this.tileEngine = tileEngine; }
// asettaa oikeat parametrit tileparameters oliolle ja tekee niistä keypairit private TileParameters GetRightTileParameters(BaseSerializedLayer serializedLayer, TileEngine tileEngine) { dynamic layer = serializedLayer; TileParameters tileParameters = new TileParameters(serializedLayer.MdiData, new List <BaseSerializedTile>(layer.Tiles), tileEngine); return(tileParameters); }
public TileSheet(string path, ContentManager contentManager, TileEngine tileEngine) : base(path, contentManager, tileEngine) { Initialize(); }
public LayerFactory(KhvGame game, TileEngine tileEngine) { this.game = game; this.tileEngine = tileEngine; }
public Layer(KhvGame game, string name, bool transparent, bool visible, Size size, TileEngine tileEngine) { this.name = name; Transparent = transparent; Visible = visible; this.size = size; this.tileEngine = tileEngine; drawOrder = new DrawOrder(name); components = new LayerComponentManager(); }
public AnimationTileSheet(string path, ContentManager contentManager, TileEngine tileEngine, AnimationManager animationManager) : base(path, contentManager, tileEngine) { AnimationManager = animationManager; Initialize(); }
public TileActor(TileEngine tileEngine, Tile tile) { this.tileEngine = tileEngine; this.tile = tile; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapGet("/", async context => { string headJs = "<script defer src=\"https://use.fontawesome.com/releases/v5.11.2/js/all.js\" crossorigin=\"anonymous\"></script><script src=\"https://unpkg.com/[email protected]/dist/leaflet.js\" integrity=\"sha512-GffPMF3RvMeYyc1LWMHtK8EbPv0iNZ8/oTtHPx9/cc2ILxQ+u905qIwdpULaqDkyBKgOaB57QTMg7ztg8Jm2Og==\" crossorigin=\"\"></script>"; string headCss = "<link rel=\"stylesheet\" href=\"https://unpkg.com/[email protected]/dist/leaflet.css\"\r\n integrity=\"sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==\"\r\n crossorigin=\"\"/>"; string js = "var mymap = L.map('mapid').setView([37.20980175586231,-93.27173709668480], 13);"; js += "L.tileLayer('https://localhost:44364/v1/{id}/{z}/{x}/{y}/tile.png', {\r\n attribution: 'Map data © <a href=\"https://www.openstreetmap.org/\">OpenStreetMap</a> contributors, <a href=\"https://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA</a>',\r\n maxZoom: 18,\r\n id: 'osm',\r\n accessToken: ''\r\n}).addTo(mymap);"; js += "var myIcon = L.divIcon({iconSize: [35,80],className:'', html:'<div class=\"fa-3x\"><span class=\"fa-layers fa-fw\"><i class=\"fas fa-map-marker\" style=\"color:red;\"></i><span class=\"fa-layers-text fa-inverse\" data-fa-transform=\"shrink-11.5 up-2\" style=\"font-weight:900;z-index:500;\">JW</span></span></div>'});\r\nL.marker([37.20980175586231,-93.27173709668480], {icon: myIcon}).addTo(mymap);"; await context.Response.WriteAsync("<!doctype html><html><head>" + headCss + headJs + "<style>body{margin:0;padding:0;} #mapid {height: 100vh; width: 80vw;}</style></head><body><div id=\"mapid\"></div><script>" + js + "</script>" + //"<script defer src=\"https://use.fontawesome.com/releases/v5.0.8/js/solid.js\" integrity=\"sha384-+Ga2s7YBbhOD6nie0DzrZpJes+b2K1xkpKxTFFcx59QmVPaSA8c7pycsNaFwUK6l\" crossorigin=\"anonymous\"></script>\r\n<script defer src=\"https://use.fontawesome.com/releases/v5.0.8/js/fontawesome.js\" integrity=\"sha384-7ox8Q2yzO/uWircfojVuCQOZl+ZZBg2D2J5nkpLqzH1HY0C1dHlTKIbpRz/LG23c\" crossorigin=\"anonymous\"></script>" + "</body></html>"); }); endpoints.MapGet("/v1/{engine}/{zoom?}/{x?}/{y?}/tile.png", async context => { string engine; switch (context.GetRouteValue("engine")?.ToString()?.ToLower()) { case "cycle": engine = "cycle"; break; case "wikimedia": engine = "wikimedia"; break; default: engine = "osm"; break; } var renderer = new TileEngine(engine, "data source=SPSDB4.sps.org;Integrated Security=SSPI;Initial Catalog=SPS_WEB_UTILITIES;", app.ApplicationServices.GetRequiredService <IModularDbClient>()); int x = DataUtility.ParseInt(context.GetRouteValue("x")); int y = DataUtility.ParseInt(context.GetRouteValue("y")); int zoom = DataUtility.ParseInt(context.GetRouteValue("zoom")); zoom = Math.Min(Math.Max(zoom, 1), 18); int max = DataUtility.ParseInt(Math.Pow(2, zoom)); x = ((x % max) + max) % max; y = ((y % max) + max) % max; var tile = renderer.FetchTile(x, y, zoom); context.Response.ContentType = "image/png"; await context.Response.Body.WriteAsync(tile.GetAsPng()); }); endpoints.MapGet("/staticmap.php", async context => { int zoom = DataUtility.ParseInt(context.Request.Query.FirstOrDefault(kvp => kvp.Key.Equals("zoom", StringComparison.InvariantCultureIgnoreCase)).Value.ToString() ?? ""); zoom = Math.Min(Math.Max(zoom, 0), 15); PointF center = MapEngine.ParsePointF(context.Request.Query.FirstOrDefault(kvp => kvp.Key.Equals("center", StringComparison.InvariantCultureIgnoreCase)).Value.ToString() ?? ""); center.Y = DataUtility.ParseFloat(Math.Max(Math.Min(center.Y, 37.3122615), 37.085441)); center.X = DataUtility.ParseFloat(Math.Max(Math.Min(center.X, -93.113170), -93.5115452)); Size size = MapEngine.ParseSize(context.Request.Query.FirstOrDefault(kvp => kvp.Key.Equals("size", StringComparison.InvariantCultureIgnoreCase)).Value.ToString() ?? ""); size.Height = Math.Max(Math.Min(1024, size.Height), 1); size.Width = Math.Max(Math.Min(1024, size.Width), 1); var renderer = new MapEngine("wikimedia", "data source=SPSDB4.sps.org;Integrated Security=SSPI;Initial Catalog=SPS_WEB_UTILITIES;", app.ApplicationServices.GetRequiredService <IModularDbClient>()); var map = renderer.FetchMapImage(center.Y, center.X, zoom, size.Width, size.Height); string sMarkers = context.Request.Query.FirstOrDefault(kvp => kvp.Key.Equals("markers", StringComparison.InvariantCultureIgnoreCase)).Value.ToString() ?? ""; //"37.20980175586231,-93.27173709668480,fa-marker-red|37.20980175586231,-93.27173709668480,fa-marker-blue"; try { renderer.OverlayMarkers(map, center.Y, center.X, zoom, sMarkers); } catch (Exception ex) {} // var marker = new MapMarker(sMarkers); //await context.Response.WriteAsync($"x: {p.X}, y:{p.Y}\n"); context.Response.ContentType = "image/png"; await context.Response.Body.WriteAsync(map.GetAsPng()); }); }); }
public MapObjectProcessor(KhvGame game, TileEngine tileEngine, string[] objectNamespaces) { this.game = game; this.tileEngine = tileEngine; this.objectNamespaces = objectNamespaces; }
public void Update() { List<Action> diagnostics = new List<Action>(); AnimationTimer += 1; bool advanceFrame = false; if (AnimationTimer >= Assets.AnimationPeriod) { AnimationTimer -= Assets.AnimationPeriod; advanceFrame = true; } //========================================================================================== // Conversations: //========================================================================================== List<Creature> availableConversers = new List<Creature>(); foreach (Creature creature in Creatures) { if (creature != Player) { float distance = (creature.Position - Player.Position).Length(); if (creature.Conversation.Length > 0 && distance < 96) { availableConversers.Add(creature); } if (creature.CanKill && State == GameState.Playing && distance < 48) { State = GameState.Losing; Engine.StopMusic(2.0f); } if (creature.CanWin && State == GameState.Playing && distance < 48) { State = GameState.Winning; Engine.StopMusic(2.0f); } } } Conversers.RemoveAll(x => !availableConversers.Contains(x)); if (!InConversation && availableConversers.Count > 0 && Engine.GetKeyDown(Key.J)) { // Begin a conversation: Creature other = availableConversers[0]; Conversers.Add(other); ConversationPage = 0; if (other.Thought == Thought.WaitToJoin) other.Thought = Thought.Follow; } else if (InConversation && Engine.GetKeyDown(Key.J)) { // Continue a conversation: ConversationPage += 1; } //========================================================================================== // Player input: //========================================================================================== Vector2 input = Vector2.Zero; if (Engine.GetKeyHeld(Key.A)) input.X -= 1; if (Engine.GetKeyHeld(Key.D)) input.X += 1; if (Engine.GetKeyHeld(Key.W)) input.Y -= 1; if (Engine.GetKeyHeld(Key.S)) input.Y += 1; Player.Movement = input; if (input.Length() != 0) { ShowMoveTip = false; } //========================================================================================== // AI: //========================================================================================== foreach (Creature creature in Creatures) { if (creature.Thought == Thought.Follow) { Vector2 vectorToPlayer = Player.Position - creature.Position; float distanceToPlayer = vectorToPlayer.Length(); if (distanceToPlayer > creature.FollowDistanceMin && distanceToPlayer < creature.FollowDistanceMax) { creature.Movement = vectorToPlayer.Normalized(); } else { creature.Movement = Vector2.Zero; } } } //========================================================================================== // Physics: //========================================================================================== foreach (Creature creature in Creatures) { if (State != GameState.Playing) { creature.Movement = Vector2.Zero; creature.Velocity = Vector2.Zero; } creature.Velocity += creature.Movement * creature.MaxAcceleration * Engine.TimeDelta; creature.Velocity.X = Clamp(creature.Velocity.X, -creature.Speed, creature.Speed); creature.Velocity.Y = Clamp(creature.Velocity.Y, -creature.Speed, creature.Speed); // Update sprite facing: if (creature.Movement.X < 0) creature.Facing = TextureMirror.Horizontal; if (creature.Movement.X > 0) creature.Facing = TextureMirror.None; // Update position and collide: { // These bounds describe the "solid" part of the entity; it is independent of position. Bounds2 creatureShape = new Bounds2( new Vector2(1 / 8f, 6 / 8f) * Assets.CellSize, new Vector2(6 / 8f, 2 / 8f) * Assets.CellSize); Vector2 motion = creature.Velocity * Engine.TimeDelta; TileIndex nearest = GetCellAt(creature.Position, Assets.WallTiles); // Find everything that could be collided with: List<Bounds2> obstacles = new List<Bounds2>(); for (int row = nearest.Row - 2; row <= nearest.Row + 2; row++) { for (int column = nearest.Column - 2; column <= nearest.Column + 2; column++) { if (Obstacles[column, row]) { Bounds2 obstacleBounds = new Bounds2( new Vector2(column, row) * Assets.CellSize, Assets.CellSize); // The effective bounds are the sum of the obstacle's and the mover's bounds: Vector2 min = obstacleBounds.Min - creatureShape.Max; Vector2 max = obstacleBounds.Max - creatureShape.Min; Bounds2 totalBounds = new Bounds2(min, max - min); obstacles.Add(totalBounds); if (Game.DebugCollision && creature == Player) { diagnostics.Add(() => Engine.DrawRectEmpty(obstacleBounds.Translated(Origin), Color.Green)); } } } } // Calculate collision along the X and Y axes independently. // Each calculation considers only motion along that axis. // Performing these steps sequentially ensures that objects can't move diagonally through other objects. // X step: Vector2 position = creature.Position; Vector2 newPosition = position + new Vector2(motion.X, 0); foreach (Bounds2 bounds in obstacles) { // Leftward: if (motion.X < 0 && position.Y > bounds.Position.Y && position.Y < bounds.Position.Y + bounds.Size.Y) { float limit = bounds.Position.X + bounds.Size.X; if (position.X >= limit && newPosition.X < limit) newPosition.X = limit; } // Rightward: if (motion.X > 0 && position.Y > bounds.Position.Y && position.Y < bounds.Position.Y + bounds.Size.Y) { float limit = bounds.Position.X; if (position.X <= limit && newPosition.X > limit) newPosition.X = limit; } } creature.Position.X = newPosition.X; // Y step: position = creature.Position; newPosition = position + new Vector2(0, motion.Y); foreach (Bounds2 bounds in obstacles) { // Upward: if (motion.Y < 0 && position.X > bounds.Position.X && position.X < bounds.Position.X + bounds.Size.X) { float limit = bounds.Position.Y + bounds.Size.Y; if (position.Y >= limit && newPosition.Y < limit) newPosition.Y = limit; } // Downward: if (motion.Y > 0 && position.X > bounds.Position.X && position.X < bounds.Position.X + bounds.Size.X) { float limit = bounds.Position.Y; if (position.Y <= limit && newPosition.Y > limit) newPosition.Y = limit; } } creature.Position.Y = newPosition.Y; if (Game.DebugCollision && creature == Player) { diagnostics.Add(() => { Engine.DrawRectEmpty(creatureShape.Translated(Origin + creature.Position), Color.Green); }); } } // Slow to a stop when there is no input -- separately on each axis: if (creature.Movement.X == 0) { float speed = Math.Abs(creature.Velocity.X); speed = Math.Max(0, speed - creature.Deceleration); creature.Velocity.X = Math.Sign(creature.Velocity.X) * speed; } if (creature.Movement.Y == 0) { float speed = Math.Abs(creature.Velocity.Y); speed = Math.Max(0, speed - creature.Deceleration); creature.Velocity.Y = Math.Sign(creature.Velocity.Y) * speed; } } //========================================================================================== // Scroll to keep the player onscreen: //========================================================================================== { Vector2 margin = new Vector2(300, 250); Origin.X = Clamp(Origin.X, -Player.Position.X + margin.X, -(Player.Position.X + Assets.PropTiles.DestinationSize.X) + Game.Resolution.X - margin.X); Origin.Y = Clamp(Origin.Y, -Player.Position.Y + margin.Y, -(Player.Position.Y + Assets.PropTiles.DestinationSize.Y) + Game.Resolution.Y - margin.Y); } //========================================================================================== // Draw the static part of the map: //========================================================================================== for (int row = 0; row < MapHeight; row++) { for (int column = 0; column < MapWidth; column++) { TileEngine.DrawTile(Assets.WallTiles, Walls[column, row], Origin + new Vector2(column, row) * Assets.CellSize); } } //========================================================================================== // Draw creatures back-to-front: //========================================================================================== foreach (Creature creature in Creatures.OrderBy(x => x.IsFlat ? 0 : 1).ThenBy(x => x.Position.Y)) { TileEngine.DrawTile(Assets.PropTiles, creature.Appearance[creature.Frame], Origin + creature.Position, mirror: creature.Facing); if (advanceFrame) { creature.Frame = (creature.Frame + 1) % creature.Appearance.Length; } } //========================================================================================== // Draw UI: //========================================================================================== if (InConversation) { string speech = Conversers[0].Conversation[ConversationPage]; int width = 16; int height = 3; Vector2 pos = new TileIndex((20 - width) / 2, 12 - height) * Assets.CellSize; DrawBorder(pos, width, height); pos += 0.5f * Assets.CellSize; TileEngine.DrawTileString(Assets.FontTiles, speech, pos); } else if (availableConversers.Count > 0) { string text = "\x18 Converse"; Vector2 pos = new Vector2((20 - (text.Length + 1) / 2) / 2, 11) * Assets.CellSize; TileEngine.DrawTileString(Assets.FontTiles, text, pos); } else if (ShowMoveTip) { string text = "\x1C \x1D \x1E \x1F Move"; Vector2 pos = new Vector2((20 - (text.Length + 1) / 2) / 2, 11) * Assets.CellSize; TileEngine.DrawTileString(Assets.FontTiles, text, pos); } //========================================================================================== // End of game cinematics: //========================================================================================== if (State == GameState.Losing) { if (advanceFrame) { EndGameFrame += 1; if (EndGameFrame == Assets.EndMusicFrame) Engine.PlayMusic(Assets.LosingMusic, fadeTime: 6.0f); } Color background = Color.Black.WithAlpha(EndGameFrame / 5f); Engine.DrawRectSolid(new Bounds2(Vector2.Zero, Game.Resolution), background); string text = "You died"; float textAlpha = Clamp((EndGameFrame - 8) / 5f, 0, 1); Color textColor = Assets.LosingTextColor.WithAlpha(textAlpha); Vector2 pos = new Vector2((20 - (text.Length + 1) / 2) / 2, 5) * Assets.CellSize; TileEngine.DrawTileString(Assets.FontTiles, text, pos, color: textColor); } else if (State == GameState.Winning) { if (advanceFrame) { EndGameFrame += 1; if (EndGameFrame == Assets.EndMusicFrame) Engine.PlayMusic(Assets.WinningMusic, fadeTime: 6.0f); } Color background = Color.White.WithAlpha(EndGameFrame / 5f); Engine.DrawRectSolid(new Bounds2(Vector2.Zero, Game.Resolution), background); string text = "You escaped!"; float textAlpha = Clamp((EndGameFrame - 8) / 5f, 0, 1); Color textColor = Assets.WinningTextColor.WithAlpha(textAlpha); Vector2 pos = new Vector2((20 - (text.Length + 1) / 2) / 2, 5) * Assets.CellSize; TileEngine.DrawTileString(Assets.FontTiles, text, pos, color: textColor); } if (EndGameFrame > 20) { string text = "\x1A New game"; Vector2 pos = new Vector2((20 - (text.Length + 1) / 2) / 2, 11) * Assets.CellSize; Color color = (State == GameState.Winning) ? Assets.WinningTextColor : Assets.LosingTextColor; TileEngine.DrawTileString(Assets.FontTiles, text, pos, color: color); if (Engine.GetKeyDown(Key.N)) { Restart = true; } } //========================================================================================== // Debug information: //========================================================================================== if (Game.Debug) { foreach (Action action in diagnostics) { action(); } } }
internal void drawOverheads(TileEngine.MapTile tile, Position3D position) { // base entities do not draw, but they can have overheads, so we draw those. foreach (KeyValuePair<int, Overhead> overhead in _overheads) { if (!overhead.Value.IsDisposed) overhead.Value.Draw(tile, position); } }
/// <summary> /// Render the map, with TL in map at mapOffset. Screenviewport is the screen viewport in tile dimensions (for now) /// </summary> /// <param name="mapToRender"></param> /// <param name="mapOffset"></param> /// <param name="screenViewport"></param> public static void RenderMap(TileEngine.TileMap mapToRender, Point mapOffset, Rectangle screenViewport) { //For libtcod //tileID = ascii char //flags = color //Get screen handle RootConsole rootConsole = RootConsole.GetInstance(); if (mapOffset.x >= mapToRender.Columns || mapOffset.y >= mapToRender.Rows) { throw new Exception("Point outside map " + mapOffset); } //Calculate visible area of map int maxColumn = mapOffset.x + screenViewport.Width - 1; int maxRow = mapOffset.y + screenViewport.Height - 1; if (maxColumn >= mapToRender.Columns) maxColumn = mapToRender.Columns - 1; if (maxRow >= mapToRender.Rows) maxRow = mapToRender.Rows - 1; //Render layers in order foreach (TileEngine.TileLayer layer in mapToRender.Layer) { for (int y = mapOffset.y; y <= maxRow; y++) { for (int x = mapOffset.x; x <= maxColumn; x++) { TileEngine.TileCell thisCell = layer.Rows[y].Columns[x]; if (thisCell.TileID == -1) continue; //Flags is a color for libtcod LibtcodColorFlags colorFlags = thisCell.TileFlag as LibtcodColorFlags; if (colorFlags == null) { rootConsole.ForegroundColor = ColorPresets.White; rootConsole.BackgroundColor = ColorPresets.Black; } else { if (colorFlags.BackgroundColor == null) { rootConsole.BackgroundColor = ColorPresets.Black; } else { rootConsole.BackgroundColor = colorFlags.BackgroundColor; } rootConsole.ForegroundColor = colorFlags.ForegroundColor; } //Id is the char char screenChar = Convert.ToChar(thisCell.TileID); //Screen coords int screenX = screenViewport.X + (x - mapOffset.x); int screenY = screenViewport.Y + (y - mapOffset.y); rootConsole.PutChar(screenX, screenY, screenChar); } } } //Reset colors - this matters for systems that don't use the tile renderer rootConsole.ForegroundColor = ColorPresets.White; rootConsole.BackgroundColor = ColorPresets.Black; }
public MdiLayer(KhvGame game, string name, bool transparent, bool visible, Size size, TileEngine tileEngine, Index startIndex) : base(game, name, transparent, visible, size, tileEngine) { rectangle = new Rectangle(startIndex.X * tileEngine.TileSize.Width, startIndex.Y * tileEngine.TileSize.Height, size.Width * tileEngine.TileSize.Width, size.Height * tileEngine.TileSize.Height); originalPosition = new Vector2(startIndex.X * tileEngine.TileSize.Width, startIndex.Y * tileEngine.TileSize.Height); position = new Vector2(OriginalPosition.X, OriginalPosition.Y); }
public TileParameters(SerializedMdiData mdiData, List <BaseSerializedTile> serializedTiles, TileEngine tileEngine) { this.mdiData = mdiData; this.serializedTiles = serializedTiles; this.tileEngine = tileEngine; tileParams = new List <TileParameter>(); MakeArguments(); }
void Awake() { tileEngine = FindObjectOfType<TileEngine>(); audio = this.GetComponent<AudioSource> (); }