From d1b2a6b26893597d145292f83674c3584402bd57 Mon Sep 17 00:00:00 2001 From: kaeza Date: Wed, 28 Aug 2013 21:22:46 -0300 Subject: [PATCH] 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. --- README.txt | 7 + init.lua | 202 ++++++++++-------- ...{soccer_ball.png => soccer_ball_black.png} | Bin ...ball_inv.png => soccer_ball_black_inv.png} | Bin textures/soccer_ball_blue.png | Bin 0 -> 148 bytes textures/soccer_ball_blue_inv.png | Bin 0 -> 266 bytes textures/soccer_ball_green.png | Bin 0 -> 145 bytes textures/soccer_ball_green_inv.png | Bin 0 -> 278 bytes textures/soccer_ball_purple.png | Bin 0 -> 149 bytes textures/soccer_ball_purple_inv.png | Bin 0 -> 266 bytes textures/soccer_ball_red.png | Bin 0 -> 145 bytes textures/soccer_ball_red_inv.png | Bin 0 -> 262 bytes textures/soccer_ball_yellow.png | Bin 0 -> 149 bytes textures/soccer_ball_yellow_inv.png | Bin 0 -> 264 bytes 14 files changed, 118 insertions(+), 91 deletions(-) rename textures/{soccer_ball.png => soccer_ball_black.png} (100%) rename textures/{soccer_ball_inv.png => soccer_ball_black_inv.png} (100%) create mode 100644 textures/soccer_ball_blue.png create mode 100644 textures/soccer_ball_blue_inv.png create mode 100644 textures/soccer_ball_green.png create mode 100644 textures/soccer_ball_green_inv.png create mode 100644 textures/soccer_ball_purple.png create mode 100644 textures/soccer_ball_purple_inv.png create mode 100644 textures/soccer_ball_red.png create mode 100644 textures/soccer_ball_red_inv.png create mode 100644 textures/soccer_ball_yellow.png create mode 100644 textures/soccer_ball_yellow_inv.png diff --git a/README.txt b/README.txt index 60f5d52..d860a23 100644 --- a/README.txt +++ b/README.txt @@ -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" 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. diff --git a/init.lua b/init.lua index eb7ad8f..183eb73 100644 --- a/init.lua +++ b/init.lua @@ -1,91 +1,120 @@ local BALL_PUSH_CHECK_INTERVAL = 0.1 -minetest.register_entity("soccer:ball", { - physical = true, - visual = "mesh", - mesh = "soccer_ball.x", - hp_max = 1000, - groups = { immortal = true }, - textures = { "soccer_ball.png" }, - collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 }, - on_step = function(self, dtime) - self.timer = self.timer + dtime - if self.timer >= BALL_PUSH_CHECK_INTERVAL then - self.object:setacceleration({x=0, y=-10, 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.80 - if vel.y < 0 then vel.y = vel.y * -0.50 end - vel.z = vel.z * 0.80 - 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 = 3 +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, + visual = "mesh", + mesh = "soccer_ball.x", + hp_max = 1000, + groups = { immortal = true }, + textures = { "soccer_ball_"..color..".png" }, + collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 }, + + timer = 0, + + on_step = function(self, dtime) + self.timer = self.timer + dtime + if self.timer >= BALL_PUSH_CHECK_INTERVAL then + self.object:setacceleration({x=0, y=-10, 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.85 + if vel.y < 0 then vel.y = vel.y * -0.65 end + vel.z = vel.z * 0.90 + 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 = 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 - 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 + if final_dir.x ~= 0 or final_dir.y ~= 0 or final_dir.z ~= 0 then + 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 - if final_dir.x ~= 0 or final_dir.y ~= 0 or final_dir.z ~= 0 then - 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, -}) + end, -minetest.register_craftitem("soccer:ball_item", { - description = "Soccer Ball", - inventory_image = "soccer_ball_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, "soccer:ball") - ent:setvelocity({x=0, y=-4, z=0}) - itemstack:take_item() - return itemstack - 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", + + 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", { description = "Soccer Goal", @@ -147,13 +176,4 @@ reg_decal("line_d", "Diagonal Line") reg_decal("line_point", "Point") reg_decal("line_corner", "Corner") -minetest.register_craft({ - output = "soccer:ball_item", - recipe = { - { "", "wool:white", "" }, - { "wool:white", "default:coal_lump", "wool:white" }, - { "", "wool:white", "" }, - }, -}) - -minetest.register_alias("ball", "soccer:ball_item") +minetest.register_alias("ball", "soccer:ball_item_black") diff --git a/textures/soccer_ball.png b/textures/soccer_ball_black.png similarity index 100% rename from textures/soccer_ball.png rename to textures/soccer_ball_black.png diff --git a/textures/soccer_ball_inv.png b/textures/soccer_ball_black_inv.png similarity index 100% rename from textures/soccer_ball_inv.png rename to textures/soccer_ball_black_inv.png diff --git a/textures/soccer_ball_blue.png b/textures/soccer_ball_blue.png new file mode 100644 index 0000000000000000000000000000000000000000..0cca107a172f3dd302657a765c8f7e833ad88ee6 GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#E{8b3veN(f4}3r&V^0^y5RLQ6Q{L@3%)sn_YU;zBndf##9GxlQ!LsH0fgk_> r*EhX$6O(VLOHe#^ckxGuVqS*R8q(4Vp^j^T+8I1u{an^LB{Ts5KMyQ% literal 0 HcmV?d00001 diff --git a/textures/soccer_ball_blue_inv.png b/textures/soccer_ball_blue_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..89e02131005bb9de868c0ad8229f583a2b3420a5 GIT binary patch literal 266 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkEh_+plH3Vl`H)3A5LlOn4tDs-et+O zlua)CzcMq-_@19${lc1INleymVTqG|;hy2!T4MKhc4nq;FxoBW;;6iT>*d?)%a_#M z+r{7i-QjEH-Z-YWS63{$?`Lh97=B__=IUFkr_`VS$@2aoPlV~Web0bSWbkzLb6Mw< G&;$TpabXJp literal 0 HcmV?d00001 diff --git a/textures/soccer_ball_green.png b/textures/soccer_ball_green.png new file mode 100644 index 0000000000000000000000000000000000000000..e2eefccd8fd83b8c75798be8b6322e0701be380c GIT binary patch literal 145 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|oCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#E{8b3GHX<*YbsF4z|+MsMB{w&lYJ-8GBC$q*>~Wk&Gw27UB-qJI5O5Ze*FLc nKg-=-9XpA?22%XZhxi$IHcEcIs%TmO)XU)M>gTe~DWM4fK`|*( literal 0 HcmV?d00001 diff --git a/textures/soccer_ball_green_inv.png b/textures/soccer_ball_green_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..f6068d83a9c0adbf5ce94f38d1eb959700ff12ac GIT binary patch literal 278 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(-A6hR@EnB%Neo^Y)^bfheEatI> z*5!X*A8$YLSY>~$#{XE z)7O>#E{8b3lKeiM-Z-F;iKmNWh{pNkJ*T$zGO}&iS9R#-^&Q)jMbncM1TVxfKmPy! rKj$v#$QprPjja;p{l}Qknldo(|Ce?TI&?J^sGq^p)z4*}Q$iB}4!0|a literal 0 HcmV?d00001 diff --git a/textures/soccer_ball_purple_inv.png b/textures/soccer_ball_purple_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..91f48eeb9d9e0e260bf28ae3a06d059d9e576c09 GIT binary patch literal 266 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE|0^$fkM+gT^vI!PA?5UDR{(yLwMevIeunS zRamX3R#@MxnJaEQL-5?jUyY6tGE7agyp#Vuy}_b|=i;cmf9vJj>&uta z-P^_A|J~th<=!}^w^vszy6{XE z)7O>#E{8b3il+LR{fgTe~DWM4fR+cGJ literal 0 HcmV?d00001 diff --git a/textures/soccer_ball_red_inv.png b/textures/soccer_ball_red_inv.png new file mode 100644 index 0000000000000000000000000000000000000000..48aff7ab38983e9a6a8ceabd6390680a702f5347 GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE{XE z)7O>#E{8b3iqN#;oO9rZDgHf0;K~mA6DytzKHa!vArip|gue_g{XcAn!@K zf%D864%Gjho5SDB?2xtfi*@J3HzlDZsopoP&OYH|?Q3G>Z`(1+tuA}{_4w^e>hA60 z@Bi-bwQ_G9)7z^rT=&l{D>}4pg6ZXbS?h!L&HKz~`AuAA^W+OxfevKwboFyt=akR{ E0N(Clq5uE@ literal 0 HcmV?d00001