Hacker News new | past | comments | ask | show | jobs | submit login

Here's an Iron Man inspired solution for the boss battle :)

    map.placeObject(map.getWidth()/2, 5, 'block');
    //map.placeObject(map.getWidth()/2, 1, 'block');
    var player = map.getPlayer();
    map.defineObject('missile', {
        'type': 'dynamic',
        'symbol': '^',
        'color': 'blue',
        'interval': 100,
        'projectile': true,
        'behavior': function (me) {
            me.move('up');
        }
    });
    
    function jericho()
    {
    	var i;
    	for (i = 3; i < map.getWidth() - 3; i++)
        {
        	map.placeObject(i, map.getHeight() - 1, 'missile');
        }
    }
    player.setPhoneCallback(function()
    {
    	jericho();
    });



For the truly lazy, this was my approach:

    map.overrideKey('up', function() {
        if (map.countObjects('boss') > 0) {
            for (var x = 0; x < map.getWidth(); x++) {
                map.placeObject(x, map.getHeight()-5, 'missile');
            }
        } else {
            map.overrideKey('up', null);
        }
    });


Interesting, probably much simpler than my approach:(I have added a few comments to give a brief explanation:

 	//Math.random = function(){ return false;};
        /* my first Idea was to try and redefine Math.random to always return <0.3, but for some reason even though this did effect the dropping of bullets, it didn't stop them completely (if someone could explain this I would really appreciate it*/
    
    map.defineObject('MagicBlock', {
    	
        'type'         : 'static',
        'symbol'       : '$',
        'color'        : 'magenta',
        'impassable'   : function() { return map.countObjects('boss') >0;}
        
    });
    
    //place a row of MagicBlock's aboove the player's starting position
    for(var i =0; i < map.getWidth(); i++)
    	map.placeObject(i, map.getHeight()-5, 'MagicBlock');
    
    map.defineObject('missile', {
    	'type' 		: 'dynamic',
        'symbol' 	: '^',
        'interval'  : 100,
        'projectile': true,
        'behavior'  : function(me) { me.move('up');},
        'color'		: 'lime'
    	});
        
        
    player = map.getPlayer();
    
    function volley(){
    	for(var i = 0; i < map.getWidth(); i++)
        	map.placeObject(i, map.getHeight()-6, 'missile');
           	map.placeObject(i, map.getHeight()-7, 'missile');
    }
    
    
	map.getPlayer().setPhoneCallback(function(){
    	volley();
    });


Nice. Lacks drama though, where's the dash through the rain of bullets to recover the missile launcher? :D


I monkey-patched Math.random() to launch horizontal missiles at the top of the screen and always return 1.

:-)


I've used their own weapon! :)

for(ii=0;ii<23;ii++){ map.getDynamicObjects()[ii].direction='down'; }

f=function(){ map.placeObject(10, 18, 'bullet'); } map.getPlayer().setPhoneCallback(f);




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: