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.
This commit is contained in:
kaeza 2013-08-28 21:22:46 -03:00
parent 235fc35751
commit d1b2a6b268
14 changed files with 118 additions and 91 deletions

View File

@ -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.

View File

@ -1,14 +1,22 @@
local BALL_PUSH_CHECK_INTERVAL = 0.1 local BALL_PUSH_CHECK_INTERVAL = 0.1
minetest.register_entity("soccer:ball", { 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, physical = true,
visual = "mesh", visual = "mesh",
mesh = "soccer_ball.x", mesh = "soccer_ball.x",
hp_max = 1000, hp_max = 1000,
groups = { immortal = true }, groups = { immortal = true },
textures = { "soccer_ball.png" }, textures = { "soccer_ball_"..color..".png" },
collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 }, collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 },
timer = 0,
on_step = function(self, dtime) on_step = function(self, dtime)
self.timer = self.timer + dtime self.timer = self.timer + dtime
if self.timer >= BALL_PUSH_CHECK_INTERVAL then if self.timer >= BALL_PUSH_CHECK_INTERVAL then
@ -18,9 +26,9 @@ minetest.register_entity("soccer:ball", {
local p = self.object:getpos(); local p = self.object:getpos();
p.y = p.y - 0.5 p.y = p.y - 0.5
if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then if minetest.registered_nodes[minetest.env:get_node(p).name].walkable then
vel.x = vel.x * 0.80 vel.x = vel.x * 0.85
if vel.y < 0 then vel.y = vel.y * -0.50 end if vel.y < 0 then vel.y = vel.y * -0.65 end
vel.z = vel.z * 0.80 vel.z = vel.z * 0.90
end end
if (math.abs(vel.x) < 0.1) if (math.abs(vel.x) < 0.1)
and (math.abs(vel.z) < 0.1) then and (math.abs(vel.z) < 0.1) then
@ -53,13 +61,15 @@ minetest.register_entity("soccer:ball", {
end end
end end
end, end,
on_punch = function(self, puncher) on_punch = function(self, puncher)
if puncher and puncher:is_player() then if puncher and puncher:is_player() then
local inv = puncher:get_inventory() local inv = puncher:get_inventory()
inv:add_item("main", ItemStack("soccer:ball_item")) inv:add_item("main", ItemStack(ball_item_name))
self.object:remove() self.object:remove()
end end
end, end,
is_moving = function(self) is_moving = function(self)
local v = self.object:getvelocity() local v = self.object:getvelocity()
if (math.abs(v.x) <= 0.1) if (math.abs(v.x) <= 0.1)
@ -71,21 +81,40 @@ minetest.register_entity("soccer:ball", {
end end
return true return true
end, end,
timer = 0, })
})
minetest.register_craftitem(ball_item_name, {
description = "Soccer Ball ("..color..")",
inventory_image = "soccer_ball_"..color.."_inv.png",
minetest.register_craftitem("soccer:ball_item", {
description = "Soccer Ball",
inventory_image = "soccer_ball_inv.png",
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above local pos = pointed_thing.above
--pos = { x=pos.x+0.5, y=pos.y, z=pos.z+0.5 } --pos = { x=pos.x+0.5, y=pos.y, z=pos.z+0.5 }
local ent = minetest.env:add_entity(pos, "soccer:ball") local ent = minetest.env:add_entity(pos, ball_ent_name)
ent:setvelocity({x=0, y=-4, z=0}) ent:setvelocity({x=0, y=-15, z=0})
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
end, 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")

View File

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 180 B

View File

Before

Width:  |  Height:  |  Size: 193 B

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B