상속: MonoBehaviour
예제 #1
0
    private void SpawnLotsOfCubes(ref world _w, int _spawnCount)
    {
        int   dimSizeX = (int)Mathf.Floor(Mathf.Sqrt(_spawnCount));
        int   dimSizeY = dimSizeX;
        float paddingX = .5f;
        float paddingY = .5f;
        int   boxIndex = 0;

        for (int y = 0; y < dimSizeY; ++y)
        {
            for (int x = 0; x < dimSizeX; ++x)
            {
                entity curr = CreateCubePrimative(new float3(x + paddingX, 0, y + paddingY));
                GameWorld.AddEntity(ref _w, ref curr);
                paddingX += .25f;
                positions[boxIndex++] = new Vector4(curr.position.x, curr.position.y, curr.position.z, 1);
            }
            paddingY += .25f;
            paddingX  = .5f;
        }
        positionBuffer.SetData(positions);
        material.SetBuffer("positionBuffer", positionBuffer);
        if (boxMesh != null)
        {
            args[0] = (uint)boxMesh.GetIndexCount(0);
            args[1] = (uint)gameWorld.entityCount;
            args[2] = (uint)boxMesh.GetIndexStart(0);
            args[3] = (uint)boxMesh.GetBaseVertex(0);
        }
        else
        {
            args[0] = args[1] = args[2] = args[3] = 0;
        }
        argsBuffer.SetData(args);
    }
예제 #2
0
        public void TestProjectileMethod()
        {
            world world1 = new world();

            projectile p = new projectile(0, new Vector2D(0, 0), new Vector2D(0, 0), true, 1);
            star       s = new star(0, new Vector2D(0, 0), 1);

            world1.addStar(s);
            String     A  = p.ToString();
            projectile s1 = JsonConvert.DeserializeObject <projectile>(A);

            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            world1.update();
            Assert.AreEqual(p.getID(), 0);
            Assert.AreEqual(new Vector2D(0, 0), p.getloc());
            Assert.AreEqual(new Vector2D(0, 0), p.getdir());
            Assert.AreEqual(p.checkAlive(), true);
            Assert.AreEqual(p.getOwner(), 1);
            p = new projectile(0, new Vector2D(0, 0), new Vector2D(0, 0), true, 1);
            p.update(750, world1.getStar().Values);
            p.die();

            projectile p1 = new projectile(1, new Vector2D(0, 376), new Vector2D(0, 0), true, 2);

            p1.update(750, world1.getStar().Values);
        }
예제 #3
0
        static int Main()
        {
            allegro_init();

            install_keyboard();
            install_timer();

            //srand(time(NULL));
            LOCK_VARIABLE(counter);
            LOCK_FUNCTION(t_my_timer_handler);

            if (set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0) != 0)
            {
                set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
                allegro_message(string.Format("Error setting graphics mode\n{0}\n", allegro_error));
                return(1);
            }

            world game = new world();  /* America! America! */

            game.loop();
            //delete game;

            return(0);
        }
예제 #4
0
    private void Start()
    {
        string fileName = Path.Combine(Application.streamingAssetsPath, objFile);

        if (!File.Exists(fileName))
        {
            Debug.LogError("FILE COULD NOT BE FOUND!");
            return;
        }

        string objData = File.ReadAllText(fileName);
        int    objLen  = (int)(objData.Split('o').Length * 1.2f);

        debugMeshes = new List <Mesh>(objLen);
        gameWorld   = new world(objLen);
        MeshHelpers.CreateMeshesFromEpa(objData);
        Raycast.InitRaycastData(ref gameWorld);

        //Generate Ground plane.
        bounds ground = new bounds();

        ground.minPoints = new float3(-1000, -.1f, -1000);
        ground.maxPoints = new float3(1000, .1f, 1000);

        groundMesh = MeshHelpers.MakeCubeFromBounds(ground);
        groundMesh.RecalculateBounds();
        entity groundEntity = new entity();

        groundEntity.bounds.minPoints = groundMesh.bounds.min;
        groundEntity.bounds.maxPoints = groundMesh.bounds.max;
        groundEntity.name             = "Ground";
        GameWorld.AddEntity(ref gameWorld, ref groundEntity);
    }
예제 #5
0
        /// <summary>
        /// there are four steps for the server
        /// (1) read xml to get necessary information
        /// (2)initalize a new world and add info to the new world
        /// (3)uisng serverawaitClientloop to awit client join in
        /// (4)using update method to send update info to the client
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            xmlRead();
            watch = new Stopwatch();
            list  = new LinkedList <SocketState>();
            watch.Start();
            liveStar = new Stopwatch();
            liveStar.Start();
            theworld = new world();
            sta.setLoc(new Vector2D(200, -200));
            star ss = new star(1, new Vector2D(200, 200), 0.01);

            theworld.addStar(sta);
            theworld.addStar(ss);
            theworld.setSize(UniverSize);
            theworld.setRespawn(RespawnRate);
            theworld.setFrame(MSperFrame);
            NController.ServerAwaitClientLoop(HandleNewClient);
            Console.WriteLine("our server start, and client could join in now");
            //create a new thread to update the world and send the updated info to the client
            Task task = new Task(() =>
            {
                while (true)
                {
                    update();
                }
            });

            task.Start();
            Console.Read();
        }
예제 #6
0
 public static bool AddEntity(ref world _w, ref entity _e)
 {
     if (_w.entityCount - 1 == _w.maxEntities)
     {
         _w.maxEntities *= 2;
     }
     _w.entities.Add(_e);
     ++_w.entityCount;
     return(true);
 }
예제 #7
0
    public void setupWorld()
    {
        firstWorld = new world();
        firstWorld.setupWorld(this.worldWidth, this.worldHeight);

        tileController = GameObject.FindGameObjectWithTag("tileSpriteController").GetComponent <tileSpriteController>();
        charController = GameObject.FindGameObjectWithTag("characterController").GetComponent <characterController>();
        WOcontroller   = GameObject.FindGameObjectWithTag("WOspriteController").GetComponent <WOspriteController>();

        generateWorld();

        Debug.Log("World is setup");
    }
예제 #8
0
        static void Main(string[] args)
        {
            world w = new world();

            w.airResistance = 0.5f;
            world y = w;

            y.airResistance = 0.4f;

            float weight = w.getWeight(3.4f);

            Console.WriteLine(y.airResistance);
            Console.WriteLine(w.airResistance);
        }
예제 #9
0
    public static tile placeInstance(tile proto, Vector2 pos, world parWorld)
    {
        tile t = parWorld.getTileAt((int)pos.x, (int)pos.y);

        t.tileType    = proto.tileType;
        t.baseType    = proto.baseType;
        t.parentWorld = parWorld;
        t.position    = pos;

        if (t.onSetCB != null)
        {
            t.onSetCB(t);             // calls the callback
        }
        return(t);
    }
예제 #10
0
        public void TestStarMethod()
        {
            world world1 = new world();
            star  s      = new star(0, new Vector2D(200, 200), 1);

            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            world1.update();
            s.update(51);
            s.update(102);
            s.update(160);
            s.update(230);
        }
예제 #11
0
        public void TestShipMethod()
        {
            world world1 = new world();
            star  s      = new star(0, new Vector2D(200, 200), 1);

            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            Ship ship = world1.generateShip("ship");

            ship.hpdecrease();
            Assert.AreEqual(ship.getHp(), 4);
            ship.getDeath();
            Assert.AreEqual(ship.getDeath(), 0);
        }
예제 #12
0
        public void TestStar1Method()
        {
            world world1 = new world();
            star  s      = new star(0, new Vector2D(0, -200), 1);

            s.setLoc(new Vector2D(0, 0));
            Assert.AreEqual(new Vector2D(0, 0), s.getloc());
            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            world1.update();
            s.update(51);
            s.update(102);
            s.update(160);
            s.update(230);
        }
예제 #13
0
        public void TestStar2Method()
        {
            world  world1 = new world();
            star   s      = new star(0, new Vector2D(0, 200), 1);
            String A      = s.ToString();
            star   s1     = JsonConvert.DeserializeObject <star>(A);

            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            world1.update();
            s.update(51);
            s.update(102);
            s.update(160);
            s.update(230);
        }
예제 #14
0
    public void writeNewUser()
    {
        User   user = new User("user1", "*****@*****.**");
        string json = JsonUtility.ToJson(user);

        Avatar avatar = new Avatar("1", "2", "1");
        string json2  = JsonUtility.ToJson(avatar);

        world  world = new world("000", "000", "000", "000");
        string json3 = JsonUtility.ToJson(world);

        mDatabaseRef.Child("users").Child("abcdefghi").SetRawJsonValueAsync(json);
        mDatabaseRef.Child("users").Child("abcdefghi").Child("avatar").SetRawJsonValueAsync(json2);
        mDatabaseRef.Child("users").Child("abcdefghi").Child("universe").Child("world1").SetRawJsonValueAsync(json3);
        mDatabaseRef.Child("users").Child("abcdefghi").Child("universe").Child("world2").SetRawJsonValueAsync(json3);
        mDatabaseRef.Child("users").Child("abcdefghi").Child("universe").Child("world3").SetRawJsonValueAsync(json3);
        mDatabaseRef.Child("users").Child("abcdefghi").Child("universe").Child("world4").SetRawJsonValueAsync(json3);
    }
예제 #15
0
    private void Start()
    {
        mainCam   = Camera.main;
        gameWorld = new world(30000);

        positions      = new Vector4[gameWorld.maxEntities];
        positionBuffer = new ComputeBuffer(gameWorld.maxEntities, 16);
        argsBuffer     = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);
#if true
        SpawnLotsOfCubes(ref gameWorld, gameWorld.maxEntities);

        float3 start = new float3(50, 0, -50);
        System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
        raycast_result hitResult;
        Raycast.RaycastJob(ref gameWorld, new float3(50, 0, -50), forward, 10000, out hitResult);

        sw.Stop();
        Debug.Log($"Raycast took {sw.ElapsedMilliseconds}ms");
#endif

#if false
        SpawnLotsOfGameObjects(gameWorld.maxEntities);
        System.Diagnostics.Stopwatch sw2 = System.Diagnostics.Stopwatch.StartNew();
        Physics.Raycast(new Vector3(50, 0, -5), Vector3.forward, 10000);
        sw2.Stop();
        Debug.Log($"Unity Raycast took {sw2.ElapsedMilliseconds}ms");
#endif

#if true
        RayCastAlongSphere(ref gameWorld, new float3(0, 0, 0), 20f);
#endif
#if false
        BoundsTests(ref test);
#endif

#if false
        float3CreationTests();
#endif
#if false
        ProjectionTests();
#endif
    }
예제 #16
0
    private static void RayCastAlongSphere(ref world _w, float3 _origin, float _radius)
    {
        System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
        float          diameter         = _radius * 2;
        float          yStep            = _radius / 25;
        float          cStep            = 360 / 25;
        raycast_result hitResult;
        int            count = 0;

        for (float y = -_radius;
             y <= _radius;
             y += yStep)
        {
            float absY  = Mathf.Abs(y);
            float ratio = (_radius - absY);
            for (float c = 0;
                 c < 360;
                 c += cStep)
            {
                float  x     = Mathf.Sin(c) * ratio;
                float  z     = Mathf.Cos(c) * ratio;
                float3 start = new float3(x, y, z);
                start = Math.Float3Normalize(start);
                start = start * _radius;
                float3 dir = Math.Float3Normalize(new float3(0, 0, 0) - start);
                if (Raycast.RaycastJob(ref _w, start, dir, _radius, out hitResult))
                {
                    raycast_result result2;
                    float3         newStart = start + Math.Float3FromDirAndMag(start, dir * 1, _radius * 2);
                    //newStart = float3Addfloat3(hitResult.hitPos, float3FromDirAndMag(hitResult.hitPos, dir, 1));
                    if (Raycast.RaycastJob(ref _w, newStart, dir * 1, _radius * 2, out result2))
                    {
                        Debug.DrawLine(hitResult.hitPos, result2.hitPos, Color.green, Mathf.Infinity);
                    }
                    count++;
                }
                count++;
            }
        }
        sw.Stop();
        Debug.Log($"ElapsedTime: {sw.ElapsedMilliseconds}ms for {count} raycasts");
    }
예제 #17
0
        public void TestWorldMethod()
        {
            world      world1 = new world();
            star       s      = new star(0, new Vector2D(0, 200), 1);
            projectile p1     = new projectile(1, new Vector2D(0, 376), new Vector2D(0, 0), true, 2);
            Ship       ship   = new Ship(1, new Vector2D(0, 0), new Vector2D(0, 0), false, "s", 5, 0);
            String     A      = s.ToString();
            star       s1     = JsonConvert.DeserializeObject <star>(A);

            world1.addStar(s);
            world1.setFrame(0);
            world1.addShip(ship);
            world1.Fire(1);

            world1.addproj(p1);
            world1.setRespawn(300);
            world1.setSize(750);

            Assert.AreEqual(world1.getProj().Values.Count, 1);
            Assert.AreEqual(world1.getShip().Values.Count, 1);
            Assert.AreEqual(world1.getStar().Values.Count, 1);
            ship = new Ship(1, new Vector2D(0, 0), new Vector2D(0, 0), true, "s", 5, 0);
            for (int i = 0; i <= 4; i++)
            {
                world1.getShip()[1].hpdecrease();
            }
            world1.respawn(ship);
            world1.addLostID(1);
            world1.cleanup();
            world1.removeProjectile(p1);
            world1.removeStar(s);
            world1.removeShip(ship);
            Assert.AreEqual(world1.getShip().Values.Count, 0);
            Assert.AreEqual(world1.getShip().Values.Count, 0);
            Assert.AreEqual(world1.getStar().Values.Count, 0);
            world1.update();
            s.update(51);
            s.update(102);
            s.update(160);
            s.update(230);
        }
예제 #18
0
        public void TestShipMethod1()
        {
            world world1 = new world();
            star  s      = new star(0, new Vector2D(200, 200), 1);

            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            Ship ship = world1.generateShip("ship");

            ship.hpdecrease();
            //    Assert.AreEqual(ship.getHp(), 4);
            ship.getDeath();
            //  Assert.AreEqual(ship.getDeath(), 0);

            Assert.AreEqual(ship.getName(), "ship");
            Assert.AreEqual(ship.getScore(), 0);
            Assert.AreEqual(ship.checkFire(10, 15), false);
            Assert.AreEqual(ship.checkFire(16, 15), true);
        }
예제 #19
0
        public void TestShipMethod3()
        {
            world world1 = new world();
            star  s      = new star(0, new Vector2D(200, 200), 1);

            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            Ship ship = world1.generateShip("ship");

            ship.hpdecrease();
            //    Assert.AreEqual(ship.getHp(), 4);
            ship.getDeath();
            //  Assert.AreEqual(ship.getDeath(), 0);

            Assert.AreEqual(ship.getName(), "ship");
            Assert.AreEqual(ship.getScore(), 0);
            Assert.AreEqual(ship.checkFire(10, 15), false);
            Assert.AreEqual(ship.checkFire(16, 15), true);
            Assert.AreEqual(ship.getThrust(), false);
            Assert.AreEqual(ship.getID(), 1);
            for (int i = 0; i <= 4; i++)
            {
                ship.hpdecrease();
            }
            Assert.AreEqual(ship.checkFire(16, 1), false);


            ship.doOperate('L');
            ship.doOperate('R');
            ship.refresh();
            ship.doOperate('T');
            ship.refresh();
            ship.getdir();
            ship.increaseScore();
            Assert.AreEqual(ship.getScore(), 1);
            ship.respawn();
            world1.update();
        }
예제 #20
0
        public void TestworldMethod1()
        {
            world      world1 = new world();
            star       s      = new star(0, new Vector2D(0, -200), 1);
            Ship       ship   = new Ship(1, new Vector2D(0, 0), new Vector2D(0, 0), false, "s", 5, 0);
            projectile p1     = new projectile(1, new Vector2D(0, 10), new Vector2D(0, 0), true, 2);

            world1.addproj(p1);
            world1.addShip(ship);

            s.setLoc(new Vector2D(0, 0));
            Assert.AreEqual(new Vector2D(0, 0), s.getloc());
            world1.addStar(s);
            world1.setFrame(50);
            world1.setRespawn(300);
            world1.setSize(750);
            world1.update();
            s.update(51);
            s.update(102);
            s.update(160);
            s.update(230);
        }
예제 #21
0
    public void writeNewUser(string userid, string useremail)
    {
        StaticVariable.UserProfile.userid = userid;
        StaticVariable.UserProfile.email  = useremail;

        Debug.Log("New user created");


        string[] myusername = useremail.Split('@');

        Debug.Log(myusername[0] + useremail);
        User   user = new User(myusername[0], useremail);
        string json = JsonUtility.ToJson(user);

        Avatar avatar = new Avatar("0", "0", "0");

        StaticVariable.UserProfile.avatar = avatar;
        string json2 = JsonUtility.ToJson(avatar);


        world    world    = new world("000", "000", "000", "000");
        Universe universe = new Universe();

        universe.world1 = world;
        universe.world2 = world;
        universe.world3 = world;
        universe.world4 = world;
        StaticVariable.UserProfile.universe = universe;
        string json3 = JsonUtility.ToJson(world);


        mDatabaseRef.Child("users").Child(userid).SetRawJsonValueAsync(json);
        mDatabaseRef.Child("users").Child(userid).Child("avatar").SetRawJsonValueAsync(json2);
        mDatabaseRef.Child("users").Child(userid).Child("universe").Child("world1").SetRawJsonValueAsync(json3);
        mDatabaseRef.Child("users").Child(userid).Child("universe").Child("world2").SetRawJsonValueAsync(json3);
        mDatabaseRef.Child("users").Child(userid).Child("universe").Child("world3").SetRawJsonValueAsync(json3);
        mDatabaseRef.Child("users").Child(userid).Child("universe").Child("world4").SetRawJsonValueAsync(json3);
    }
예제 #22
0
 internal void staticWorldSetupMethod(world gameObject)
 {
     World = gameObject;
     World.customer_count++;
 }
예제 #23
0
    void ParseObj(string _obj)
    {
        string[] lines = _obj.Split(new string[] { System.Environment.NewLine, "\n" }, System.StringSplitOptions.RemoveEmptyEntries);

        entity         curr         = new entity();
        Mesh           currMesh     = new Mesh();
        List <Vector3> verts        = new List <Vector3>();
        List <int>     triangles    = new List <int>();
        List <entity>  entities     = new List <entity>();
        bool           first        = true;
        int            vertexOffset = 0;
        int            count        = 0;

        foreach (string line in lines)
        {
            char function = line[0];
            //New object coming in!!!
            if (function == 'o')
            {
                count++;
                if (!first)
                {
                    curr.position.x /= verts.Count;
                    curr.position.z /= verts.Count;

                    for (int i = 0; i < verts.Count; ++i)
                    {
                        Vector3 newPos = verts[i];
                        newPos.x -= curr.position.x;
                        newPos.y -= curr.position.y;
                        newPos.z -= curr.position.z;
                        verts[i]  = newPos;
                    }

                    currMesh.SetVertices(verts);
                    currMesh.SetTriangles(triangles, 0);
                    currMesh.RecalculateNormals();
                    currMesh.RecalculateBounds();
                    curr.bounds.minPoints = currMesh.bounds.min;
                    curr.bounds.maxPoints = currMesh.bounds.max;

                    currMesh = MakeCubeFromBounds(curr.bounds);
                    currMesh.RecalculateNormals();
                    entities.Add(curr);
                    meshes.Add(currMesh);
                    vertexOffset += verts.Count;
                }
                else
                {
                    first = false;
                }
                int    endNameIndex = line.IndexOf("_Mesh");
                string objName      = line.Substring(2, endNameIndex - 2);
                //print(objName);
                curr     = new entity();
                currMesh = new Mesh();
                triangles.Clear();
                verts.Clear();
            }
            //New vert coming in
            else if (function == 'v')
            {
                string[] points = line.Substring(2).Split(' ');
                float    x      = float.Parse(points[0]);
                float    y      = float.Parse(points[1]);
                float    z      = float.Parse(points[2]);

                curr.bounds = SetBounds(ref curr.bounds, x, y, z);

                if (curr.position.y > y)
                {
                    curr.position.y = y;
                }
                curr.position.x += x;
                curr.position.z += z;
                verts.Add(new Vector3(x, y, z));
            }
            else if (function == 'f')
            {
                string[] points = line.Substring(2).Split(' ');
                //obj vert index starts at 1.
                int a = int.Parse(points[0]) - 1 - vertexOffset;
                int b = int.Parse(points[1]) - 1 - vertexOffset;
                int c = int.Parse(points[2]) - 1 - vertexOffset;
                triangles.Add(a);
                triangles.Add(b);
                triangles.Add(c);
            }
        }
        Debug.Log(count);
        gameWorld = new world(entities.Count);
        for (int i = 0; i < entities.Count; ++i)
        {
            gameWorld.entities[i] = entities[i];
            gameWorld.entityCount++;
        }
    }
예제 #24
0
 public character(Vector2 position, string name, float moveSpeed, world theWorld)
 {
     this.position  = position;
     this.name      = name;
     this.moveSpeed = moveSpeed;
 }
예제 #25
0
        // not roslyn friendly?

        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            // where does the tcp server put the memory?

            #region ChromeTCPServer
            dynamic self = Native.self;
            dynamic self_chrome = self.chrome;
            object self_chrome_socket = self_chrome.socket;

            if (self_chrome_socket != null)
            {
                chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Preview().src;
                chrome.Notification.DefaultTitle = "NatureBoyTestPadExperiment";


                ChromeTCPServer.TheServerWithStyledForm.Invoke(
                    AppSource.Text
                );

                return;
            }
            #endregion

            //global::DiagnosticsConsole.ApplicationContent.BindKeyboardToDiagnosticsConsole();


            #region music
            var music = default(world);

            Action loop = null;

            loop = delegate
            {
                music = new world { volume = 0.1 }.AttachToDocument();

                music.onended +=
                    delegate
                    {
                        Console.WriteLine(" music.onended ");
                        music.Orphanize();

                        loop();
                    };

                music.play();

            };

            loop();
            #endregion

            //music.setAttribute("loop", "loop");

            new[]
            {
                new [] {
                Frames.WolfSoldier,
                Frames.DoomImp,
                MyFrames.NPC3.Frames_Stand,
                MyFrames.ManWithHorns.Frames_Stand,
                MyFrames.ThePig.Frames_Stand,
                MyFrames.TheSheep.Frames_Stand,
                },
                Frames.WolfSoldier_Walk,
                Frames.DoomImp_Walk,
                MyFrames.NPC3.Frames_Walk,
                MyFrames.ManWithHorns.Frames_Walk
            }.ContinueAfterImagesReady(

                    // why cannot we just set progress and skip innerText, should work, a bug?
                c => page.progress.innerText = c + " images loaded"
            )(
                 NatureBoyTestPad.js.NatureBoyTestPad.InitializeContent
            );

        }
예제 #26
0
        // not roslyn friendly?

        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            // where does the tcp server put the memory?

            #region ChromeTCPServer
            dynamic self               = Native.self;
            dynamic self_chrome        = self.chrome;
            object  self_chrome_socket = self_chrome.socket;

            if (self_chrome_socket != null)
            {
                chrome.Notification.DefaultIconUrl = new HTML.Images.FromAssets.Preview().src;
                chrome.Notification.DefaultTitle   = "NatureBoyTestPadExperiment";


                ChromeTCPServer.TheServerWithStyledForm.Invoke(
                    AppSource.Text
                    );

                return;
            }
            #endregion

            //global::DiagnosticsConsole.ApplicationContent.BindKeyboardToDiagnosticsConsole();


            #region music
            var music = default(world);

            Action loop = null;

            loop = delegate
            {
                music = new world {
                    volume = 0.1
                }.AttachToDocument();

                music.onended +=
                    delegate
                {
                    Console.WriteLine(" music.onended ");
                    music.Orphanize();

                    loop();
                };

                music.play();
            };

            loop();
            #endregion

            //music.setAttribute("loop", "loop");

            new[]
            {
                new [] {
                    Frames.WolfSoldier,
                    Frames.DoomImp,
                    MyFrames.NPC3.Frames_Stand,
                    MyFrames.ManWithHorns.Frames_Stand,
                    MyFrames.ThePig.Frames_Stand,
                    MyFrames.TheSheep.Frames_Stand,
                },
                Frames.WolfSoldier_Walk,
                Frames.DoomImp_Walk,
                MyFrames.NPC3.Frames_Walk,
                MyFrames.ManWithHorns.Frames_Walk
            }.ContinueAfterImagesReady(

                // why cannot we just set progress and skip innerText, should work, a bug?
                c => page.progress.innerText = c + " images loaded"
                )(
                NatureBoyTestPad.js.NatureBoyTestPad.InitializeContent
                );
        }
예제 #27
0
파일: Form1.cs 프로젝트: jiiehe/SpaceWars
        public DrawingPanel(world w)
        {
            DoubleBuffered = true;
            theWorld       = w;


            ships   = new HashSet <Image>();
            thrusts = new HashSet <Image>();
            shoots  = new HashSet <Image>();
            star    = Image.FromFile("..//..//..//Resources//Images//star.jpg");
            //import the images from the resources file
            Image ship1  = Image.FromFile("..//..//..//Resources//Images//ship-coast-blue.png");
            Image ship2  = Image.FromFile("..//..//..//Resources//Images//ship-coast-brown.png");
            Image ship3  = Image.FromFile("..//..//..//Resources//Images//ship-coast-green.png");
            Image ship4  = Image.FromFile("..//..//..//Resources//Images//ship-coast-grey.png");
            Image ship5  = Image.FromFile("..//..//..//Resources//Images//ship-coast-red.png");
            Image ship6  = Image.FromFile("..//..//..//Resources//Images//ship-coast-violet.png");
            Image ship7  = Image.FromFile("..//..//..//Resources//Images//ship-coast-white.png");
            Image ship8  = Image.FromFile("..//..//..//Resources//Images//ship-coast-yellow.png");
            Image ship9  = Image.FromFile("..//..//..//Resources//Images//ship-thrust-blue.png");
            Image ship10 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-brown.png");
            Image ship11 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-green.png");
            Image ship12 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-grey.png");
            Image ship13 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-red.png");
            Image ship14 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-violet.png");
            Image ship15 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-white.png");
            Image ship16 = Image.FromFile("..//..//..//Resources//Images//ship-thrust-yellow.png");

            ships.Add(ship1);
            ships.Add(ship2);
            ships.Add(ship3);
            ships.Add(ship4);
            ships.Add(ship5);
            ships.Add(ship6);
            ships.Add(ship7);
            ships.Add(ship8);
            arrays = ships.ToArray();
            thrusts.Add(ship9);
            thrusts.Add(ship10);
            thrusts.Add(ship11);
            thrusts.Add(ship12);
            thrusts.Add(ship13);
            thrusts.Add(ship14);
            thrusts.Add(ship15);
            thrusts.Add(ship16);
            arrays1 = thrusts.ToArray();
            Image ship17 = Image.FromFile("..//..//..//Resources//Images//shot-blue.png");
            Image ship18 = Image.FromFile("..//..//..//Resources//Images//shot-brown.png");
            Image ship19 = Image.FromFile("..//..//..//Resources//Images//shot-green.png");
            Image ship20 = Image.FromFile("..//..//..//Resources//Images//shot-grey.png");
            Image ship21 = Image.FromFile("..//..//..//Resources//Images//shot-red.png");
            Image ship22 = Image.FromFile("..//..//..//Resources//Images//shot-violet.png");
            Image ship23 = Image.FromFile("..//..//..//Resources//Images//shot-white.png");
            Image ship24 = Image.FromFile("..//..//..//Resources//Images//shot-yellow.png");

            shoots.Add(ship17);
            shoots.Add(ship18);
            shoots.Add(ship19);
            shoots.Add(ship20);
            shoots.Add(ship21);
            shoots.Add(ship22);
            shoots.Add(ship23);
            shoots.Add(ship24);
            arrays2 = shoots.ToArray();
        }
예제 #28
0
 internal void staticWorldSetupMethod(world gameObject)
 {
     World = gameObject;
     World.customer_count++;
 }
예제 #29
0
파일: Form1.cs 프로젝트: jiiehe/SpaceWars
 public ScorePanel(world w)
 {
     this.DoubleBuffered = true;
     theWorld            = w;
     ships = new List <int>();
 }
예제 #30
0
    // Update is called once per frame
    void Update()
    {
        // var navpath = this.GetComponent<UnityEngine.AI.NavMeshAgent>().path;
        // if (navpath.status == UnityEngine.AI.NavMeshPathStatus.PathInvalid || navpath.status == UnityEngine.AI.NavMeshPathStatus.PathPartial)
        // {
        //  print("Path unreachable");
        // }
        // Target is unreachable


        crowding -= 0.01f;

        var changeSlider = GameObject.Find("changeSlider").GetComponent <Slider> ().value;

        if (explorer_seed < changeSlider)
        {
            if (crowding > 0.8)
            {
                // this.GetComponent<Renderer>().material = angry_mat;
                crowded_flg = 1;
            }
            else
            {
                this.GetComponent <Renderer>().material = normal_mat;
                if (crowding < 0.5)
                {
                    crowded_flg      = 0;
                    crowded_path_flg = 0;
                }
            }
        }

        var random_path = 0;

        if (internal_clock < 0)
        {
            random_path    = 1;
            internal_clock = time_resetl;
        }
        else
        {
            internal_clock = internal_clock - Time.deltaTime;
        }


        // Find current position
        GameObject Cam    = GameObject.Find("Main Camera");
        world      obj    = (Cam.GetComponent("world") as world);
        int        worldx = (int)(((transform.position.x + moveAreaX / 2) / moveAreaX) * 100);
        int        worldz = (int)(((transform.position.z + moveAreaZ / 2) / moveAreaZ) * 100);

        // print("world");
        // print(worldx);
        // print(worldz);

        // Check food cell
        if (carry_cheese == 0)
        {
            // Check for cheese block
            if (obj.cheese[worldx, worldz] > 0)
            {
                carry_cheese = 1;
                var bite = transform.Find("bite").GetComponent <Renderer>();
                bite.enabled = true;

                // Lower cheese reserve
                obj.cheese[worldx, worldz] -= 0.5f;
                // print(obj.cheese[worldx,worldz]);
                //Check if cheese reserve finished. remove asset.
                if (obj.cheese[worldx, worldz] <= 0)
                {
                    obj.cheese[worldx, worldz] = 0;
                    var rend = obj.cheese_coll[worldx + worldz * 100].GetComponent <Renderer>();
                    rend.enabled = false;
                }
            }
            // Check for best option

            path_matrix[1, 1] = -1;            //center
            var max_val = 0f;
            var max_x   = 0;
            var max_z   = 0;

            // Find the nearest cheese
            var        DistT          = (float)10 * moveAreaZ / 100;
            GameObject cheese_target1 = GetClosestEnemy(obj.cheese_coll, DistT);

            if (cheese_target1 != null && crowded_flg == 0)
            {
                UnityEngine.AI.NavMeshAgent agent = GetComponent <UnityEngine.AI.NavMeshAgent>();
                agent.destination = cheese_target1.transform.position;
            }
            else if (crowded_flg == 0)
            {
                // Look for pheromons
                var scan_t = 11;
                //Vector3[] cand_heatmap = new Vector3[scan_t*scan_t];
                List <Vector3> cand_heatmap = new List <Vector3>();


                var   heatmap_T = (int)Mathf.Floor(scan_t / 2);                // Always odd
                float high_heat = -1f;
                int   max_x1    = 0;
                int   max_z1    = 0;
                int   cand_heat = 0;

                for (int dx = 0; dx <= heatmap_T; dx++)
                {
                    for (int dz = 0; dz <= heatmap_T; dz++)
                    {
                        if (dx != 0 && dz != 0)
                        {
                            // var rend = obj.heatmap[worldx + dx + (worldz + dz) * 100].GetComponent<Renderer>();
                            var c_z = worldz + dz;
                            var c_x = worldx + dx;

                            if (c_z > 99)
                            {
                                c_z = 99;
                            }
                            if (c_x > 99)
                            {
                                c_x = 99;
                            }

                            if (c_z < 0)
                            {
                                c_z = 0;
                            }
                            if (c_x < 0)
                            {
                                c_x = 0;
                            }

                            if (obj.world_score[c_x, c_z] > 0)
                            {
                                //cand_heatmap[cnt] = obj.heatmap[worldx + dx + (worldz + dz) * 100].transform.position;
                                //cand_heatmap.Add(obj.heatmap[worldx + dx + (worldz + dz) * 100].transform.position);
                                cand_heat += 1;
                                if (obj.world_score[c_x, c_z] > high_heat)
                                {
                                    high_heat = obj.world_score[c_x, c_z];
                                    max_x1    = c_x;
                                    max_z1    = c_z;
                                }
                            }
                        }
                    }
                }
                if (high_heat > 0.0)
                {
                    // print("heatmap");
                    var targetX1 = max_x1 * moveAreaX / 100 - moveAreaX / 2;
                    var targetZ1 = max_z1 * moveAreaZ / 100 - moveAreaZ / 2;

                    Vector3 target1 = new Vector3(targetX1, 0, targetZ1);
                    UnityEngine.AI.NavMeshAgent agent1 = GetComponent <UnityEngine.AI.NavMeshAgent>();
                    agent1.destination = target1;
                    // this.GetComponent<Renderer>().material = angry_mat;
                    //GameObject g = Instantiate(marker, target1, Quaternion.identity) as GameObject;
                }



                // var DistT1 = (float) 10*moveAreaZ/100;

                // Vector3 target_heatmap = GetClosestEnemy_pos(cand_heatmap, DistT1);

                // if (target_heatmap != new Vector3(-1,0,-1))
                // {
                // UnityEngine.AI.NavMeshAgent agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
                //              agent.destination = target_heatmap;
                //              //print("Nearest heatmap");
                //              }

                else if (random_path == 1)
                {
                    // Random move
                    var     targetZ = (((Random.Range(0, 100)) - moveAreaZ / 2) * 100 / moveAreaZ);
                    var     targetX = (((Random.Range(0, 100)) - moveAreaX / 2) * 100 / moveAreaX);
                    Vector3 target  = new Vector3(targetX, 0, targetZ);

                    // transform.position = Vector3.MoveTowards(transform.position, target, step);
                    UnityEngine.AI.NavMeshAgent agent = GetComponent <UnityEngine.AI.NavMeshAgent>();
                    agent.destination = target;
                }
            }
            else if (crowded_path_flg == 0)
            {
                // wander off when crowded
                var     targetZ = (((Random.Range(0, 100)) - moveAreaZ / 2) * 100 / moveAreaZ);
                var     targetX = (((Random.Range(0, 100)) - moveAreaX / 2) * 100 / moveAreaX);
                Vector3 target  = new Vector3(targetX, 0, targetZ);

                // transform.position = Vector3.MoveTowards(transform.position, target, step);
                UnityEngine.AI.NavMeshAgent agent = GetComponent <UnityEngine.AI.NavMeshAgent>();
                agent.destination = target;
                crowded_path_flg  = 1;
            }
        }

        else          // Carrying cheese

        {
            path_matrix[1, 1] = -1;            //center
            var max_val = 0f;
            var max_x   = 0;
            var max_z   = 0;

            // Check for home block
            if (worldx < 10 && worldz < 10)
            {
                carry_cheese    = 0;
                obj.home_stock += 0.1f;
                var bite = transform.Find("bite").GetComponent <Renderer>();
                bite.enabled = false;

                Vector3 position = new Vector3(-moveAreaX / 2 + Random.Range(0, 10), 2, -moveAreaZ / 2 + Random.Range(0, 10));

                GameObject c  = Instantiate(cheese_drop, position, Quaternion.identity) as GameObject;
                Rigidbody  rb = c.GetComponent <Rigidbody>();
                rb.AddRelativeForce(Vector3.forward * 1f);
            }

            obj.world_score[worldx, worldz] += 0.01f;
            if (obj.world_score[worldx, worldz] > 1.0f)
            {
                obj.world_score[worldx, worldz] = 1.0f;
            }


            var targetZ = ((Random.Range(1, 9) - moveAreaZ / 2) * 100 / moveAreaZ);
            var targetX = ((Random.Range(1, 9) - moveAreaX / 2) * 100 / moveAreaX);

            Vector3 target = new Vector3(targetX, 0, targetZ);
            UnityEngine.AI.NavMeshAgent agent = GetComponent <UnityEngine.AI.NavMeshAgent>();
            agent.destination = target;
        }

        // look at surrunding block to find next step
    }
예제 #31
0
 List <int> died  = new List <int>(); // list to store the numes of the died ship
 //contructor
 public GController()
 {
     theworld = new world();
 }
예제 #32
0
 public void setMyWorld(world myWorld)
 {
     this.myWorld = myWorld;
 }