private void JumpBackgrounds(Transform cameraTransform, List <ParallaxObject> backgrounds)
    {
        ParallaxObject left  = backgrounds[0];
        ParallaxObject right = backgrounds[0];

        foreach (var background in backgrounds)
        {
            if (background.Position < left.Position)
            {
                left = background;
            }
            if (background.Position > right.Position)
            {
                right = background;
            }
        }

        if (right.Position - cameraTransform.position.x < tileWidth / 2)
        {
            left.Jump(tileWidth * 5);
        }
        else if (cameraTransform.position.x - left.Position < tileWidth / 2)
        {
            right.Jump(-tileWidth * 5);
        }
    }
Пример #2
0
    public void AddObject(ParallaxObject parallaxObject)
    {
        if (_parallaxObjects.Contains(parallaxObject))
        {
            return;
        }

        _parallaxObjects.Add(parallaxObject);
    }
Пример #3
0
 // Manually scroll the parallax object by x and y distances.
 public void Scroll(float xdistance, float ydistance)
 {
     for (int index = 0; index < m_Layers.Length; ++index)
     {
         LayerInfo      layer  = m_Layers[index];
         ParallaxObject script = layer.GetParallaxObject();
         if (script != null)
         {
             script.Scroll(xdistance, ydistance);
         }
     }
 }
 // Update is called once per frame
 void FixedUpdate()
 {
     UpdateAll();
     JumpBackgrounds(cameraTransform, activeFarBackgrounds);
     JumpBackgrounds(cameraTransform, activeMidBackgrounds);
     if (TimeKeeper.GetTime() > nextNearBackground)
     {
         var toInstantiate  = Random.Range(0, nearBackgrounds.Length);
         var nearBackground = Instantiate(nearBackgrounds[toInstantiate], new Vector3(cameraTransform.position.x + 30, cameraTransform.position.y, 30), Quaternion.identity);
         var parallax       = new ParallaxObject(nearBackground.transform, cameraTransform, nearParallax, alignmentPoint);
         activeNearBackgrounds.Add(parallax);
         nextNearBackground = TimeKeeper.GetTime() + Random.Range(nearBackgroundMin, nearBackgroundMax);
     }
 }
Пример #5
0
    private void CreateParallaxObject(float timeAdjustment)
    {
        float      randHeight = Random.Range(0, 15);
        float      randDepth  = Random.Range(1, 2);
        GameObject go         = GameObject.Instantiate(parallaxPrefab, spawnPosition.transform.position + (Vector3.up * randHeight) + Vector3.forward * randDepth, Quaternion.identity) as GameObject;

        go.transform.SetParent(CreationParent.transform);
        go.transform.localScale = new Vector3(8, 8, 8);
        ParallaxObject para = go.GetComponent <ParallaxObject>();

        para.zBack = randDepth;

        //para.affiliation = (Obstacle.Element)random;

        parallax.Add(para);
    }
Пример #6
0
    protected void Update()
    {
        if (m_Layers == null)
        {
            enabled = false;
            return;
        }

        for (int index = 0; index < m_Layers.Length; ++index)
        {
            LayerInfo      layer  = m_Layers[index];
            ParallaxObject script = layer.GetParallaxObject();
            if (script != null)
            {
                script.SetScrollVelocity(m_Velocity);
                script.SetVerticalScrollVelocity(m_VerticalVelocity);
            }
        }
    }
    void SpawnLayerAt(float x, int index, ParallaxLayer p)
    {
        // Spawn a new sprite
        GameObject newObject = new GameObject("ParalaxLayer");

        newObject.transform.SetParent(gameObject.transform);
        newObject.transform.position   = new Vector3(x, p.yPos, 0);
        newObject.transform.localScale = new Vector3(1, p.yStretch, 1);
        newObject.transform.parent     = transform;

        newObject.AddComponent <SpriteRenderer>();
        SpriteRenderer renderer = newObject.GetComponent <SpriteRenderer>();

        renderer.sprite       = p.sprite;
        renderer.sortingOrder = -41 - (layers.Count - index);

        newObject.AddComponent <ParallaxObject>();
        ParallaxObject po = newObject.GetComponent <ParallaxObject>();

        po.movementFactor = p.movementFactor;
        po.sprite         = p.sprite;
    }
Пример #8
0
 void Update()
 {
     if (parallaxSpawnTimer.TimeIsOver())
     {
         int    parallaxID = Random.Range(0, (int)(typeof(BackgroundController).GetField("planet_" + planetID.ToString() + "_maximum_parallax").GetValue(null)) + 1);
         string path       = "Prefabs/Backgrounds/planet_" + planetID + "/Parallax/parallax_" + parallaxID.ToString();
         //Debug.Log (path);
         for (int i = 0; i < Random.Range(1, 3); i++)
         {
             GameObject     newParallaxObject = ObjectsPool.PullObject(path);
             ParallaxObject parallaxObject    = newParallaxObject.GetComponent <ParallaxObject> ();
             parallaxObject.poolPath = path;
             float positionZ = parallaxObject.objectTransform.position.z;
             if (currentSystem.upToDown)
             {
                 parallaxObject.objectTransform.position = SpawnerController.instance.parallaxSpawnerTop.GetRandomPositionInWorld();
             }
             else
             {
                 parallaxObject.objectTransform.localScale = new Vector3(parallaxObject.objectTransform.localScale.x, parallaxObject.objectTransform.localScale.y * -1, parallaxObject.objectTransform.localScale.z);
                 parallaxObject.objectTransform.position   = SpawnerController.instance.parallaxSpawnerBottom.GetRandomPositionInWorld();
             }
             parallaxObject.objectTransform.position = new Vector3(
                 parallaxObject.objectTransform.position.x,
                 parallaxObject.objectTransform.position.y,
                 positionZ
                 );
             parallaxObject.speed = currentSystem.speed * 1.5f;
             if (currentSystem.upToDown)
             {
                 parallaxObject.speed = parallaxObject.speed * -1f;
             }
             parallaxSpawnTimer.SetTimer(Random.Range(minimumTime, maximumTimer));
             parallaxObject.frameRate = 0;
         }
     }
 }
Пример #9
0
        protected override void ResourceLoader()
        {
            base.ResourceLoader();

            /* create the element corresponding to the hud */
            hudElement         = new ImageElement(this, 0, 0, 640, 480, TranslucentIndex);
            hudElement.Text    = String.Format(Builtins.Game_ConsolePcx, Util.RaceCharLower[(int)Game.Instance.Race]);
            hudElement.Visible = true;
            Elements.Add(hudElement);

            /* create the portrait playing area */
            portraitElement         = new MovieElement(this, 415, 415, 48, 48, false);
            portraitElement.Visible = true;
            Elements.Add(portraitElement);

            Pcx pcx = new Pcx();

            pcx.ReadFromStream((Stream)mpq.GetResource("game\\tunit.pcx"), -1, -1);
            //unit_palette = pcx.Palette;

            pcx = new Pcx();
            pcx.ReadFromStream((Stream)mpq.GetResource("tileset\\badlands\\dark.pcx"), 0, 0);
            tileset_palette = pcx.Palette;

            if (scenario.Tileset == Tileset.Platform)
            {
                Spk starfield = (Spk)mpq.GetResource("parallax\\star.spk");

                starfield_layers = new Surface [starfield.Layers.Length];
                for (int i = 0; i < starfield_layers.Length; i++)
                {
                    starfield_layers[i] = new Surface(Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);

                    starfield_layers[i].TransparentColor = Color.Black;

                    for (int o = 0; o < starfield.Layers[i].Objects.Length; o++)
                    {
                        ParallaxObject obj = starfield.Layers[i].Objects[o];

                        starfield_layers[i].Fill(new Rectangle(new Point(obj.X, obj.Y), new Size(2, 2)),
                                                 Color.White);
                    }
                }
            }

            mapRenderer = new MapRenderer(mpq, scenario, Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);

            // load the cursors we'll show when scrolling with the mouse
            string[] cursornames = new string[] {
                "cursor\\ScrollUL.grp",
                "cursor\\ScrollU.grp",
                "cursor\\ScrollUR.grp",
                "cursor\\ScrollR.grp",
                "cursor\\ScrollDR.grp",
                "cursor\\ScrollD.grp",
                "cursor\\ScrollDL.grp",
                "cursor\\ScrollL.grp",
            };
            ScrollCursors = new CursorAnimator [cursornames.Length];
            for (int i = 0; i < cursornames.Length; i++)
            {
                ScrollCursors[i] = new CursorAnimator((Grp)mpq.GetResource(cursornames[i]),
                                                      effectpal.Palette);
                ScrollCursors[i].SetHotSpot(60, 60);
            }

            // load the mag cursors
            string[] magcursornames = new string[] {
                "cursor\\MagG.grp",
                "cursor\\MagY.grp",
                "cursor\\MagR.grp"
            };
            MagCursors = new CursorAnimator [magcursornames.Length];
            for (int i = 0; i < magcursornames.Length; i++)
            {
                MagCursors[i] = new CursorAnimator((Grp)mpq.GetResource(magcursornames[i]),
                                                   effectpal.Palette);
                MagCursors[i].SetHotSpot(60, 60);
            }

            // load the targeting cursors
            string[] targetcursornames = new string[] {
                "cursor\\TargG.grp",
                "cursor\\TargY.grp",
                "cursor\\TargR.grp"
            };
            TargetCursors = new CursorAnimator [targetcursornames.Length];
            for (int i = 0; i < targetcursornames.Length; i++)
            {
                TargetCursors[i] = new CursorAnimator((Grp)mpq.GetResource(targetcursornames[i]),
                                                      effectpal.Palette);
                TargetCursors[i].SetHotSpot(60, 60);
            }

            /* the following could be made global to speed up the entry to the game screen.. */
            statTxt = (Tbl)mpq.GetResource("rez\\stat_txt.tbl");

            // load the wireframe image info
            wireframe = (Grp)mpq.GetResource("unit\\wirefram\\wirefram.grp");

            // load the command icons
            cmdicons = (Grp)mpq.GetResource("unit\\cmdbtns\\cmdicons.grp");
            pcx      = new Pcx();
            pcx.ReadFromStream((Stream)mpq.GetResource("unit\\cmdbtns\\ticon.pcx"), 0, 0);
            cmdicon_palette = pcx.Palette;

            // create the wireframe display element
            wireframeElement         = new GrpElement(this, wireframe, cmdicon_palette, 170, 390);
            wireframeElement.Visible = false;
            Elements.Add(wireframeElement);

            labelElements = new LabelElement [(int)HudLabels.Count];

            labelElements[(int)HudLabels.UnitName] = new LabelElement(this, fontpal.Palette,
                                                                      GuiUtil.GetFonts(Mpq)[1],
                                                                      254, 390);
            labelElements[(int)HudLabels.ResourceUsed] = new LabelElement(this, fontpal.Palette,
                                                                          GuiUtil.GetFonts(Mpq)[0],
                                                                          292, 420);
            labelElements[(int)HudLabels.ResourceProvided] = new LabelElement(this, fontpal.Palette,
                                                                              GuiUtil.GetFonts(Mpq)[0],
                                                                              292, 434);
            labelElements[(int)HudLabels.ResourceTotal] = new LabelElement(this, fontpal.Palette,
                                                                           GuiUtil.GetFonts(Mpq)[0],
                                                                           292, 448);
            labelElements[(int)HudLabels.ResourceMax] = new LabelElement(this, fontpal.Palette,
                                                                         GuiUtil.GetFonts(Mpq)[0],
                                                                         292, 462);

            for (int i = 0; i < labelElements.Length; i++)
            {
                Elements.Add(labelElements[i]);
            }

            cmdButtonElements = new GrpButtonElement[9];
            int x = 0;
            int y = 0;

            for (int i = 0; i < cmdButtonElements.Length; i++)
            {
                cmdButtonElements[i] = new GrpButtonElement(this, cmdicons, cmdicon_palette, button_xs[x], button_ys[y]);
                x++;
                if (x == 3)
                {
                    x = 0;
                    y++;
                }
                cmdButtonElements[i].Visible = false;
                Elements.Add(cmdButtonElements[i]);
            }

            PlaceInitialUnits();

            Events.Tick += ScrollTick;
        }