-
Notifications
You must be signed in to change notification settings - Fork 0
/
npc-1.lua
41 lines (35 loc) · 1.21 KB
/
npc-1.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local npcManager = require("npcManager")
local basic = {}
local npcID = NPC_ID
local STATE_WANDER = 0
local STATE_COLLIDED = 1
local DEACCEL_RATE = 0.065
local BASE_SPEED = 2
function basic.onTickEndNPC(v)
--Text.showMessageBox("AAA")
local data = v.data
if not data.state then
data.state = STATE_WANDER
end
if data.state == STATE_COLLIDED then
local e = Effect.spawn(74,0,0)
e.x = v.x+(v.width/2)+(e.width/2)-v.speedX+RNG.random(-v.width/10,v.width/10)
e.y = v.y+v.height-e.height
Text.showMessageBox(string.format("%f speed", v.speedX))
v.speedX = v.speedX - (math.sign(v.speedX)*DEACCEL_RATE)
if math.abs(v.speedX) <= 0.3 then
data.state = STATE_WANDER
v.speedX = RNG.random() < 0.5 and BASE_SPEED or -1 * BASE_SPEED
end
end
for _,p in ipairs(Player.getIntersecting(v.x,v.y,v.x+v.width,v.y+v.height)) do
local direction = (math.sign((p.x+(p.width/2))-(v.x+(v.width/2))))
p:mem(0x138, FIELD_FLOAT, 3.5 * direction)
v.speedX = -5 * direction
data.state = STATE_COLLIDED
end
end
function basic.onInitAPI()
npcManager.registerEvent(npcID, basic, "onTickEndNPC")
end
return basic