199 lines
5.8 KiB
Lua
199 lines
5.8 KiB
Lua
-- licensed as follows:
|
|
-- MIT License, ExeVirus (c) 2021
|
|
--
|
|
-- Please see the LICENSE file for more details
|
|
|
|
local spawn_time = 10
|
|
local time = 0
|
|
|
|
-- --Common node between styles, used for hidden floor to fall onto
|
|
-- minetest.register_node("game:ground",
|
|
-- {
|
|
-- description = "Ground Block",
|
|
-- tiles = {"ground.png"},
|
|
-- light_source = 11,
|
|
-- })
|
|
|
|
-- --Override the default hand
|
|
-- minetest.register_item(":", {
|
|
-- type = "none",
|
|
-- wield_image = "wieldhand.png",
|
|
-- wield_scale = {x = 1, y = 1, z = 2.5},
|
|
-- range = 12,
|
|
-- groups = {not_in_creative_inventory=1},
|
|
-- })
|
|
|
|
-- local num_balloons = 1
|
|
local rand = PcgRandom(os.time())
|
|
|
|
-- local function spawn_balloon(arena)
|
|
-- num_balloons = num_balloons + 1
|
|
-- minetest.chat_send_all(num_balloons .. " balloons!")
|
|
-- local players = minetest.get_connected_players()
|
|
-- local player = players[rand:next(1,#players)] --random player
|
|
-- local pos = player:get_pos()
|
|
-- minetest.add_entity({
|
|
-- x=pos.x+rand:next(1,7)-3.5,
|
|
-- y=22,
|
|
-- z=pos.z+rand:next(1,7)-3.5,
|
|
-- }, "game:balloon", nil)
|
|
-- minetest.sound_play("balloon", {
|
|
-- gain = 1.0, -- default
|
|
-- loop = false,
|
|
-- })
|
|
-- spawn_time = spawn_time + 3
|
|
-- end
|
|
|
|
-- local first = true -- first player?
|
|
-- local started = false -- delay
|
|
-- minetest.register_on_joinplayer(
|
|
-- function(player)
|
|
-- player:hud_set_flags(
|
|
-- {
|
|
-- hotbar = false,
|
|
-- healthbar = false,
|
|
-- crosshair = true,
|
|
-- wielditem = false,
|
|
-- breathbar = false,
|
|
-- minimap = false,
|
|
-- minimap_radar = false,
|
|
-- }
|
|
-- )
|
|
-- music = minetest.sound_play("balloon", {
|
|
-- gain = 1.0, -- default
|
|
-- loop = false,
|
|
-- to_player = player:get_player_name(),
|
|
-- })
|
|
|
|
-- player:set_physics_override({
|
|
-- speed = 4.0,
|
|
-- jump = 1.0,
|
|
-- gravity = 4.0,
|
|
-- sneak = false,
|
|
-- })
|
|
|
|
-- player:set_pos({x=0,y=1.1,z=0})
|
|
-- player:set_look_horizontal(0)
|
|
-- player:set_look_vertical(-0.5)
|
|
-- minetest.sound_play("theme", {
|
|
-- gain = 0.8, -- default
|
|
-- loop = true,
|
|
-- to_player = player:get_player_name()
|
|
-- })
|
|
-- if first then
|
|
-- minetest.add_entity({x=0,y=12,z=10}, "game:balloon", nil)
|
|
-- first = false
|
|
-- minetest.after(1, function() started = true end)
|
|
-- end
|
|
-- end
|
|
-- )
|
|
|
|
-- minetest.register_globalstep(
|
|
-- function(dtime)
|
|
-- if started then
|
|
-- time = time + dtime
|
|
-- if time > spawn_time then
|
|
-- time = 0
|
|
-- spawn_balloon()
|
|
-- end
|
|
-- end
|
|
-- end)
|
|
local function add_points(self,pts)
|
|
minetest.chat_send_all(self._arenaid)
|
|
if self._arenaid then
|
|
if arena_lib.mods["balloon_bop"].arenas[self._arenaid].in_game == true then
|
|
local arena = arena_lib.mods["balloon_bop"].arenas[self._arenaid]
|
|
arena.score = arena.score + pts
|
|
end
|
|
end
|
|
end
|
|
-- Balloon
|
|
|
|
|
|
balloon_bop.spawn = function(arena)
|
|
local obj = minetest.add_entity(vector.new(
|
|
arena.balloon_spawner.x+rand:next(1,7)-arena.spawner_range,
|
|
arena.balloon_spawner.y,
|
|
arena.balloon_spawner.z+rand:next(1,7)-arena.spawner_range)
|
|
, "balloon_bop:balloon", minetest.write_json({
|
|
_arenaid = arena_lib.get_arena_by_name("balloon_bop", arena.name),
|
|
}))
|
|
minetest.sound_play("balloon", {
|
|
gain = 1.0, -- default
|
|
loop = false,
|
|
pos = arena.balloon_spawner,
|
|
})
|
|
end
|
|
|
|
|
|
local balloon = {
|
|
initial_properties = {
|
|
hp_max = 10,
|
|
visual = "mesh",
|
|
visual_size = {x=0.1,y=0.117,z=0.1},
|
|
-- glow = 10,
|
|
static_save = false,
|
|
mesh = "balloon.obj",
|
|
physical = true,
|
|
collide_with_objects = true,
|
|
collisionbox = {-0.6, -0.5, -0.6, 0.6, 0.5, 0.6},
|
|
textures = {"balloon.1.png"},
|
|
},
|
|
|
|
--Physics, and collisions
|
|
on_step = function(self, dtime, moveresult)
|
|
if minetest.find_node_near(self.object:get_pos(), 1.5, {"balloon_bop:spike"}) then
|
|
-- pop balloon harmlessly
|
|
minetest.sound_play("balloon_pop", {
|
|
gain = 1.0, -- default
|
|
loop = false,
|
|
pos = self.object:get_pos()
|
|
})
|
|
add_points(self,25)
|
|
self.object:remove()
|
|
--todo: add pop sound
|
|
return
|
|
end
|
|
if moveresult.touching_ground then
|
|
self._touching_ground = true
|
|
else
|
|
--slow our x,z velocities
|
|
local vel = self.object:get_velocity()
|
|
if vel == nil then vel = {x=0,y=0,z=0} end
|
|
self.object:set_velocity({x=vel.x*0.97, y=vel.y*0.97, z=vel.z*0.97})
|
|
end
|
|
end,
|
|
|
|
--Punch Physics
|
|
on_punch = function(self, puncher, _, _, dir)
|
|
self.object:set_velocity(dir*25)
|
|
minetest.sound_play("punch", {
|
|
gain = 1.0, -- default
|
|
loop = false,
|
|
pos = self.object:get_pos()
|
|
})
|
|
end,
|
|
|
|
--Setup fallspeed
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
self.object:set_acceleration({x=0,y=-4.0,z=0})
|
|
local props = self.object:get_properties()
|
|
props.textures = {"balloon." .. rand:next(1,4) .. ".png"}
|
|
self.object:set_properties(props)
|
|
minetest.sound_play("balloon_inflate", {
|
|
gain = 1.0, -- default
|
|
loop = false,
|
|
pos = self.object:get_pos()
|
|
})
|
|
if staticdata ~= "" and staticdata ~= nil then
|
|
local data = minetest.parse_json(staticdata) or {}
|
|
if data._arenaid then
|
|
self._arenaid = data._arenaid
|
|
end
|
|
end
|
|
end,
|
|
_touching_ground = false,
|
|
}
|
|
|
|
minetest.register_entity("balloon_bop:balloon", balloon)
|