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
master
MirceaKitsune 2012-11-23 00:07:35 +02:00 committed by Perttu Ahola
parent b97400d71d
commit dce87664d2
1 changed files with 56 additions and 37 deletions

View File

@ -1,54 +1,73 @@
-- Minetest 0.4 mod: player
-- See README.txt for licensing and other information.
-- The API documentation in here was moved into doc/lua_api.txt
-- Default animation speed. Special animations (such as the walk animation) should be offset from this factor
-- Animation speed
animation_speed = 30
-- Animation blending / transitioning amount
-- Animation blending
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
animation_blend = 0
-- Animations frame ranges:
-- For player.x:
animation_player_stand_START = 0
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
-- Default player appearance
player_model = "character.x"
player_texture = "character.png"
-- Set mesh for all players
function switch_player_visual()
-- Frame ranges for each player model
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 = {
mesh = "character.x",
textures = {"character.png", },
mesh = player_model,
textures = {player_texture, },
visual = "mesh",
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
obj:set_properties(prop)
obj:set_animation({x=animation_player_death_START, y=animation_player_death_END}, animation_speed, animation_blend)
if(player_anim[obj:get_player_name()] == 0) then
print("on_step")
end
minetest.after(10.0, switch_player_visual)
end
minetest.after(10.0, switch_player_visual)
-- 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
minetest.register_globalstep(on_step)
-- END