[ADD] Add something, commit before debugging

This commit is contained in:
tacigar
2016-09-13 20:03:15 +09:00
parent 3210635e88
commit 55b0af6189
2 changed files with 79 additions and 2 deletions

View File

@ -3,16 +3,56 @@
-- https://github.com/tacigar/maidroid
------------------------------------------------------------
local function on_start(self)
local state = {
IDLE = 0,
ACCOMPANY = 1,
}
local function on_start(self)
self.state = state.IDLE
self.object:setacceleration{x = 0, y = -10, z = 0}
self.object:setvelocity{x = 0, y = 0, z = 0}
end
local function on_stop(self)
self.state = nil
self.object:setvelocty{x = 0, y = 0, z = 0}
end
local function on_step(self, dtime)
local player = self:get_nearest_player(10)
if player == nil then
self:set_animation(maidroid.animation_frames.STAND)
return
end
local position = self.object:getpos()
local player_position = player:getpos()
local direction = vector.subtract(player_position, position)
local velocity = self.object:getvelocity()
if vector.length(dir) < 3 then
if self.state == state.ACCOMPANY then
self:set_animation(maidroid.animation_frames.STAND)
self.state = state.idle
self.object:setvelocity{x = 0, y = velocity.y, z = 0}
end
else
if self.state == state.IDLE then
self:set_animation(maidroid.animation_frames.WALK)
self.state = state.ACCOMPANY
end
self.object:setvelocity{x = direction.x, y = velocity.y, z = direction.z} -- TODO
end
self:set_yaw_by_direction(direction)
-- if maidroid is stoped by obstacle, the maidroid must jump.
if velocity == 0 and self.state = state.ACCOMPANY then
local front_node = self:get_front_node()
if front_node.name ~= "air" then
self.object:setvelocity{x = direction.x, y = 3, z = direction.z}
end
end
end
maidroid.register_core("maidroid_core_basic:core_basic", {