Exemplo n.º 1
0
        public Obstacle(int x, int y, Vector2 size, Vector2 mapSize, Animation animation,
                        SpriteSheet ss, Vector2 scale, bool solid, GraphicsContext g) :
            base((int)(g.Screen.Width / 2 - mapSize.X / 2 + x), (int)(y + 24 * scale.Y), (int)(size.X), (int)(size.Y), animation)
        {
            //this.position.x = this.position.x - 8 * scale;
            //this.position.y = this.position.y + 24 * scale;
            this.solid = solid;

            ss = new SpriteSheet(ss.getImage().Resize(new ImageSize((int)(ss.getWidth() * scale.X),
                                                                    (int)(ss.getHeight() * scale.Y))));

            Sprite[] obstacle = { ss.obtenerSprite((int)(2 * size.X), 0, (int)(size.X), (int)(size.Y), g) };
            a1 = new Animation(obstacle, 1, Animation.Direction.DOWN);

            Sprite[] explosion = { ss.obtenerSprite((int)(size.X * 7),  (int)(size.Y), (int)(size.X), (int)(size.Y), g),
                                   ss.obtenerSprite((int)(size.X * 8),  (int)(size.Y), (int)(size.X), (int)(size.Y), g),
                                   ss.obtenerSprite((int)(size.X * 9),  (int)(size.Y), (int)(size.X), (int)(size.Y), g),
                                   ss.obtenerSprite((int)(size.X * 10), (int)(size.Y), (int)(size.X), (int)(size.Y), g),
                                   ss.obtenerSprite((int)(size.X * 11), (int)(size.Y), (int)(size.X), (int)(size.Y), g),
                                   ss.obtenerSprite((int)(size.X * 12), (int)(size.Y), (int)(size.X), (int)(size.Y), g),
                                   ss.obtenerSprite((int)(size.X * 13), (int)(size.Y), (int)(size.X), (int)(size.Y), g) };

            a2 = new Animation(explosion, 6, Animation.Direction.DOWN);

            Sprite[] blink = { ss.obtenerSprite((int)(2 * size.X),             0, (int)(size.X), (int)(size.Y), g),
                               ss.obtenerSprite((int)(size.X * 7), (int)(size.Y), (int)(size.X), (int)(size.Y), g) };

            a3 = new Animation(blink, 20, Animation.Direction.DOWN);

            this.animation = a1;
        }
Exemplo n.º 2
0
        public Score(int score, int w, int h, GraphicsContext g, Vector2 scale)
        {
            this.g     = g;
            this.scale = scale;
            int pos = 0;

            if (score % 1000 == 0)
            {
                pos = (int)(Math.Log(score / 1000) / Math.Log(2)) + 7;
            }
            else
            {
                pos = (int)(Math.Log(score / 100) / Math.Log(2));
            }

            this.sl = new SpriteLoader();
            this.sl.cargarImagen(this.score);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scale.X),
                                                                (int)(sl.getImage().Size.Height *scale.Y))));
            this.ss = new SpriteSheet(this.sl.getImage());

            scoreImg = ss.obtenerSprite((int)(pos * W * scale.X), 0, (int)(W * scale.X), (int)(H * scale.Y));

            scoreFinal = new Image(ImageMode.Rgba, new ImageSize((int)(w * scale.X), (int)(h * scale.Y)), new ImageColor(0, 0, 0, 0));
            scoreFinal.DrawImage(scoreImg, new ImagePosition((int)(w * scale.X / 2 - W * scale.X / 2),
                                                             (int)(h * scale.Y / 2 - H * scale.Y / 2)));

            Texture2D texture = new Texture2D(scoreFinal.Size.Width, scoreFinal.Size.Height, false, PixelFormat.Rgba);

            texture.SetPixels(0, scoreFinal.ToBuffer(), PixelFormat.Rgba);
            scoreSprite = new Sprite(g, texture);
        }
Exemplo n.º 3
0
        public MapMenu(int level, int map, GraphicsContext g, Vector2 scales) : base(g, scales, new Vector4(0, 0, 0, 255))
        {
            this.sl = new SpriteLoader();
            this.sl.cargarImagen(sprites);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scales.X),
                                                                (int)(sl.getImage().Size.Height *scales.Y))));
            this.ss = new SpriteSheet(this.sl.getImage());

            this.stage      = ss.obtenerSprite(0, 0, (int)(79 * scales.X), (int)(13 * scales.Y), g);
            this.game_start = ss.obtenerSprite(0, (int)(14 * scales.Y), (int)(107 * scales.X), (int)(13 * scales.Y), g);
            this.level      = ss.obtenerSprite((int)(8 * level * scales.X), (int)(28 * scales.Y), (int)(6 * scales.X), (int)(13 * scales.Y), g);
            this.map        = ss.obtenerSprite((int)(8 * map * scales.X), (int)(28 * scales.Y), (int)(6 * scales.X), (int)(13 * scales.Y), g);

            sound = new MP3Player("/Application/res/sound/map_start.mp3");
            sound.play();
            //MP3Player.map_start.play();
            this.clock = new Stopwatch();
            this.clock.Start();
        }
Exemplo n.º 4
0
        public void loadTiles(SpriteSheet s)
        {
            try {
                tileset = s;

                int numTilesAcross = (tileset.getWidth() + 1) / tileSize;
                tiles = new Tile[2, numTilesAcross];

                Image subimage;
                for (int col = 0; col < numTilesAcross; col++)
                {
                    subimage = tileset.obtenerSprite(col * tileSize, 0, tileSize,
                                                     tileSize);
                    tiles[0, col] = new Tile(subimage, false);
                    subimage      = tileset.obtenerSprite(col * tileSize, tileSize,
                                                          tileSize, tileSize);
                    tiles[1, col] = new Tile(subimage, true);
                }
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
            }
        }
Exemplo n.º 5
0
        private void loadTiles()
        {
            try {
                int numTilesAcross = (tileset.getWidth() + 1) / TILE_SIZE;
                font = new Sprite[2, numTilesAcross];
                shad = new Sprite[2, numTilesAcross];

                Image  subimage, shadowImage;
                Sprite aux;

                for (int col = 0; col < numTilesAcross; col++)
                {
                    subimage = tileset.obtenerSprite(col * TILE_SIZE, 0, TILE_SIZE, TILE_SIZE);
                    aux      = ImageToSprite(subimage.Resize(new ImageSize((int)(subimage.Size.Width * scale.X), (int)(subimage.Size.Height * scale.Y))), g);
                    aux.SetColor(color);
                    font[0, col] = aux;

                    subimage = tileset.obtenerSprite(col * TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE);
                    aux      = ImageToSprite(subimage.Resize(new ImageSize((int)(subimage.Size.Width * scale.X), (int)(subimage.Size.Height * scale.Y))), g);
                    aux.SetColor(color);
                    font[1, col] = aux;

                    if (shadows)
                    {
                        shadowImage = tileset.obtenerSprite(col * TILE_SIZE, 0, TILE_SIZE, TILE_SIZE);
                        aux         = ImageToSprite(shadowImage.Resize(new ImageSize((int)(shadowImage.Size.Width * scale.X), (int)(shadowImage.Size.Height * scale.Y))), g);
                        aux.SetColor(new Vector4(0, 0, 0, 255));
                        shad[0, col] = aux;

                        shadowImage = tileset.obtenerSprite(col * TILE_SIZE, TILE_SIZE, TILE_SIZE, TILE_SIZE);
                        aux         = ImageToSprite(shadowImage.Resize(new ImageSize((int)(shadowImage.Size.Width * scale.X), (int)(shadowImage.Size.Height * scale.Y))), g);
                        aux.SetColor(new Vector4(0, 0, 0, 255));
                        shad[1, col] = aux;
                    }
                }
            } catch (Exception e) {
                Console.Error.WriteLine(e.Message);
            }
        }
Exemplo n.º 6
0
        public PasswordMenu(TitleMenu titleMenu, GraphicsContext g, Vector2 scales) : base(g, scales, new Vector4(73, 102, 192, 255))
        {
            this.menu = titleMenu;
            //this.scale = scale;
            this.font1    = new Font(new Vector4(255, 255, 255, 255), true, scales, g);
            this.password = new String[8];

            this.sl = new SpriteLoader();
            this.sl.cargarImagen(cursor);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scales.X),
                                                                (int)(sl.getImage().Size.Height *scales.Y))));

            this.ss = new SpriteSheet(this.sl.getImage());

            Sprite[] bomb = { ss.obtenerSprite(0,                    0, (int)(20 * scales.X), (int)(23 * scales.Y), g),
                              ss.obtenerSprite((int)(20 * scales.X), 0, (int)(20 * scales.X), (int)(23 * scales.Y), g),
                              ss.obtenerSprite((int)(40 * scales.X), 0, (int)(22 * scales.X), (int)(23 * scales.Y), g) };
            this.bomb = new Animation(bomb, 10);

            passwords = new String[8, 8];

            using (StreamReader sr = new StreamReader(File.OpenRead("/Application/res/maps/definitions/passwords.txt")))
            {
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        string line = Convert.ToString(sr.ReadLine());
                        passwords[i, j] = line.Substring(line.Length - 8);
                    }
                }
                sr.Dispose();
            }

            backgroundColor = Textures.CreateTexture(g.Screen.Width, g.Screen.Height, g, bgColor);

            this.bomb.start();
        }
Exemplo n.º 7
0
        public LevelMenu(int level, GraphicsContext g, Vector2 scales) : base(g, scales, new Vector4(0, 0, 0, 0))
        {
            this.lev = level;

            this.sl = new SpriteLoader();
            this.sl.cargarImagen(sprites);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scales.X),
                                                                (int)(sl.getImage().Size.Height *scales.Y))));
            this.ss = new SpriteSheet(this.sl.getImage());

            this.bg    = ss.obtenerSprite(0, 0, (int)(256 * scales.X), (int)(160 * scales.Y), g);
            this.round = ss.obtenerSprite((int)(76 * scales.X), (int)(161 * scales.Y), (int)(49 * scales.X), (int)(14 * scales.Y), g);
            this.level = ss.obtenerSprite((int)(12 * (level - 1) * scales.X + 134 * scales.X), (int)(160 * scales.Y),
                                          (int)(12 * scales.X), (int)(14 * scales.Y), g);

            // TODO Arreglar parpadeo de ronda y nivel
            int    scale    = 2;
            Sprite levelaux = ss.obtenerSprite(12 * (level - 1) * scale + 134 * scale, 160 * scale, 12 * scale, 14 * scale, g);

            levelaux.SetColor(new Vector4(0, 0, 0, 255));
            Sprite roundaux = ss.obtenerSprite(76 * scale, 161 * scale, 49 * scale, 14 * scale, g);

            roundaux.SetColor(new Vector4(0, 0, 0, 255));

            Sprite[] roundFlicker = { this.round, roundaux };
            Sprite[] levelFlicker = { this.level, levelaux };
            Sprite[] head         = { ss.obtenerSprite(1,            (int)(160 * scales.Y), (int)(23 * scales.X), (int)(23 * scales.Y), g),
                                      ss.obtenerSprite((int)(23 * scales.X), (int)(160 * scales.Y), (int)(24 * scales.X), (int)(23 * scales.Y), g),
                                      ss.obtenerSprite((int)(48 * scales.X), (int)(160 * scales.Y), (int)(24 * scales.X), (int)(23 * scales.Y), g) };

            this.head         = new Animation(head, 12);
            this.roundFlicker = new Animation(roundFlicker, 5);
            this.levelFlicker = new Animation(levelFlicker, 5);

            switch (level)
            {
            case 1:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 18 * scales.X);
                this.y = (int)(134 * scales.Y);
                break;

            case 2:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 48 * scales.X);
                this.y = (int)(112 * scales.Y);
                break;

            case 3:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 66 * scales.X);
                this.y = (int)(168 * scales.Y);
                break;

            case 4:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 104 * scales.X);
                this.y = (int)(128 * scales.Y);
                break;

            case 5:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 154 * scales.X);
                this.y = (int)(120 * scales.Y);
                break;

            case 6:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 210 * scales.X);
                this.y = (int)(138 * scales.Y);
                break;

            case 7:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 210 * scales.X);
                this.y = (int)(104 * scales.Y);
                break;

            case 8:
                this.x = (int)(graphics.Screen.Width / 2 - this.bg.Width / 2 + 210 * scales.X);
                this.y = (int)(62 * scales.Y);
                break;
            }
            this.head.start();
            this.roundFlicker.start();
            this.levelFlicker.start();

            //MP3Player.level_start.play();
            this.sound = new MP3Player("/Application/res/sound/level_start.mp3");
            this.sound.play();

            this.clock = new Stopwatch();
            this.clock.Start();
        }
Exemplo n.º 8
0
        public GameOverMenu(int lives, int level, int map, GraphicsContext g, Vector2 scales) : base(g, scales, new Vector4(0, 97, 146, 255))
        {
            this.lives       = lives;
            this.level       = level;
            this.map         = map;
            this.options[0] += " " + lives;
            this.font        = new Font(new Vector4(255, 255, 255, 255), true, scales, g);

            // Ultimo continue
            if (lives == -1)
            {
                options[0] = "Continue last";
                this.font  = new Font(new Vector4(255, 0, 0, 255), true, scales, g);
            }

            // No hay mas continues
            if (lives == -2)
            {
                options = new String[] { "End" };
            }

            // Buscar password
            using (StreamReader sr = new StreamReader(File.OpenRead("/Application/res/maps/definitions/passwords.txt")))
            {
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if (level == i + 1 && map == j + 1)
                        {
                            string line = Convert.ToString(sr.ReadLine());
                            this.password = line.Substring(line.Length - 8);
                            goto found;
                        }
                        //else
                        //sr.Read();
                    }
                }
            }

            found : this.sl = new SpriteLoader();
            this.sl.cargarImagen(sprites);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scales.X),
                                                                (int)(sl.getImage().Size.Height *scales.Y))));

            this.ss = new SpriteSheet(this.sl.getImage());

            this.bg    = ss.obtenerSprite(0, 0, (int)(193 * scales.X), (int)(65 * scales.Y), g);
            this.title = ss.obtenerSprite(0, (int)(65 * scales.Y), (int)(156 * scales.X), (int)(27 * scales.Y), g);

            this.sl.cargarImagen(cursor);
            this.sl.setImage(sl.getImage().Resize(new ImageSize((int)(sl.getImage().Size.Width *scales.X),
                                                                (int)(sl.getImage().Size.Height *scales.Y))));
            this.ss = new SpriteSheet(this.sl.getImage());

            this.cu = this.sl.ImageToSprite(g);

            backgroundColor = Textures.CreateTexture(g.Screen.Width, g.Screen.Height, g, bgColor);

            this.passfont = new Font(new Vector4(255, 255, 255, 255), true, scales, g);
            //MP3Player.no_continue.play();
        }