Skip to content

Commit

Permalink
添加随机位置多个怪物和吃豆人
Browse files Browse the repository at this point in the history
  • Loading branch information
neekey committed Jul 22, 2012
1 parent 9396ec2 commit 3c69815
Show file tree
Hide file tree
Showing 3 changed files with 447 additions and 22 deletions.
43 changes: 24 additions & 19 deletions public/javascripts/index.js
Expand Up @@ -13,40 +13,45 @@ requirejs( [ 'underscore', 'crafty-min', 'map', 'wall', 'role', 'monster', 'bean
]
});

var mapGenerator = Crafty.e( 'MapGenerator' );
var mapArray = mapGenerator.randomMap( 20, 10 );
var pacmanMap = Crafty.e( 'PacmanMap' ).pacmanMap( 20, 10 );
var mapArray = pacmanMap.attr( 'mapArray' );
var pacman;
var monster;

Crafty.e( 'Wall' ).wall({
map: mapArray
});

_.each( mapArray, function( rows, row ){
// 画豆子
_.each( pacmanMap.attr( 'noWallArray' ), function( cube ){

_.each( rows, function( ifWall, col ){
// 画一颗豆子
Crafty.e( 'Bean' ).bean( cube[ 1 ] * 32 + 10, cube[ 0 ] * 32 + 10 );
});

if( ifWall === 0 ){
var roleArray = pacmanMap.getRandomNoWallCubes( 5 );

if( pacman !== undefined && monster === undefined ){
console.log( roleArray );

monster = Crafty.e( 'Monster' ).monster( mapArray ).attr({ x: col * 32, y: row * 32, z: 100 });
}
// 画妖怪
_.each( roleArray, function( cube, index ){

if( pacman === undefined ){
if( index === 0 ){

pacman = Crafty.e( 'Pacman' ).attr({ x: col * 32, y: row * 32, z: 100 });
}
// 画吃豆人
pacman = Crafty.e( 'Pacman' ).attr({ x: cube[ 1 ] * 32, y: cube[ 0 ] * 32, z: 100 });


else {

// 画一颗豆子
Crafty.e( 'Bean' ).bean( col * 32 + 10, row * 32 + 10 );
}
}
})
});
}
else {

Crafty.e( 'Monster' ).monster( mapArray ).attr({ x: cube[ 1 ] * 32, y: cube[ 0 ] * 32, z: 100 });
}

console.log( arguments );

console.log( roleArray[ 0 ][ 1 ] * 32, roleArray[ 0 ][ 0 ] * 32 );
})

// Crafty.audio.play( 'bgMusic', -1, 0.1 );

Expand Down

0 comments on commit 3c69815

Please sign in to comment.