public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { switch (property) { case DmlTokens.INTRINSIC_DIRECTION: ((DmlBullet)bullet.Value).Direction = (Vector2)(stack.Pop().Value); break; case DmlTokens.INTRINSIC_SPEED: ((DmlBullet)bullet.Value).Speed = (double)(stack.Pop().Value); break; case DmlTokens.INTRINSIC_COLOUR: ((DmlBullet)bullet.Value).Colour = (Color)(stack.Pop().Value); break; case DmlTokens.INTRINSIC_SPRITE: string name = (string)(stack.Pop().Value); ((DmlBullet)bullet.Value).SetSprite(name.Substring(1, name.Length - 2)); break; default: throw new DmlSyntaxError(String.Format("Unknown intrinsic property \"{0}\"", property)); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var absolute = false; if (hasAbsolutePosition) { absolute = (bool)(stack.Pop().Value); } var duration = (double)(stack.Pop().Value); var endPos = (Vector2)(stack.Pop().Value); var b = (DmlBullet)bullet.Value; if (absolute) { b.Components.Add(new MoveToComponent(b.Position, endPos, endPos - b.Origin, b.LocalTime, duration)); } else { b.Components.Add(new MoveToComponent(Vector2.Zero, endPos, b.RelativePosition + endPos, b.LocalTime, duration)); } }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject amtObj = stack.Pop(); DmlObject endObj = stack.Pop(); DmlObject startObj = stack.Pop(); if (startObj.Type != DmlType.Vector) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, startObj.Type); } if (endObj.Type != DmlType.Vector) { throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Vector, endObj.Type); } if (amtObj.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, amtObj.Type); } double amt = (double)(amtObj.Value); Vector2 end = (Vector2)(endObj.Value); Vector2 start = (Vector2)(startObj.Value); return(new DmlObject(DmlType.Vector, Vector2.Lerp(start, end, (float)amt))); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type != DmlType.Vector) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, first.Type); } if (second.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, second.Type); } double angle = Math.PI / 180 * (double)(second.Value); Vector2 vec = (Vector2)(first.Value); float x = vec.X; float y = vec.Y; float cos = (float)Math.Cos(angle); float sin = (float)Math.Sin(angle); var newVec = new Vector2(x * cos - y * sin, x * sin + y * cos); newVec.Normalize(); // This avoids rounding errors that cause the bullets to eventually speed up. return(new DmlObject(DmlType.Vector, newVec)); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { switch (property) { case DmlTokens.INTRINSIC_DIRECTION: ((DmlBullet)bullet.Value).Direction = (Vector2)(stack.Pop().Value); break; case DmlTokens.INTRINSIC_SPEED: ((DmlBullet)bullet.Value).Speed = (double)(stack.Pop().Value); break; case DmlTokens.INTRINSIC_COLOUR: ((DmlBullet)bullet.Value).Colour = (Color)(stack.Pop().Value); break; case DmlTokens.INTRINSIC_SPRITE: string name = (string)(stack.Pop().Value); ((DmlBullet)bullet.Value).SetSprite(name.Substring(1, name.Length - 2)); break; default: throw new DmlSyntaxError(String.Format("Unknown intrinsic property \"{0}\"", property)); } }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); switch (top.Type) { case DmlType.Number: double p = (double)top.Value; double val = (int)p; if (val != Math.Floor(p)) { throw new DmlSyntaxError( "Invalid syntax; `Factorial` requires that argument one be an integer." ); } int factorial = 1; for (int i = 2; i < val; i++) { factorial *= i; } top.Value = val; return(top); default: throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { switch (property) { case DmlTokens.INTRINSIC_ORIGIN: stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Origin)); break; case DmlTokens.INTRINSIC_POSITION: stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Position)); break; case DmlTokens.INTRINSIC_DIRECTION: stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Direction)); break; case DmlTokens.INTRINSIC_SPEED: stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Speed)); break; case DmlTokens.INTRINSIC_COLOUR: stack.Push(new DmlObject(DmlType.Colour, ((DmlBullet)bullet.Value).Colour)); break; case DmlTokens.INTRINSIC_TIME: stack.Push(new DmlObject(DmlType.Number, ((DmlBullet)bullet.Value).LocalTime)); break; case DmlTokens.INTRINSIC_VELOCITY: DmlBullet b = (DmlBullet)bullet.Value; stack.Push(new DmlObject(DmlType.Vector, b.Direction * (float)b.Speed)); break; default: throw new DmlSyntaxError(String.Format("Unknown bullet property \"{0}\"", property)); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { system.GlobalVars.Add(name, stack.Pop()); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { ((DmlBullet)bullet.Value).Dead = true; }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { bullet.BoundVars[name] = stack.Pop(); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { bullet.BoundVars[name] = stack.Pop(); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { stack.Push(system.GlobalVars[name]); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { ((DmlBullet)bullet.Value).Dead = true; }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { system.GlobalVars.Add(name, stack.Pop()); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { stack.Push(system.GlobalVars[name]); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var paramNames = new string[paramCount]; var values = new DmlObject[paramCount]; DmlObject top; List<DmlObject> param; for (int i = 0; i < paramCount; i++) { top = stack.Pop(); param = (List<DmlObject>)top.Value; paramNames[i] = (string)(param[0].Value); values[i] = param[1]; } var currentAngle = 0d; if (hasAngleOffset) currentAngle = (double)(stack.Pop().Value); if (hasAngleOffsetD) currentAngle = Math.PI / 180 * (double)(stack.Pop().Value); var speed = (double)(stack.Pop().Value); var streams = (int)(double)(stack.Pop().Value); var factory = (DmlBulletFactory)(stack.Pop().Value); var oldBullet = (DmlBullet)(bullet.Value); var angleIncrement = 2*Math.PI/streams; DmlObject newBulletObj; DmlBullet newBullet; Vector2 direction; bool local = bullet != null; for (int i = 0; i < streams; i++) { newBulletObj = factory.Instantiate(oldBullet.Origin, system); newBullet = (DmlBullet)(newBulletObj.Value); direction = new Vector2((float)Math.Cos(currentAngle), (float)Math.Sin(currentAngle)); newBullet.Direction = direction; newBullet.Speed = speed; for (int j = 0; j < paramCount; j++) newBulletObj.SetVar(paramNames[j], values[j]); if (local) oldBullet.Children.Add(newBullet); system.AddBullet(newBullet); currentAngle += angleIncrement; } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value - (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Vector: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value - (Vector2)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Colour: Color c1 = (Color)first.Value; Color c2 = (Color)second.Value; stack.Push(new DmlObject(DmlType.Colour, new Color( c1.R - c2.R, c1.G - c2.G, c1.B - c2.B, c1.A - c2.A) )); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var b = (DmlBullet)(bullet.Value); b.Direction = GeometryUtils.RotateVector(b.Direction, (double)(stack.Pop().Value), degrees: degrees); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var local = bullet != null; DmlBullet parent = null; Vector2 origin = Vector2.Zero; if (local) { parent = (DmlBullet)(bullet.Value); origin = parent.Position; } if (hasOrigin) origin = (Vector2)(stack.Pop().Value); double angleMin = 0, angleMax = 2 * Math.PI, speedMin, speedMax; if (hasAngleRange) { var angleRange = (List<DmlObject>)(stack.Pop().Value); angleMin = (double)angleRange[0].Value; angleMax = (double)angleRange[1].Value; if (degrees) { angleMin *= Math.PI / 180; angleMax *= Math.PI / 180; } } var speedRange = (List<DmlObject>)(stack.Pop().Value); speedMin = (double)speedRange[0].Value; speedMax = (double)speedRange[1].Value; var count = (double)(stack.Pop().Value); var factory = (DmlBulletFactory)(stack.Pop().Value); double crntAngle, crntSpeed; Vector2 direction; DmlObject newObj; DmlBullet newBullet; for (int i = 0; i < count; i++) { crntAngle = (angleMax - angleMin) * Globals.randGen.NextDouble() + angleMin; crntSpeed = (speedMax - speedMin) * Globals.randGen.NextDouble() + speedMin; direction = new Vector2((float)Math.Cos(crntAngle), (float)Math.Sin(crntAngle)); newObj = factory.Instantiate(origin, system); newBullet = (DmlBullet)(newObj.Value); newBullet.Direction = direction; newBullet.Speed = crntSpeed; if (local) parent.Children.Add(newBullet); system.AddBullet(newBullet); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { if (!(bool)(stack.Pop().Value)) block.currentPosition = position; }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { switch (argCount) { case 1: DmlObject top = stack.Pop(); if (top.Type != DmlType.List) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type); } double low = Double.PositiveInfinity; try { double val; foreach (DmlObject v in (DmlObject[])top.Value) { val = (double)v.Value; if (val <= low) { low = val; } } } catch (InvalidCastException) { throw new DmlSyntaxError( "Invalid syntax; `Min` requires input array to be composed entirely of numbers." ); } return(new DmlObject(DmlType.Number, low)); case 2: DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type); } else if (second.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type); } return(new DmlObject( DmlType.Number, (double)first.Value < (double)second.Value ? first.Value : second.Value )); default: throw new DmlSyntaxError( "Invalid syntax; `Min` requires either 1 or 2 arguments." ); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); // Add the two objects together ya dingus! }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); // Add the two objects together ya dingus! }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var b = (DmlBullet)(bullet.Value); b.Direction = GeometryUtils.RotateVector(b.Direction, (double)(stack.Pop().Value), degrees: degrees); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { if (!(bool)(stack.Pop().Value)) { block.currentPosition = position; } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { double second = (double)(stack.Pop().Value); double first = (double)(stack.Pop().Value); if (first <= second) block.currentPosition = position; }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { var list = new List <DmlObject>(); for (int i = 0; i < argCount; i++) { list.Add(stack.Pop()); } list.Reverse(); // We have to reverse it since we pop the objects from the stack in reverse order. return(new DmlObject(DmlType.List, list)); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var duration = (double)(stack.Pop().Value); var endSpeed = (double)(stack.Pop().Value); var b = (DmlBullet)bullet.Value; b.Components.Add(new TransitionSpeedComponent(b.Speed, endSpeed, b.LocalTime, duration)); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var weight = (float)(double)(stack.Pop().Value); var direction = (Vector2)(stack.Pop().Value); var b = (DmlBullet)(bullet.Value); b.Direction += weight * direction / 100f; }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type); } double angle = Math.PI / 180 * (double)(top.Value); return(new DmlObject(DmlType.Vector, new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)))); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type == DmlType.Number) stack.Push(new DmlObject(DmlType.Number, Math.Abs((double)top.Value))); else throw DmlSyntaxError.BadUnaryOperandType("~", top.Type); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var weight = (float)(double)(stack.Pop().Value); var direction = (Vector2)(stack.Pop().Value); var b = (DmlBullet)(bullet.Value); b.Direction += weight * direction / 100f; }
public DmlObject Instantiate(Vector2 Position, DmlSystem system) { DmlBullet bullet = new DmlBullet(Position, this); DmlObject bulletObject = new DmlObject(DmlType.Bullet, bullet); bullet.SetObject(bulletObject); // Execute the initialziation code. Init.Execute(bulletObject, system); return(bulletObject); }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type != DmlType.Vector) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, top.Type); } Vector2 vec = (Vector2)(top.Value); return(new DmlObject(DmlType.Vector, new Vector2(-vec.Y, vec.X))); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type != DmlType.Number || second.Type != DmlType.Number) throw DmlSyntaxError.BadBinaryOperandTypes("<", first.Type, second.Type); stack.Push(new DmlObject(DmlType.Bool, (double)(first.Value) < (double)(second.Value))); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type != DmlType.Function) throw new DmlSyntaxError("Error: attempt to call uncallable object."); DmlFunction func = (DmlFunction)(top.Value); stack.Push(func.CallDynamic(argCount, stack, bullet, system)); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var duration = (double)(stack.Pop().Value); var endSpeed = (double)(stack.Pop().Value); var b = (DmlBullet)bullet.Value; b.Components.Add(new TransitionSpeedComponent(b.Speed, endSpeed, b.LocalTime, duration)); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value * (double)second.Value)); break; case DmlType.Vector: stack.Push(new DmlObject(DmlType.Vector, (float)(double)first.Value * (Vector2)second.Value)); break; case DmlType.Colour: stack.Push(new DmlObject(DmlType.Colour, (Color)second.Value * (float)(double)first.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value * (float)(double)second.Value)); break; case DmlType.Vector: stack.Push(new DmlObject(DmlType.Number, Vector2.Dot((Vector2)first.Value, (Vector2)second.Value))); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Colour, (Color)first.Value * (float)(double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type); } }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type != DmlType.Vector) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, top.Type); } Vector2 vec = (Vector2)(top.Value); return(new DmlObject(DmlType.Number, (double)Vector2.DistanceSquared(vec, Vector2.Zero))); }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject timeObj = stack.Pop(); if (timeObj.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, timeObj.Type); } double time = (double)(timeObj.Value); double ltime = system.GlobalTime; return(new DmlObject(DmlType.Bool, ltime >= time)); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type == DmlType.Number && second.Type == DmlType.Number) stack.Push(new DmlObject(DmlType.Number, (double)first.Value % (double)second.Value)); else throw DmlSyntaxError.BadBinaryOperandTypes("%", first.Type, second.Type); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value - (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Vector: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value - (Vector2)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Colour: Color c1 = (Color)first.Value; Color c2 = (Color)second.Value; stack.Push(new DmlObject(DmlType.Colour, new Color( c1.R - c2.R, c1.G - c2.G, c1.B - c2.B, c1.A - c2.A) )); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value / (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value / (float)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Colour, (Color)first.Value * (1 / (float)second.Value))); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("/", first.Type, second.Type); } }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject intervalObj; double start, end, interval, ltime; switch (argCount) { case 1: intervalObj = stack.Pop(); if (intervalObj.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, intervalObj.Type); } interval = (double)(stack.Pop().Value); ltime = system.GlobalTime; return(new DmlObject(DmlType.Bool, (ltime % (2 * interval)) < interval)); case 3: DmlObject endObj = stack.Pop(); DmlObject startObj = stack.Pop(); intervalObj = stack.Pop(); if (intervalObj.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, intervalObj.Type); } if (startObj.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, startObj.Type); } if (endObj.Type != DmlType.Number) { throw DmlSyntaxError.BadArgumentType(Name, 3, DmlType.Number, endObj.Type); } end = (double)(stack.Pop().Value); start = (double)(stack.Pop().Value); interval = (double)(stack.Pop().Value); ltime = system.GlobalTime; double t2 = ltime - start; return(new DmlObject(DmlType.Bool, (t2 >= 0 && ltime <= end) && (t2 % (2 * interval)) < interval)); default: return(null); // Should never get here. } }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); switch (top.Type) { case DmlType.Number: top.Value = Math.Exp((double)top.Value); return(top); default: throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type); } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { double second = (double)(stack.Pop().Value); double first = (double)(stack.Pop().Value); if (first <= second) { block.currentPosition = position; } }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type != DmlType.Number || second.Type != DmlType.Number) { throw DmlSyntaxError.BadBinaryOperandTypes("<", first.Type, second.Type); } stack.Push(new DmlObject(DmlType.Bool, (double)(first.Value) < (double)(second.Value))); }
public void Perform( CodeBlock block, Stack <DmlObject> stack, Dictionary <string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject top = stack.Pop(); if (top.Type != DmlType.Function) { throw new DmlSyntaxError("Error: attempt to call uncallable object."); } DmlFunction func = (DmlFunction)(top.Value); stack.Push(func.CallDynamic(argCount, stack, bullet, system)); }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { double leeway = 0; if (hasLeeway) leeway = (double)(stack.Pop().Value); DmlBullet b = (DmlBullet)(bullet.Value); double x = b.Position.X; double y = b.Position.Y; if (-leeway <= x && x <= max_x + leeway && -leeway <= y && y <= max_y + leeway) return; b.Dead = true; }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var absolute = false; if (hasAbsolutePosition) absolute = (bool)(stack.Pop().Value); var duration = (double)(stack.Pop().Value); var endPos = (Vector2)(stack.Pop().Value); var b = (DmlBullet)bullet.Value; if (absolute) b.Components.Add(new MoveToComponent(b.Position, endPos, endPos - b.Origin, b.LocalTime, duration)); else b.Components.Add(new MoveToComponent(Vector2.Zero, endPos, b.RelativePosition + endPos, b.LocalTime, duration)); }
public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system) { DmlObject top; string msg = ""; for (int i = 0; i < argCount; i++) { top = stack.Pop(); msg += top.Value.ToString(); if (i != argCount - 1) { msg += " "; } } Console.WriteLine(msg); return(null); }
private void Spawn( Vector2 origin, Vector2 direction, List<DmlObject> speeds, string[] paramNames, DmlObject[] values, DmlBullet parent, DmlBulletFactory factory, DmlSystem system) { bool local = parent != null; double speed; DmlObject newObj; DmlBullet newBullet; foreach (DmlObject s in speeds) { speed = (double)(s.Value); newObj = factory.Instantiate(origin, system); newBullet = (DmlBullet)(newObj.Value); newBullet.Direction = direction; newBullet.Speed = speed; for (int i = 0; i < paramCount; i++) newObj.SetVar(paramNames[i], values[i]); if (local) parent.Children.Add(newBullet); system.AddBullet(newBullet); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { DmlObject second = stack.Pop(); DmlObject first = stack.Pop(); if (first.Type == DmlType.String) stack.Push(new DmlObject(DmlType.String, (string)first.Value + second.Value.ToString())); else if (first.Type == DmlType.List) { var old = (DmlObject[])first.Value; var @new = new DmlObject[old.Length + 1]; @new[old.Length] = second; for (int i = 0; i <= old.Length; i++) { @new[i] = old[i]; } stack.Push(new DmlObject(DmlType.List, @new)); } else if (second.Type == DmlType.String) stack.Push(new DmlObject(DmlType.String, first.Value.ToString() + (string)second.Value)); else if (second.Type == DmlType.List) { var old = (DmlObject[])second.Value; var @new = new DmlObject[old.Length + 1]; @new[0] = first; for (int i = 0; i <= old.Length; i++) { @new[i + 1] = old[i]; } stack.Push(new DmlObject(DmlType.List, @new)); } else { switch (first.Type) { case DmlType.Number: switch (second.Type) { case DmlType.Number: stack.Push(new DmlObject(DmlType.Number, (double)first.Value + (double)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } break; case DmlType.Vector: switch (second.Type) { case DmlType.Vector: stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value + (Vector2)second.Value)); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } break; case DmlType.Colour: switch (second.Type) { case DmlType.Colour: Color c1 = (Color)first.Value; Color c2 = (Color)second.Value; stack.Push(new DmlObject(DmlType.Colour, new Color( c1.R + c2.R, c1.G + c2.G, c1.B + c2.B, c1.A + c2.A) )); break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } break; default: throw DmlSyntaxError.BadBinaryOperandTypes("+", first.Type, second.Type); } } }
private void Spawn( Vector2 origin, Vector2 direction, double speed, string[] paramNames, DmlObject[] values, DmlBullet parent, DmlBulletFactory factory, DmlSystem system) { DmlObject newObj = factory.Instantiate(origin, system); DmlBullet newBullet = (DmlBullet)newObj.Value; newBullet.Direction = direction; newBullet.Speed = speed; for (int i = 0; i < paramCount; i++) newObj.SetVar(paramNames[i], values[i]); if (parent != null) parent.Children.Add(newBullet); system.AddBullet(newBullet); }
private void Spawn( List<DmlObject> origins, List<DmlObject> directions, List<DmlObject> speeds, string[] paramNames, DmlObject[] values, DmlBullet parent, DmlBulletFactory factory, DmlSystem system) { if (origins.Count != directions.Count || origins.Count != speeds.Count || directions.Count != speeds.Count) throw new BehaviourException("Origins, Directions and Speeds must all have the same number of elements."); bool local = parent != null; Vector2 origin, direction; double speed; DmlObject newObj; DmlBullet newBullet; for (int i = 0; i < origins.Count; i++) { origin = (Vector2)(origins[i].Value); direction = (Vector2)(directions[i].Value); speed = (double)(speeds[i].Value); newObj = factory.Instantiate(origin, system); newBullet = (DmlBullet)(newObj.Value); newBullet.Direction = direction; newBullet.Speed = speed; for (int j = 0; j < paramCount; j++) newObj.SetVar(paramNames[j], values[j]); if (local) parent.Children.Add(newBullet); system.AddBullet(newBullet); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { var paramNames = new string[paramCount]; var values = new DmlObject[paramCount]; DmlObject top; List<DmlObject> param; for (int i = 0; i < paramCount; i++) { top = stack.Pop(); param = (List<DmlObject>)top.Value; paramNames[i] = (string)(param[0].Value); values[i] = param[1]; } DmlObject originObj = null, directionObj = null, speedObj = null; if (speedParam != ParamState.None) speedObj = stack.Pop(); if (directionParam != ParamState.None) directionObj = stack.Pop(); if (originParam != ParamState.None) originObj = stack.Pop(); var factory = (DmlBulletFactory)(stack.Pop().Value); if (multi) { Vector2? origin = null, direction = null; double speed = 0; List<DmlObject> origins = null, directions = null, speeds = null; if (originParam == ParamState.None) origin = ((DmlBullet)bullet.Value).Position; else if (originParam == ParamState.Single) origin = (Vector2)(originObj.Value); else origins = (List<DmlObject>)(originObj.Value); if (directionParam == ParamState.None) direction = new Vector2(0, 1); else if (directionParam == ParamState.Single) direction = (Vector2)(directionObj.Value); else directions = (List<DmlObject>)(directionObj.Value); if (speedParam == ParamState.None) speed = 0; else if (speedParam == ParamState.Single) speed = (double)(speedObj.Value); else speeds = (List<DmlObject>)(speedObj.Value); DmlBullet parent = null; if (bullet != null) parent = (DmlBullet)(bullet.Value); if (origins == null) { if (directions == null) { if (speeds == null) Spawn(origin.Value, direction.Value, speed, paramNames, values, parent, factory, system); else Spawn(origin.Value, direction.Value, speeds, paramNames, values, parent, factory, system); } else { if (speeds == null) Spawn(origin.Value, directions, speed, paramNames, values, parent, factory, system); else Spawn(origin.Value, directions, speeds, paramNames, values, parent, factory, system); } } else { if (directions == null) { if (speeds == null) Spawn(origins, direction.Value, speed, paramNames, values, parent, factory, system); else Spawn(origins, direction.Value, speeds, paramNames, values, parent, factory, system); } else { if (speeds == null) Spawn(origins, directions, speed, paramNames, values, parent, factory, system); else Spawn(origins, directions, speeds, paramNames, values, parent, factory, system); } } } else { Vector2 origin; if (originParam == ParamState.None) origin = ((DmlBullet)bullet.Value).Origin; else origin = (Vector2)(originObj.Value); DmlObject newObj = factory.Instantiate(origin, system); DmlBullet newBullet = (DmlBullet)newObj.Value; if (directionParam != ParamState.None) newBullet.Direction = (Vector2)(directionObj.Value); if (speedParam != ParamState.None) newBullet.Speed = (double)(speedObj.Value); for (int i = 0; i < paramCount; i++) newObj.SetVar(paramNames[i], values[i]); if (bullet != null) // We have to check if bullet is null because Spawn is one of the few behaviours // that can be used in a Timeline. When the Timeline's code is executed, `null` // is sent in for `bullet`. ((DmlBullet)bullet.Value).Children.Add(newBullet); } }
public void Perform( CodeBlock block, Stack<DmlObject> stack, Dictionary<string, DmlObject> locals, DmlObject bullet, DmlSystem system) { string[] paramNames = new string[paramCount]; DmlObject[] values = new DmlObject[paramCount]; DmlObject top; List<DmlObject> param; for (int i = 0; i < paramCount; i++) { top = stack.Pop(); param = (List<DmlObject>)top.Value; paramNames[i] = (string)(param[0].Value); values[i] = param[1]; } var speed = 0d; var direction = new Vector2(0, 1); Vector2 origin; if (hasSpeed) speed = (double)(stack.Pop().Value); switch (this.direction) { case DirectionType.Direction: direction = (Vector2)(stack.Pop().Value); direction.Normalize(); break; case DirectionType.Angle: double angle = (double)(stack.Pop().Value); direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)); break; default: break; } if (hasOrigin) origin = (Vector2)(stack.Pop().Value); else origin = ((DmlBullet)bullet.Value).Position; var type = (DmlBulletFactory)(stack.Pop().Value); DmlObject newObj = type.Instantiate(origin, system); DmlBullet newBullet = (DmlBullet)newObj.Value; if (this.direction != DirectionType.None) newBullet.Direction = direction; if (hasSpeed) newBullet.Speed = speed; for (int i = 0; i < paramCount; i++) newObj.SetVar(paramNames[i], values[i]); if (bullet != null) // We have to check if bullet is null because Spawn is one of the few behaviours // that can be used in a Timeline. When the Timeline's code is executed, `null` // is sent in for `bullet`. ((DmlBullet)bullet.Value).Children.Add(newBullet); system.AddBullet(newBullet); }
public LoadConstant(DmlObject constant) { this.constant = constant; }