public TilesetBuilder CreateLedge(CollisionModel model, int ledgeDirection) { tileData.CollisionModel = model; tileData.LedgeDirection = ledgeDirection; tileData.SolidType = TileSolidType.Ledge; return(this); }
//----------------------------------------------------------------------------- // Override //----------------------------------------------------------------------------- public CollisionModelSR(TemporaryResources resources = null) { this.resources = resources; // Sprite <name> AddCommand("Model", delegate(CommandParam parameters) { modelName = parameters.GetString(0); model = new CollisionModel(); }); // End AddCommand("End", delegate(CommandParam parameters) { if (model != null) { Resources.AddResource(modelName, model); model = null; } }); // Variant <name> <file-path> AddCommand("Add", delegate(CommandParam parameters) { model.AddBox( parameters.GetInt(0), parameters.GetInt(1), parameters.GetInt(2), parameters.GetInt(3)); }); }
public long ParsePathFindingSpheres(CollisionModel coll, BinaryReader reader, int count) { var originalPos = reader.BaseStream.Position; coll.PathfindingSpheres = new List <CollisionModel.PathfindingSphere>(); for (uint i = 0; i < count; ++i) { var pfSphere = new CollisionModel.PathfindingSphere(); reader.BaseStream.Position = originalPos + (i * PATHF_SPHERE_SIZE); var node_idx = BitConverter.ToInt16(reader.ReadBytes(2).Reverse().ToArray(), 0); reader.BaseStream.Position += 14; //14 bytes between node index and sphere location,radius var center_x = BitConverter.ToSingle(reader.ReadBytes(4).Reverse().ToArray(), 0); var center_y = BitConverter.ToSingle(reader.ReadBytes(4).Reverse().ToArray(), 0); var center_z = BitConverter.ToSingle(reader.ReadBytes(4).Reverse().ToArray(), 0); var radius = BitConverter.ToSingle(reader.ReadBytes(4).Reverse().ToArray(), 0); pfSphere.CenterX = center_x; pfSphere.CenterY = center_y; pfSphere.CenterZ = center_z; pfSphere.Radius = radius; pfSphere.Node = node_idx; coll.PathfindingSpheres.Add(pfSphere); } return(originalPos + (count * PATHF_SPHERE_SIZE)); }
//----------------------------------------------------------------------------- // Debug drawing //----------------------------------------------------------------------------- // Draw a collision model as a solid color. public void DrawCollisionModel(CollisionModel model, Vector2F position, Color color) { for (int i = 0; i < model.Boxes.Count; i++) { FillRectangle(Rectangle2F.Translate(model.Boxes[i], position), color); } }
//----------------------------------------------------------------------------- // Override //----------------------------------------------------------------------------- public CollisionModelSR(TemporaryResources resources = null) { this.resources = resources; //===================================================================================== AddCommand("Model", "string name", delegate(CommandParam parameters) { modelName = parameters.GetString(0); model = new CollisionModel(); }); //===================================================================================== AddCommand("End", "", delegate(CommandParam parameters) { if (model != null) { Resources.AddResource(modelName, model); model = null; } }); //===================================================================================== AddCommand("Add", "int x, int y, int width, int height", delegate(CommandParam parameters) { model.AddBox( parameters.GetInt(0), parameters.GetInt(1), parameters.GetInt(2), parameters.GetInt(3)); }); //===================================================================================== }
public CollisionModel(CollisionModel copy) { bounds = Rectangle2I.Zero; boxes = new List<Rectangle2I>(); for (int i = 0; i < copy.boxes.Count; ++i) boxes.Add(copy.boxes[i]); }
public void ReadFromFile(BinaryReader reader) { if (reader.ReadInt32() != Version) { throw new Exception("Unknown collision version"); } Platform = reader.ReadUInt32(); if (Platform > 2) { throw new Exception($"Unknown platform {Platform}"); } int numPlacements = reader.ReadInt32(); Placements = new List <Placement>(numPlacements); for (int i = 0; i < numPlacements; i++) { Placements.Add(new Placement(reader)); } int numModels = reader.ReadInt32(); Models = new SortedDictionary <ulong, CollisionModel>(); for (int i = 0; i < numModels; i++) { CollisionModel model = new CollisionModel(reader); Models.Add(model.Hash, model); } }
/// <summary> /// This file parser will parse Halo 1 CE 'model_collision_geometry' tags. /// The addresses of the tagblocks inside the tag are likely to be garbage /// values. The Halo 1 CE development tool 'guerilla' does not use the /// reflexive address value and expects chunks to occur in the order that /// the reflexives occur in the parent struct. /// /// The Halo1 CE collision tag is used due to high compatibility and /// availability of 'Tool' - a program which can compile collision tags. /// /// The parser expects the following format: /// h1ce coll tag format: ///main struct ///all materials sequential ///all regions sequential ///all permutations sequential ///all path finding spheres sequential ///all nodes sequential ///bsp 0 /// bsp0 3dnodes sequential /// ... /// bsp0 vertices sequential ///bsp 1 /// ... ///... /// </summary> /// <param name="fpath"></param> /// <returns></returns> public bool ParseFromFile(string fpath) { FileStream fs = null; try { fs = new FileStream(fpath, FileMode.Open, FileAccess.Read); } catch (FileNotFoundException) { Console.WriteLine("The system cannot find the file specified."); return(false); } var reader = new BinaryReader(fs); var coll = new CollisionModel(); // h1 ce tags will have a 64 byte header. The main struct is immediately after. var len = reader.BaseStream.Length; reader.BaseStream.Position = MAIN_STRUCT_OFFSET; var size = ParseMain(coll, reader); if (len != size) { Console.WriteLine("length expected was not actual.\nexpected: " + len + ", actual: " + size); return(false); } //builder succeeded Definition = coll; return(true); }
public void OnCollisionEnter2DManual(GameObject col) { CollisionModel model = new CollisionModel { mainCollider = this.gameObject, CollidedWith = col.gameObject }; onCollisionFacade(model); }
public void playerCollidedWithWall(CollisionModel model) { LeanTween.cancel(model.mainCollider.gameObject, true); movmentLogic.ResetRotation(); animationLogic.UnSetDashing(); animationLogic.CheckIfGrounded(); soundLogic.playLandingSound(); }
// Return true if the entity would collide with a tile if it were at the given position. public bool IsPlaceMeetingTile(Vector2F position, Tile tile) { if (CanCollideWithTile(tile)) { return(CollisionModel.Intersecting(tile.CollisionModel, tile.Position, collisionBox, position)); } return(false); }
public void Collision(CollisionModel model) { var pair = PairModel.New <string, string> (model.mainCollider.tag, model.CollidedWith.tag); if (collisionDictionary.ContainsKey(pair)) { collisionDictionary [pair].Invoke(model); } }
public AttackParameter( IBattleObjectModel fromModel, CollisionModel targetCollision, float damageValue) { this.fromModel = fromModel; this.TargetCollision = targetCollision; this.DamageValue = damageValue; }
public void OnCollisionEnter2DManual(GameObject col) { // Debug.Log("collision detected"); CollisionModel model = new CollisionModel { mainCollider = this.gameObject, CollidedWith = col.gameObject }; onCollisionFacade(model); }
void Awake() { _collider = GetComponent <BoxCollider2D>(); _transform = GetComponent <Transform>(); _stats = GetComponent <ControllableStats>(); _velocity = Vector3.zero; Collisions = new CollisionModel(); }
/// <summary> /// Parses all H1CE Collision Node tagblocks stored sequentially. /// The purpose of 'Node' is similar to 'Region' in Halo Online. /// </summary> /// <param name="coll"></param> /// <param name="reader"></param> /// <param name="count"></param> /// <returns></returns> public long ParseNodes(CollisionModel coll, BinaryReader reader, int count) { var originalPos = reader.BaseStream.Position; coll.Nodes = new List <CollisionModel.Node>(); //destroy the old list of regions, it may not be fine-grained enough coll.Regions = new List <CollisionModel.Region>(); var new_region_count = 0; var current_bsp_offset = originalPos + (count * NODE_SIZE); for (var i = 0; i < count; ++i) { var node = new CollisionModel.Node(); node.Name = new StringId(0x140 + (uint)i); //offset of the parent node in the h1 ce node tagblock reader.BaseStream.Position = originalPos + (i * NODE_SIZE) + 32; short region_idx = BitConverter.ToInt16(reader.ReadBytes(2).Reverse().ToArray(), 0); short parent_node_idx = BitConverter.ToInt16(reader.ReadBytes(2).Reverse().ToArray(), 0); short next_sibling_idx = BitConverter.ToInt16(reader.ReadBytes(2).Reverse().ToArray(), 0); short first_child_idx = BitConverter.ToInt16(reader.ReadBytes(2).Reverse().ToArray(), 0); node.ParentNode = parent_node_idx; node.NextSiblingNode = next_sibling_idx; node.FirstChildNode = first_child_idx; coll.Nodes.Add(node); //there exists a region when the region index of the h1 ce collision node tagblock is not null if (region_idx >= 0) { var region = new CollisionModel.Region(); coll.Regions.Add(region); region.Name = new StringId(0x140 + (uint)new_region_count); reader.BaseStream.Position = originalPos + (i * NODE_SIZE) + 52; //bsp tagblock count //each bsp is placed into a separate permutation. In h1 ce // a node referencing a region with n permutations has n bsps region.Permutations = new List <CollisionModel.Region.Permutation>(); CollisionModel.Region.Permutation permutation = new CollisionModel.Region.Permutation(); region.Permutations.Add(permutation); permutation.Bsps = new List <BSP>(); uint n_bsps = (uint)BitConverter.ToInt32(reader.ReadBytes(4).Reverse().ToArray(), 0); for (uint j = 0; j < n_bsps; ++j) { reader.BaseStream.Position = current_bsp_offset; current_bsp_offset = ParseBSP(permutation, reader); } new_region_count++; } } return(current_bsp_offset); }
public ExtractModelCommand(CollisionModel definition) : base(true, "ExtractModel", "", "ExtractModel <File>", "") { Definition = definition; }
//----------------------------------------------------------------------------- // Static methods //----------------------------------------------------------------------------- public static bool Intersecting(CollisionModel model, Vector2F modelPosition, Rectangle2F box, Vector2F boxPosition) { Rectangle2F boxTranslated = Rectangle2F.Translate(box, boxPosition - modelPosition); for (int i = 0; i < model.boxes.Count; i++) { Rectangle2F modelBox = model.boxes[i]; if (boxTranslated.Intersects(modelBox)) return true; } return false; }
private void TurnOffFrictionWhileFlying(CollisionModel collision) { if (_currentlyBeingLaunched) { _stats.Friction = 0; } if (collision.TouchingBottom && _currentlyBeingLaunched) { _currentlyBeingLaunched = false; _stats.Friction = _storedFriction; } }
public ExtractModelCommand(HaloOnlineCacheContext cacheContext, CollisionModel definition) : base(true, "ExtractModel", "", "ExtractModel <File>", "") { CacheContext = cacheContext; Definition = definition; }
public ExtractModelCommand(GameCache cache, CollisionModel definition) : base(true, "ExtractModel", "", "ExtractModel <File>", "") { Cache = cache; Definition = definition; }
// Return an enumerable list of solid tiles colliding with the given collision box. public IEnumerable <Tile> GetSolidTilesColliding(Rectangle2F collisionBox, TileLayerOrder layerOrder = TileLayerOrder.LowestToHighest) { Rectangle2I area = GetTileAreaFromRect(collisionBox); foreach (Tile tile in GetTilesInArea(area, layerOrder)) { if (tile.IsSolid && tile.CollisionModel != null && CollisionModel.Intersecting(tile.CollisionModel, tile.Position, collisionBox)) { yield return(tile); } } }
/// <summary> /// Stub for now, creates n materials, which are named 0 to (n-1) /// </summary> /// <param name="coll"></param> /// <param name="tag_data"></param> /// <param name="pos"></param> /// <returns></returns> public long ParseMaterials(CollisionModel coll, BinaryReader reader, int count) { coll.Materials = new List <CollisionModel.Material>(); for (uint i = 0; i < count; ++i) { var material = new CollisionModel.Material(); material.Name = new StringId(0x140 + i); coll.Materials.Add(material); } return(reader.BaseStream.Position + MATERIAL_TAGBLOCK_SIZE * count); }
private void AttackZako() { // 一定時間は攻撃できない attackTime += Time.deltaTime; if (attackTime < AttackIntervalTIme) { return; } attackTime = 0; // ここもやっぱり共通化しないといけないな if (targetModel.Life.IsDead()) { return; } var targetCollision = targetModel.View.GetCollision(); // 攻撃をする判定を行う範囲は広くする targetCollision.Scale(2.0f); foreach (var zako in GetOppositeZakoGroup().Zakos) { var enemyCollision = zako.View.GetCollision(); // 近くにいたら if (targetCollision.IsIn(enemyCollision)) { // 攻撃のコリジョンを作成 ( この辺は別のモデルで行いたい ) var attackCollision = new CollisionModel( targetModel.View.RootTransform.GetRadius(), targetModel.View.RootTransform.GetPosition() + targetModel.View.Direction.normalized * targetModel.View.RootTransform.GetRadius() ); // 攻撃方向をむく // targetModel.View.Direction = enemyCollision.Position - targetModel.View.RootTransform.GetColliderPosition (); // 攻撃命令をメディエイターに送る BattleGlobal.Instance.CollisionMediater.RequestPlayerChampionAttack( new AttackParameter(targetModel, attackCollision, 30 /* TODO : とりあえずこの値 */) ); return; } } }
public override void Update() { base.Update(); hasUpdated = true; Player player = RoomControl.Player; if (isPlayerBlockingClose && !CollisionModel.Intersecting(CollisionModel, Position, player.Physics.CollisionBox, player.Position)) { Close(); isPlayerBlockingClose = false; player.MarkRespawn(); } }
//----------------------------------------------------------------------------- // Overridden methods //----------------------------------------------------------------------------- public override void OnInitialize() { base.OnInitialize(); // Create the turnstile collision model. // It loooks like this: (each character is a quarter-tile) // X X // X X // XX // XX // X X // X X CollisionModel = new CollisionModel(); CollisionModel.AddBox(0, 0, 8, 8); CollisionModel.AddBox(8, 8, 8, 8); CollisionModel.AddBox(40, 0, 8, 8); CollisionModel.AddBox(32, 8, 8, 8); CollisionModel.AddBox(0, 40, 8, 8); CollisionModel.AddBox(8, 32, 8, 8); CollisionModel.AddBox(40, 40, 8, 8); CollisionModel.AddBox(32, 32, 8, 8); CollisionModel.AddBox(16, 16, 16, 16); // center. SolidType = TileSolidType.Solid; IsSolid = true; turnDirection = -1; // Setup based on the winding order. windingOrder = (Properties.GetBoolean("clockwise", false) ? WindingOrder.Clockwise : WindingOrder.CounterClockwise); if (windingOrder == WindingOrder.Clockwise) { arrowsAnimationPlayer.Play(GameData.ANIM_TURNSTILE_ARROWS_CLOCKWISE); turnstileAnimationPlayer.SubStripIndex = 0; } else { arrowsAnimationPlayer.Play(GameData.ANIM_TURNSTILE_ARROWS_COUNTERCLOCKWISE); turnstileAnimationPlayer.SubStripIndex = 1; } turnstileAnimationPlayer.Play(GameData.ANIM_TURNSTILE_ROTATE_CLOCKWISE); turnstileAnimationPlayer.SkipToEnd(); }
public void playerCollideWithEnemy(CollisionModel model) { if (playerStatsLogic.powerUpModeActive == PowerUpType.SUPERHIT) { playerStatsLogic.resetDash(); playerStatsLogic.addOneToCombo(); return; } movmentLogic.ResetRotation(); LeanTween.cancel(model.mainCollider.gameObject, true); //to remove secondary collisions if (model.CollidedWith != null) { Physics2D.IgnoreCollision(model.CollidedWith.GetComponent <Collider2D> (), model.mainCollider.GetComponent <Collider2D> ()); } var enemyPosition = model.CollidedWith.transform.position; var playerPosition = model.mainCollider.transform.position; var VectorForce = (Vector2)((playerPosition - enemyPosition).normalized); soundLogic.playSliceSound(); //if player hit some1 than he get back is dashes playerStatsLogic.resetDash(); playerStatsLogic.addOneToCombo(); //building path var sign = VectorForce.x > 0 ? 1 : -1; Vector3[] path = new Vector3[] { new Vector3(playerPosition.x + (-2.697063f * sign), playerPosition.y), new Vector3(playerPosition.x + (-1.397063f * sign), playerPosition.y + 5.108706f), new Vector3(playerPosition.x + (0.397063f * sign), playerPosition.y + 6.408706f), new Vector3(playerPosition.x + (1f * sign), playerPosition.y + 7.749998f), }; LeanTween.move(model.mainCollider.gameObject, path, impactTimeOnPlayer).setOnComplete(() => { stopAfterBounce(new StopAfterCollisionModel { collidedWith = model.CollidedWith.gameObject, subject = model.mainCollider.GetComponent <Rigidbody2D> () }); }); rollOver(model.mainCollider); animationLogic.UnSetDashing(); animationLogic.SetSlicing(); }
public override void UpdateByFrame() { base.UpdateByFrame(); if (targetModel.Life.IsDead()) { // 死亡時に玉を出す GetEnemyArea().Bettery.ReciveMessage("Burn", null); // 消去可能にする targetModel.IsDelete = true; return; } // エリア内でコリジョンを持っている時、つまり移動中の時 if (targetModel.View.IsCollisionEnable) { // 攻撃のためのインターバル時間を経過 attackIntervalTime += Time.deltaTime; // 攻撃のタイミングになったら if (attackIntervalTime > attackIntervalLimitTime) { // はみ出していたら if (GetEnemyArea().IsNearWall(targetModel)) { // 攻撃のコリジョンを作成 ( この辺は別のモデルで行いたい ) CollisionModel attackCollision = new CollisionModel( targetModel.View.RootTransform.GetRadius(), targetModel.View.RootTransform.GetPosition() + targetModel.View.Direction.normalized * targetModel.View.RootTransform.GetRadius() ); // 攻撃命令をメディエイターに送る BattleGlobal.Instance.CollisionMediater.RequestPlayerAttack( new AttackParameter(targetModel, attackCollision, 1 /* TODO : とりあえずこの値 */) ); } attackIntervalTime = 0; } } }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- public TileData() { type = null; size = Point2I.One; flags = TileFlags.Default; spriteList = new SpriteAnimation[0]; spriteAsObject = new SpriteAnimation(); breakAnimation = null; collisionModel = null; sheetLocation = Point2I.Zero; tileset = null; properties = new Properties(); properties.Set("id", "") .SetDocumentation("ID", "", "", "The id used to refer to this tile.", true, false); properties.Set("sprite_index", 0) .SetDocumentation("Sprite Index", "sprite_index", "", "The current sprite in the sprite list to draw.", true, true); }
public void OnCollisionEnter2D(Collision2D col) { // Debug.Log("collision detected"); if (col.collider.tag.Equals("Wall")) { if (Time.fixedTime - lastCollisionWithPodium < intervalBetweenCollisionWithPodium) { return; } lastCollisionWithPodium = Time.fixedTime; } CollisionModel model = new CollisionModel { mainCollider = this.gameObject, CollidedWith = col.gameObject }; onCollisionFacade(model); }
// Return a list of tiles colliding with this entity (solidity is ignored). public IEnumerable <Tile> GetTilesMeeting(Vector2F position, CollisionBoxType collisionBoxType) { // Find the rectangular area of nearby tiles to collide with. Rectangle2F myBox = GetCollisionBox(collisionBoxType); myBox.Point += position; myBox.Inflate(2, 2); Rectangle2I area = entity.RoomControl.GetTileAreaFromRect(myBox, 1); // Iterate the tiles in the area. foreach (Tile t in entity.RoomControl.GetTilesInArea(area)) { if (t.CollisionModel != null && CollisionModel.Intersecting(t.CollisionModel, t.Position, collisionBox, position)) { yield return(t); } } }
public CollisionModel FindCollision(ResultJsonModel[] loadedHashes, string filename) { Array.Sort(loadedHashes, delegate(ResultJsonModel x, ResultJsonModel y) { return(x.HexHash.CompareTo(y.HexHash)); }); CollisionModel collisionModel = new CollisionModel() { Filename = filename, Data = new List <ResultJsonModel>() }; for (int i = 0; i < loadedHashes.Length - 1; i++) { if (loadedHashes[i].HexHash == loadedHashes[i + 1].HexHash) { collisionModel.HasCollision = true; if (!collisionModel.Data.Contains(loadedHashes[i])) { collisionModel.Data.Add(loadedHashes[i]); } if (!collisionModel.Data.Contains(loadedHashes[i + 1])) { collisionModel.Data.Add(loadedHashes[i + 1]); } } if (i % 1000 == 0) { if (SearchCollisionUpdateEvent != null) { SearchCollisionUpdateEvent.Invoke(i, loadedHashes.Length); } } } if (SearchCollisionCompleteEvent != null) { SearchCollisionCompleteEvent.Invoke(); } return(collisionModel); }
public TileData(TileData copy) : this() { type = copy.type; size = copy.size; flags = copy.flags; spriteList = new SpriteAnimation[copy.spriteList.Length]; spriteAsObject = new SpriteAnimation(copy.spriteAsObject); breakAnimation = copy.breakAnimation; collisionModel = copy.collisionModel; sheetLocation = copy.sheetLocation; tileset = copy.tileset; properties = new Properties(); properties.Merge(copy.properties, true); for (int i = 0; i < spriteList.Length; i++) spriteList[i] = new SpriteAnimation(copy.spriteList[i]); }
private void InvokeRangeAttack() { var attackCollision = new CollisionModel( targetModel.View.RootTransform.GetRadius() * (2 + currentSkillRank * 0.5f), targetModel.View.RootTransform.GetPosition() + targetModel.View.Direction.normalized * targetModel.View.RootTransform.GetRadius() * (2) ); // 攻撃命令をメディエイターに送る BattleGlobal.Instance.CollisionMediater.RequestPlayerChampionAttack( new AttackParameter(targetModel, attackCollision, 50 * currentSkillRank) ); // ダメージエフェクトをつけたい ( まあ、なんとか、攻撃しているが。。。って感じ ) GameObject prefab = Resources.Load <GameObject>("Particle/Skill"); GameObject instance = GameObject.Instantiate(prefab); instance.transform.position = attackCollision.Position; instance.transform.localScale = new Vector3(1, 1, 1) * (0.5f + currentSkillRank * 0.5f); }
public void EnemyCollidedWithPlayer(CollisionModel model) { // Debug.Log("enemy collision detected"); var enemyController = model.mainCollider.GetComponent <AIController> (); var enemy = model.mainCollider.GetComponent <IEnemy> (); var position = (Vector2)model.mainCollider.transform.position; if (enemy.lifeDown(playerStatsLogic.Strength)) //if enemy dead { scoreLogic.addPoint(new AddPointModel { type = enemyController.type, combo = playerStatsLogic.combo }); missionLogic.addKill(enemyController.type); LeanTween.cancel(model.mainCollider.gameObject, false); if (Time.timeScale != 0) //could happen in super hit power up { enemy.Split(position); enemy.Death(); } } }
public TilesetBuilder CreateLedge(CollisionModel model, int ledgeDirection) { tileData.CollisionModel = model; tileData.Flags |= TileFlags.Solid | (TileFlags) ((int) TileFlags.LedgeRight << ledgeDirection); return this; }
public Collision SetModel(CollisionModel model) { Model = model; return this; }
public void Clone(TileData copy) { type = copy.type; size = copy.size; flags = copy.flags; breakAnimation = copy.breakAnimation; collisionModel = copy.collisionModel; properties = new Properties(); properties.Merge(copy.properties, true); }
private bool ResolveCollision(int axis, Tile tile, Vector2F modelPos, CollisionModel model) { bool collide = false; for (int i = 0; i < model.Boxes.Count; ++i) { Rectangle2F box = Rectangle2F.Translate((Rectangle2F) model.Boxes[i], modelPos); if (ResolveCollision(axis, tile, box)) collide = true; } return collide; }
public TilesetBuilder SetSolidModel(CollisionModel model) { tileData.CollisionModel = model; tileData.Flags |= TileFlags.Solid; return this; }
//----------------------------------------------------------------------------- // Debug drawing //----------------------------------------------------------------------------- // Draw a collision model as a solid color. public void DrawCollisionModel(CollisionModel model, Vector2F position, Color color) { for (int i = 0; i < model.Boxes.Count; i++) FillRectangle(Rectangle2F.Translate(model.Boxes[i], position), color); }
// Begins reading the script. protected override void BeginReading() { modelName = ""; model = null; }