void NormalPlay()
    {
        Vector2 touchPos = Vector2.zero;

        if (forMobile)
        {
            Touch touch = Input.GetTouch(0);
            touchPos = touch.position;

            // if (Input.touchCount > 0)
            {
                bottomLeftRect = new Rect(0, 0, Screen.width / 2, Screen.height / 2);
                TopLeftRect    = new Rect(0, Screen.height / 2, Screen.width / 2, Screen.height / 2);
                //check this
                RightHalf = new Rect(Screen.width / 2, 0, Screen.width / 2, Screen.height);
                Lefthalf  = new Rect(0, 0, Screen.width / 2, Screen.height);
                Debug.Log(Lefthalf + "+" + RightHalf);
            }
        }


        Movement();



        if (Input.GetKey(KeyCode.Space) || RightHalf.Contains(touchPos))
        {
            //Debug.Log("fire");
            isFiring = true;

            startFire();
            // InvokeRepeating("startFire", 0.003f, 0.4f);

            //
        }
        if (Input.GetKeyUp(KeyCode.Space))
        {
            isFiring = false;
        }
    }
    // In hard play space will fire and up arrow will make player jump control using both hand
    void HardPlay()
    {
        Debug.Log("HardPlay 1");
        Vector2 touchPos = Vector2.zero;

        if (forMobile)
        {
            Debug.Log("HardPlay 2");
            Touch touch = Input.GetTouch(0);
            touchPos = touch.position;
            Debug.Log(touch);
        }

        rgbd.bodyType = RigidbodyType2D.Dynamic;
        rgbd.mass     = 1f;
        // Debug.Log("Lefthalf.Contains(touchPos)" + Lefthalf.Contains(touchPos));
        // Debug.Log("HardPlay 3");
        if (forMobile && Lefthalf.Contains(touchPos) || Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("HardPlay 4");
            // hacve to change something

            rgbd.velocity = new Vector2(0, 7);
            //   Debug.Log(rgbd.velocity);


            rgbd.gravityScale = 1f;
            rgbd.constraints  = RigidbodyConstraints2D.FreezeRotation;
        }
        if (forMobile && RightHalf.Contains(touchPos) || Input.GetKey(KeyCode.Space))
        {
            isFiring = true;

            startFire();
            //  Debug.Log("RightClick");
        }
    }
Exemplo n.º 3
0
        public void LoadContent(Vector2 tileDimensions)
        {
            Image.LoadContent();
            if (Water.Path != String.Empty)
            {
                Water.LoadContent();
            }
            Vector2 position = -tileDimensions; //tileDimensions - new Vector2(128,128)

            foreach (string row in Tile.Row)
            {
                string[] split = row.Split(']');
                position.X  = -tileDimensions.X;
                position.Y += tileDimensions.Y;
                rowLength   = split.Length - 1;
                foreach (string s in split)
                {
                    if (s != String.Empty)
                    {
                        position.X += tileDimensions.X;
                        tilesCount.Add(TileCollision.Passive);

                        if (!s.Contains("x"))
                        {
                            Tile tile = new Tile();

                            string str    = s.Replace("[", String.Empty);
                            int    value1 = int.Parse(str.Substring(0, str.IndexOf(':')));
                            int    value2 = int.Parse(str.Substring(str.IndexOf(':') + 1));

                            //Set TileTypes
                            if (SolidTiles.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.Solid;
                            }
                            else if (RightWall.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.RightWall;
                            }
                            else if (TopWall.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.TopWall;
                            }
                            else if (BottomWall.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.BottomWall;
                            }
                            else if (BottomDoor.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.BottomDoor;
                            }
                            else if (SEWallCorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.SEWallCorner;
                            }
                            else if (SWWallCorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.SWWallCorner;
                            }
                            else if (NEWallCorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.NEWallCorner;
                            }
                            else if (NWWallCorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.NWWallCorner;
                            }
                            else if (RightHalf.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.RightHalf;
                            }
                            else if (LeftHalf.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.LeftHalf;
                            }
                            else if (SECorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.SECorner;
                            }
                            else if (SWCorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.SWCorner;
                            }
                            else if (NECorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.NECorner;
                            }
                            else if (NWCorner.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.NWCorner;
                            }
                            else if (BattleTiles.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.Battle;
                            }
                            else if (WaterTiles.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                tilesCount[tilesCount.Count() - 1] = TileCollision.Water;
                                Water.IsActive = true;
                            }
                            else if (NpcTiles.Contains("[" + value1.ToString() + ":" + value2.ToString() + "-"))
                            {
                                string[] p    = NpcTiles.Split(']');
                                string   name = String.Empty;
                                foreach (string pstr in p)
                                {
                                    if (pstr.Contains("[" + value1.ToString() + ":" + value2.ToString() + "-"))
                                    {
                                        name = pstr.Substring(pstr.IndexOf('-') + 1);
                                        tilesCount[tilesCount.Count() - 1] = TileCollision.NPC;
                                        Vector2 npcLocation = new Vector2((int)Math.Floor(position.X / tileDimensions.X),
                                                                          (int)Math.Floor(position.Y / tileDimensions.Y));
                                        npcTiles.Add(npcLocation, name);
                                        npcName.Add(name, npcLocation);
                                    }
                                }
                            }
                            else if (PortalTiles.Contains("[" + value1.ToString() + ":" + value2.ToString() + "-"))
                            {
                                string[] p      = PortalTiles.Split(']');
                                string   value3 = String.Empty;
                                foreach (string pstr in p)
                                {
                                    if (pstr.Contains("[" + value1.ToString() + ":" + value2.ToString() + "-"))
                                    {
                                        value3 = pstr.Substring(pstr.IndexOf('-') + 1);
                                        tilesCount[tilesCount.Count() - 1] = TileCollision.Portal;
                                        portalTiles.Add(new Vector2((int)Math.Floor(position.X / tileDimensions.X),
                                                                    (int)Math.Floor(position.Y / tileDimensions.Y)), value3);
                                    }
                                }
                            }

                            tile.LoadContent(position, new Rectangle(
                                                 (int)(value1 * tileDimensions.X), (int)(value2 * tileDimensions.Y),
                                                 (int)tileDimensions.X, (int)tileDimensions.Y), tilesCount[tilesCount.Count() - 1]);


                            if (OverlayTiles.Contains("[" + value1.ToString() + ":" + value2.ToString() + "]"))
                            {
                                overlayTiles.Add(tile);
                            }
                            else
                            {
                                underlayTiles.Add(tile);
                            }

                            tileLength = tile.SourceRect.Width;
                        }
                    }
                }
            }
        }