Add coloured arrows
This commit is contained in:
parent
dc86ef4ecb
commit
a6f3caeaf5
5 changed files with 101 additions and 70 deletions
14
README.txt
14
README.txt
|
@ -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]
|
||||||
|
|
||||||
+---+---+
|
+---+---+
|
||||||
|
|
153
crossbow.lua
153
crossbow.lua
|
@ -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,77 +163,87 @@ minetest.register_entity("shooter:arrow_entity", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_tool("shooter:crossbow_loaded", {
|
for _, color in pairs(dye.basecolors) do
|
||||||
description = "Crossbow",
|
minetest.register_craftitem("shooter:arrow_"..color, {
|
||||||
inventory_image = get_texture("crossbow_loaded", "white"),
|
description = color:gsub("%a", string.upper, 1).." Arrow",
|
||||||
groups = {not_in_creative_inventory=1},
|
inventory_image = get_texture("arrow_inv", color),
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
})
|
||||||
minetest.sound_play("shooter_click", {object=user})
|
minetest.register_tool("shooter:crossbow_loaded_"..color, {
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
description = "Crossbow",
|
||||||
itemstack:add_wear(65535/SHOOTER_CROSSBOW_USES)
|
inventory_image = get_texture("crossbow_loaded", color),
|
||||||
end
|
groups = {not_in_creative_inventory=1},
|
||||||
itemstack = "shooter:crossbow 1 "..itemstack:get_wear()
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
local pos = user:getpos()
|
minetest.sound_play("shooter_click", {object=user})
|
||||||
local dir = user:get_look_dir()
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
local yaw = user:get_look_yaw()
|
itemstack:add_wear(65535/SHOOTER_CROSSBOW_USES)
|
||||||
if pos and dir and yaw then
|
|
||||||
pos.y = pos.y + 1.5
|
|
||||||
local obj = minetest.add_entity(pos, "shooter:arrow_entity")
|
|
||||||
local ent = nil
|
|
||||||
if obj then
|
|
||||||
ent = obj:get_luaentity()
|
|
||||||
end
|
end
|
||||||
if ent then
|
itemstack = "shooter:crossbow 1 "..itemstack:get_wear()
|
||||||
minetest.sound_play("shooter_throw", {object=obj})
|
local pos = user:getpos()
|
||||||
local frame = get_animation_frame(dir)
|
local dir = user:get_look_dir()
|
||||||
obj:setyaw(yaw + math.pi)
|
local yaw = user:get_look_yaw()
|
||||||
obj:set_animation({x=frame, y=frame}, 0)
|
if pos and dir and yaw then
|
||||||
obj:setvelocity({x=dir.x * 14, y=dir.y * 14, z=dir.z * 14})
|
pos.y = pos.y + 1.5
|
||||||
if pointed_thing.type ~= "nothing" then
|
local obj = minetest.add_entity(pos, "shooter:arrow_entity")
|
||||||
local ppos = minetest.get_pointed_thing_position(pointed_thing, false)
|
local ent = nil
|
||||||
local _, npos = minetest.line_of_sight(pos, ppos, 1)
|
if obj then
|
||||||
if npos then
|
ent = obj:get_luaentity()
|
||||||
ppos = npos
|
end
|
||||||
pointed_thing.type = "node"
|
if ent then
|
||||||
end
|
ent.color = color
|
||||||
if pointed_thing.type == "object" then
|
obj:set_properties({
|
||||||
punch_object(user, pointed_thing.ref)
|
textures = {get_texture("arrow_uv", color)}
|
||||||
elseif pointed_thing.type == "node" then
|
})
|
||||||
local node = minetest.get_node(ppos)
|
minetest.sound_play("shooter_throw", {object=obj})
|
||||||
local tpos = get_target_pos(pos, ppos, dir, 0.66)
|
local frame = get_animation_frame(dir)
|
||||||
minetest.after(0.2, function(object, pos, npos)
|
obj:setyaw(yaw + math.pi)
|
||||||
ent.node_pos = npos
|
obj:set_animation({x=frame, y=frame}, 0)
|
||||||
ent.state = "stuck"
|
obj:setvelocity({x=dir.x * 14, y=dir.y * 14, z=dir.z * 14})
|
||||||
stop_arrow(object, pos, true)
|
if pointed_thing.type ~= "nothing" then
|
||||||
shooter:play_node_sound(node, npos)
|
local ppos = minetest.get_pointed_thing_position(pointed_thing, false)
|
||||||
end, obj, tpos, ppos)
|
local _, npos = minetest.line_of_sight(pos, ppos, 1)
|
||||||
return itemstack
|
if npos then
|
||||||
end
|
ppos = npos
|
||||||
|
pointed_thing.type = "node"
|
||||||
|
end
|
||||||
|
if pointed_thing.type == "object" then
|
||||||
|
punch_object(user, pointed_thing.ref)
|
||||||
|
elseif pointed_thing.type == "node" then
|
||||||
|
local node = minetest.get_node(ppos)
|
||||||
|
local tpos = get_target_pos(pos, ppos, dir, 0.66)
|
||||||
|
minetest.after(0.2, function(object, pos, npos)
|
||||||
|
ent.node_pos = npos
|
||||||
|
ent.state = "stuck"
|
||||||
|
stop_arrow(object, pos, true)
|
||||||
|
shooter:play_node_sound(node, npos)
|
||||||
|
end, obj, tpos, ppos)
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
end
|
||||||
|
obj:setacceleration({x=dir.x * -3, y=-5, z=dir.z * -3})
|
||||||
|
ent.player = ent.player or user
|
||||||
|
ent.state = "flight"
|
||||||
end
|
end
|
||||||
obj:setacceleration({x=dir.x * -3, y=-5, z=dir.z * -3})
|
|
||||||
ent.player = ent.player or user
|
|
||||||
ent.state = "flight"
|
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
minetest.sound_play("shooter_reload", {object=user})
|
if inv:contains_item("main", "shooter:arrow_"..color) then
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
minetest.sound_play("shooter_reload", {object=user})
|
||||||
inv:remove_item("main", "shooter:arrow 1")
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
inv:remove_item("main", "shooter:arrow_"..color.." 1")
|
||||||
|
end
|
||||||
|
return "shooter:crossbow_loaded_"..color.." 1 "..itemstack:get_wear()
|
||||||
end
|
end
|
||||||
itemstack = "shooter:crossbow_loaded 1 "..itemstack:get_wear()
|
|
||||||
else
|
|
||||||
minetest.sound_play("shooter_click", {object=user})
|
|
||||||
end
|
end
|
||||||
return itemstack
|
minetest.sound_play("shooter_click", {object=user})
|
||||||
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
|
||||||
|
|
||||||
|
|
|
@ -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 |
Loading…
Reference in a new issue