Example #1
0
        public override void create()
        {
            base.create();

            ImgGibs=FlxG.Content.Load<Texture2D>("Mode/spawner_gibs");

            _timer = 0;
            _fading = false;
            FlxG.flash.start(new Color(0xd8, 0xeb, 0xa2));

            //Gibs emitted upon death
            FlxEmitter gibs = new FlxEmitter(0,-50);
            gibs.setSize(FlxG.width,0);
            gibs.setXSpeed();
            gibs.setYSpeed(0,100);
            gibs.setRotation(-360,360);
            gibs.gravity = 80;
            gibs.createSprites(ImgGibs,800);
            add(gibs);
            gibs.start(false,0.005f);

            add((new FlxText(0,FlxG.height/3,FlxG.width,"VICTORY\nSCORE: "+FlxG.score)).setFormat(null,3,new Color(0xd8, 0xeb, 0xa2), FlxJustification.Center, Color.Black));
        }
Example #2
0
        public override void create()
        {
            base.create();

            ImgTech=FlxG.Content.Load<Texture2D>("Mode/tech_tiles");
            ImgDirtTop=FlxG.Content.Load<Texture2D>("Mode/dirt_top");
            ImgDirt=FlxG.Content.Load<Texture2D>("Mode/dirt");
            ImgNotch=FlxG.Content.Load<Texture2D>("Mode/notch");
            ImgGibs=FlxG.Content.Load<Texture2D>("Mode/gibs");
            ImgSpawnerGibs = FlxG.Content.Load<Texture2D>("Mode/spawner_gibs");

            FlxG.mouse.hide();
            reload = false;

            //get the gibs set up and out of the way
            _littleGibs = new FlxEmitter();
            _littleGibs.delay = 3;
            _littleGibs.setXSpeed(-150,150);
            _littleGibs.setYSpeed(-200,0);
            _littleGibs.setRotation(-720,-720);
            _littleGibs.createSprites(ImgGibs,100,true,0.5f,0.65f);
            _bigGibs = new FlxEmitter();
            _bigGibs.setXSpeed(-200,200);
            _bigGibs.setYSpeed(-300,0);
            _bigGibs.setRotation(-720,-720);
            _bigGibs.createSprites(ImgSpawnerGibs,50,true,0.5f,0.35f);

            //level generation needs to know about the spawners (and thusly the bots, players, etc)
            _blocks = new FlxGroup();
            _decorations = new FlxGroup();
            _bullets = new FlxGroup();
            _player = new Player(316,300,_bullets.members,_littleGibs);
            _bots = new FlxGroup();
            _botBullets = new FlxGroup();
            _spawners = new FlxGroup();

            //simple procedural level generation
            int i;
            int r = 160;
            FlxTileblock b;

            b = new FlxTileblock(0,0,640,16);
            b.loadGraphic(ImgTech);
            _blocks.add(b);

            b = new FlxTileblock(0,16,16,640-16);
            b.loadGraphic(ImgTech);
            _blocks.add(b);

            b = new FlxTileblock(640-16,16,16,640-16);
            b.loadGraphic(ImgTech);
            _blocks.add(b);

            b = new FlxTileblock(16,640-24,640-32,8);
            b.loadGraphic(ImgDirtTop);
            _blocks.add(b);

            b = new FlxTileblock(16,640-16,640-32,16);
            b.loadGraphic(ImgDirt);
            _blocks.add(b);

            buildRoom(r * 0, r * 0, true);
            buildRoom(r*1,r*0);
            buildRoom(r*2,r*0);
            buildRoom(r * 3, r * 0, true);
            buildRoom(r * 0, r * 1, true);
            buildRoom(r*1,r*1);
            buildRoom(r*2,r*1);
            buildRoom(r * 3, r * 1, true);
            buildRoom(r*0,r*2);
            buildRoom(r*1,r*2);
            buildRoom(r*2,r*2);
            buildRoom(r*3,r*2);
            buildRoom(r*0,r*3,true);
            buildRoom(r*1,r*3);
            buildRoom(r*2,r*3);
            buildRoom(r*3,r*3,true);

            //Add bots and spawners after we add blocks to the state,
            // so that they're drawn on top of the level, and so that
            // the bots are drawn on top of both the blocks + the spawners.
            add(_spawners);
            add(_littleGibs);
            add(_bigGibs);
            add(_blocks);
            add(_decorations);
            add(_bots);

            //actually create the bullets now
            for(i = 0; i < 50; i++)
                _botBullets.add(new BotBullet());
            for(i = 0; i < 8; i++)
                _bullets.add(new Bullet());

            //add player and set up scrolling camera
            add(_player);
            FlxG.follow(_player,2.5f);
            FlxG.followAdjust(0.5f,0.0f);
            FlxG.followBounds(0,0,640,640);

            //add gibs + bullets to scene here, so they're drawn on top of pretty much everything
            add(_botBullets);
            add(_bullets);

            //finally we are going to sort things into a couple of helper groups.
            //we don't add these to the state, we just use them for collisions later!
            _enemies = new FlxGroup();
            _enemies.add(_botBullets);
            _enemies.add(_spawners);
            _enemies.add(_bots);
            _objects = new FlxGroup();
            _objects.add(_botBullets);
            _objects.add(_bullets);
            _objects.add(_bots);
            _objects.add(_player);
            _objects.add(_littleGibs);
            _objects.add(_bigGibs);

            //HUD - score
            Vector2 ssf = new Vector2(0,0);
            _score = new FlxText(0,0,FlxG.width);
            _score.color = new Color (0xd8, 0xeb, 0xa2);
            _score.scale = 2;
            _score.alignment = FlxJustification.Center;
            _score.scrollFactor = ssf;
            _score.shadow = new Color(0x13, 0x1c, 0x1b);
            add(_score);
            if (FlxG.scores.Count < 2)
            {
                FlxG.scores.Add(0);
                FlxG.scores.Add(0);
            }

            //HUD - highest and last scores
            _score2 = new FlxText(FlxG.width/2,0,FlxG.width/2);
            _score2.color = new Color(0xd8, 0xeb, 0xa2);
            _score2.alignment = FlxJustification.Right;
            _score2.scrollFactor = ssf;
            _score2.shadow = _score.shadow;
            add(_score2);
            if (FlxG.score > FlxG.scores[0])
                FlxG.scores[0] = FlxG.score;
            if (FlxG.scores[0] != 0)
                _score2.text = "HIGHEST: " + FlxG.scores[0] + "\nLAST: " + FlxG.score;
            FlxG.score = 0;
            _scoreTimer = 0;

            //HUD - the "number of spawns left" icons
            _notches = new List<FlxSprite>();
            FlxSprite tmp;
            for(i = 0; i < 6; i++)
            {
                tmp = new FlxSprite(4+i*10,4);
                tmp.loadGraphic(ImgNotch,true);
                tmp.scrollFactor.X = tmp.scrollFactor.Y = 0;
                tmp.addAnimation("on", new int[] {0});
                tmp.addAnimation("off",new int[] {1});
                tmp.moves = false;
                tmp.solid = false;
                tmp.play("on");
                _notches.Add((FlxSprite)this.add(tmp));
            }

            //HUD - the "gun jammed" notification
            _jamBar = this.add((new FlxSprite(0,FlxG.height-22)).createGraphic(FlxG.width,24, new Color(0x13, 0x1c, 0x1b))) as FlxSprite;
            _jamBar.scrollFactor.X = _jamBar.scrollFactor.Y = 0;
            _jamBar.visible = false;
            _jamText = new FlxText(0,FlxG.height-22,FlxG.width,"GUN IS JAMMED");
            _jamText.color = new Color(0xd8, 0xeb, 0xa2);
            _jamText.scale = 2;
            _jamText.alignment = FlxJustification.Center;
            _jamText.scrollFactor = ssf;
            _jamText.visible = false;
            add(_jamText);

            FlxG.playMusic(SndMode);
            FlxG.flash.start(new Color(0x13, 0x1c, 0x1b), 0.5f, null, false);
            _fading = false;
        }