コード例 #1
0
    private IEnumerator DoInitNewRow()
    {
        if (missString)
        {
            for (int i = 0; i < SceneObjects.Count; i++)
            {
                var objPosition = SceneObjects[i].transform.position;
                var target      = new Vector2(objPosition.x, objPosition.y - 100);
                SceneObjects[i].MoveObject(target);
            }
        }
        missString = true;
        count      = SceneObjects.Count;
        int colorChoise;
        int testChance = 0;

        ChangeLvlCube();

        for (int i = 0; i < cubecount; i++)
        {
            var objectPosition = new Vector2(-(Screen.width / 2 - 53) + (i * 100), Screen.height / 2 - 53);
            if (Random.value > 1 - cubeChance)
            {
                testChance++;
                var canGenerateBonus = Random.value > 1 - bonusChance;
                if (canGenerateBonus)
                {
                    BonusManager.I.GenerateBonus(BonusType.NewBall, objectPosition);
                    count++;
                }
                continue;
            }
            else
            {
                var cube      = Instantiate(cubePrefab);
                var colorCube = cube.GetComponent <ColorCube>();
                SceneObjects.Add(colorCube);
                colorCube.transform.SetParent(rect);
                colorCube.transform.localPosition = objectPosition;
            }

            colorChoise = Random.Range(CubesLvlMin, CubesLvlMax);


            if (SceneObjects[count].GetComponent <ColorCube>() != null)
            {
                SceneObjects[count].GetComponent <ColorCube>().Init(colorChoise, Color.HSVToRGB(0.71f, 0.6f, 0.3f * colorChoise / 15));
            }
            count++;
        }
        addTestMissChanse(testChance);

        if (CubesLvlMax - CubesLvlMin > 5)
        {
            CubesLvlMin++;
        }

        CubesLvlMax++;
        yield return(new WaitForSeconds(0.2f));
    }
コード例 #2
0
    public void InitNewRound()
    {
        int colorChoise;
        int minLimit   = 1;
        int maxLimit   = 2;
        int testChanse = 0;
        int count      = default(int);


        for (int i = 0; i < 1; i++)
        {
            for (int j = 0; j < cubecount; j++)
            {
                if (Random.value > 1 - cubeChance)
                {
                    testChanse++;
                    continue;
                }
                else
                {
                    var cube      = Instantiate(cubePrefab);
                    var colorCube = cube.GetComponent <ColorCube>();
                    SceneObjects.Add(colorCube);
                    colorCube.transform.SetParent(rect);
                    colorCube.transform.localPosition = new Vector2(-(Screen.width / 2 - 53) + (j * 100), Screen.height / 2 - 53);
                }

                colorChoise = Random.Range(minLimit, maxLimit);
                SceneObjects[count].GetComponent <ColorCube>().Init(colorChoise, Color.HSVToRGB(initColor.r, initColor.g, initColor.b * colorChoise / 15));
                count++;
            }
            TestMissChance(testChanse);
        }
    }
コード例 #3
0
        public SecondScene(PastelGame game)
        {
            BackgroundColour = RgbaFloat.DarkRed;
            Game             = game;

            var rectangle = new Rectangle(new Vector2(-0.4f, 0.3f), 20);

            SceneObjects.Add(rectangle);
        }
コード例 #4
0
        public FirstScene(PastelGame game)
        {
            BackgroundColour = RgbaFloat.CornflowerBlue;
            Game             = game;

            var rec = new Rectangle(new Vector2(0.5f, -0.5f), 10);

            SceneObjects.Add(rec);
        }
コード例 #5
0
        public static GameObject instance_create(Vector2 position, Type obj, string layer)
        {
            // First we need to convert layer name to actual layer
            RoomLayer realLayer = roomLayers.FirstOrDefault(x => x.Name == layer);

            GameObject  o = (GameObject)Activator.CreateInstance(obj);
            Spritesheet s = new Spritesheet();

            if (o.Sprite != null)
            {
                s = Sprites.FirstOrDefault(x => x.Name == o.Sprite.TextureSource);
            }

            o.OriginalType = obj;
            o.TypeString   = obj.ToString();


            if (s == null)
            {
                Texture2D tx = ConvertToTexture(SimplexIde.Properties.Resources.Question_16x, GraphicsDevice);

                o.Sprite                    = new Sprite();
                o.Sprite.Texture            = tx;
                o.Sprite.ImageRectangle     = new Microsoft.Xna.Framework.Rectangle(0, 0, 16, 16);
                o.Sprite.TextureRows        = 1;
                o.Sprite.TextureCellsPerRow = 1;
                o.Sprite.ImageSize          = new Vector2(16, 16);
                o.Sprite.FramesCount        = 1;
                o.FramesCount               = 1;
                o.Sprite.cellW              = 16;
                o.Sprite.cellH              = 16;

                o.Position = new Vector2(position.X - 8, position.Y - 8);
                o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, 16, 16);
            }
            else
            {
                o.Sprite.Texture            = s.Texture;
                o.Sprite.ImageRectangle     = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
                o.Sprite.TextureRows        = s.Rows;
                o.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth;
                o.Sprite.ImageSize          = new Vector2(s.CellWidth, s.CellHeight);
                o.Sprite.FramesCount        = Math.Max((s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1, 1);
                o.FramesCount  = Math.Max(o.Sprite.FramesCount - 1, 1);
                o.Sprite.cellW = s.CellHeight;
                o.Sprite.cellH = s.CellWidth;

                o.Position = new Vector2(position.X - s.CellWidth / 2f, position.Y - s.CellHeight / 2f);
                o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
            }


            o.LayerName = realLayer.Name;
            o.Layer     = (ObjectLayer)realLayer;

            currentObject = o;
            o.EvtCreate();


            o.Layer.Objects.Add(o);
            SceneObjects.Add(o);
            sh.RegisterObject(o);

            return(o);
        }
コード例 #6
0
        public static void game_load(string path)
        {
            bool flag = false;

            // First we f**k current scene
            ClearAll();

            RoomEditor?.ClearNodes();

            // Prepare XML serializer
            // Then we load raw data
            XmlSerializer ser      = new XmlSerializer(typeof(Root), Form1.reflectedTypes.ToArray());
            StreamReader  w        = new StreamReader(path);
            bool          flagGood = true;
            Root          rawData  = null;

            try
            {
                rawData = (Root)ser.Deserialize(w);
            }
            catch (Exception e)
            {
                flagGood = false;
                DarkMessageBox.Show("Loading of room failed\n\n" + e.InnerException.Message, "Simplex Engine 3");
            }

            if (flagGood)
            {
                // Filter out duplicated layers
                List <string>    names      = new List <string>();
                List <RoomLayer> goodLayers = new List <RoomLayer>();
                for (var i = 0; i < rawData.Room.Layers.Count; i++)
                {
                    if (!names.Contains(rawData.Room.Layers[i].Name))
                    {
                        names.Add(rawData.Room.Layers[i].Name);
                        goodLayers.Add(rawData.Room.Layers[i]);
                    }
                }

                rawData.Room.Layers = goodLayers;

                // First load back room itself
                Form1.width  = (int)rawData.Room.Size.X;
                Form1.height = (int)rawData.Room.Size.Y;


                currentRoom = rawData.Room;

                if (RoomEditor != null)
                {
                    RoomEditor.currentRoom = currentRoom;
                    RoomEditor?.PropagateNodes();
                    RoomEditor.roomsControl.execute = false;

                    RoomEditor.roomsControl.dtv.SelectNode(RoomEditor.roomsControl.dtv.Nodes[0].Nodes
                                                           .FirstOrDefault(x => x.Text == currentRoom.GetType().ToString().Split('.').Last()));
                    RoomEditor.roomsControl.execute = true;
                }

                // we need to initialize layers by type
                if (tilesets != null)
                {
                    foreach (RoomLayer rl in currentRoom.Layers)
                    {
                        if (rl.LayerType == RoomLayer.LayerTypes.typeTile)
                        {
                            // Start with empty cell data and load stuff later on
                            ((TileLayer)rl).Data =
                                new int[(int)currentRoom.Size.X / 32, (int)currentRoom.Size.Y / 32];

                            // Now select correct tileset and assign it to this.. well tileset
                            Tileset tl = tilesets.FirstOrDefault(x => x.Name == ((TileLayer)rl).TilelistName);

                            // this can fail so check for that
                            if (tl != null)
                            {
                                // also we need to load textures for the tileset
                                // all good
                                ((TileLayer)rl).Tileset = tl;
                            }
                        }
                    }
                }

                // Time to load babies
                foreach (GameObject g in rawData.Objects)
                {
                    Spritesheet s = Sprites.FirstOrDefault(x => x.Name == g.Sprite.TextureSource);

                    g.Sprite.Texture            = s.Texture;
                    g.Sprite.ImageRectangle     = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
                    g.Sprite.TextureRows        = s.Rows;
                    g.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth;
                    g.Sprite.ImageSize          = new Vector2(s.CellWidth, s.CellHeight);
                    g.Sprite.FramesCount        = (s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1;
                    g.FramesCount  = g.Sprite.FramesCount - 1;
                    g.Sprite.cellW = s.CellHeight;
                    g.Sprite.cellH = s.CellWidth;

                    RoomLayer rt = currentRoom.Layers.FirstOrDefault(x => x.Name == g.LayerName);
                    g.Layer = (ObjectLayer)rt;

                    g.Sprite.UpdateImageRectangle();
                    g.UpdateState();
                    g.UpdateColliders();

                    // Need to give object OriginalType !!!
                    g.OriginalType = Type.GetType(g.TypeString);

                    currentObject = g;
                    g.EvtCreate();
                    g.EvtLoad();

                    SceneObjects.Add(g);
                    g.Layer.Objects.Add(g);
                    sh.RegisterObject(g);

                    if (g.Colliders.Count > 0)
                    {
                        SceneColliders.Add(g);
                    }
                }

                foreach (GameObject g in SceneObjects)
                {
                    g.EvtCreateEnd();
                }

                // Load tiles
                foreach (Tile t in rawData.Tiles)
                {
                    RoomLayer correctLayer = currentRoom.Layers.FirstOrDefault(x => x.Name == t.TileLayerName);

                    if (correctLayer != null)
                    {
                        TileLayer crt = (TileLayer)correctLayer;
                        t.TileLayer = crt;
                        crt.Tiles.Add(t);
                    }
                    else
                    {
                        Debug.WriteLine("Tile could not be loaded - TileLayerName is wrong");
                    }
                }

                // Now update all tiles
                Texture2D ttt = tilesets.FirstOrDefault(x => x.Name == "tileset0").Texture;

                foreach (RoomLayer rl in currentRoom.Layers)
                {
                    if (rl is TileLayer)
                    {
                        TileLayer crt = (TileLayer)rl;

                        foreach (Tile t in crt.Tiles)
                        {
                            t.SourceTexture = ttt;
                            Autotile.UpdateTile(t, crt);
                        }
                    }
                }

                w.Close();
            }
        }
コード例 #7
0
ファイル: SgmlGame.cs プロジェクト: lofcz/SimplexRpgEngine
        public static void __loadGameObjects(List <GameObject> objects, bool execCreateEvt = true, bool execLoadEvt = true, bool execSetupEvt = true, bool reset = true)
        {
            SceneObjects.Clear();

            foreach (RoomLayer rl in currentRoom.Layers)
            {
                if (rl is ObjectLayer)
                {
                    ObjectLayer ol = (ObjectLayer)rl;
                    ol.Objects.Clear();
                }
            }

            foreach (GameObject g in objects)
            {
                if (reset)
                {
                    g.Reset();
                }

                Spritesheet s = Sprites.FirstOrDefault(x => x.Name == g.Sprite.TextureSource);

                g.Position   = g.__DefaultPosition;
                g.ImageAngle = g.__DefaultImageAngle;
                g.Direction  = g.__DefaultDirection;
                g.ImageScale = g.__DefaultImageScale;
                g.ImageIndex = g.__DefaultImageIndex;

                g.Sprite.Texture            = s.Texture;
                g.Sprite.ImageRectangle     = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight);
                g.Sprite.TextureRows        = s.Rows;
                g.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth;
                g.Sprite.ImageSize          = new Vector2(s.CellWidth, s.CellHeight);
                g.Sprite.FramesCount        = (s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1;
                g.FramesCount  = g.Sprite.FramesCount - 1;
                g.Sprite.cellW = s.CellHeight;
                g.Sprite.cellH = s.CellWidth;

                RoomLayer rt = currentRoom.Layers.FirstOrDefault(x => x.Name == g.LayerName);
                g.Layer = (ObjectLayer)rt;

                g.Sprite.UpdateImageRectangle();
                g.UpdateState();
                g.UpdateColliders();

                // Need to give object OriginalType !!!
                g.OriginalType = Type.GetType(g.TypeString);

                currentObject = g;

                if (execCreateEvt)
                {
                    g.EvtCreate();
                }

                if (execLoadEvt)
                {
                    g.EvtLoad();
                }

                if (execSetupEvt)
                {
                    g.EvtSetup();
                }

                SceneObjects.Add(g);
                g.Layer.Objects.Add(g);
                sh.RegisterObject(g);

                if (g.Colliders.Count > 0)
                {
                    SceneColliders.Add(g);
                }
            }

            foreach (GameObject g in SceneObjects)
            {
                g.EvtCreateEnd();
            }
        }