mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-23 07:10:19 +01:00
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:
parent
b97400d71d
commit
dce87664d2
@ -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)
|
||||||
|
|
||||||
for _, obj in pairs(minetest.get_connected_players()) do
|
local anim = player_get_animations(player_model)
|
||||||
obj:set_properties(prop)
|
player:set_animation({x=anim.stand_START, y=anim.stand_END}, animation_speed, animation_blend)
|
||||||
obj:set_animation({x=animation_player_death_START, y=animation_player_death_END}, animation_speed, animation_blend)
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.after(10.0, switch_player_visual)
|
|
||||||
end
|
end
|
||||||
minetest.after(10.0, switch_player_visual)
|
|
||||||
|
|
||||||
-- Definitions made by this mod that other mods can use too
|
-- Update appearance when the player joins
|
||||||
default = {}
|
minetest.register_on_joinplayer(player_update_visuals)
|
||||||
|
|
||||||
-- Load other files
|
-- Player states, used to know when to change animations
|
||||||
dofile(minetest.get_modpath("default").."/mapgen.lua")
|
local player_anim = {}
|
||||||
dofile(minetest.get_modpath("default").."/leafdecay.lua")
|
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
|
||||||
|
if(player_anim[obj:get_player_name()] == 0) then
|
||||||
|
print("on_step")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.register_globalstep(on_step)
|
||||||
|
|
||||||
-- END
|
-- END
|
||||||
|
Loading…
Reference in New Issue
Block a user