Exemple #1
0
        public static void DrawDefaultObject(Game _assets, LInstance _inst)
        {
            LValue _index = _inst.Variables["sprite_index"];
            LValue _image = _inst.Variables["image_index"];

            if (_index.I32 >= 0 && _index < _assets.SpriteMapping.Count)
            {
                LSprite _sprite = _assets.SpriteMapping[_index];
                double  _x      = _inst.Variables["x"];
                double  _y      = _inst.Variables["y"];
                GL.PushMatrix();
                GL.Translate(_x, _y, 0);
                GL.Rotate(_inst.Variables["image_angle"].Number, 0, 0, 1);
                GL.Enable(EnableCap.Texture2D);
                GL.BindTexture(TextureTarget.Texture2D, _assets.TextureEntries[_image].GLTexture);
                GL.Begin(PrimitiveType.TriangleStrip);
                byte[] _color = BitConverter.GetBytes((int)_inst.Variables["image_blend"].Number);
                GL.Color4(_color[2] / 255d, _color[1] / 255d, _color[0] / 255d, _inst.Variables["image_alpha"]);
                GL.TexCoord2(0.0, 0.0);
                GL.Vertex2(-_sprite.XOrigin, -_sprite.YOrigin);
                GL.TexCoord2(1.0, 0.0);
                GL.Vertex2(-_sprite.XOrigin + _sprite.Width, -_sprite.YOrigin);
                GL.TexCoord2(0.0, 1.0);
                GL.Vertex2(-_sprite.XOrigin, -_sprite.YOrigin + _sprite.Height);
                GL.TexCoord2(1.0, 1.0);
                GL.Vertex2(-_sprite.XOrigin + _sprite.Width, -_sprite.YOrigin + _sprite.Height);
                GL.End();
                GL.Disable(EnableCap.Texture2D);
                GL.PopMatrix();
            }
        }
Exemple #2
0
 public static LValue operator >=(LValue a, LValue b)
 {
     switch (a.Type)
     {
     case LType.Number: return(LValue.Real(a.Number >= b.Number ? 1 : 0));
     }
     throw new Exception(String.Format("Could not check if {0} (Type: {2}) is greater than or equal to {1} (Type: {3})", a.ToString(), b.ToString(), a.Type, b.Type));
 }
Exemple #3
0
 public static LValue operator /(LValue a, LValue b)
 {
     if (a.Type == LType.Number && b.Type == LType.Number)
     {
         return(LValue.Real(a.Number / b.Number));
     }
     throw new Exception(String.Format("Could not divide {0} (Type: {2}) by {1} (Type: {3})", a.ToString(), b.ToString(), a.Type, b.Type));
 }
Exemple #4
0
 public static LValue operator -(LValue a, LValue b)
 {
     if (a.Type == LType.Number && b.Type == LType.Number)
     {
         return(LValue.Real(a.Number - b.Number));
     }
     throw new Exception(String.Format("Could not subtract {0} (Type: {2}) from {1} (Type: {3})", a.ToString(), b.ToString(), a.Type, b.Type));
 }
Exemple #5
0
 public static bool GetBool(LValue a)
 {
     if (a.Type == LType.Number)
     {
         if (a.Number >= 0.5)
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #6
0
        public static LValue operator !=(LValue a, LValue b)
        {
            switch (a.Type)
            {
            case LType.Number: return(LValue.Real(Math.Abs(a.Number - b.Number) > 0.00001 ? 1 : 0));

            case LType.String: return(LValue.Real(a.String != b.String ? 1 : 0));

            case LType.Undefined: return(LValue.Bool(b.Type != LType.Undefined));
            }
            throw new Exception(String.Format("Could not check if {0} (Type: {2}) is not equal to {1} (Type: {3})", a.ToString(), b.ToString(), a.Type, b.Type));
        }
Exemple #7
0
 public static LValue operator +(LValue a, LValue b)
 {
     if (a.Type == LType.Number && a.Type == LType.Number)
     {
         return(LValue.Real(a.Number + b.Number));
     }
     else if (a.Type == LType.String && b.Type == LType.String)
     {
         return(LValue.Text(a.String + b.String));
     }
     throw new Exception(String.Format("Could not add {0} (Type: {2}) to {1} (Type: {3})", a.ToString(), b.ToString(), a.Type, b.Type));
 }
Exemple #8
0
        public static void LoadRoom(Game _assets, LRoom _room)
        {
            _assets.CurrentRoom = _room;
            LInstance[] _roomInstances = new LInstance[_room.Instances.Count];
            for (int i = 0; i < _room.Instances.Count; i++)
            {
                LRoomInstance _instGet    = _room.Instances[i];
                LInstance     _instCreate = new LInstance(_assets, _instGet.Index, true, _instGet.X, _instGet.Y);
                _instCreate.Variables["image_xscale"] = LValue.Real(_instGet.ScaleX);
                _instCreate.Variables["image_yscale"] = LValue.Real(_instGet.ScaleY);
                _instCreate.Variables["image_speed"]  = LValue.Real(_instGet.ImageSpeed);
                _instCreate.Variables["image_index"]  = LValue.Real(_instGet.ImageIndex);
                _instCreate.Variables["image_blend"]  = LValue.Real(_instGet.ImageBlend);
                _instCreate.Variables["image_angle"]  = LValue.Real(_instGet.Rotation);
                _instCreate.RoomPreCreate             = _instGet.PreCreate;
                _instCreate.RoomCreate = _instGet.CreationCode;
                _roomInstances[i]      = _instCreate;
            }

            for (int i = 0; i < _roomInstances.Length; i++)
            {
                LInstance _instGet = _roomInstances[i];
                if (_instGet.PreCreate != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.PreCreate);
                }
                if (_instGet.RoomPreCreate != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.RoomPreCreate);
                }
                if (_instGet.Create != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.Create);
                }
                if (_instGet.RoomCreate != null)
                {
                    _instGet.Environment.ExecuteCode(_assets, _instGet.RoomCreate);
                }
            }

            if (_room.CreationCode != null)
            {
                Domain _roomEnvironment = new LInstance(_assets, -100, false).Environment;
                _roomEnvironment.ExecuteCode(_assets, _room.CreationCode);
            }
        }
Exemple #9
0
 public static LValue Values(params Object[] _values)
 {
     LValue[] _vals = new LValue[_values.Length];
     for (int i = 0; i < _values.Length; i++)
     {
         object _val = _values[i];
         if (_val is String _str)
         {
             _vals[i] = Text(_str);
         }
         else if (_val is IConvertible _conv)
         {
             _vals[i] = Real(_conv.ToDouble(null));
         }
         else
         {
             _vals[i] = Real(0);   //failed to convert, change this to undefined when it's implemented
         }
     }
     return(Values(_vals));
 }
Exemple #10
0
        public override string ToString()
        {
            switch (this.Type)
            {
            case LType.Number: return(this.Number.ToString());

            case LType.String: return(this.String);

            case LType.Int32: return(this.I32.ToString());

            case LType.Int64: return(this.I64.ToString());

            case LType.Undefined: return("undefined");

            case LType.Array: {
                string _valReturn = "[ ";
                for (int i = 0; i < this.Array.Length; i++)
                {
                    LValue _valGet = this.Array[i];
                    if (_valGet.Type == LType.String)
                    {
                        _valReturn += '"';
                    }
                    _valReturn += _valGet.ToString();
                    if (_valGet.Type == LType.String)
                    {
                        _valReturn += '"';
                    }
                    if (i < this.Array.Length - 1)
                    {
                        _valReturn += ",";
                    }
                }
                return(_valReturn + " ]");
            }
            }
            throw new Exception(String.Format("Could not convert type \"{0}\" to string", this.Type));
        }
Exemple #11
0
 //Shorthand for Real 1
 public static LValue True()
 {
     return(LValue.Real(1));
 }
Exemple #12
0
 //Shorthand for Real 0
 public static LValue False()
 {
     return(LValue.Real(0));
 }