// Create a star block and listen to the event. private void SpawnStarBlocks() { StarBlock sb = (StarBlock)Instantiate(sbPrefab); sb.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z - 0.01f); sb.Destroyed += Empty; }
public override Choice GetComplexEBNFBlock(GrammarAST ebnfRoot, IList <CodeBlockForAlt> alts) { int ebnf = 0; if (ebnfRoot != null) { ebnf = ebnfRoot.Type; } Choice c = null; switch (ebnf) { case ANTLRParser.OPTIONAL: c = new OptionalBlock(this, ebnfRoot, alts); break; case ANTLRParser.CLOSURE: c = new StarBlock(this, ebnfRoot, alts); break; case ANTLRParser.POSITIVE_CLOSURE: c = new PlusBlock(this, ebnfRoot, alts); break; } return(c); }
public void CheckBlocks() { foreach (StarBlock block in seedToBlock.Values) { block.ResetTagged(); } Vector3 lowerLeft = camera.ViewportToWorldPoint(new Vector3(0, 0, 10 + Depth)); Vector3 upperRight = camera.ViewportToWorldPoint(new Vector3(1, 1, 10 + Depth)); for (int x = Mathf.FloorToInt(lowerLeft.x); x <= Mathf.CeilToInt(upperRight.x); x++) { for (int y = Mathf.FloorToInt(lowerLeft.y); y <= Mathf.CeilToInt(upperRight.y); y++) { int seed = SeedFromCoordinates(x, y); if (seedToBlock.ContainsKey(seed) == false) { seedToBlock[seed] = new StarBlock(x, y, seed, transform, this); } else { seedToBlock[seed].Tag(); } } } foreach (KeyValuePair <int, StarBlock> block in seedToBlock) { if (block.Value.tagged == false) { block.Value.Deactivate(this); seedToBlock.Remove(block.Key); } } }
// The event used for my starblocks. private void Empty(StarBlock sb) { isStarblock = false; sb.Destroyed -= Empty; if (sb != null) { CloseSwitch(sb); } }
void OnMouseDown() { // Get my mouse pos on screen with world coordinate using the origin. Ray mousePos = Camera.main.ScreenPointToRay(Input.mousePosition); // Check if the range to pickup blocks is ok if (Mathf.Abs(mousePos.origin.x - myPlayer.transform.position.x) <= myPlayer.playerRange && Mathf.Abs(mousePos.origin.y - myPlayer.transform.position.y) <= myPlayer.playerRange && mousePos.origin.y >= myPlayer.transform.position.y - 0.1f) { // Switch for door #1. if (name == switch1 && myPlayer.inventoryStarBlocks > 0) { OpenDoor(0); } // Switch for door #2. if (name == switch2 && myPlayer.inventoryStarBlocks > 0) { OpenDoor(1); } // Switch for the bridge. if (name == switch3 && myPlayer.inventoryStarBlocks > 0) { OpenBridge(0); } // Switch for door #3. if (name == switch4 && myPlayer.inventoryStarBlocks > 0) { OpenDoor(2); } // Switch for door #4. if (name == switch5 && myPlayer.inventoryStarBlocks > 0) { OpenDoor(3); } // MAKE SURE TO PLACE BEHAVIORS BEFORE DELETING THE BLOCK ! // Do I have any star blocks to place in my inventory? if (isStarblock == false && myPlayer.inventoryStarBlocks > 0) { StarBlock starBlock = (StarBlock)Instantiate(sbPrefab); starBlock.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z - 0.01f); // Start listening to my event. starBlock.Destroyed += Empty; isStarblock = true; // Make sure to take it out myPlayer.inventoryStarBlocks--; myPlayer.blockSource.PlayOneShot(myPlayer.block, myPlayer.SFXVolume); } } }
// When the player takes a star block out of a switch, this method is called to respawn the correct asset. private void CloseSwitch(StarBlock sb) { // Get all my switches and associate the correct ones to the right ones. GameObject[] switches = GameObject.FindGameObjectsWithTag("Switch"); // Had to use Epsilon in order to get through a bug where the platform was not closing. if (sb != null && switches != null) { if (sb.transform.position.x >= switches[0].transform.position.x - Mathf.Epsilon && sb.transform.position.x <= switches[0].transform.position.x + Mathf.Epsilon && sb.transform.position.y >= switches[0].transform.position.y - Mathf.Epsilon && sb.transform.position.y <= switches[0].transform.position.y + Mathf.Epsilon) { CloseDoor(0); } else if (sb.transform.position.x >= switches[1].transform.position.x - Mathf.Epsilon && sb.transform.position.x <= switches[1].transform.position.x + Mathf.Epsilon && sb.transform.position.y >= switches[1].transform.position.y - Mathf.Epsilon && sb.transform.position.y <= switches[1].transform.position.y + Mathf.Epsilon) { CloseDoor(1); } else if (sb.transform.position.x >= switches[2].transform.position.x - Mathf.Epsilon && sb.transform.position.x <= switches[2].transform.position.x + Mathf.Epsilon && sb.transform.position.y >= switches[2].transform.position.y - Mathf.Epsilon && sb.transform.position.y <= switches[2].transform.position.y + Mathf.Epsilon) { CloseBridge(0); } else if (sb.transform.position.x >= switches[3].transform.position.x - Mathf.Epsilon && sb.transform.position.x <= switches[3].transform.position.x + Mathf.Epsilon && sb.transform.position.y >= switches[3].transform.position.y - Mathf.Epsilon && sb.transform.position.y <= switches[3].transform.position.y + Mathf.Epsilon) { CloseDoor(2); } else if (sb.transform.position.x >= switches[4].transform.position.x - Mathf.Epsilon && sb.transform.position.x <= switches[4].transform.position.x + Mathf.Epsilon && sb.transform.position.y >= switches[4].transform.position.y - Mathf.Epsilon && sb.transform.position.y <= switches[4].transform.position.y + Mathf.Epsilon) { CloseDoor(3); } } }
public virtual void BuildLeftRecursiveRuleFunction(LeftRecursiveRule r, LeftRecursiveRuleFunction function) { BuildNormalRuleFunction(r, function); // now inject code to start alts AbstractTarget target = @delegate.GetTarget(); TemplateGroup codegenTemplates = target.GetTemplates(); // pick out alt(s) for primaries CodeBlockForOuterMostAlt outerAlt = (CodeBlockForOuterMostAlt)function.code[0]; IList <CodeBlockForAlt> primaryAltsCode = new List <CodeBlockForAlt>(); SrcOp primaryStuff = outerAlt.ops[0]; if (primaryStuff is Choice) { Choice primaryAltBlock = (Choice)primaryStuff; foreach (var alt in primaryAltBlock.alts) { primaryAltsCode.Add(alt); } } else { // just a single alt I guess; no block primaryAltsCode.Add((CodeBlockForAlt)primaryStuff); } // pick out alt(s) for op alts StarBlock opAltStarBlock = (StarBlock)outerAlt.ops[1]; CodeBlockForAlt altForOpAltBlock = opAltStarBlock.alts[0]; IList <CodeBlockForAlt> opAltsCode = new List <CodeBlockForAlt>(); SrcOp opStuff = altForOpAltBlock.ops[0]; if (opStuff is AltBlock) { AltBlock opAltBlock = (AltBlock)opStuff; foreach (var alt in opAltBlock.alts) { opAltsCode.Add(alt); } } else { // just a single alt I guess; no block opAltsCode.Add((CodeBlockForAlt)opStuff); } // Insert code in front of each primary alt to create specialized context if there was a label for (int i = 0; i < primaryAltsCode.Count; i++) { LeftRecursiveRuleAltInfo altInfo = r.recPrimaryAlts[i]; if (altInfo.altLabel == null) { continue; } Template altActionST = codegenTemplates.GetInstanceOf("recRuleReplaceContext"); altActionST.Add("ctxName", Utils.Capitalize(altInfo.altLabel)); AltLabelStructDecl ctx = null; if (altInfo.altLabel != null) { function.altLabelCtxs.TryGetValue(altInfo.altLabel, out ctx); } Action altAction = new Action(@delegate, ctx, altActionST); CodeBlockForAlt alt = primaryAltsCode[i]; alt.InsertOp(0, altAction); } // Insert code to set ctx.stop after primary block and before op * loop Template setStopTokenAST = codegenTemplates.GetInstanceOf("recRuleSetStopToken"); Action setStopTokenAction = new Action(@delegate, function.ruleCtx, setStopTokenAST); outerAlt.InsertOp(1, setStopTokenAction); // Insert code to set _prevctx at start of * loop Template setPrevCtx = codegenTemplates.GetInstanceOf("recRuleSetPrevCtx"); Action setPrevCtxAction = new Action(@delegate, function.ruleCtx, setPrevCtx); opAltStarBlock.AddIterationOp(setPrevCtxAction); // Insert code in front of each op alt to create specialized context if there was an alt label for (int i = 0; i < opAltsCode.Count; i++) { Template altActionST; LeftRecursiveRuleAltInfo altInfo = r.recOpAlts.GetElement(i); string templateName; if (altInfo.altLabel != null) { templateName = "recRuleLabeledAltStartAction"; altActionST = codegenTemplates.GetInstanceOf(templateName); altActionST.Add("currentAltLabel", altInfo.altLabel); } else { templateName = "recRuleAltStartAction"; altActionST = codegenTemplates.GetInstanceOf(templateName); altActionST.Add("ctxName", Utils.Capitalize(r.name)); } altActionST.Add("ruleName", r.name); // add label of any LR ref we deleted altActionST.Add("label", altInfo.leftRecursiveRuleRefLabel); if (altActionST.impl.FormalArguments.Any(x => x.Name == "isListLabel")) { altActionST.Add("isListLabel", altInfo.isListLabel); } else if (altInfo.isListLabel) { @delegate.GetGenerator().tool.errMgr.ToolError(ErrorType.CODE_TEMPLATE_ARG_ISSUE, templateName, "isListLabel"); } AltLabelStructDecl ctx = null; if (altInfo.altLabel != null) { function.altLabelCtxs.TryGetValue(altInfo.altLabel, out ctx); } Action altAction = new Action(@delegate, ctx, altActionST); CodeBlockForAlt alt = opAltsCode[i]; alt.InsertOp(0, altAction); } }