コード例 #1
0
ファイル: FeatureCatalog.cs プロジェクト: weimingtom/Sakura
    public static Scene MakeManySpritesScene()
    {
        var tex1 = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/slime_green_frames.png", false)
                                   , new Vector2i(4, 4));

        var scene = new Scene()
        {
            Name = "many SpriteUV scene"
        };

        Bounds2 bounds = scene.Camera.CalcBounds();

        Vector2i num_cells = new Vector2i(8, 8);
        Vector2  cell_size = bounds.Size / num_cells.Vector2();

        Math.RandGenerator rgen   = new Math.RandGenerator();
        System.Random      random = new System.Random();

        for (int y = 0; y < num_cells.Y; ++y)
        {
            for (int x = 0; x < num_cells.X; ++x)
            {
                Vector2 uv = new Vector2((float)x, (float)y) / num_cells.Vector2();

                var sprite = new SpriteTile()
                {
                    TextureInfo = tex1
                    , Color     = Math.SetAlpha(new Vector4(0.5f) + rgen.NextVector4(Math._0000, Math._1111) * 0.5f, 0.75f)
                                  //, Color = Math.SetAlpha( new Vector4(0.5f), 1f/*0.75f*/ )
                    , BlendMode   = BlendMode.None
                    , TileIndex2D = new Vector2i(random.Next(0, 4),
                                                 random.Next(0, 4))
                };

                Vector2 p = bounds.Min + bounds.Size * uv;

                // init position/size
                sprite.Position = p;
                sprite.Quad.S   = cell_size;               // note: we don't want to touch the Node.Scale here
                sprite.Pivot    = sprite.Quad.S * 0.5f;

                sprite.Schedule((dt) =>
                {
                    sprite.Rotation = sprite.Rotation.Rotate(Math.Deg2Rad(1.0f));
                    sprite.Rotation = sprite.Rotation.Normalize();

                    if (Common.FrameCount % 8 == 0)
                    {
                        sprite.TileIndex1D = (sprite.TileIndex1D + 1) % 16;
                    }
                });

                scene.AddChild(sprite);
            }
        }

        scene.RegisterDisposeOnExit((System.IDisposable)tex1);

        return(scene);
    }
コード例 #2
0
    // Clears all active tiles on the grid and re-initializes it with fresh randomized tiles from the tile pool.
    public void ResetGrid()
    {
        _grid.Clear(_tilePool);
        GameSettings.LevelSettings settings = GameSettings.currentLevelSettings;

        _grid.ResizeGrid(settings.gridSize.x + 2, settings.gridSize.y + 2);
        int tileCount = settings.gridSize.x * settings.gridSize.y;

        SpriteTileInfo[] tiles = GetRandomTilePairs(settings.uniqueTileCount, tileCount);

        // Fill the grid leaving cells around the border empty
        for (int x = 1; x < _grid.columns - 1; x++)
        {
            for (int y = 1; y < _grid.rows - 1; y++)
            {
                int i = (y - 1) * (_grid.columns - 2) + (x - 1);

                if (tiles[i] != null)
                {
                    // Grab a new tile from the pool and initalize it
                    SpriteTile tile = _tilePool.Pop();
                    tile.SetSpriteTileInfo(tiles[i]);
                    tile.SetGridNode(_grid[x, y]);
                    tile.SetHighlighted(false);
                    tile.SetColliderEnabled(true);
                }
            }
        }

        // Make sure we haven't spawned a grid with an unwinnable pattern of tiles
        FixUnwinnables();
    }
コード例 #3
0
    // Looks for an 'x' pattern of tiles in the grid and swaps the tiles in any it finds so that it can be completed.
    void FixUnwinnables()
    {
        bool done = false;

        // Repeat until no cross patterns are detected
        do
        {
            done = true;

            for (int x = 1; x < _grid.columns - 2; x++)
            {
                for (int y = 1; y < _grid.rows - 2; y++)
                {
                    // Check for 'crosses' of tiles that result in an unwinnable puzzle.
                    // [ n3, n4 ]
                    // [ n1, n2 ]
                    GridNode n1 = _grid[x, y];
                    GridNode n2 = _grid[x + 1, y];
                    GridNode n3 = _grid[x, y + 1];
                    GridNode n4 = _grid[x + 1, y + 1];

                    // Pattern is unwinnable if n1 == n4 and n2 == n3
                    if (n1.tile != null && n2.tile != null && n3.tile != null && n4.tile != null && n1.tile.Matches(n4.tile) && n2.tile.Matches(n3.tile))
                    {
                        // Swap n1 and n2 to move the pattern
                        SpriteTile t = n2.tile;
                        n1.tile.SetGridNode(n2);
                        t.SetGridNode(n1);
                        done = false;
                    }
                }
            }
        } while(!done);
    }
コード例 #4
0
 public TileGenerator(bool givenPassable, String givenName, float givenVisibilityCoefficient, SpriteTile givenBitmap)
 {
     this.passable = givenPassable;
     this.name     = givenName;
     this.visibilityCoefficient = givenVisibilityCoefficient;
     this.tileBitmap            = givenBitmap;
 }
コード例 #5
0
 protected Tile(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : this(home, position)
 {
     this._myName = name;
     //this._visibilityCoefficient = visibilityCoefficient;
     this._myBitmap = myBitmap;
 }
コード例 #6
0
        public Player()
        {
            //load the player's sprite
            var tex1 = new TextureInfo(new Texture2D("/Application/data/tiles/machinegun_fire.png", false)
                                       , new Vector2i(14, 1));

            tex1.Texture.SetFilter(TextureFilterMode.Disabled);
            playerBodySprite             = new SpriteTile();
            playerBodySprite.TextureInfo = tex1;
            playerBodySprite.TileIndex2D = new Vector2i(0, 0);
            //playerBodySprite.BlendMode = BlendMode.None; //testing only


            //set up scale,position ect

            playerBodySprite.CenterSprite(new Vector2(0.2f, 0.1f));

            playerBodySprite.Pivot = new Vector2(0.08f, 0.0f);

            playerBodySprite.Scale = new Vector2(0.75f, 1.5f);

            this.AddChild(playerBodySprite);

            //Position = new Vector2 (MapManager.Instance.currentMap.width/2.0f, MapManager.Instance.currentMap.height/2.0f);

            var list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor);

            Position = list[Support.random.Next(0, list.Count - 1)].position;

            //get the local bounds of the sprite
            bounds = new Bounds2();
            playerBodySprite.GetlContentLocalBounds(ref bounds);
            bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f);
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: edhaker13/Flabola
        // Public functions.
        public Player(Scene scene)
        {
            textureInfo     = new TextureInfo(new Texture2D("/Application/assets/player-spritemap.png", false), new Vector2i(13, 1));
            sprite          = new SpriteTile(textureInfo);
            sprite.Position = new Vector2(AppMain.ScreenWidth * .2f, AppMain.ScreenHeight * .5f);
            sprite.Quad.S   = textureInfo.TileSizeInPixelsf;
            sprite.CenterSprite(TRS.Local.Center);
            // Player variables
            isAlive     = true;
            moveState   = MoveStatus.Disabled;
            rotateAngle = .0f;

            // Attach update fucntion to scheduler
            sprite.Schedule(Update);

            // Create animation function
            sprite.ScheduleInterval((dt) => {
                if (IsAlive)
                {
                    int tileIndex      = sprite.TileIndex1D < 8 ? sprite.TileIndex1D + 1 : 1;
                    sprite.TileIndex1D = tileIndex;
                }
            }, 0.2f);
            sprite.ScheduleInterval((dt) => {
                if (!IsAlive)
                {
                    int tileIndex      = sprite.TileIndex1D < 12 ? sprite.TileIndex1D + 1 : 12;
                    sprite.TileIndex1D = tileIndex;
                }
            }, 0.16f);

            // Add to the current scene.
            scene.AddChild(sprite);
        }
コード例 #8
0
 void PlayMatchEffect(SpriteTile t1, SpriteTile t2)
 {
     if (_matchEffect != null)
     {
         _matchEffect.PlayOneShot(_matchEffect.clip);
     }
 }
コード例 #9
0
 protected Tile(Map home, Coords position, TileGenerator generator)
     : this(home, position)
 {
     this._myName = generator.name;
     //this._visibilityCoefficient = generator.visibilityCoefficient;
     this._myBitmap = generator.tileBitmap;
 }
コード例 #10
0
        //public readonly float passability;

        public TileGenerator(String givenName, SpriteTile givenBitmap, TerrainType givenTerrainType, float givenVisibilityCoefficient)
        {
            //this.passability = givenPassability;
            this.terrainType           = givenTerrainType;           // this contains passability info
            this.name                  = givenName;
            this.visibilityCoefficient = givenVisibilityCoefficient; // visibility should be uniform across creatures?
            this.tileBitmap            = givenBitmap;
        }
コード例 #11
0
        public void initTitle()
        {
            this.Camera2D.SetViewFromViewport();

            logo          = new SpriteUV(new TextureInfo("/Application/data/logo.png"));
            logo.Scale    = logo.TextureInfo.TextureSizef * 1.8f;
            logo.Pivot    = new Vector2(0.5f, 0.5f);
            logo.Position = new Vector2((960.0f / 2.0f), (540.0f / 2.0f) + 80f);

            sprite_button_newgame          = new SpriteUV(new TextureInfo("/Application/data/button_newgame.png"));
            sprite_button_newgame.Scale    = sprite_button_newgame.TextureInfo.TextureSizef * 1.2f;
            sprite_button_newgame.Position = new Vector2((960.0f / 5.0f), (540.0f / 4.0f) - sprite_button_newgame.TextureInfo.TextureSizef.Y / 2.0f);

            sprite_button_tutorial          = new SpriteUV(new TextureInfo("/Application/data/button_tutorial.png"));
            sprite_button_tutorial.Scale    = sprite_button_newgame.TextureInfo.TextureSizef * 1.2f;
            sprite_button_tutorial.Position = new Vector2((960.0f / 2.0f), (540.0f / 4.0f) - sprite_button_newgame.TextureInfo.TextureSizef.Y / 2.0f);

            sprite_button_autoaim          = new SpriteUV(new TextureInfo("/Application/data/button_autoaimon.png"));
            sprite_button_autoaim.Scale    = sprite_button_newgame.TextureInfo.TextureSizef * 1.2f;
            sprite_button_autoaim.Position = new Vector2((960.0f / 2.0f) + (960.0f / 3.5f), (540.0f / 4.0f) - sprite_button_newgame.TextureInfo.TextureSizef.Y / 2.0f);

            sprite_button_newgame.Pivot  = new Vector2(0.5f, 0.5f);
            sprite_button_autoaim.Pivot  = new Vector2(0.5f, 0.5f);
            sprite_button_tutorial.Pivot = new Vector2(0.5f, 0.5f);

            Foreground.AddChild(sprite_button_newgame);
            Foreground.AddChild(sprite_button_tutorial);
            Foreground.AddChild(sprite_button_autoaim);
            Foreground.AddChild(logo);


            var tex     = new Texture2D("/Application/data/tiles/simple5.png", false);
            var texture = new TextureInfo(tex, new Vector2i(1, 13));

            menuBackground = new SpriteList(texture);

            int menuBackgroundWidth  = 100;
            int menuBackgroundHeight = 50;


            //mini background discofloor
            for (int x = 0; x < 30; x++)
            {
                for (int y = 0; y < 17; y++)
                {
                    SpriteTile bgTile = new SpriteTile(texture);
                    bgTile.TileIndex1D = Support.random.Next(4, 13);
                    bgTile.Position    = new Vector2((float)x * 32.0f, (float)y * 32.0f);
                    bgTile.Scale       = bgTile.TextureInfo.TileSizeInPixelsf * 2.0f;
                    bgTile.ScheduleInterval((dt) => { bgTile.TileIndex1D = Support.random.Next(4, 13); }, 0.2f, -1);
                    menuBackground.AddChild(bgTile);
                }
            }

            Background.AddChild(menuBackground);
        }
コード例 #12
0
    // Return the matched tiles to their source pool and trigger the all cleared event if there are no more tiles left on the grid.
    void OnTilesMatched(SpriteTile tile1, SpriteTile tile2)
    {
        _tilePool.Push(tile1);
        _tilePool.Push(tile2);

        if (_grid.tileCount == 0)
        {
            OnAllTilesCleared();
        }
    }
コード例 #13
0
ファイル: PlanetCute.cs プロジェクト: weimingtom/Sakura
        public SpriteTile NewObject(Vector2i index, Vector3 start_pos)
        {
            SpriteTile sprite = new SpriteTile();

            sprite.TextureInfo = ObjectsMap;
            sprite.TileIndex2D = index;
            sprite.Scale       = SpriteSize;
            sprite.Position    = GetCellPos(start_pos);
            return(sprite);
        }
コード例 #14
0
 public Tile(Map home, Coords position, TileGenerator generator)
     : this(home, position)
 {
     this._myName        = generator.name;
     this._myTerrainType = generator.terrainType;
     //this._passability = generator.passability;
     this._visibilityCoefficient = generator.visibilityCoefficient;
     this._myBitmap = generator.tileBitmap;
     _myInventory   = (Constants.APMoveCostsStandard[(sbyte)generator.terrainType] > 0) ? new Inventory(this, 1) : null;
 }
コード例 #15
0
    private IEnumerator AnimateTiles(Vector2[] points, float duration)
    {
        if (onAnimationStart != null)
        {
            onAnimationStart(this);
        }

        // Make sure we disable collisions with the matches tiles
        endTile.SetColliderEnabled(false);
        startTile.SetColliderEnabled(false);

        // Shift the start tile up slightly so it renders above other grid tiles and the line
        startTile.transform.position += new Vector3(0, 0, -0.2f);
        if (startTile.gridNode != null)
        {
            startTile.gridNode.Clear();
        }

        // Place the line between the depths of start and end
        _line = LinePoolManager.Instance.PopLine();
        SetLinePositions(_line, points, startTile.transform.position.z + 0.1f);

        for (int i = 0; i < points.Length - 1; i++)
        {
            float timer = 0f;
            // Pre-calculate the division
            float durationInverse = 1f / duration;

            while (timer <= 1f)
            {
                yield return(null);

                // Lerp between the two key points in the path based on the timer
                timer += Time.deltaTime * durationInverse;
                Vector3 newPos = (Vector3)Vector2.Lerp(points[i], points[i + 1], EaseSineInOut(timer));
                newPos.z = startTile.transform.position.z;
                startTile.transform.position = newPos;
            }
        }

        // Clean up
        _animationRoutine = null;
        LinePoolManager.Instance.PushLine(_line);
        _line = null;

        // Fire the end event before we destroy ourselves
        if (onAnimationEnd != null)
        {
            onAnimationEnd(this);
        }

        // Kill the animation script and tell the tiles to match with each other
        Destroy(this);
        SpriteTile.MatchTiles(startTile, endTile);
    }
コード例 #16
0
    // Start animating the tiles.  The 'start' tile will be removed from the grid immediately and moved along the given AStar path until it reaches 'end'
    // moveDuration is the duration it takes to travel along each straight line in the path.
    public void Play(SpriteTile start, SpriteTile end, IAStarNode[] path, float moveDuration = 0.4f)
    {
        if (!playing)
        {
            playing = true;

            startTile = start;
            endTile   = end;
            Vector2[] points = GetKeyWorldPoints(path);
            _animationRoutine = StartCoroutine(AnimateTiles(points, moveDuration));
        }
    }
コード例 #17
0
        public void initLevelSelect()
        {
            this.levelSelection = 0;

            this.Camera2D.SetViewFromViewport();

            //labels
            labels = new List <Support.CustomLabel> ();


            //mini background discofloor

            var tex     = new Texture2D("/Application/data/tiles/simple5.png", false);
            var texture = new TextureInfo(tex, new Vector2i(1, 13));

            var menuBackground = new SpriteList(texture);

            for (int x = 0; x < 30; x++)
            {
                for (int y = 0; y < 17; y++)
                {
                    SpriteTile bgTile = new SpriteTile(texture);
                    bgTile.TileIndex1D = Support.random.Next(4, 13);
                    bgTile.Position    = new Vector2((float)x * 32.0f, (float)y * 32.0f);
                    bgTile.Scale       = bgTile.TextureInfo.TileSizeInPixelsf * 2.0f;
                    bgTile.ScheduleInterval((dt) => {
                        bgTile.TileIndex1D = Support.random.Next(4, 13);
                    }, 0.2f, -1);
                    menuBackground.AddChild(bgTile);
                }
            }

            Background.AddChild(menuBackground);



            for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++)
            {
                //add thumbnail
                float newX        = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing);
                float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize);
                MapManager.Instance.predefinedMaps [i].thumbnailSprite.Scale    = new Vector2(scaleFactor, scaleFactor);
                MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position = new Vector2(newX, 544.0f / 2.0f);

                Foreground.AddChild(MapManager.Instance.predefinedMaps [i].thumbnailSprite);

                //add label:
                var tempLabel = new Support.CustomLabel(new Vector2(newX, 544.0f / 2.0f - thumbnailSize * 0.6f), "Level " + (i + 1) + "\nHighscore: 0", SceneManager.UIFontMap);
                labels.Add(tempLabel);

                Foreground.AddChild(tempLabel);
            }
        }
コード例 #18
0
 public virtual void Copy(SpriteRoot s)
 {
     if (!this.managed)
     {
         if (this.m_spriteMesh != null && s.spriteMesh != null)
         {
             ((SpriteMesh)this.m_spriteMesh).material = s.spriteMesh.material;
         }
         else if (!s.managed)
         {
             base.renderer.sharedMaterial = s.renderer.sharedMaterial;
         }
     }
     this.drawLayer = s.drawLayer;
     if (s.renderCamera != null)
     {
         this.SetCamera(s.renderCamera);
     }
     if (this.renderCamera == null)
     {
         this.renderCamera = Camera.main;
     }
     if (this.m_spriteMesh != null)
     {
         if (this.m_spriteMesh.texture != null)
         {
             this.SetPixelToUV(this.m_spriteMesh.texture);
         }
         else if (!this.managed)
         {
             ((SpriteMesh)this.m_spriteMesh).material = base.renderer.sharedMaterial;
             this.SetPixelToUV(this.m_spriteMesh.texture);
         }
     }
     this.plane             = s.plane;
     this.winding           = s.winding;
     this.offset            = s.offset;
     this.anchor            = s.anchor;
     this.bleedCompensation = s.bleedCompensation;
     this.autoResize        = s.autoResize;
     this.pixelPerfect      = s.pixelPerfect;
     this.uvRect            = s.uvRect;
     this.scaleFactor       = s.scaleFactor;
     this.topLeftOffset     = s.topLeftOffset;
     this.bottomRightOffset = s.bottomRightOffset;
     this.width             = s.width;
     this.height            = s.height;
     this.m_sprTile         = s.m_sprTile;
     this.m_v3TotalVertices = s.m_v3TotalVertices;
     this.SetColor(s.color);
 }
コード例 #19
0
ファイル: Animation.cs プロジェクト: PssProgram/Lost-In-Trek
        public Animation(SpriteTile sprite, int a, int b, float seconds, bool loop)
        {
            this.loop = loop;
            speed     = 1.0f;

            actionSprite = sprite;

            int min    = System.Math.Min(a, b);         //最大值
            int max    = System.Math.Max(a, b);         //最小值
            int frames = System.Math.Max(1, max - min); //帧数

            frame_time = seconds;
            start      = min;
            end        = max;
        }
コード例 #20
0
ファイル: Animation.cs プロジェクト: PssProgram/Lost-In-Trek
        public Animation(SpriteTile sprite, int a, int b, float seconds, bool loop)
        {
            this.loop = loop;
            speed = 1.0f;

            actionSprite = sprite;

            int min = System.Math.Min(a,b);//最大值
            int max = System.Math.Max(a,b);//最小值
            int frames = System.Math.Max(1, max - min);//帧数

            frame_time = seconds;
            start = min;
            end = max;
        }
コード例 #21
0
ファイル: Obstacle.cs プロジェクト: edhaker13/Flabola
        // Public functions.
        public Obstacle(float startX, Scene scene)
        {
            textureInfo = new TextureInfo(new Texture2D("/Application/assets/zombie_pipes.png", false), new Vector2i(4, 8));

            sprites = new SpriteTile[2];

            // Top
            sprites[0]             = new SpriteTile(textureInfo);
            sprites[0].Quad.S      = textureInfo.TileSizeInPixelsf;
            sprites[0].TileIndex2D = new Vector2i(0, (int)RandomPosition(0f, 4f));
            // Add to the current scene.
            scene.AddChild(sprites[0]);

            // Bottom
            sprites[1]             = new SpriteTile(textureInfo);
            sprites[1].Quad.S      = textureInfo.TileSizeInPixelsf;
            sprites[1].TileIndex2D = new Vector2i(0, (int)RandomPosition(0f, 4f));
            // Add to the current scene.
            scene.AddChild(sprites[1]);

            // Get sprite bounds.
            Bounds2 b = sprites[0].Quad.Bounds2();

            width  = b.Point10.X;
            height = b.Point11.Y;

            // Position pipes.
            sprites[0].Position = new Vector2(startX, AppMain.ScreenHeight * RandomPosition(0.5f, 1.0f - height / AppMain.ScreenHeight / 2));
            sprites[1].Position = new Vector2(startX, AppMain.ScreenHeight * RandomPosition(-height / AppMain.ScreenHeight / 2, 0.4f));
            // Position gap rect
            pipeGap = new Bounds2(new Vector2(sprites[1].Position.X, sprites[1].Position.Y + height),
                                  new Vector2(sprites[0].Position.X + width, sprites[0].Position.Y));
            isGapOccupied = false;

            sprites[0].Schedule(Update);
            // Animations
            sprites[0].ScheduleInterval((dt) => {
                int tileIndex          = sprites[0].TileIndex2D.X < 4 ? sprites[0].TileIndex2D.X + 1: 0;
                sprites[0].TileIndex2D = new Vector2i(sprites[0].TileIndex2D.Y, tileIndex);
            }, 0.25f);
            sprites[1].Schedule(Update);
            sprites[0].ScheduleInterval((dt) => {
                int tileIndex          = sprites[1].TileIndex2D.X < 4 ? sprites[1].TileIndex2D.X + 1: 0;
                sprites[1].TileIndex2D = new Vector2i(sprites[1].TileIndex2D.Y, tileIndex);
            }, 0.25f);
        }
コード例 #22
0
ファイル: PlanetCute.cs プロジェクト: weimingtom/Sakura
        public SpriteTile NewTree(Vector2i index, Vector3 start_pos)
        {
            SpriteTile sprite = NewObject(index, start_pos);

            // make the sprite bottom center point be the new pivot (for Skew)
            sprite.Quad.Centering(TRS.Local.BottomCenter);

            // make the trees move in the wind
            Schedule((dt) => {
                int hc             = sprite.GetHashCode();
                System.Random rnd2 = new System.Random(hc);

                sprite.Skew = new Vector2(Math.Deg2Rad(1.0f) * FMath.Sin((float)Director.Instance.DirectorTime * 1.0f * rnd2.Next(4096) / 4096.0f),
                                          Math.Deg2Rad(2.0f) * FMath.Sin((float)Director.Instance.DirectorTime * 3.0f * rnd2.Next(4096) / 4096.0f));
            });

            return(sprite);
        }
コード例 #23
0
    void OnTileClicked(SpriteTile sender)
    {
        if (_currentTile != null)
        {
            if (sender == _currentTile)
            {
                // Deselect if we click the same tile again
                SetCurrentTile(null);
            }
            else if (sender.Matches(_currentTile))
            {
                int turns = int.MaxValue;

                // Temporarily set the target node to be walkable before pathfinding since AStar needs to be able to walk onto the node to find it.
                float oldWeight = sender.gridNode.pathfindingWeight;
                sender.gridNode.pathfindingWeight = 1;
                IAStarNode[] path = AStar.CalculatePath(_currentTile.gridNode, sender.gridNode, out turns);
                sender.gridNode.pathfindingWeight = oldWeight;

                if (turns <= GameSettings.maxPathfindingTurns)
                {
                    // If it's a valid match spawn a MatchAnimation and play it
                    _currentTile.gameObject.AddComponent <MatchAnimation>().Play(_currentTile, sender, path);
                    SetCurrentTile(null);
                }
                else
                {
                    // If the path has too many turns simply select the tile instead
                    SetCurrentTile(sender);
                }
            }
            else
            {
                // Tile's don't match, select the new one
                SetCurrentTile(sender);
            }
        }
        else
        {
            // We don't have a selected tile yet, select the new one
            SetCurrentTile(sender);
        }
    }
コード例 #24
0
        public Tank(Scene scene)
        {
            // Tank Base
            texture2D   = new Texture2D("/Application/Assets/tankBase2.png", false);
            numTiles    = new Vector2i(1, 1);      // tiles in the sprite sheet
            tiles       = new Vector2i(0, 0);      // tile you are displaying
            textureInfo = new TextureInfo(texture2D, numTiles);
            sprite      = new SpriteTile(textureInfo);

            sprite.Quad.S      = new Vector2(textureInfo.TextureSizef.X, textureInfo.TextureSizef.Y);
            sprite.TileIndex2D = tiles;             // sets which tile you are viewing
            sprite.CenterSprite();

            // tank turret
            turretTex     = new TextureInfo("/Application/Assets/tankTurret2.png");
            turret        = new SpriteUV(turretTex);
            turret.Quad.S = turretTex.TextureSizef;
            turret.CenterSprite(TRS.Local.Center);

            if (SceneManager.Instance.rand.NextDouble() > 0.5)
            {
                leftRight = true;
                sprite.Rotate((float)System.Math.PI / 2);
                //turret.Rotate((float)System.Math.PI/2);
            }
            else
            {
                leftRight = false;
                sprite.Rotate(-(float)System.Math.PI / 2);
                //turret.Rotate(-(float)System.Math.PI/2);
            }

            speed    = (float)SceneManager.Instance.rand.NextDouble() * 800.0f;
            position = new Vector2(300.0f, 300.0f);
            minSpeed = 100;
            maxSpeed = 200;
            setRandom();


            scene.AddChild(sprite);
            scene.AddChild(turret);
        }
コード例 #25
0
        public Foreground(float x, Scene scene)
        {
            seaweedInfo = new TextureInfo(new Texture2D("/Application/textures/seaweed.png", false),
                                          new Vector2i(3, 1), TRS.Quad0_1);
            seawead        = new SpriteTile(seaweedInfo);
            seawead.Quad.S = seaweedInfo.TileSizeInPixelsf;

            scene.AddChild(seawead);

            seawead.TileIndex2D = new Vector2i(0, 0);

            //Get sprite bounds.
            Bounds2 b = seawead.Quad.Bounds2();

            width  = b.Point10.X;
            height = b.Point01.Y;

            seawead.Position = new Vector2(x, -20.0f);
            count            = 0;
        }
コード例 #26
0
        public LevelFlag() : base()
        {
            textureInfo = new TextureInfo(new Texture2D("/Application/textures/Level/levelFlag.png", false), new Vector2i(4, 1));

            sprite        = new SpriteTile(textureInfo);
            sprite.Quad.S = textureInfo.TileSizeInPixelsf;
            sprite.Scale  = new Vector2(1.7f, 1.7f);

            tileIndex = 0;

            sprite.ScheduleInterval((dt) =>
            {
                if (tileIndex >= 4)
                {
                    tileIndex = 0;
                }

                sprite.TileIndex2D = new Vector2i(tileIndex, 0);
                tileIndex++;
            }, 0.12f);
        }
コード例 #27
0
        public BlackHole() : base()
        {
            textureInfo = new TextureInfo(new Texture2D("/Application/textures/Level/BlackHoles.png", false), new Vector2i(4, 1));

            sprite        = new SpriteTile(textureInfo);
            sprite.Quad.S = textureInfo.TileSizeInPixelsf;
            //sprite.Pivot  = new Vector2(sprite.Quad.S.X/2, sprite.Quad.S.Y/2);

            tileIndex = 0;

            sprite.ScheduleInterval((dt) =>
            {
                if (tileIndex >= 4)
                {
                    tileIndex = 0;
                }

                sprite.TileIndex2D = new Vector2i(tileIndex, 0);
                tileIndex++;
            }, 0.10f);
        }
コード例 #28
0
ファイル: Map.cs プロジェクト: gambiting/VitaShooter
        /*
         * returns a sprite constructed from the given tile name
         * tile needs to be part of the given texture
         * */
        public SpriteTile returnSpriteFromTile(MapTile.Types tileName, TextureInfo texture)
        {
            //get the location from the dictionary
            Vector2i textureLocation;

            if (!tileLocations.TryGetValue(tileName, out textureLocation))
            {
                //if there was no such tile in the dictionary then set the location to 0,0 as a failsafe
                textureLocation = new Vector2i(1, 0);
            }

            var rand = new Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.RandGenerator();

            //construct the sprite using given texture and knowing the location of the tile in the tilemap
            var sprite = new SpriteTile()
            {
                TextureInfo   = texture
                , TileIndex2D = textureLocation
            };

            return(sprite);
        }
コード例 #29
0
        public Gem() : base()
        {
            textureInfo = new TextureInfo(new Texture2D("/Application/textures/Level/gem.png", false), new Vector2i(8, 1));

            sprite        = new SpriteTile(textureInfo);
            sprite.Quad.S = textureInfo.TileSizeInPixelsf;

            tileIndex = 0;

            scoreValue = 200;

            sprite.ScheduleInterval((dt) =>
            {
                if (tileIndex >= 6)
                {
                    tileIndex = 0;
                }

                sprite.TileIndex2D = new Vector2i(tileIndex, 0);
                tileIndex++;
            }, 0.12f);
        }
コード例 #30
0
        public LaserGate(int random) : base()
        {
            textureInfo = new TextureInfo(new Texture2D("/Application/textures/Level/LaserBeams.png", false), new Vector2i(18, 1));

            sprite        = new SpriteTile(textureInfo);
            sprite.Quad.S = textureInfo.TileSizeInPixelsf;

            //sprite.Pivot = new Vector2(sprite.Quad.S.X/2, sprite.Quad.S.Y/2);

            tileIndex = random;

            sprite.ScheduleInterval((dt) =>
            {
                if (tileIndex >= 18)
                {
                    tileIndex = 0;
                }

                sprite.TileIndex2D = new Vector2i(tileIndex, 0);
                tileIndex++;
            }, 0.10f);
        }
コード例 #31
0
    // Triggers two tiles to be matched and fires the onTileMatched event.
    public static void MatchTiles(SpriteTile tile1, SpriteTile tile2)
    {
        // Make sure both tiles are cleared from the grid
        if (tile1._currentNode != null)
        {
            tile1._currentNode.Clear();
        }
        if (tile2._currentNode != null)
        {
            tile2._currentNode.Clear();
        }

        // Add score for each tile
        GameSettings.score += tile1._info.pointValue;
        GameSettings.score += tile2._info.pointValue;

        // Fire the match event.  The GridController handles returning the tiles to their object pool.
        if (onTilesMatched != null)
        {
            onTilesMatched(tile1, tile2);
        }
    }
コード例 #32
0
ファイル: Animation.cs プロジェクト: PssProgram/Lost-In-Trek
        public static int IncrementTile(SpriteTile sprite, int steps, int min, int max, bool loop)
        {
            int x = sprite.TextureInfo.NumTiles.X;
            int y = sprite.TextureInfo.NumTiles.Y;

            int current = sprite.TileIndex2D.X + sprite.TileIndex2D.Y * x;

            if (loop)
            {
                current -= min;
                current += steps;
                current %= max - min;
                current += min;
            }
            else
            {
                current += steps;
                current = System.Math.Min(current, max);
            }

            sprite.TileIndex1D = current;

            return current;
        }
コード例 #33
0
 public TileGenerator(bool givenPassable, String givenName, float givenVisibilityCoefficient, SpriteTile givenBitmap)
 {
     this.passable = givenPassable;
     this.name = givenName;
     this.visibilityCoefficient = givenVisibilityCoefficient;
     this.tileBitmap = givenBitmap;
 }
コード例 #34
0
 protected Tile(Map home, Coords position, TileGenerator generator)
     : this(home, position)
 {
     this._myName = generator.name;
     //this._visibilityCoefficient = generator.visibilityCoefficient;
     this._myBitmap = generator.tileBitmap;
 }
コード例 #35
0
 protected Tile(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : this(home, position)
 {
     this._myName = name;
     //this._visibilityCoefficient = visibilityCoefficient;
     this._myBitmap = myBitmap;
 }
コード例 #36
0
 public TileImpassable(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : base(home, position, name, visibilityCoefficient, myBitmap)
 {
 }
コード例 #37
0
 public TilePassable(Map home, Coords position, String name, float visibilityCoefficient, SpriteTile myBitmap)
     : base(home, position, name, visibilityCoefficient, myBitmap)
 {
     this._myInventory = new Inventory(this);
 }
コード例 #38
0
ファイル: Animation.cs プロジェクト: PssProgram/Lost-In-Trek
 public Animation(SpriteTile sprite,float seconds)
     : this(sprite, 0, sprite.TextureInfo.NumTiles.X * sprite.TextureInfo.NumTiles.Y - 1, seconds,true)
 {
 }
コード例 #39
0
ファイル: Animation.cs プロジェクト: PssProgram/Lost-In-Trek
 public static void SetTile(SpriteTile sprite, int n)
 {
     sprite.TileIndex1D = n;
 }