Esempio n. 1
0
        public static bool Create(SMScript script, string name, string code)
        {
            SMScript script2 = Program.SMRuntime.FindScript(name);

            //don't allow a script to kill itself
            if (script2 != null && script == script2)
                return false;

            Program.SMRuntime.DestroyScript(name);

            script = Program.SMRuntime.InitScript(name, typeof(Program));

            if (script == null) return false;

            if (!script.Compile(code))
            {
                script.Dispose();
                return false;
            }
            else script.Execute();

            if (ScriptLoaded != null)
                ScriptLoaded(script, EventArgs.Empty);

            return true;
        }
Esempio n. 2
0
    void Explode()
    {
        //Screenshake
        camera.GetComponent <FollowTarget>().TriggerShake();

        SMScript.PlaySound("explode");
        SMScript.PlaySound("song");
        //Change position
        transform.position = new Vector3(transform.position.x, transform.position.y - 1, 0);
        //Instantiate prefabs
        for (int i = 0; i < fragments.Length; i++)
        {
            int     x         = Random.Range(-5, 5);
            int     y         = Random.Range(-1, -10);
            Vector3 randomPos = new Vector3(transform.position.x + x, transform.position.y + y, 0);

            Instantiate(fragments[i], randomPos, Quaternion.identity);
        }

        camera.GetComponent <GameManager>().start        = true;
        player.GetComponent <PlayerController>().started = true;

        //Instantiate Leave Arrows

        //Delete door
        Destroy(this.gameObject);
    }
        public object OnPropertyGetter(SMScript script, string name)
        {
            if (name == "name")
                return Name;

            return null;
        }
Esempio n. 4
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         SMScript.PlaySound("explode");
         gm.GetComponent <GameManager>().ended = true;
         gm.GetComponent <FollowTarget>().TriggerShake();
     }
 }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (started)
        {
            colorChangeTimer -= Time.deltaTime;
            if (!jazz.isEmitting)
            {
                jazz.Play();
            }
        }
        speed = fastSpeed;
        //GET INPUT
        x   = Input.GetAxisRaw("Horizontal");
        y   = Input.GetAxisRaw("Vertical");
        dir = new Vector2(x, y);

        Vector3 mousePosition = Input.mousePosition;

        mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
        faceDir       = new Vector2(mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);
        transform.up  = -faceDir;



        if (colorChangeTimer <= 0)
        {
            ChangeColor();
            kazooChanger    += 1;
            colorChangeTimer = colorChangeCooldown;
        }


        sprRend.color = selectedColor;

        if (Input.GetMouseButton(0))
        {
            if (kazooTimer <= 0)
            {
                SMScript.PlaySound("" + kazooChanger);
                kazooTimer = kazooCD;
            }


            speed = slowSpeed;


            if (shootTimer <= 0)
            {
                Shoot();

                shootTimer = shootCoolDown;
            }
        }

        shootTimer -= Time.deltaTime;
        kazooTimer -= Time.deltaTime;
    }
Esempio n. 6
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.tag == "Player")
     {
         SMScript.PlaySound("coin");
         gm.GetComponent <GameManager>().money += 1;
         Destroy(this.gameObject);
     }
 }
Esempio n. 7
0
 public static bool Destroy(SMScript script, string name)
 {
     //don't allow a script to kill itself
     if (script.Name != name)
     {
         Program.SMRuntime.DestroyScript(name);
         return true;
     }
     return false;
 }
Esempio n. 8
0
File: Preview.cs Progetto: kebby/jss
        public void Dispose()
        {
            Stop();

            if (Script != null)
            {
                Script.Dispose();
                Script = null;
            }

            Runtime.Dispose();
        }
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        PlayLoopFromSource();
    }
Esempio n. 10
0
        public static bool Load(SMScript script, string name, string filename)
        {
            if (File.Exists(filename))
            {
                SMScript script2 = Program.SMRuntime.FindScript(name);

                //don't allow a script to kill itself
                if (script2 != null && script == script2)
                    return false;

                Program.SMRuntime.DestroyScript(name);

                script = Program.SMRuntime.InitScript(name, typeof(Program));

                if (script == null) return false;

                Stream stream = null;
                StreamReader reader = null;
                try
                {
                    stream = File.Open(filename, FileMode.Open, FileAccess.Read);
                    reader = new StreamReader(stream);

                    string code = reader.ReadToEnd();

                    if (!script.Compile(code))
                    {
                        script.Dispose();
                        return false;
                    }
                    else script.Execute();

                    if (ScriptLoaded != null)
                        ScriptLoaded(script, EventArgs.Empty);

                    return true;
                }
                catch { return false; }
                finally
                {
                    if (reader != null)
                        reader.Dispose();

                    else if (stream != null)
                        stream.Dispose();
                }
            }
            else return false;
        }
        public void Request(SMScript script, string url)
        {
            Uri uri = null;
            if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri))
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

                request.BeginGetResponse(
                    new AsyncCallback(RequestCallback),
                    new RequestState()
                    {
                        Script = script,
                        Request = request
                    });
            }
        }
Esempio n. 12
0
File: Preview.cs Progetto: kebby/jss
        public bool SetCode(string code)
        {
            Stop();
            Trace.WriteLine(code);
            var script = Runtime.InitScript("myScriptName.js", typeof(MyGlobalObject));

            if (script.Compile(code) && script.Execute())
            {
                Script = script;
                return true;
            }
            else
            {
                script.Dispose();
                return false;
            }
        }
Esempio n. 13
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "Note")
        {
            Color check = col.GetComponent <SpriteRenderer>().color;
            if (check == spr.color)
            {
                var projectile = Instantiate(moneyPrefab, this.transform);
                projectile.GetComponent <Rigidbody2D>().AddForce(Random.insideUnitSphere * 900f);

                projectile = Instantiate(moneyPrefab, this.transform);
                projectile.GetComponent <Rigidbody2D>().AddForce(Random.insideUnitSphere * 900f);

                projectile = Instantiate(moneyPrefab, this.transform);
                projectile.GetComponent <Rigidbody2D>().AddForce(Random.insideUnitSphere * 900f);

                SMScript.PlaySound("happy");
                happy.Play();
                gm.GetComponent <GameManager>().peopleHappy += 1;
                spr.color = Color.white;
            }
        }
    }
Esempio n. 14
0
    void ChangeColor()
    {
        SMScript.PlaySound("color");
        if (colors.Count != 0)
        {
            int r = Random.Range(0, colors.Count);

            if (selectedColor != colors[r])
            {
                selectedColor = colors[r];
                colors.Remove(colors[r]);
            }
            else if (r != 0)
            {
                selectedColor = colors[r - 1];
                colors.Remove(colors[r - 1]);
            }
            else
            {
                selectedColor = colors[r + 1];
                colors.Remove(colors[r + 1]);
            }
        }
    }
 public SpiderMonkeyJavascriptRuntime()
 {
     LockTimeout         = TimeSpan.FromSeconds(10);
     ScriptEngineContext = new SMRuntime();
     ScriptEngine        = ScriptEngineContext.InitScript(ScriptName);
 }
 public void OnPropertySetter(SMScript script, string name, object value)
 {
     if (name == "name")
         Name = (string)value;
 }
Esempio n. 17
0
 public static void Register(SMScript script, EventType @event, SMFunction method)
 {
     ScriptObj scriptObj = ScriptManager.Items.Find(script.Name);
     ServerEvents.RegisterEvent(scriptObj.ScriptName, @event, method);
 }