[soccer] Add soccer mod

This commit is contained in:
LeMagnesium 2015-10-05 22:55:39 +02:00
parent 82c90e76e9
commit 19f0bc0273
18 changed files with 1176 additions and 0 deletions

25
mods/soccer/LICENSE.txt Normal file
View File

@ -0,0 +1,25 @@
Copyright (c) 2013, Diego Martínez
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

24
mods/soccer/README.txt Normal file
View File

@ -0,0 +1,24 @@
Soccer Mod
----------
Play soccer on Minetest!
This currently only provides the ball; the actual logic for implementing a match
will be implemented in the future. For now, you can use Mesecons Wooden Pressure
Plates along with some logic to at least handle scoring. Goals are also provided
but have no functionality.
The ball is not craftable ATM. Use /giveme soccer:ball_item, and place it with
right-click. You can take it again by punching it.
You can push the ball by standing near it, and kick it by holding the "sneak"
key (by default "Shift"). The ball will get pushed/kicked in the direction the
player is facing (you can center-on the ball by looking up).
Special thanks
--------------
- 12Me21: Ideas about the crafting recipe.
- ecube: Original (black) texture.
- Xiug: Ideas and textures.

2
mods/soccer/depends.txt Normal file
View File

@ -0,0 +1,2 @@
default
wool

124
mods/soccer/init.lua Normal file
View File

@ -0,0 +1,124 @@
local function reg_ball(color)
local ball_item_name = "soccer:ball_" .. color .. "_item"
local ball_ent_name = "soccer:ball_" .. color .. "_entity"
minetest.register_entity(ball_ent_name, {
physical = true,
hp_max = 32767,
collide_with_objects = false,
visual = "mesh",
visual_size = {x = 1.125, y = 1.125, z = 1.125},
mesh = "soccer_ball.x",
groups = {immortal = true},
textures = {"soccer_ball_" .. color .. ".png"},
collisionbox = { -0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
timer = 0,
on_step = function(self, dtime)
self.timer = self.timer + dtime
if self.timer >= 0.2 then
self.object:setacceleration({x = 0, y = -14.5, z = 0})
self.timer = 0
local vel = self.object:getvelocity()
local p = self.object:getpos();
p.y = p.y - 0.5
if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then
vel.x = vel.x * 0.9
if vel.y < 0 then vel.y = vel.y * -0.6 end
vel.z = vel.z * 0.9
end
if (math.abs(vel.x) <= 0.1) and (math.abs(vel.z) <= 0.1) then
vel.x = 0
vel.z = 0
end
self.object:setvelocity(vel)
local pos = self.object:getpos()
local objs = minetest.env:get_objects_inside_radius(pos, 1)
local player_count = 0
local final_dir = {x = 0, y = 0, z = 0}
for _,obj in ipairs(objs) do
if obj:is_player() then
local objdir = obj:get_look_dir()
local mul = 1
if (obj:get_player_control().sneak) then mul = 2 end
final_dir.x = final_dir.x + (objdir.x * mul)
final_dir.y = final_dir.y + (objdir.y * mul)
final_dir.z = final_dir.z + (objdir.z * mul)
player_count = player_count + 1
end
end
if final_dir.x ~= 0 or final_dir.y ~= 0 or final_dir.z ~= 0 then
final_dir.x = (final_dir.x * 7.2) / player_count
final_dir.y = (final_dir.y * 9.6) / player_count
final_dir.z = (final_dir.z * 7.2) / player_count
self.object:setvelocity(final_dir)
minetest.sound_play("default_dig_oddly_breakable_by_hand", {object = self.object, gain = 0.5})
end
end
end,
on_punch = function(self, puncher)
if puncher and puncher:is_player() then
local inv = puncher:get_inventory()
inv:add_item("main", ItemStack(ball_item_name))
self.object:remove()
end
end,
is_moving = function(self)
local v = self.object:getvelocity()
if (math.abs(v.x) <= 0.1) and (math.abs(v.z) <= 0.1) then
v.x = 0
v.z = 0
self.object:setvelocity(v)
return false
end
return true
end,
})
minetest.register_craftitem(ball_item_name, {
description = "Soccer Ball ("..color..")",
inventory_image = "soccer_ball_"..color.."_inv.png",
wield_scale = {x = 0.75, y = 0.75, z = 4.5},
on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above
-- pos = { x =pos.x + 0.5, y = pos.y, z = pos.z + 0.5 }
local ent = minetest.env:add_entity(pos, ball_ent_name)
minetest.log("action", placer:get_player_name() .. " placed a ball at " .. minetest.pos_to_string(pointed_thing.above) .. ".")
ent:setvelocity({x = 0, y = -14.5, z = 0})
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
})
if color == "purple" then
color = "pink"
end
minetest.register_craft({
output = ball_item_name,
recipe = {
{ "", "wool:white", "" },
{ "wool:white", "wool:" .. color, "wool:white" },
{ "", "wool:white", "" },
},
})
end
colors = {
"black", "red", "green", "blue", "yellow", "purple",
}
for _,color in ipairs(colors) do
reg_ball(color)
end
minetest.register_alias("ball", "soccer:ball_black_item") -- For quickly using the /give command.
if minetest.setting_getbool("log_mods") then
minetest.log("action", "Carbone: [soccer] loaded.")
end

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

View File

@ -25,6 +25,7 @@ load_mod_mapfix = true
load_mod_worldedge = true
load_mod_maze = true
load_mod_peace_areas = true
load_mod_soccer = true
load_mod_meru = true
load_mod_watershed = true