Created
June 16, 2022 12:26
-
-
Save margauxflores/0553f1fcca65a8e5d1f0e7626469d8b3 to your computer and use it in GitHub Desktop.
Rabbit!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lua_script = (function() { | |
var tmp; | |
var G = lua_newtable2(lua_core); | |
for (var i in lua_libs) { | |
G.str[i] = lua_newtable2(lua_libs[i]); | |
} | |
G.str['arg'] = lua_newtable(); | |
G.str['_G'] = G; | |
G.str['module'] = function (name) { | |
lua_createmodule(G, name, slice(arguments, 1)); | |
}; | |
G.str['require'] = function (name) { | |
lua_require(G, name); | |
}; | |
G.str['package'].str['seeall'] = function (module) { | |
if (!module.metatable) { | |
module.metatable = lua_newtable(); | |
} | |
module.metatable.str['__index'] = G; | |
}; | |
{ | |
return [(function (_state) { | |
var tmp; | |
var varargs = slice(arguments, 1); | |
_state = lua_or(_state, function () {return lua_newtable();}); | |
lua_call(G.str['assert'], [lua_eq(lua_call(G.str['type'], [_state])[0], 'table'), 'Invalid state. Must receive a table']); | |
lua_tableset(_state, 'type', "rabbit"); | |
lua_tablegetcall(G.str['math'], 'randomseed', lua_tablegetcall(G.str['os'], 'time', [])); | |
lua_tablegetcall(G.str['math'], 'random', []); | |
lua_tablegetcall(G.str['math'], 'random', []); | |
lua_tablegetcall(G.str['math'], 'random', []); | |
var _distance_2 = (function (_x1, _y1, _x2, _y2) { | |
var tmp; | |
var _x_3 = lua_subtract(_x1, _x2); | |
var _y_3 = lua_subtract(_y1, _y2); | |
var _d_3 = lua_tablegetcall(G.str['math'], 'sqrt', [lua_add((lua_multiply(_x_3, _x_3)), (lua_multiply(_y_3, _y_3)))])[0]; | |
return [_d_3]; | |
return []; | |
}); | |
var _plot_course_2 = (function (_xx, _yy) { | |
var tmp; | |
var _d_4; | |
var _curx_4 = lua_call(G.str['loc_x'], [])[0]; | |
var _cury_4 = lua_call(G.str['loc_y'], [])[0]; | |
var _x_4 = lua_subtract(_xx, _curx_4); | |
var _y_4 = lua_subtract(_yy, _cury_4); | |
if (lua_eq(_x_4, 0)) { | |
if (lua_lt(_cury_4, _yy)) { | |
_d_4 = 90.0; | |
} else { | |
_d_4 = 270.0; | |
} | |
} else { | |
_d_4 = lua_divide(lua_multiply(lua_tablegetcall(G.str['math'], 'atan', [_y_4, _x_4])[0], 180), lua_tableget(G.str['math'], 'pi')); | |
} | |
return [_d_4]; | |
return []; | |
}); | |
var _wanderspeed_2 = 20; | |
var _wandertimer_2 = 5; | |
if (lua_eq(lua_tableget(_state, 'status'), null)) { | |
lua_tableset(_state, 'status', "wandering"); | |
lua_tableset(_state, 'damage', lua_call(G.str['damage'], [])[0]); | |
lua_tableset(_state, 'wander_lust', _wandertimer_2); | |
lua_tableset(_state, 'dest', lua_newtable([lua_tablegetcall(G.str['math'], 'random', [1000])[0]].concat(lua_tablegetcall(G.str['math'], 'random', [1000])))); | |
lua_tableset(_state, 'course', lua_call(_plot_course_2, [lua_tableget(lua_tableget(_state, 'dest'), 1), lua_tableget(lua_tableget(_state, 'dest'), 2)])[0]); | |
lua_call(G.str['drive'], [lua_tableget(_state, 'course'), _wanderspeed_2]); | |
return [_state]; | |
} else if (!lua_eq(lua_tableget(_state, 'damage'), lua_call(G.str['damage'], [])[0])) { | |
lua_tableset(_state, 'damage', lua_call(G.str['damage'], [])[0]); | |
lua_tableset(_state, 'dest', lua_newtable([lua_tablegetcall(G.str['math'], 'random', [1000])[0]].concat(lua_tablegetcall(G.str['math'], 'random', [1000])))); | |
lua_tableset(_state, 'course', lua_call(_plot_course_2, [lua_tableget(lua_tableget(_state, 'dest'), 1), lua_tableget(lua_tableget(_state, 'dest'), 2)])[0]); | |
lua_call(G.str['drive'], [lua_tableget(_state, 'course'), 100]); | |
lua_tableset(_state, 'status', "running"); | |
return [_state]; | |
} else if ((lua_eq(lua_tableget(_state, 'status'), "wandering") || lua_eq(lua_tableget(_state, 'status'), "running"))) { | |
if (lua_lt(lua_call(_distance_2, [lua_call(G.str['loc_x'], [])[0], lua_call(G.str['loc_y'], [])[0], lua_tableget(lua_tableget(_state, 'dest'), 1), lua_tableget(lua_tableget(_state, 'dest'), 2)])[0], 50)) { | |
lua_call(G.str['drive'], [0, 0]); | |
lua_tableset(_state, 'status', "eating"); | |
} | |
return [_state]; | |
} else if ((lua_eq(lua_tableget(_state, 'status'), "eating") && lua_lt(0, lua_tableget(_state, 'wander_lust')))) { | |
lua_tableset(_state, 'wander_lust', lua_subtract(lua_tableget(_state, 'wander_lust'), 1)); | |
return [_state]; | |
} else if (((lua_eq(lua_tableget(_state, 'status'), "wandering") || lua_eq(lua_tableget(_state, 'status'), "eating")) && lua_lt(lua_tableget(_state, 'wander_lust'), 0))) { | |
if (lua_eq(lua_tableget(_state, 'status'), "wandering")) { | |
lua_tableset(_state, 'status', "eating"); | |
lua_call(G.str['drive'], [0, 0]); | |
} else if (lua_eq(lua_tableget(_state, 'status'), "eating")) { | |
lua_tableset(_state, 'status', "wandering"); | |
lua_tableset(_state, 'dest', lua_newtable([lua_tablegetcall(G.str['math'], 'random', [1000])[0]].concat(lua_tablegetcall(G.str['math'], 'random', [1000])))); | |
lua_tableset(_state, 'course', lua_call(_plot_course_2, [lua_tableget(lua_tableget(_state, 'dest'), 1), lua_tableget(lua_tableget(_state, 'dest'), 2)])[0]); | |
lua_call(G.str['drive'], [lua_tableget(_state, 'course'), _wanderspeed_2]); | |
} | |
lua_tableset(_state, 'wander_lust', _wandertimer_2); | |
return [_state]; | |
} | |
return [_state]; | |
return []; | |
})]; | |
}; | |
return [G]; | |
})()[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment