diff options
| author | Fernando Carmona Varo <ferkiwi@gmail.com> | 2015-10-21 22:22:58 +0200 | 
|---|---|---|
| committer | Fernando Carmona Varo <ferkiwi@gmail.com> | 2015-10-21 22:22:58 +0200 | 
| commit | 6ea7381e9f0fd639f87de33cad6d9497c0c83888 (patch) | |
| tree | 064bc665ee053ba8634f41afcbcf4d4e678e151e /gamestate.lua | |
| parent | 6d338337d362af15f1038cf73ca154daa57b6b2b (diff) | |
Added power pellet state, ghosts will run away from the player and get teleported to the ghost spawn
Diffstat (limited to 'gamestate.lua')
| -rwxr-xr-x | gamestate.lua | 25 | 
1 files changed, 25 insertions, 0 deletions
diff --git a/gamestate.lua b/gamestate.lua index 683ce3f..8b642cb 100755 --- a/gamestate.lua +++ b/gamestate.lua @@ -2,6 +2,9 @@  -- Array to hold all the running game states  mypacman.games = {} +-- Duration of the power pellet effect (in seconds) +local power_pellet_duration = 10 +  ---------------------------------------------------------  -- Public functions (these can be called from any other place) @@ -50,6 +53,8 @@ function mypacman.game_reset(id, player)  	local gamestate = mypacman.games[id]  	minetest.log("action", "resetting game " .. id) +	gamestate.power_pellet = false +  	-- Position the player  	local player = player or minetest.get_player_by_name(gamestate.player_name)  	player:setpos(gamestate.start) @@ -117,7 +122,27 @@ function mypacman.on_player_got_pellet(player)  			minetest.sound_play("mypacman_beginning", {pos = pos,max_hear_distance = 40,gain = 10.0,})  		end)  	end +end + +-- A player got a power pellet, update the state +function mypacman.on_player_got_power_pellet(player) +	local name = player:get_player_name() +	local gamestate = mypacman.get_game_by_player(name) +	if not gamestate then return end + +	minetest.chat_send_player(name, "You got a POWER PELLET") +	gamestate.power_pellet = os.time() + power_pellet_duration + +	local boardcenter = vector.add(gamestate.pos, {x=13,y=0.5,z=15}) +	local powersound = minetest.sound_play("mypacman_beginning", {pos = boardcenter,max_hear_distance = 20, object=player, loop=true}) +	minetest.after(power_pellet_duration, function() +		if os.time() >= (gamestate.power_pellet or 0) then +			gamestate.power_pellet = false +			minetest.chat_send_player(name, "POWER PELLET wore off") +			minetest.sound_stop(powersound) +		end +	end)  end  -- Get the game that the given player is playing  | 
