Add coloured arrows

This commit is contained in:
stujones11 2015-01-25 17:18:10 +00:00
parent dc86ef4ecb
commit a6f3caeaf5
5 changed files with 101 additions and 70 deletions

View file

@ -5,7 +5,7 @@ Mod Version: 0.5.2
Minetest Version: 0.4.9, 0.4.10 Minetest Version: 0.4.9, 0.4.10
Depends: default, wool, tnt Depends: default, dye, tnt, wool
An experimental first person shooter mod that uses simple vector mathematics An experimental first person shooter mod that uses simple vector mathematics
to produce an accurate and server-firendly method of hit detection. to produce an accurate and server-firendly method of hit detection.
@ -22,6 +22,10 @@ as the base for a 'Spades' style FPS game using the minetest engine.
Crafting Crafting
======== ========
<color> = grey, black, red, yellow, green, cyan, blue, magenta
A = Arrow [shooter:arrow_white]
C = Color Dye [dye:<color>]
W = Wooden Stick [default:stick] W = Wooden Stick [default:stick]
P = Paper [default:paper] P = Paper [default:paper]
S = Steel Ingot [default:steel_ingot] S = Steel Ingot [default:steel_ingot]
@ -41,7 +45,7 @@ Crossbow: [shooter:crossbow]
| W | | B | | W | | B |
+---+---+---+ +---+---+---+
Arrow: [shooter:arrow] White Arrow: [shooter:arrow_white]
+---+---+---+ +---+---+---+
| S | | | | S | | |
@ -51,6 +55,12 @@ Arrow: [shooter:arrow]
| | P | W | | | P | W |
+---+---+---+ +---+---+---+
Coloured Arrow: [shooter:arrow_<color>]
+---+---+
| C | A |
+---+---+
Pistol: [shooter:pistol] Pistol: [shooter:pistol]
+---+---+ +---+---+

View file

@ -2,6 +2,9 @@ SHOOTER_CROSSBOW_USES = 50
SHOOTER_ARROW_TOOL_CAPS = {damage_groups={fleshy=2}} SHOOTER_ARROW_TOOL_CAPS = {damage_groups={fleshy=2}}
SHOOTER_ARROW_LIFETIME = 180 -- 3 minutes SHOOTER_ARROW_LIFETIME = 180 -- 3 minutes
minetest.register_alias("shooter:arrow", "shooter:arrow_white")
minetest.register_alias("shooter:crossbow_loaded", "shooter:crossbow_loaded_white")
local function get_animation_frame(dir) local function get_animation_frame(dir)
local angle = math.atan(dir.y) local angle = math.atan(dir.y)
local frame = 90 - math.floor(angle * 360 / math.pi) local frame = 90 - math.floor(angle * 360 / math.pi)
@ -52,11 +55,6 @@ local function get_texture(name, colour)
return "shooter_"..name..".png^wool_"..colour..".png^shooter_"..name..".png^[makealpha:255,126,126" return "shooter_"..name..".png^wool_"..colour..".png^shooter_"..name..".png^[makealpha:255,126,126"
end end
minetest.register_craftitem("shooter:arrow", {
description = "Arrow",
inventory_image = get_texture("arrow_inv", "white"),
})
minetest.register_entity("shooter:arrow_entity", { minetest.register_entity("shooter:arrow_entity", {
physical = false, physical = false,
visual = "mesh", visual = "mesh",
@ -65,6 +63,7 @@ minetest.register_entity("shooter:arrow_entity", {
textures = { textures = {
get_texture("arrow_uv", "white"), get_texture("arrow_uv", "white"),
}, },
color = "white",
timer = 0, timer = 0,
lifetime = SHOOTER_ARROW_LIFETIME, lifetime = SHOOTER_ARROW_LIFETIME,
player = nil, player = nil,
@ -80,7 +79,7 @@ minetest.register_entity("shooter:arrow_entity", {
on_punch = function(self, puncher) on_punch = function(self, puncher)
if puncher then if puncher then
if puncher:is_player() then if puncher:is_player() then
local stack = "shooter:arrow" local stack = "shooter:arrow_"..self.color
local inv = puncher:get_inventory() local inv = puncher:get_inventory()
if inv:room_for_item("main", stack) then if inv:room_for_item("main", stack) then
inv:add_item("main", stack) inv:add_item("main", stack)
@ -164,9 +163,14 @@ minetest.register_entity("shooter:arrow_entity", {
end, end,
}) })
minetest.register_tool("shooter:crossbow_loaded", { for _, color in pairs(dye.basecolors) do
minetest.register_craftitem("shooter:arrow_"..color, {
description = color:gsub("%a", string.upper, 1).." Arrow",
inventory_image = get_texture("arrow_inv", color),
})
minetest.register_tool("shooter:crossbow_loaded_"..color, {
description = "Crossbow", description = "Crossbow",
inventory_image = get_texture("crossbow_loaded", "white"), inventory_image = get_texture("crossbow_loaded", color),
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
minetest.sound_play("shooter_click", {object=user}) minetest.sound_play("shooter_click", {object=user})
@ -185,6 +189,10 @@ minetest.register_tool("shooter:crossbow_loaded", {
ent = obj:get_luaentity() ent = obj:get_luaentity()
end end
if ent then if ent then
ent.color = color
obj:set_properties({
textures = {get_texture("arrow_uv", color)}
})
minetest.sound_play("shooter_throw", {object=obj}) minetest.sound_play("shooter_throw", {object=obj})
local frame = get_animation_frame(dir) local frame = get_animation_frame(dir)
obj:setyaw(yaw + math.pi) obj:setyaw(yaw + math.pi)
@ -219,22 +227,23 @@ minetest.register_tool("shooter:crossbow_loaded", {
return itemstack return itemstack
end, end,
}) })
end
minetest.register_tool("shooter:crossbow", { minetest.register_tool("shooter:crossbow", {
description = "Crossbow", description = "Crossbow",
inventory_image = "shooter_crossbow.png", inventory_image = "shooter_crossbow.png",
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
local inv = user:get_inventory() local inv = user:get_inventory()
if inv:contains_item("main", "shooter:arrow") then for _, color in pairs(dye.basecolors) do
if inv:contains_item("main", "shooter:arrow_"..color) then
minetest.sound_play("shooter_reload", {object=user}) minetest.sound_play("shooter_reload", {object=user})
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
inv:remove_item("main", "shooter:arrow 1") inv:remove_item("main", "shooter:arrow_"..color.." 1")
end
return "shooter:crossbow_loaded_"..color.." 1 "..itemstack:get_wear()
end
end end
itemstack = "shooter:crossbow_loaded 1 "..itemstack:get_wear()
else
minetest.sound_play("shooter_click", {object=user}) minetest.sound_play("shooter_click", {object=user})
end
return itemstack
end, end,
}) })
@ -248,12 +257,22 @@ if SHOOTER_ENABLE_CRAFTING == true then
}, },
}) })
minetest.register_craft({ minetest.register_craft({
output = "shooter:arrow", output = "shooter:arrow_white",
recipe = { recipe = {
{"default:steel_ingot", "", ""}, {"default:steel_ingot", "", ""},
{"", "default:stick", "default:paper"}, {"", "default:stick", "default:paper"},
{"", "default:paper", "default:stick"}, {"", "default:paper", "default:stick"},
}, },
}) })
for _, color in pairs(dye.basecolors) do
if color ~= "white" then
minetest.register_craft({
output = "shooter:arrow_"..color,
recipe = {
{"", "dye:"..color, "shooter:arrow_white"},
},
})
end
end
end end

View file

@ -1,3 +1,5 @@
default default
wool dye
tnt tnt
wool

Binary file not shown.

Before

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB