chore:首次提交
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"manifest": {
|
||||
"id": "example-patrol",
|
||||
"name": "敌人巡逻系统",
|
||||
"version": "1.0.0",
|
||||
"author": "OES-WEB",
|
||||
"description": "让敌人在闲置时巡逻,增加游戏真实感",
|
||||
"priority": 200,
|
||||
"dependencies": [],
|
||||
"scripts": ["patrol.js"]
|
||||
},
|
||||
"data": {},
|
||||
"scripts": {
|
||||
"patrol.js": "log('Patrol mod loaded!');\n\nconst patrolData = new Map();\nconst PATROL_SPEED = 40;\nconst PATROL_RANGE = 100;\nconst IDLE_TIME = 2000;\n\ngame.on('entity:created', (data) => {\n const entity = data.entity;\n if (entity.type === 'enemy') {\n const pos = entity.position;\n if (pos) {\n patrolData.set(entity.id, {\n originX: pos.x,\n originY: pos.y,\n targetX: pos.x,\n targetY: pos.y,\n state: 'idle',\n idleTimer: 0,\n waitTime: utils.random(1000, 3000)\n });\n }\n }\n});\n\ngame.on('entity:destroyed', (data) => {\n patrolData.delete(data.entity.id);\n});\n\ngame.on('game:update', (data) => {\n const delta = data.delta;\n \n for (const [entityId, patrol] of patrolData) {\n const entity = game.getEntity(entityId);\n if (!entity || !entity.position) continue;\n \n const ai = entity.getComponent('ai');\n if (ai && ai.state === 'chase') continue;\n \n if (patrol.state === 'idle') {\n patrol.idleTimer += delta;\n if (patrol.idleTimer >= patrol.waitTime) {\n patrol.state = 'patrol';\n patrol.waitTime = utils.random(1500, 4000);\n const angle = utils.random(0, Math.PI * 2);\n const dist = utils.random(30, PATROL_RANGE);\n patrol.targetX = patrol.originX + Math.cos(angle) * dist;\n patrol.targetY = patrol.originY + Math.sin(angle) * dist;\n }\n } else if (patrol.state === 'patrol') {\n const dx = patrol.targetX - entity.position.x;\n const dy = patrol.targetY - entity.position.y;\n const dist = Math.sqrt(dx * dx + dy * dy);\n \n if (dist < 5) {\n patrol.state = 'idle';\n patrol.idleTimer = 0;\n } else {\n const nx = dx / dist;\n const ny = dy / dist;\n entity.position = {\n x: entity.position.x + nx * PATROL_SPEED * (delta / 1000),\n y: entity.position.y + ny * PATROL_SPEED * (delta / 1000)\n };\n entity.faceToward(patrol.targetX, patrol.targetY);\n }\n }\n }\n});\n\nlog('Patrol behavior registered for all enemies');"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user