Important improvements to the player script. Instead of setting model and texture every X seconds, only do it when the player joins (so far)

Add a function which allows registering different frame ranges for different player models

Cosmetic improvements to the player script

More progress on the player animation functions, this commit adds useles code currently
This commit is contained in:
MirceaKitsune 2012-11-23 00:07:35 +02:00 committed by Perttu Ahola
parent b97400d71d
commit dce87664d2

View File

@ -1,54 +1,73 @@
-- Minetest 0.4 mod: player -- Minetest 0.4 mod: player
-- See README.txt for licensing and other information. -- See README.txt for licensing and other information.
-- The API documentation in here was moved into doc/lua_api.txt -- Animation speed
-- Default animation speed. Special animations (such as the walk animation) should be offset from this factor
animation_speed = 30 animation_speed = 30
-- Animation blending
-- Animation blending / transitioning amount -- Note: This is currently broken due to a bug in Irrlicht, leave at 0
animation_blend = 0 animation_blend = 0
-- Animations frame ranges: -- Default player appearance
-- For player.x: player_model = "character.x"
animation_player_stand_START = 0 player_texture = "character.png"
animation_player_stand_END = 79
animation_player_walk_forward_START = 81
animation_player_walk_forward_END = 100
animation_player_walk_backward_START = 102
animation_player_walk_backward_END = 121
animation_player_walk_right_START = 123
animation_player_walk_right_END = 142
animation_player_walk_left_START = 144
animation_player_walk_left_END = 163
animation_player_mine_START = 165
animation_player_mine_END = 179
animation_player_death_START = 181
animation_player_death_END = 200
-- Set mesh for all players -- Frame ranges for each player model
function switch_player_visual() function player_get_animations(model)
if(model == "character.x") then
return {
stand_START = 0,
stand_END = 79,
walk_forward_START = 81,
walk_forward_END = 100,
walk_backward_START = 102,
walk_backward_END = 121,
walk_right_START = 123,
walk_right_END = 142,
walk_left_START = 144,
walk_left_END = 163,
mine_START = 165,
mine_END = 179,
death_START = 181,
death_END = 200
}
end
end
-- Called whenever a player's appearance needs to be updated
function player_update_visuals(player)
prop = { prop = {
mesh = "character.x", mesh = player_model,
textures = {"character.png", }, textures = {player_texture, },
visual = "mesh", visual = "mesh",
visual_size = {x=1, y=1}, visual_size = {x=1, y=1},
} }
player:set_properties(prop)
local anim = player_get_animations(player_model)
player:set_animation({x=anim.stand_START, y=anim.stand_END}, animation_speed, animation_blend)
end
-- Update appearance when the player joins
minetest.register_on_joinplayer(player_update_visuals)
-- Player states, used to know when to change animations
local player_anim = {}
local ANIM_STAND = 1
local ANIM_WALK_FORWARD = 2
local ANIM_WALK_BACKWARD = 3
local ANIM_WALK_LEFT = 4
local ANIM_WALK_RIGHT = 5
local ANIM_MINE = 6
local ANIM_DEATH = 7
-- Global environment step function
function on_step(dtime)
for _, obj in pairs(minetest.get_connected_players()) do for _, obj in pairs(minetest.get_connected_players()) do
obj:set_properties(prop) if(player_anim[obj:get_player_name()] == 0) then
obj:set_animation({x=animation_player_death_START, y=animation_player_death_END}, animation_speed, animation_blend) print("on_step")
end end
minetest.after(10.0, switch_player_visual)
end end
minetest.after(10.0, switch_player_visual) end
minetest.register_globalstep(on_step)
-- Definitions made by this mod that other mods can use too
default = {}
-- Load other files
dofile(minetest.get_modpath("default").."/mapgen.lua")
dofile(minetest.get_modpath("default").."/leafdecay.lua")
-- END -- END