commit 6255c81015e5269f7fdb8bee8faa458bfeac8ad1 Author: stujones11 Date: Tue Nov 26 21:22:21 2013 +0000 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a57dbc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +## Generic ignorable patterns and files +*~ +.*.swp +*bak* +tags +*.vim + diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..412765a --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,12 @@ +Minetest Mod - Simple Shooter [shooter] +======================================= + +License Source: 2013 Stuart Jones - LGPL + +License Textures: Stuart Jones - WTFPL + +License Sounds: freesound.org + + flobert1_20070728.wav by Nonoo - Attribution 3.0 Unported (CC BY 3.0) + GUNSHOT.WAV by erkanozan - CC0 1.0 Universal (CC0 1.0) + diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..139cbfe --- /dev/null +++ b/README.txt @@ -0,0 +1,54 @@ +Minetest Mod - Simple Shooter [shooter] +======================================= + +Mod Version: 0.1.0 + +Minetest Version: 0.4.8 + +Depends: default + +An experimental first person shooter mod using vector mathematics instead of +physical projectile entities. This has a number of advantages along with a +number disadvantages. + +Pros: + +Fast and responsive +Fairly light weight +Not affected by chunk boundaries + +Cons: + +Only works against other players +Slightly less realistic + +This is still very much a work in progress and currently not much use in a +singleplayer game. I plan to eventually use this as a base for a 'Spades' style +FPS game using the minetest engine, however, I decided to add a couple of craft +recipes and release this simple version for minetest_game. + +Crafting +======== + +S = Steel Ingot [default:steel_ingot] +B = Bronze Ingot [default:bronze_ingot] +M = Mese Crystal [default:mese_crysytal] + +Pistol: [shooter:pistol] + ++---+---+ +| S | B | ++---+---+ +| | M | ++---+---+ + +Riffle: [shooter:riffle] + ++---+---+---+ +| S | | | ++---+---+---+ +| | B | | ++---+---+---+ +| | M | B | ++---+---+---+ + diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..3a7daa1 --- /dev/null +++ b/depends.txt @@ -0,0 +1,2 @@ +default + diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..54f5cf4 --- /dev/null +++ b/init.lua @@ -0,0 +1,47 @@ +dofile(minetest.get_modpath(minetest.get_current_modname()).."/shooter.lua") + +minetest.register_tool("shooter:pistol", { + description = "Pistol", + inventory_image = "shooter_pistol.png", + on_use = function(itemstack, user, pointed_thing) + shooter:fire_weapon(user, { + range_func = {a=-0.1, b=-1.5, c=100}, + tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=3}}, + sound = "shooter_pistol", + }) + itemstack:add_wear(328) -- 200 Rounds + return itemstack + end, +}) + +minetest.register_tool("shooter:riffle", { + description = "Riffle", + inventory_image = "shooter_riffle.png", + on_use = function(itemstack, user, pointed_thing) + shooter:fire_weapon(user, { + range_func = {a=-0.02, b=-0.6, c=100}, + tool_caps = {full_punch_interval=1.0, damage_groups={fleshy=5}}, + sound = "shooter_riffle", + }) + itemstack:add_wear(656) -- 100 Rounds + return itemstack + end, +}) + +minetest.register_craft({ + output = "shooter:pistol", + recipe = { + {"default:steel_ingot", "default:bronze_ingot"}, + {"", "default:mese_crystal"}, + }, +}) + +minetest.register_craft({ + output = "shooter:riffle", + recipe = { + {"default:steel_ingot", "", ""}, + {"", "default:bronze_ingot", ""}, + {"", "default:mese_crystal", "default:bronze_ingot"}, + }, +}) + diff --git a/shooter.lua b/shooter.lua new file mode 100644 index 0000000..7d4218c --- /dev/null +++ b/shooter.lua @@ -0,0 +1,52 @@ +shooter = {} + +local function in_range(r, x) + local chance = r.a * (x * x) + r.b * x + r.c + if math.random(100) < chance then + return true + end + return false +end + +function shooter:fire_weapon(user, def) + minetest.sound_play(def.sound, {object=user}) + local target = {player=nil, distance=50} + local p1 = user:getpos() + for _,player in ipairs(minetest.get_connected_players()) do + local p2 = player:getpos() + if p1 and p2 then + local x = vector.distance(p1, p2) + p2.y = p2.y - 0.75 + if x > 0 and x < target.distance and x < 50 then + if in_range(def.range_func, x) == true then + local v1 = user:get_look_dir() + local v2 = vector.normalize(vector.direction(p1, p2)) + local vd = vector.subtract(v1, v2) + local yx = 0.00002 * (x * x) - 0.002 * x + 0.05 + local yy = yx * 3 + if math.abs(vd.x) < yx and + math.abs(vd.z) < yx and + math.abs(vd.y) < yy then + target = { + player = player, + distance = x, + direction = v1, + pos1 = {x=p1.x, z=p1.z, y=p1.y+1}, + pos2 = {x=p2.x, z=p2.z, y=p2.y+1.75}, + } + end + end + end + end + end + if target.player then + if minetest.line_of_sight(target.pos1, target.pos2, 1) then + target.player:punch(user, nil, def.tool_caps, target.direction) + end + end +end + +minetest.register_on_joinplayer(function(player) + player:hud_set_flags({crosshair = true}) +end) + diff --git a/sounds/shooter_pistol.ogg b/sounds/shooter_pistol.ogg new file mode 100644 index 0000000..14fc786 Binary files /dev/null and b/sounds/shooter_pistol.ogg differ diff --git a/sounds/shooter_riffle.ogg b/sounds/shooter_riffle.ogg new file mode 100644 index 0000000..1ea68bf Binary files /dev/null and b/sounds/shooter_riffle.ogg differ diff --git a/textures/crosshair.png b/textures/crosshair.png new file mode 100644 index 0000000..30844f7 Binary files /dev/null and b/textures/crosshair.png differ diff --git a/textures/shooter_pistol.png b/textures/shooter_pistol.png new file mode 100644 index 0000000..56c821f Binary files /dev/null and b/textures/shooter_pistol.png differ diff --git a/textures/shooter_riffle.png b/textures/shooter_riffle.png new file mode 100644 index 0000000..451ed5f Binary files /dev/null and b/textures/shooter_riffle.png differ