GemView RemoveGemView(GemModel gemModel, bool needToChaining) { GemView gemView; if (gemViews.TryGetValue(gemModel.id, out gemView)) { gemViews.Remove(gemModel.id); } else { // Debug.Log("Can't remove the gem! " + gemModel.ToString()); } if (needToChaining) { ActByChaining( gemModel.Type, gemModel.specialKey, gemModel.Position, gemModel.endurance, gemModel.id, new Vector2(gemModel.PositionVector.colOffset, gemModel.PositionVector.rowOffset) ); } return(gemView); }
bool IsFalling(GemModel gemModel) { bool result = false; var sourcePosition = gemModel.Position; while (true) { var gravity = GetGravityModel(sourcePosition).vector; if (!IsAcceptableIndex(sourcePosition, gravity[0], gravity[1])) { break; } var nearPosition = Position.Get(sourcePosition, gravity[0], gravity[1]); if (!IsMovableTile(nearPosition)) { break; } if (GetGemModel(nearPosition).Type == GemType.EmptyGem) { result = true; break; } sourcePosition = nearPosition; } return(result); }
static void SetEndurance(GemModel gemModel) { int endurance = 0; switch (gemModel.Type) { case GemType.ChocoGem: endurance = 5; break; } switch (gemModel.specialKey) { case Literals.H: case Literals.V: endurance = int.MaxValue; break; case Literals.C: endurance = 1; break; } gemModel.endurance = endurance; }
public void Clear() { gemModel = null; gemModels.Clear(); isNextBreakable = false; isNextMovable = false; }
GemView MakeGemView(GemModel gemModel) { var gemView = ResourceCache.Instantiate <GemView>(gemModel.Name, gems.transform); gemView.UpdateModel(gemModel); gemView.transform.localPosition = new Vector2(gemModel.Position.col * gemSize.x, gemModel.Position.row * gemSize.y); gemViews.Add(gemModel.id, gemView); return(gemView); }
public int CompareTo(object obj) { if (obj == null) { return(1); } GemModel comparing = obj as GemModel; return((id == comparing.id) ? 0 : 1); }
private GemTrainManager m; // A pointer to the manager (not needed here, but potentially useful in general). // The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int gemType, GemTrainManager m) { this.gemType = gemType; this.m = m; GameObject modelObject = new GameObject(); GemModel model = modelObject.AddComponent <GemModel>(); modelObject.AddComponent <SpriteRenderer>(); modelObject.name = "GemModel"; model.init(gemType, this); }
// The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int gemType, GemManager m) { this.gemType = gemType; this.manager = m; name = "Gem"; age = 0.0f; var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); // Create a quad object for holding the gem texture. model = modelObject.AddComponent<GemModel>(); // Add a gemModel script to control visuals of the gem. model.init(gemType, this); BoxCollider2D coll = gameObject.AddComponent<BoxCollider2D>(); coll.isTrigger = true; }
int MergeEndurance(GemModel merger, GemModel mergee) { if (merger.specialKey == Literals.CC) { return(2); } if (merger.specialKey == Literals.HSQ || merger.specialKey == Literals.SQH) { return(5); } return(Math.Max(merger.endurance, mergee.endurance)); }
GemModel CopyAsSpecial(Int64 replacerID, GemModel targetGemModel, string specialKey, int endurance) { var copiedGemModel = GemModelFactory.Get( ReadGemType(targetGemModel.Type, specialKey), targetGemModel.Position ); copiedGemModel.id = targetGemModel.id; copiedGemModel.replacedBy = replacerID; SetGemModel(copiedGemModel); return(copiedGemModel); }
private MarbleManager m; // A pointer to the manager (not needed here, but potentially useful in general). // The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int gemType, MarbleManager m) { this.gemType = gemType; this.m = m; var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); // Create a quad object for holding the gem texture. model = modelObject.AddComponent <GemModel>(); //Rigidbody gemBody = gameObject.AddComponent<Rigidbody>(); model.init(gemType, this); }
// The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int x, int y, GemManager owner) { num_tiles_w = owner.num_tiles_w; num_tiles_h = owner.num_tiles_h; coordinants = new int[] {x, y}; float[] pos = position (x, y); screen_x = (int) pos [0]; screen_y = (int) pos [1]; this.transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (screen_x, screen_y, 9)); var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); // Create a quad object for holding the gem texture. model = modelObject.AddComponent<GemModel>(); // Add a gem_model script to control visuals of the gem. model.init(this); }
GemModel CopyAsBlock(Int64 markerID, GemModel targetGemModel) { var copiedGemModel = GemModelFactory.Get(GemType.BlockedGem, targetGemModel.Position); copiedGemModel.id = targetGemModel.id; copiedGemModel.markedBy = markerID; copiedGemModel.Type = targetGemModel.Type; copiedGemModel.specialKey = targetGemModel.specialKey; copiedGemModel.endurance = targetGemModel.endurance; copiedGemModel.Position = targetGemModel.Position; copiedGemModel.positionBefore = targetGemModel.positionBefore; SetGemModel(copiedGemModel); return(copiedGemModel); }
// The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int gemType, GemManager m) { this.gemType = gemType; this.manager = m; name = "Gem"; age = 0.0f; var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); // Create a quad object for holding the gem texture. model = modelObject.AddComponent <GemModel>(); // Add a gemModel script to control visuals of the gem. model.init(gemType, this); BoxCollider2D coll = gameObject.AddComponent <BoxCollider2D>(); coll.isTrigger = true; }
// The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int x, int y, GemManager owner) { num_tiles_w = owner.num_tiles_w; num_tiles_h = owner.num_tiles_h; coordinants = new int[] { x, y }; float[] pos = position(x, y); screen_x = (int)pos [0]; screen_y = (int)pos [1]; this.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(screen_x, screen_y, 9)); var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); // Create a quad object for holding the gem texture. model = modelObject.AddComponent <GemModel>(); // Add a gem_model script to control visuals of the gem. model.init(this); }
void ActBySwipe(GemModel sourceGemModel, Vector2 direction) { var sourcePosition = sourceGemModel.Position; var colOffset = (int)direction.x; var rowOffset = (int)direction.y; if (!Controller.IsAcceptableIndex(sourcePosition, colOffset, rowOffset)) { return; } var nearPosition = Position.Get(sourcePosition, colOffset, rowOffset); if (!Controller.IsMovableTile(nearPosition)) { return; } var nearGemModel = Controller.GetGemModel(nearPosition); if ((sourceGemModel.IsSpecialType() && nearGemModel.IsSpecialType()) || sourceGemModel.Type == GemType.SuperGem || nearGemModel.Type == GemType.SuperGem ) { Merge(sourcePosition, nearPosition); UpdateChanges(); } else if (sourceGemModel.Type == GemType.ChocoGem) { LinedBreaking( sourcePosition, direction, sourceGemModel.endurance, sourceGemModel.id, breakingOffset: 5, comparingToMoveon: CompareIsMovable, isChaining: false ); UpdateChanges(); } else { Swap(sourcePosition, nearPosition); UpdateChanges((Int64 passedTurn) => { Swap(nearPosition, sourcePosition, 1); }); } }
public List <GemModel> GetAnyMatches(GemModel sourceGemModel, MatchLineModel matchLineModel) { matchedGemModels.Clear(); foreach (var whereCanMatch in matchLineModel.wheresCanMatch) { foreach (var matchOffset in whereCanMatch.MatchOffsets) { if (!IsAcceptableIndex(sourceGemModel.Position, matchOffset[0], matchOffset[1])) { continue; } var matchingPosition = Position.Get(sourceGemModel.Position, matchOffset[0], matchOffset[1]); if (!IsMovableTile(matchingPosition)) { continue; } var matchingGemModel = GetGemModel(matchingPosition); if (sourceGemModel.CanMatch(matchingGemModel.Type) && Model.currentTurn > matchingGemModel.preservedFromMatch && !IsFalling(matchingGemModel) ) { matchedGemModels.Add(matchingGemModel); } else { // Need to match about all offsets. break; } } if (matchedGemModels.Count == whereCanMatch.MatchOffsets.Count) { // Finally found! break; } else { matchedGemModels.Clear(); } } return(matchedGemModels); }
void BreakGems(GemModel gemModel, bool needToChaining, GOSequence sequence, float currentTime) { if (gemModel == null) { return; } var gemView = RemoveGemView(gemModel, needToChaining); if (gemView == null) { return; } sequence.InsertCallback(currentTime, () => { gemView.ReturnToPool(); OnGemRemoved.Invoke((int)gemModel.Type, gemView.transform.position, effects.transform); }); }
string MergeSpecialKey(GemModel merger, GemModel mergee) { var mergerType = merger.Type; var mergerKey = merger.specialKey; var mergeeType = mergee.Type; var mergeeKey = mergee.specialKey; var maxOfGemtype = Math.Max((int)merger.Type, (int)mergee.Type); merger.Type = (maxOfGemtype >= 10) ? (GemType)maxOfGemtype : GemType.Nil; mergee.Type = GemType.Nil; merger.specialKey = mergee.specialKey = Literals.Nil; var sb = new StringBuilder(); sb.Append(ReadMergingKey(mergerType, mergerKey)); sb.Append(ReadMergingKey(mergeeType, mergeeKey)); return(sb.ToString()); }
// The Start function is good for initializing objects, but doesn't allow you to pass in parameters. // For any initialization that requires input, you'll probably want your own init function. public void init(int gemType, GameManager gm, Tile t) { this.gemType = gemType; this.gm = gm; this.tile = t; var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad); modelObject.tag = "gem"; MeshCollider mc = modelObject.GetComponent<MeshCollider> (); mc.enabled = false; BoxCollider bc = modelObject.AddComponent<BoxCollider> (); bc.size = new Vector3(.85f, .8f, 0); Rigidbody rb = modelObject.AddComponent<Rigidbody> (); rb.useGravity = false; rb.isKinematic = false; model = modelObject.AddComponent<GemModel>(); // Add a gemModel script to control visuals of the gem. model.init(gemType, this, modelObject); tile.hasGem = true; }
public void Clear() { mergee = null; merger = null; }
public void Clear() { blockedGemModel = null; gemModels.Clear(); }
public void SetGemModel(GemModel gemModel) { Model.GemModels[gemModel.Position.row, gemModel.Position.col] = gemModel; }
public void Clear() { gemModel = null; gemModels.Clear(); }