screeps 页面javascript游戏代码以及文档地址
//https://screeps-cn.github.io/api/#Game.creeps
//https://screeps.com/a/#!/sim/tutorial/1
module.exports.loop = function () {
for(var name in Game.creeps) {
var creep = Game.creeps[name];
//采集者则进行采集的操作
if(creep.memory.role == 'harvester') {
roleHarvester.run(creep);
}
if(creep.memory.role == 'upgrader') {
roleUpgrader.run(creep);
}
if(creep.memory.role == 'builder') {
roleBuilder.run(creep);
}
}
}
// for(var rob=2;rob<30;rob++){
// Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE], 'harvester3', {
// memory: {role: 'harvester'}
// });
// }
// for(var rob=2;rob<10;rob++){
// Game.spawns['Spawn1'].spawnCreep( [WORK, CARRY, MOVE], 'Builder'+rob,
// { memory: { role: 'builder' } } );
// }
var tower = Game.getObjectById('693092d10bdaba0a44c94e45');
if(tower) {
//寻找不属于我们自己的细胞,并且攻击他
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(closestHostile) {
tower.attack(closestHostile);
}
}
var roleBuilder = {
/** @param {Creep} creep **/
run: function(creep) {
//当为建造,但没有能量的时候,身份切换为采集
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false;
creep.say('
版权属于:BLOG DEWEBSTUDIO 本文作者:狒狒
原文地址: http://blog.dewebstudio.com/?post=141
版权声明:转载时必须以链接形式注明原始出处及本声明。
继续浏览: screeps javascript 游戏
下一篇:仿facebook选时间段
发表评论