Add multiple ball colors, and increased a bit ball maxspeed.
Idea and textures due to user Xiug. Thanks goes to him. Also added contributors to the README.
@ -15,3 +15,10 @@ 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"
|
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
|
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).
|
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.
|
||||||
|
202
init.lua
@ -1,91 +1,120 @@
|
|||||||
|
|
||||||
local BALL_PUSH_CHECK_INTERVAL = 0.1
|
local BALL_PUSH_CHECK_INTERVAL = 0.1
|
||||||
|
|
||||||
minetest.register_entity("soccer:ball", {
|
local function reg_ball(color)
|
||||||
physical = true,
|
|
||||||
visual = "mesh",
|
local ball_item_name = "soccer:ball_"..color.."_item"
|
||||||
mesh = "soccer_ball.x",
|
local ball_ent_name = "soccer:ball_"..color.."_entity"
|
||||||
hp_max = 1000,
|
|
||||||
groups = { immortal = true },
|
minetest.register_entity(ball_ent_name, {
|
||||||
textures = { "soccer_ball.png" },
|
physical = true,
|
||||||
collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 },
|
visual = "mesh",
|
||||||
on_step = function(self, dtime)
|
mesh = "soccer_ball.x",
|
||||||
self.timer = self.timer + dtime
|
hp_max = 1000,
|
||||||
if self.timer >= BALL_PUSH_CHECK_INTERVAL then
|
groups = { immortal = true },
|
||||||
self.object:setacceleration({x=0, y=-10, z=0})
|
textures = { "soccer_ball_"..color..".png" },
|
||||||
self.timer = 0
|
collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 },
|
||||||
local vel = self.object:getvelocity()
|
|
||||||
local p = self.object:getpos();
|
timer = 0,
|
||||||
p.y = p.y - 0.5
|
|
||||||
if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then
|
on_step = function(self, dtime)
|
||||||
vel.x = vel.x * 0.80
|
self.timer = self.timer + dtime
|
||||||
if vel.y < 0 then vel.y = vel.y * -0.50 end
|
if self.timer >= BALL_PUSH_CHECK_INTERVAL then
|
||||||
vel.z = vel.z * 0.80
|
self.object:setacceleration({x=0, y=-10, z=0})
|
||||||
end
|
self.timer = 0
|
||||||
if (math.abs(vel.x) < 0.1)
|
local vel = self.object:getvelocity()
|
||||||
and (math.abs(vel.z) < 0.1) then
|
local p = self.object:getpos();
|
||||||
vel.x = 0
|
p.y = p.y - 0.5
|
||||||
vel.z = 0
|
if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then
|
||||||
end
|
vel.x = vel.x * 0.85
|
||||||
self.object:setvelocity(vel)
|
if vel.y < 0 then vel.y = vel.y * -0.65 end
|
||||||
local pos = self.object:getpos()
|
vel.z = vel.z * 0.90
|
||||||
local objs = minetest.env:get_objects_inside_radius(pos, 1)
|
end
|
||||||
local player_count = 0
|
if (math.abs(vel.x) < 0.1)
|
||||||
local final_dir = { x=0, y=0, z=0 }
|
and (math.abs(vel.z) < 0.1) then
|
||||||
for _,obj in ipairs(objs) do
|
vel.x = 0
|
||||||
if obj:is_player() then
|
vel.z = 0
|
||||||
local objdir = obj:get_look_dir()
|
end
|
||||||
local mul = 1
|
self.object:setvelocity(vel)
|
||||||
if (obj:get_player_control().sneak) then
|
local pos = self.object:getpos()
|
||||||
mul = 3
|
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 = 3
|
||||||
|
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
|
||||||
final_dir.x = final_dir.x + (objdir.x * mul)
|
end
|
||||||
final_dir.y = final_dir.y + (objdir.y * mul)
|
if final_dir.x ~= 0 or final_dir.y ~= 0 or final_dir.z ~= 0 then
|
||||||
final_dir.z = final_dir.z + (objdir.z * mul)
|
final_dir.x = (final_dir.x * 5) / player_count
|
||||||
player_count = player_count + 1
|
final_dir.y = (final_dir.y * 5) / player_count
|
||||||
|
final_dir.z = (final_dir.z * 5) / player_count
|
||||||
|
self.object:setvelocity(final_dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if final_dir.x ~= 0 or final_dir.y ~= 0 or final_dir.z ~= 0 then
|
end,
|
||||||
final_dir.x = (final_dir.x * 5) / player_count
|
|
||||||
final_dir.y = (final_dir.y * 5) / player_count
|
|
||||||
final_dir.z = (final_dir.z * 5) / player_count
|
|
||||||
self.object:setvelocity(final_dir)
|
|
||||||
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("soccer:ball_item"))
|
|
||||||
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,
|
|
||||||
timer = 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craftitem("soccer:ball_item", {
|
on_punch = function(self, puncher)
|
||||||
description = "Soccer Ball",
|
if puncher and puncher:is_player() then
|
||||||
inventory_image = "soccer_ball_inv.png",
|
local inv = puncher:get_inventory()
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
inv:add_item("main", ItemStack(ball_item_name))
|
||||||
local pos = pointed_thing.above
|
self.object:remove()
|
||||||
--pos = { x=pos.x+0.5, y=pos.y, z=pos.z+0.5 }
|
end
|
||||||
local ent = minetest.env:add_entity(pos, "soccer:ball")
|
end,
|
||||||
ent:setvelocity({x=0, y=-4, z=0})
|
|
||||||
itemstack:take_item()
|
is_moving = function(self)
|
||||||
return itemstack
|
local v = self.object:getvelocity()
|
||||||
end,
|
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",
|
||||||
|
|
||||||
|
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)
|
||||||
|
ent:setvelocity({x=0, y=-15, z=0})
|
||||||
|
itemstack:take_item()
|
||||||
|
return itemstack
|
||||||
|
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_node("soccer:goal", {
|
minetest.register_node("soccer:goal", {
|
||||||
description = "Soccer Goal",
|
description = "Soccer Goal",
|
||||||
@ -147,13 +176,4 @@ reg_decal("line_d", "Diagonal Line")
|
|||||||
reg_decal("line_point", "Point")
|
reg_decal("line_point", "Point")
|
||||||
reg_decal("line_corner", "Corner")
|
reg_decal("line_corner", "Corner")
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_alias("ball", "soccer:ball_item_black")
|
||||||
output = "soccer:ball_item",
|
|
||||||
recipe = {
|
|
||||||
{ "", "wool:white", "" },
|
|
||||||
{ "wool:white", "default:coal_lump", "wool:white" },
|
|
||||||
{ "", "wool:white", "" },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_alias("ball", "soccer:ball_item")
|
|
||||||
|
Before Width: | Height: | Size: 180 B After Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 193 B After Width: | Height: | Size: 193 B |
BIN
textures/soccer_ball_blue.png
Normal file
After Width: | Height: | Size: 148 B |
BIN
textures/soccer_ball_blue_inv.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
textures/soccer_ball_green.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
textures/soccer_ball_green_inv.png
Normal file
After Width: | Height: | Size: 278 B |
BIN
textures/soccer_ball_purple.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
textures/soccer_ball_purple_inv.png
Normal file
After Width: | Height: | Size: 266 B |
BIN
textures/soccer_ball_red.png
Normal file
After Width: | Height: | Size: 145 B |
BIN
textures/soccer_ball_red_inv.png
Normal file
After Width: | Height: | Size: 262 B |
BIN
textures/soccer_ball_yellow.png
Normal file
After Width: | Height: | Size: 149 B |
BIN
textures/soccer_ball_yellow_inv.png
Normal file
After Width: | Height: | Size: 264 B |