public void Register(MapBase map, TNativeMap nativeMap) { this.Map = map; this.NativeMap = nativeMap; map.UiSettings.PropertyChanged += UiSettings_PropertyChanged; }
public void CreateMapInstance(MapID mapID) { // Check for a valid map if (!MapBase.MapIDExists(mapID)) { UserChat("Invalid map ID: " + mapID); return; } // Try to create the map MapInstance instance; try { instance = new MapInstance(mapID, World); } catch (Exception ex) { UserChat("Failed to create instance: " + ex); return; } // Add the user to the map User.Teleport(instance, new Vector2(50, 50)); }
public Game(int noOfFactions) { //Adds the number of specified factions _faction = new List <Faction>(); for (int i = 1; i <= noOfFactions; i++) { _faction.Add((Faction)i); } //Load Map string mapPath = Path.Combine("Maps", "map_serialized.txt"); map = new MapTextImport(mapPath); //set capitals of factions int[] capitals = map.GetCapitals(); int counter = 0; foreach (Faction f in _faction) { map.SetTileToFaction(f, capitals[counter], capitals[counter + 1]); counter = counter + 2; } //Generate Coins on Tilemap GenerateCoins(5, 70, 90); //setup free population of factions _freepopulation = new Dictionary <Faction, int>(); foreach (Faction f in _faction) { _freepopulation.Add(f, 1); } }
//Helper Functions public override MapBase[,] GenerateAutotileGrid() { var mapBase = new MapBase[3, 3]; if (Globals.MapGrid != null && Globals.MapGrid.Contains(Id)) { for (var x = -1; x <= 1; x++) { for (var y = -1; y <= 1; y++) { var x1 = MapGridX + x; var y1 = MapGridY + y; if (x1 >= 0 && y1 >= 0 && x1 < Globals.MapGrid.GridWidth && y1 < Globals.MapGrid.GridHeight) { if (x == 0 && y == 0) { mapBase[x + 1, y + 1] = this; } else { mapBase[x + 1, y + 1] = Lookup.Get <MapInstance>(Globals.MapGrid.Grid[x1, y1].MapId); } } } } } mapBase[1, 1] = this; return(mapBase); }
private static void FillItems(List <Item> items, Vector2 beginPos, Layer layer, Dictionary <int, List <int> > delayInfo) { var beginPixelPosition = MapBase.ToPixelPosition(beginPos, false); for (var h = 0; h < layer.Height; h++) { for (var w = 0; w < layer.Width; w++) { var tileIndex = layer.Data[w + h * layer.Width]; if (tileIndex == 0) { continue; } var offset = MapBase.ToPixelPosition(w, h, false) - beginPixelPosition; if (delayInfo.ContainsKey(tileIndex)) { items.AddRange(delayInfo[tileIndex].Select(delay => new Item(offset, delay))); } else { items.Add(new Item(offset, 0)); } } } }
public void Warp(MapID mapID) { // Check for a valid map if (!MapBase.MapIDExists(mapID)) { UserChat("Invalid map ID `{0}`.", mapID); return; } var map = World.GetMap(mapID); if (map == null) { UserChat("No map with ID `{0}` exists.", mapID); return; } var pos = User.Position; if (pos.X < 0 || pos.Y < 0 || pos.X > map.Width || pos.Y > map.Height) { UserChat("The position of your current coordinates are out of the map's range. Map size: {0}", map.Size); return; } // Move the user User.Teleport(map, pos); }
/// <summary> /// Bounce at wall, find wall tiles. /// </summary> /// <param name="direction"></param> /// <param name="worldPosition"></param> /// <param name="targetTilePosition"></param> /// <returns>Bouncing direction</returns> public static Vector2 BouncingAtWall(Vector2 direction, Vector2 worldPosition, Vector2 targetTilePosition) { if (direction == Vector2.Zero) { return(direction); } var dir = Utils.GetDirectionIndex(direction, 8); var checks = new[] { (dir + 2) % 8, (dir + 6) % 8, (dir + 1) % 8, (dir + 7) % 8 }; var get = 8; var neighbors = FindAllNeighbors(targetTilePosition); for (var i = 0; i < checks.Count(); i++) { if (MapBase.Instance.IsObstacleForMagic(neighbors[checks[i]])) { get = checks[i]; break; } } if (get == 8) { return(BouncingAtPoint(direction, worldPosition, MapBase.ToPixelPosition(targetTilePosition))); } var normal = MapBase.ToPixelPosition(targetTilePosition) - MapBase.ToPixelPosition(neighbors[get]); normal = Vector2.Normalize(new Vector2(-normal.Y, normal.X)); return(Vector2.Reflect(direction, normal)); }
// 战斗开始 public void CombatStart() { if (State == EnGameState.Start) { return; } State = EnGameState.Start; m_SceneID = 1; // 检查是否要销毁原场景 if (m_SceneObj != null && m_LastSceneID != m_SceneID) { DestroyObject(m_SceneObj); m_SceneObj = null; } // 检查是否需要加载场景 if (m_SceneObj == null) { m_SceneObj = ResMgr.It.LoadScene(m_SceneID, SceneRoot); m_SceneMap = m_SceneObj.GetComponent <MapBase>(); } if (m_SceneMap) { m_SceneMap.OnStart(); } m_LastSceneID = m_SceneID; m_Joystick.activated = true; m_Joystick.enabled = true; }
private static NameSyntax GetNamespaceName(MapBase map) { var namespaceText = !string.IsNullOrWhiteSpace(map.Namespace) ? map.Namespace : DefaultNamespace; return(ParseName(namespaceText)); }
/// <summary> /// Move to ceter tile position in speed /// </summary> /// <param name="centerTilePosition"></param> /// <param name="speed"></param> public void MoveTo(Vector2 centerTilePosition, int speed) { _moveToBeginDestination = MapBase.ToPixelPosition(centerTilePosition) - GetHalfViewSize(); _moveSpeed = speed; IsInMoveTo = true; }
public void TestMoveUp() { var tankEngine = new TankEngine(); var map = new MapBase(); map.GameMap = new int[100, 100]; map.Borders = new List <int> { 0, 0, 100, 100 }; int tankInitX = 5, tankInitY = 10; var tank = new List <TankFragment>(); var gameMap = new int[100, 100]; tankEngine.TankInit(out tank, tankInitX, tankInitY, MoveDirection.Right, gameMap); var testList = new List <TankFragment>(tank.Count); foreach (TankFragment t in tank) { var item = new TankFragment(t.X, t.Y); testList.Add(item); } tankEngine.TankMove(tank, MoveDirection.Up, map); Assert.IsTrue(testList[0].Y - 1 == tank[0].Y && testList[1].Y - 1 == tank[1].Y && testList[2].Y - 1 == tank[2].Y && testList[3].Y - 1 == tank[3].Y && testList[4].Y - 1 == tank[4].Y && testList[5].Y - 1 == tank[5].Y && testList[6].Y - 1 == tank[6].Y && testList[7].Y - 1 == tank[7].Y && testList[8].Y - 1 == tank[8].Y); }
private void RegisterHadler() { _leftButton.MouseLeftClicking += (arg1, arg2) => Left(); _rightButton.MouseLeftClicking += (arg1, arg2) => Right(); _upButton.MouseLeftClicking += (arg1, arg2) => Up(); _downButton.MouseLeftClicking += (arg1, arg2) => Down(); _closeButton.Click += (arg1, arg2) => IsShow = false; MouseLeftDown += (object arg1, MouseLeftDownEvent arg2) => { if (DrawRegion.Contains(new Point((int)arg2.MouseScreenPosition.X, (int)arg2.MouseScreenPosition.Y))) { var position = arg2.MousePosition - new Vector2(MapViewDrawBeginX, MapViewDrawBeginY); position += new Vector2(ViewBeginX, ViewBeginY); position *= Ratio; PathFinder.TemporaryDisableRestrict = true; if (Globals.ThePlayer.canRun(Keyboard.GetState())) { Globals.ThePlayer.RunTo(MapBase.ToTilePosition(position)); } else { Globals.ThePlayer.WalkTo(MapBase.ToTilePosition(position)); } if (Globals.ThePlayer.Path != null) { IsShow = false; } else { _messageTip.IsShow = true; } } }; }
static void DeleteMiniMap(MapID mapId) { try { // Delete file string filePathDev = MapBase.GetMiniMapFilePath(ContentPaths.Dev, mapId); if (File.Exists(filePathDev)) { File.Delete(filePathDev); } try { string filePathBuild = MapBase.GetMiniMapFilePath(ContentPaths.Build, mapId); if (File.Exists(filePathBuild)) { File.Delete(filePathBuild); } } catch { } } catch (Exception ex) { const string errmsg = "Failed to delete the mini-map for mapId `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, mapId, ex); } Debug.Fail(string.Format(errmsg, mapId, ex)); throw; } }
public static MapBehaviour CreateMainMap(Type mapType, SizeInt mapSize, Size cellSize) { MapBehaviour currentMainMapBehaviour = MainMapBehaviour; if (currentMainMapBehaviour != null) { UnityEngine.Object.DestroyImmediate(currentMainMapBehaviour.gameObject); currentMainMapBehaviour = null; } GameObject mapGO = new GameObject("Map"); mapGO.layer = LayerMask.NameToLayer(EditorStringReferences.ShadowWitchLayerName); MapBehaviour mapBehaviour = mapGO.AddComponent <MapBehaviour>(); MapBase map = mapType.Assembly.CreateInstance(mapType.ToString()) as MapBase; map.Init(mapSize, cellSize); mapBehaviour.Init(map, CreateLayerGameObjects()); mainMapBehaviour = mapBehaviour; BoxCollider boxCollider = mapGO.AddComponent <BoxCollider>(); boxCollider.isTrigger = true; boxCollider.center = new Vector3(mapSize.Width / 2f * cellSize.Width, 0f, -mapSize.Height / 2f * cellSize.Height); boxCollider.size = new Vector3(mapSize.Width * cellSize.Width, 0f, mapSize.Height * cellSize.Height); return(mainMapBehaviour); }
public override void Register(MapBase map, MapView nativeMap) { base.Register(map, nativeMap); _nativeMap.WillMove += NativeMap_WillMove; _nativeMap.CameraPositionChanged += NativeMap_CameraPositionChanged; _nativeMap.CameraPositionIdle += NativeMap_CameraPositionIdle; }
public new MapElementBase AddTo(MapBase map) { Map = map; map.AddElement(this); map.AddElement(Trigger); return this; }
//Helper Functions public MapBase[,] GenerateAutotileGrid() { var mapBase = new MapBase[3, 3]; if (Globals.MapGrid != null && Globals.GridMaps.Contains(Id)) { for (var x = -1; x <= 1; x++) { for (var y = -1; y <= 1; y++) { var x1 = MapGridX + x; var y1 = MapGridY + y; if (x1 >= 0 && y1 >= 0 && x1 < Globals.MapGridWidth && y1 < Globals.MapGridHeight) { if (x == 0 && y == 0) { mapBase[x + 1, y + 1] = this; } else { mapBase[x + 1, y + 1] = Lookup.Get <MapInstance>(Globals.MapGrid[x1, y1]); } } } } } else { Debug.WriteLine("Returning null mapgrid for map " + Name); } return(mapBase); }
/// <summary> /// 转换地图数据为地图单位 /// </summary> /// <param name="mapData">地图数据</param> /// <param name="layer">层级</param> /// <param name="mapBase">地图基类</param> /// <returns></returns> private static MapCellBase[,] GetCells(int[][] mapData, UnitType layer, MapBase mapBase = null) { var height = mapData.Length; var width = mapData[0].Length; var mapCellDataArray = new MapCellBase[height, width]; // 遍历内容 for (var i = 0; i < height; i++) { for (var j = 0; j < width; j++) { if (mapData[i][j] > 0) { // 加载模型 var mapCell = UnitFictory.Single.CreateUnit <MapCellBase>(layer, mapData[i][j]); mapCell.X = j; mapCell.Y = i; if (mapBase != null) { mapCell.Draw(mapBase.Leftdown, mapBase.UnitWidth); } //根据数据加载 mapCellDataArray[i, j] = mapCell; } } } return(mapCellDataArray); }
/// <summary> /// Initializes a new instance of the <see cref="World"/> class. /// </summary> /// <param name="parent">Server this world is part of.</param> /// <exception cref="ArgumentNullException"><paramref name="parent" /> is <c>null</c>.</exception> /// <exception cref="ArgumentException">The unarmed weapon ID is not a valid item template ID.</exception> public World(Server parent) { if (parent == null) { throw new ArgumentNullException("parent"); } _respawnTaskList = new RespawnTaskList(this); // Store the parent _server = parent; // Create some objects _guildMemberPerformer = new GuildMemberPerformer(DbController, FindUser); // Create the unarmed weapon var unarmedWeaponID = ServerSettings.Default.UnarmedItemTemplateID; var unarmedWeaponTemplate = _itemTemplateManager[unarmedWeaponID]; if (unarmedWeaponTemplate == null) { const string errmsg = "Unable to create unarmed weapon - couldn't find item template with ID `{0}`."; if (log.IsFatalEnabled) { log.FatalFormat(errmsg, unarmedWeaponID); } throw new ArgumentException(string.Format(errmsg, unarmedWeaponID)); } _unarmedWeapon = new ItemEntity(unarmedWeaponTemplate, 1); // Load the maps var mapFiles = MapBase.GetMapFiles(ContentPaths.Build); _maps = new DArray <Map>(mapFiles.Count() + 10); foreach (var mapFile in mapFiles) { MapID mapID; if (!MapBase.TryGetIndexFromPath(mapFile, out mapID)) { const string errmsg = "Failed to get the ID of map file `{0}`."; if (log.IsFatalEnabled) { log.FatalFormat(errmsg, mapFile); } throw new ArgumentException(string.Format(errmsg, mapFile)); } var m = new Map(mapID, this); _maps[(int)mapID] = m; m.Load(); } // Trim down the maps array under the assumption we won't be adding more maps _maps.Trim(); // Add some event hooks BanningManager.Instance.AccountBanned -= BanningManager_AccountBanned; BanningManager.Instance.AccountBanned += BanningManager_AccountBanned; }
public void TestMoveDown() { var tankEngine = new TankEngine(); var map = new MapBase { GameMap = new int[100, 100], Borders = new List <int> { 0, 0, 100, 100 } }; int tankInitX = 5, tankInitY = 10; var tank = new List <TankFragment>(); var gameMap = new int[100, 100]; tankEngine.TankInit(out tank, tankInitX, tankInitY, MoveDirection.Right, gameMap); var testList = new List <TankFragment>(tank.Count); testList.AddRange(tank.Select(t => new TankFragment(t.X, t.Y))); tankEngine.TankMove(tank, MoveDirection.Down, map); Assert.IsTrue(testList[0].Y + 1 == tank[0].Y && testList[1].Y + 1 == tank[1].Y && testList[2].Y + 1 == tank[2].Y && testList[3].Y + 1 == tank[3].Y && testList[4].Y + 1 == tank[4].Y && testList[5].Y + 1 == tank[5].Y && testList[6].Y + 1 == tank[6].Y && testList[7].Y + 1 == tank[7].Y && testList[8].Y + 1 == tank[8].Y); }
public void Warp(MapID mapID, int x, int y) { // Check for a valid map if (!MapBase.MapIDExists(mapID)) { UserChat("Invalid map ID `{0}`.", mapID); return; } var map = World.GetMap(mapID); if (map == null) { UserChat("No map with ID `{0}` exists.", mapID); return; } var pos = new Vector2(x, y); if (pos.X < 0 || pos.Y < 0 || pos.X > map.Width || pos.Y > map.Height) { UserChat("The specified coordinates are out of the map's range. Map size: {0}", map.Size); return; } // Move the user User.Teleport(map, pos); }
private void AddEventHandlers() { // Check to see if this is the event handlers have been attached yet and if not, attach them. // This will only happen on the first click of the Pushpin. MapLayer parentLayer = Parent as MapLayer; if (parentLayer != null) { MapBase parentMap = parentLayer.ParentMap; if (parentMap != null) { if (ParentMapMousePanHandler == null) { ParentMapMousePanHandler = new EventHandler <MapMouseDragEventArgs>(ParentMap_MousePan); parentMap.MousePan += ParentMapMousePanHandler; } if (ParentMapMouseLeftButtonUpHandler == null) { ParentMapMouseLeftButtonUpHandler = new MouseButtonEventHandler(ParentMap_MouseLeftButtonUp); parentMap.MouseLeftButtonUp += ParentMapMouseLeftButtonUpHandler; } if (ParentMapMouseMoveHandler == null) { ParentMapMouseMoveHandler = new MouseEventHandler(ParentMap_MouseMove); parentMap.MouseMove += ParentMapMouseMoveHandler; } } } }
public override void Update(GameTime gameTime, ObjectPlayer player, MapBase map) { if (health > 0) { Vector2 releventPlayerPosition = new Vector2(player.Position.X + Convert.ToInt32(map.Offset.X), player.Position.Y + Convert.ToInt32(map.Offset.Y)); this.Rotation = float.Parse(GameFunctions.GetAngle(this.Position, releventPlayerPosition).ToString()); int rot = Convert.ToInt32(MathHelper.ToDegrees(float.Parse(this.Rotation.ToString()))) - 90; double xs = Math.Cos((rot * Math.PI) / 180); double xy = Math.Sin((rot * Math.PI) / 180); Vector2 OldPos = this.Position; this.Position = new Vector2(this.Position.X - float.Parse(xs.ToString()), this.Position.Y - float.Parse(xy.ToString())); this.BoundingRectangle = new Rectangle(Convert.ToInt32(this.Position.X - ((Texture.Width * scale) / 2)), Convert.ToInt32(this.Position.Y - ((Texture.Height * scale) / 2)), Convert.ToInt32(Texture.Width * scale), Convert.ToInt32(Texture.Height * scale)); //Hit Test! float dis = Vector2.Distance(this.Position, releventPlayerPosition); Vector2 MV = (this.Position - releventPlayerPosition) * .05f;// / dis; if (dis < 40) { this.Position = OldPos; this.Position = this.Position + MV; //player.Position = player.Position - MV; player.Health -= 1; } } base.Update(gameTime); }
/// <summary> /// Get line path without care obstacle. /// </summary> /// <param name="startTile">Start tile positon</param> /// <param name="endTile">End tile positon</param> /// <param name="maxTry">Max strep</param> /// <param name="tilePositon">If true, path position in path list is tile position.Otherwise is postion in world.</param> /// <returns>Path positition in world list.</returns> public static LinkedList <Vector2> GetLinePath(Vector2 startTile, Vector2 endTile, int maxTry, bool tilePositon = false) { if (startTile == endTile) { return(null); } var path = new LinkedList <Vector2>(); var frontier = new C5.IntervalHeap <Node <Vector2> >(); frontier.Add(new Node <Vector2>(startTile, 0f)); while (!frontier.IsEmpty) { if (maxTry-- < 0) { break; } var current = frontier.DeleteMin().Location; path.AddLast(tilePositon? current : MapBase.ToPixelPosition(current)); if (current == endTile) { break; } foreach (var neighbor in FindAllNeighbors(current)) { frontier.Add(new Node <Vector2>(neighbor, GetTilePositionCost(neighbor, endTile))); } } return(path); }
public void Init(MapBase map, Dictionary <string, GameObject> layerGODict) { this.map = map; layerGOKeyList = new List <string>(); layerGOList = new List <GameObject>(); this.layerGODict = layerGODict; }
public override void OnInvoke(CommandObject[] obj) { if (obj.Length != 2) { Print(Info.HelpText); return; } if (obj[0].type == Program.engine.STRING && !obj[0].IsNull && obj[1].type == Program.engine.STRING && !obj[1].IsNull) { string name = (string)obj[0].value; int count; if (!int.TryParse((string)obj[1].value, out count)) { Print(Info.HelpText); return; } MapBase map = GlobalServer.FindMap(name); if (map == null) { Print("指定地图不存在"); return; } map.MaxBlockCount = count; Print("操作成功"); } }
private void LoadMap(string name) { _map = name switch { "Berlin" => new BerlinMap() }; }
public TreeGen(MapBase map) { instance = this; Map = map; Trees = new List <Vector2L>(); ReadTrees(); }
private static void AddRegionFileMagicSprite(Character user, Magic magic, Vector2 origin, Vector2 destination, bool destroyOnEnd) { if (magic.RegionFile == null) { return; } var direction = destination - origin; var directionIndex = Utils.GetDirectionIndex(direction, 8); var items = magic.RegionFile.ContainsKey(directionIndex) ? magic.RegionFile[directionIndex] : magic.RegionFile[0]; //Make destination at tile center destination = MapBase.ToPixelPosition(MapBase.ToTilePosition(destination)); foreach (var item in items) { var magicSprite = GetFixedPositionMagicSprite(user, magic, destination + item.Offset, destroyOnEnd); if (item.Delay > 0) { AddWorkItem(new WorkItem(item.Delay, magicSprite)); } else { AddMagicSprite(magicSprite); } } }
private static void AddVTypeFixedPOsitionMagicSprite(Character user, Magic magic, Vector2 origin, Vector2 destination, bool destroyOnEnd) { var direction = destination - origin; var directionIndex = Utils.GetDirectionIndex(direction, 8); var count = 3; if (magic.EffectLevel > 3) { count += ((magic.EffectLevel - 1) / 3) * 2; } var orgTile = PathFinder.FindNeighborInDirection(MapBase.ToTilePosition(origin), directionIndex); AddMagicSprite(GetFixedPositionMagicSprite(user, magic, MapBase.ToPixelPosition(orgTile), destroyOnEnd)); const float magicDelayMilliseconds = 60f; var leftVTile = orgTile; var rightVTile = orgTile; for (var i = 1; i < count; i++) { leftVTile = PathFinder.FindNeighborInDirection(leftVTile, (directionIndex + 7) % 8); rightVTile = PathFinder.FindNeighborInDirection(rightVTile, (directionIndex + 1) % 8); AddWorkItem(new WorkItem(i * magicDelayMilliseconds, GetFixedPositionMagicSprite(user, magic, MapBase.ToPixelPosition(leftVTile), destroyOnEnd))); AddWorkItem(new WorkItem(i * magicDelayMilliseconds, GetFixedPositionMagicSprite(user, magic, MapBase.ToPixelPosition(rightVTile), destroyOnEnd))); } }
/// <summary> /// Saves a map as a new map. /// </summary> /// <param name="map">The map to save.</param> /// <param name="showConfirmation">If true, a confirmation will be shown to make sure the user wants to /// perform this operation.</param> public static void SaveMapAs(EditorMap map, bool showConfirmation = true) { try { if (map == null) { return; } var newID = MapBase.GetNextFreeIndex(ContentPaths.Dev); int newSetID; if (!int.TryParse(InputBox.Show("Save as...", "Save map ID as:", newID.ToString()), out newSetID)) { return; } if (!MapBase.MapIDExists((MapID)newSetID)) { newID = ((MapID)newSetID); // Confirm save if (showConfirmation) { const string confirmMsg = "Are you sure you wish to save map `{0}` as a new map (with ID `{1}`)?"; if (MessageBox.Show(string.Format(confirmMsg, map, newID), "Save map as?", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } } else { const string confirmMsgOverWrite = "Are you sure you wish to save map `{0}` and overwrite map (with ID `{1}`)?"; if (MessageBox.Show(string.Format(confirmMsgOverWrite, map.ID, newSetID), "Save map as?", MessageBoxButtons.YesNo) == DialogResult.No) { return; } newID = ((MapID)newSetID); } // Change the map ID map.ChangeID(newID); // Save SaveMap(map, false); SaveMiniMap(map.ID, ContentPaths.Dev.Grhs + "MiniMap"); } catch (Exception ex) { const string errmsg = "Failed to save map `{0}` as a new map. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, map, ex); } Debug.Fail(string.Format(errmsg, map, ex)); } }
/// <summary> /// Finds the MapIds for maps that exist in the database but not on file, or vise versa. /// </summary> public static MapID[] FindMissingMapIds() { // Get ids from file & db MapID[] idsFromFile = MapBase.GetUsedMapIds(ContentPaths.Dev); MapID[] idsFromDb = FindAllMaps().Select(x => x.ID).ToArray(); return(idsFromFile.NotIntersect(idsFromDb).ToArray()); }
public override void Shoot(double rotation, int fromX, int fromY, MapBase map, double aimX, double aimY) { if (canFire == true) { elapsedSinceShot = DateTime.Now; base.Shoot(rotation, fromX, fromY, map, aimX, aimY); } canFire = false; }
public override void Update(MapBase map) { _bulletLife++; if (_bulletLife > 50) { IsActive = false; } base.Update(map); }
private void movement(MapBase map) { keyboardState = Keyboard.GetState(); if (keyboardState.IsKeyDown(Keys.S)) { map.Offset.Y += Speed; } if (keyboardState.IsKeyDown(Keys.W)) { map.Offset.Y -= Speed; } if (keyboardState.IsKeyDown(Keys.A)) { map.Offset.X -= Speed; } if (keyboardState.IsKeyDown(Keys.D)) { map.Offset.X += Speed; } if (prevReleased == false) { if (keyboardState.IsKeyUp(Keys.Escape)) { prevReleased = true; } } else { if (keyboardState.IsKeyDown(Keys.Escape)) { GameData.GameState = GameData.GameStates.Paused; prevReleased = false; } } if (Keyboard.GetState().IsKeyDown(Keys.LeftShift)) run = true; else run = false; if (run == true && stamina > 5 && usedRun == false) { speed = RUN; stamina -= 5; if (stamina == 0) usedRun = true; } else { usedRun = true; speed = WALK; if (stamina < 998) stamina += 2; if (stamina >= STAMINATHRESHOLD) usedRun = false; } }
public override void Update(GameTime gameTime, ObjectPlayer player, MapBase map) { if (Math.Abs(Convert.ToInt32(Position.Y - map.Offset.Y - originalOffset.Y)) > Texture.Width) { Position = new Vector2(Position.X, Convert.ToInt32(map.Offset.Y) + originalOffset.Y); } if (Math.Abs(Convert.ToInt32(Position.X - map.Offset.X - originalOffset.X)) > Texture.Height) { Position = new Vector2(Convert.ToInt32(map.Offset.X) + originalOffset.X, Position.Y); } base.Update(gameTime); }
public override void Update(MapBase map) { time++; if (Time<16) { Distance = new Point(2, 0); } else { Distance = new Point(-2,0); } base.Update(map); }
public override void Update(GameTime gameTime, MapBase map) { if (health <= 0 && alive == true) { GameStats.AppendStat("DeadCount", 1); alive = false; } if (alive == true && GameData.GameState == GameData.GameStates.Playing) { movement(map); this.Rotation = float.Parse(GameFunctions.GetAngle(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Position).ToString()); } base.Update(gameTime); }
public override void Update(GameTime gameTime, MapBase map, ObjectPlayer player) { for (int i = 0; i < Objects.Keys.Count;i++) { string[] arrayShit = new string[Objects.Keys.Count]; Objects.Keys.CopyTo(arrayShit,0); string ObjectKey = arrayShit[i]; ObjectBase Object = (ObjectBase)Objects[ObjectKey]; switch (Object.Type) { case ObjectPooling.ObjectPool.ObjectTypes.Enemy: Object.Update(gameTime, player, map); break; case ObjectPooling.ObjectPool.ObjectTypes.EnemySpawner: Object.Update(gameTime, map, ObjectPool); break; } } base.Update(gameTime, map, player); }
public virtual void Shoot(double rotation, int fromX, int fromY, MapBase map, double aimX, double aimY) { if (Content != null && this.Bullets != null && ammo > 0) { //TODO: Ray Trace & Muzzle Flash Goes Here int hitEnemies = 0; Ray2D ray = new Ray2D(new Vector2(fromX, fromY), new Vector2(float.Parse(aimX.ToString()), float.Parse(aimY.ToString()))); ObjectBase o = ray.FirstIntersect(map.Objects); if (o != null) { o.OnHit(this, new Vector2(fromX, fromY)); hitEnemies++; ObjectBase o2 = ray.IndexIntersect(map.Objects, 2); if (o2 != null) { o2.OnHit(this, new Vector2(fromX, fromY)); float oDist = Vector2.Distance(new Vector2(fromX, fromY), o.Position); float o2Dist = Vector2.Distance(new Vector2(fromX, fromY), o2.Position); } } ammo--; } }
public override void Update(MapBase map) { // 銃 if (Input.Instance.Z) { if (_bulletIntervalCount <= 0) { Bullet bullet; if (Direction == Direction.Right) { bullet = new Bullet(new Point(Point.X + 11, Point.Y + 7), Direction); } else { bullet = new Bullet(new Point(Point.X - 11, Point.Y + 7), Direction); } map.AddElement(bullet); map.UpdateElement(); _bulletIntervalCount = BULLETINTERVAL; } } if (_bulletIntervalCount > 0) { _bulletIntervalCount--; } // ジャンプ if (Input.Instance.LeftShift) { if (jumpflame != 0) { if (jumpflame < 20) { if (jumpflame == 1) { SoundManager.Play("jump", DX.DX_PLAYTYPE_BACK); } jumpflame++; _vy = -8; } else { jumpflame = 0; } } } else { jumpflame = 0; } // 移動 ay = 5; ax = 0; if (Input.Instance.Right) { Direction = Direction.Right; ax += 5; } if (Input.Instance.Left) { Direction = Direction.Left; ax -= 5; } if (!Input.Instance.Right && !Input.Instance.Left) { _vx = 0; } if (movingFloor != null) { Top = new Point(Top.X + movingFloor.Distance.X * 2, Top.Y + movingFloor.Distance.Y * 2); movingFloor = null; } // 状態 if (Top.Y > 600) { Death(); } if (Vy < 0) { MainCharactorStatus = MainCharactorStatus.Jump; } else if (Vy > 5) { MainCharactorStatus = MainCharactorStatus.Fall; } // 更新 base.Update(map); Distance = new Point(Vx, Vy); }
public override void Update(MapBase map) { if (_isTriggered) { if (_isTriggered) { SoundManager.Play("death", DX.DX_PLAYTYPE_BACK); } IsActive = false; } }
public override void Update(MapBase map) { if (GameTimer.Loop(100) == 0 || Input.Instance.Z) { var rand = new Random(); //var bullet = new BossBullet(new Point(Point.X + rand.Next(-100, 100), Point.Y + rand.Next(-100, 100))); var bullet = new BossBullet(new Point(Top.X-16, Top.Y + rand.Next(96))); if (life != maxlife) { map.AddElement(bullet); } map.UpdateElement(); } //Size = new Size(Math.Abs((int)(baseSize.Width * Math.Sin(GameTimer.Frame / 50.0))), Math.Abs((int)(baseSize.Height * Math.Sin(GameTimer.Frame / 50.0)))); //Top = basePoint + new Size((baseSize.Width - Size.Width)/2, (baseSize.Height - Size.Height)/2); base.Update(map); }
/// <summary> /// Initializes a new instance of the <see cref="ItemEntity"/> class. /// </summary> /// <param name="t">The item template to copy the initial values from.</param> /// <param name="pos">The world position of the item.</param> /// <param name="amount">The amount of the item.</param> /// <param name="map">The map the item is to spawn on.</param> public ItemEntity(IItemTemplateTable t, Vector2 pos, byte amount, MapBase map) : this(t, pos, amount) { // Since the item is spawning on a map, ensure that the position is valid for the map var validPos = ValidatePosition(map, pos); if (!IsDisposed) { Teleport(validPos); map.AddEntity(this); } }
/// <summary> /// Validates the given <paramref name="position"/> by attempting to make it a legal position if it is not /// one already. /// </summary> /// <param name="map">The map that the <see cref="ItemEntity"/> is on or will be on.</param> /// <param name="position">The position to validate.</param> /// <returns>If the <paramref name="position"/> was already valid, or no valid position was found, contains /// the same value as the <paramref name="position"/>; otherwise, contains the corrected valid position.</returns> Vector2 ValidatePosition(MapBase map, Vector2 position) { if (map == null) return position; var tempRect = new Rectangle((int)position.X, (int)position.Y, (int)Size.X, (int)Size.Y); Vector2 closestLegalPosition; bool isClosestPositionValid; if (!map.IsValidPlacementPosition(tempRect, out closestLegalPosition, out isClosestPositionValid)) { if (isClosestPositionValid) { // Legal position found return closestLegalPosition; } else { // No legal position found, so just destroy the item... const string errmsg = "No legal position could be found for item `{0}` (Map: `{1}`; Position: `{2}`). Destroying item..."; if (log.IsWarnEnabled) log.WarnFormat(errmsg, this, map, position); Debug.Fail(string.Format(errmsg, this, map, position)); Destroy(); } } return position; }
public virtual void Update(GameTime gameTime, ObjectPlayer player, MapBase map) { }
/// <summary> /// Sets the spawn area for this <see cref="MapSpawnValues"/>. /// </summary> /// <param name="map">Instance of the Map with the <see cref="MapID"/> equal to the <see cref="MapID"/> handled by this /// <see cref="MapSpawnValues"/>. This is to ensure that the <paramref name="newSpawnArea"/> given is in a /// valid map range.</param> /// <param name="newSpawnArea">New MapSpawnRect values.</param> /// <exception cref="ArgumentOutOfRangeException">The <paramref name="newSpawnArea"/> contains one or more /// values that are not in range of the <paramref name="map"/>.</exception> /// <exception cref="ArgumentException">The <paramref name="map"/>'s <see cref="MapID"/> does not match this /// MapSpawnValues's <see cref="MapID"/>.</exception> /// <exception cref="ArgumentNullException"><paramref name="map"/> is null.</exception> public void SetSpawnArea(MapBase map, MapSpawnRect newSpawnArea) { if (map == null) throw new ArgumentNullException("map"); if (map.ID != MapID) throw new ArgumentException("The ID of the specified map does not match this MapID", "map"); if (newSpawnArea == SpawnArea) return; var x = newSpawnArea.X.HasValue ? newSpawnArea.X.Value : (ushort)0; var y = newSpawnArea.Y.HasValue ? newSpawnArea.Y.Value : (ushort)0; const string errmsg = "One or more of the `newSpawnArea` parameter values are out of range of the map!"; if (x < 0) throw new ArgumentOutOfRangeException("newSpawnArea", errmsg); if (y < 0) throw new ArgumentOutOfRangeException("newSpawnArea", errmsg); if (newSpawnArea.Width.HasValue && (x + newSpawnArea.Width.Value) > map.Width) throw new ArgumentOutOfRangeException("newSpawnArea", errmsg); if (newSpawnArea.Height.HasValue && (y + newSpawnArea.Height.Value) > map.Height) throw new ArgumentOutOfRangeException("newSpawnArea", errmsg); SpawnArea = newSpawnArea; }
/// <summary> /// Initializes a new instance of the <see cref="EditorMapSpawnValues"/> class. /// </summary> /// <param name="msv">The <see cref="MapSpawnValues"/>.</param> /// <param name="map">The map.</param> public EditorMapSpawnValues(MapSpawnValues msv, MapBase map) { _msv = msv; _map = map; }
public void Update(GameTime gameTime, int playerX, int playerY, MapBase map, double rotation, double aimX, double aimY) { KeyboardState kybd = Keyboard.GetState(); if (kybd.IsKeyDown(Keys.Tab) && tabActivated == false) { if (currentWeapon != null) { if (availableWeapons.IndexOf(currentWeapon) + 1 < availableWeapons.Count) { currentWeapon = availableWeapons[availableWeapons.IndexOf(currentWeapon) + 1]; } else { if (availableWeapons.Count >= 1) { currentWeapon = availableWeapons[0]; } } } else { if (availableWeapons.Count >= 1) { currentWeapon = availableWeapons[0]; } } tabActivated = true; } if (kybd.IsKeyUp(Keys.Tab) && tabActivated == true) { tabActivated = false; } if (Mouse.GetState().LeftButton == ButtonState.Pressed && canFire) { currentWeapon.Shoot(rotation, playerX + int.Parse(map.Offset.X.ToString()), playerY + int.Parse(map.Offset.Y.ToString()), map, aimX, aimY); GameStats.AppendStat("FiredBullets", 1); } if ((kybd.IsKeyDown(Keys.R) && canReload) || (currentWeapon.Ammo == 0 && canReload)) { if (currentWeapon.Ammo == currentWeapon.MaxClip) { } timeSinceReload = DateTime.Now; reloading = true; canFire = false; canReload = false; } if (reloading) { TimeSpan reloadCheck = DateTime.Now - timeSinceReload; if((reloadCheck.TotalMilliseconds / 1000) >= currentWeapon.ReloadTime) { int ammoToAdd = currentWeapon.MaxClip - currentWeapon.Ammo; currentWeapon.Ammo += ammoToAdd; ammo9MM.Remaining -= ammoToAdd; reloading = false; canReload = true; canFire = true; } } currentWeapon.Update(gameTime, playerX, playerY, rotation); }
public virtual void Update(GameTime gameTime, MapBase map) { }
/// <summary> /// Teleports the character to a new position and informs clients in the area of /// interest that the character has teleported. /// </summary> /// <param name="newMap">The new map to teleport to.</param> /// <param name="position">Position to teleport to.</param> public void Teleport(MapBase newMap, Vector2 position) { if (newMap != Map) { // Take the character off the old map, teleport, then put them on the new map if (Map != null) Map.RemoveEntity(this); _map = null; Teleport(position); if (newMap != null) { newMap.AddEntity(this); _spSync.ForceSynchronize(); } } else { // Just teleport since the map didn't change Teleport(position); } Debug.Assert(Map == newMap); }
public override void Update(MapBase map) { //int y = 5; //int x = 0; //Distance = new Point(x, y); //base.Update(map); }
public override void Update(MapBase map) { if (_isTrigered) { Distance = new Point(x, y); } else { Distance = new Point(0, 0); } base.Update(map); }
public override void Shoot(double rotation, int fromX, int fromY, MapBase map, double aimX, double aimY) { if(canFire == true) base.Shoot(rotation, fromX, fromY, map, aimX, aimY); canFire = false; }