From 197cb88523cf8580d3a38d13dd3c9a07ce001687 Mon Sep 17 00:00:00 2001 From: Piezo_ Date: Sun, 25 Nov 2018 13:49:26 -0800 Subject: merged https://github.com/kestral246/hangglider, changed a couple things --- LICENSE.txt | 2 + README.md | 38 +++++++++ init.lua | 198 +++++++++++++++++++++++++++++++++++++------- textures/blank.png | Bin 0 -> 4194 bytes textures/glider_struts.png | Bin 0 -> 28576 bytes textures/glider_struts.png~ | Bin 0 -> 32906 bytes 6 files changed, 208 insertions(+), 30 deletions(-) create mode 100644 README.md mode change 100755 => 100644 init.lua create mode 100644 textures/blank.png create mode 100644 textures/glider_struts.png create mode 100644 textures/glider_struts.png~ diff --git a/LICENSE.txt b/LICENSE.txt index 9c34541..4cbb63b 100755 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,7 @@ License for Code ---------------- Copyright (C) 2018 Piezo_ +Copyright (C) 2018 kestral246 Copyright (C) 2016 cd2 (cdqwertz) This program is free software; you can redistribute it and/or @@ -23,6 +24,7 @@ License for Media Textures: glider_inventory.png: CC-BY-SA 3.0 UNPORTED. Created by cd2 (cdqwertz) + glider_struts.png: CC-BY-SA 3.0, Piezo_. Default wood and wool textures from minetest-game. Models and sounds: diff --git a/README.md b/README.md new file mode 100644 index 0000000..56c6a48 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Hang Glider Mod for Minetest +---------------------------- +This is a fork of the minetest-hangglider mod by Piezo_ (orderofthefourthwall@gmail.com) + +Which is located at: + + +**This version is an experimental version that is not intended for general use.** + +It includes the following changes by David G (kestral246@gmail.com): + +- Give visual indication that hangglider is equiped. + - Display simple overlay with blurred struts when equiped. + - Issue: don't know how to disable overlay when using third person view. + +- Also unequip hangglider when landing on water. + +- Attempt to linearize parabolic flight path. + - Start gravity stronger, but gradually reduce it as descent velocity increases. + - Don't use airstopper when equipped from the ground (descent velocity is low). + - Slightly increase flight speed to 1.25. + +- Unequip/equip cycling mid-flight should not fly farther than continuous flight. + - When equipping mid-air (descent velocity higher), use airstopper but increase descent slope afterwards. + - Create airbreak flag so all equips mid-flight use faster descent. + - Reset airbreak flag only when land (canExist goes false). + - Issue: it wouldn't reset if land in water, use fly, and launch from air, before I added test for water, + - Not sure if there are other such cases. + +- Did another round of parameter tuning. + - Commented out hud debug display code with prefix "--debug:". + +- For Minetest 5.x the glider's set_attach point needs to be offset by 1 node. + - Provided alternate commented out version of this line that has the correct offset. + +- Discovered that sprint mod interferes with this mod's speed settings. + - It's likely that other mods that affect player_physics will have this same problem. + - May need to consider adding player_monoid support to this mod. diff --git a/init.lua b/init.lua old mode 100755 new mode 100644 index 4b6c6d7..ca145a7 --- a/init.lua +++ b/init.lua @@ -1,5 +1,50 @@ -hangglider = {} +-- Hangglider mod for Minetest +-- Original code by Piezo_ (orderofthefourthwall@gmail.com) +-- 2018-11-14 + +-- Modifications by David G (kestral246@gmail.com) +-- 2018-11-24 +-- For Minetest 5.x, glider's set_attach needs to be offset by 1 node +-- Switch to alternate commented line below with correct offset. +-- Additional tuning of parameters. +-- Commented out debug hud display code, prefixed with "--debug:". + +-- 2018-11-22 +-- Give visual indication that hangglider is equiped. +-- Display simple overlay with blurred struts when equiped. +-- Issue: don't know how to disable overlay in third person view. +-- Also Unequip hangglider when landing on water. +-- Attempt to linearize parabolic flight path. +-- Start gravity stronger, but gradually reduce it as descent velocity increases. +-- Don't use airstopper when equipped from the ground (descent velocity is low). +-- Slightly increase flight speed to 1.25. +-- Unequip/equip cycling mid-flight should not fly farther than continuous flight. +-- When equipping mid-air (descent velocity higher), use airstopper but increase descent slope afterwards. +-- Create airbreak flag so all equips mid-flight use faster descent. +-- Reset airbreak flag only when land (canExist goes false). +-- Issue: it wouldn't reset if land in water, use fly, and launch from air, before I added test for water, +-- not sure if there are other such cases. +-- Temporarily add hud debug display to show descent velocity, gravity override, and airbreak flag. +-- Still in process of tuning all the parameters. + + +-- Modifications by Piezo_ +-- 2018-11-25 +-- hud overlay and debug can be enabled/disabled +-- Added blender-rendered overlay for struts using the actual model. +-- Reduced airbreak penalty severity +-- gave glider limited durability. + + +local HUD_Overlay = true --show glider struts as overlay on HUD +local debug = false --show debug info in top-center of hud +hangglider = {} --Make this global, so other mods can tell if hangglider exists. hangglider.use = {} +if HUD_Overlay then +hangglider.id = {} -- hud id for displaying overlay with struts +end +if debug then hangglider.debug = {} end -- hud id for debug data +hangglider.airbreak = {} -- true if falling fast when equip minetest.register_entity("hangglider:airstopper", { --A one-instant entity that catches the player and slows them down. hp_max = 3, @@ -31,19 +76,65 @@ minetest.register_entity("hangglider:glider", { local player = self.object:get_attach("parent") if player then local pos = player:getpos() - if hangglider.use[player:get_player_name()] then - if minetest.registered_nodes[minetest.get_node(vector.new(pos.x, pos.y-0.5, pos.z)).name] then - if not minetest.registered_nodes[minetest.get_node(vector.new(pos.x, pos.y-0.5, pos.z)).name].walkable then + local pname = player:get_player_name() + if hangglider.use[pname] then + local mrn_name = minetest.registered_nodes[minetest.get_node(vector.new(pos.x, pos.y-0.5, pos.z)).name] + if mrn_name then + if not (mrn_name.walkable or (mrn_name.drowning and mrn_name.drowning == 1)) then canExist = true - if player:get_player_velocity().y > -4.5 and player:get_physics_override().gravity < 0 then - player:set_physics_override({ - gravity = 0.02, - }) - elseif player:get_player_velocity().y < -5 and player:get_physics_override().gravity > 0 then - player:set_physics_override({ - gravity = -0.02, - }) + local vel = player:get_player_velocity() + local grav = player:get_physics_override().gravity + if debug then player:hud_change(hangglider.debug[pname].id, "text", vel.y..', '..grav..', '..tostring(hangglider.airbreak[pname])) end + -- If airbreaking used, increase the descent progression to not give + -- mid-flight unequip/equip cycles a distance advantage. + if hangglider.airbreak[pname] then + if vel.y <= -4.0 then + grav = -0.2 --Extreme measures are needed, as sometimes speed will get a bit out of control + elseif vel.y <= -2.0 then + grav = -0.02 + elseif vel.y <= -1.75 then + grav = 0.00125 -- *1 + elseif vel.y <= -1.5 then + grav = 0.0025 -- *2 + elseif vel.y <= -1.25 then + grav = 0.005 -- *2 + elseif vel.y <= -1 then + grav = 0.015 -- *3 + elseif vel.y <= -0.75 then + grav = 0.04 -- *4 + elseif vel.y <= -0.5 then + grav = 0.08 -- *4 + elseif vel.y <= -0.25 then + grav = 0.12 -- *3 + elseif vel.y <= 0 then + grav = 0.3 -- *3 + else -- vel.y > 0 + grav = 0.75 -- *1.5 + end + else -- normal descent progression + if vel.y <= -4.0 then + grav = -0.2 + elseif vel.y <= -2.0 then + grav = -0.02 + elseif vel.y <= -1.5 then + grav = 0.00125 + elseif vel.y <= -1.25 then + grav = 0.0025 + elseif vel.y <= -1 then + grav = 0.005 + elseif vel.y <= -0.75 then + grav = 0.01 + elseif vel.y <= -0.5 then + grav = 0.02 + elseif vel.y <= -0.25 then + grav = 0.04 + elseif vel.y <= 0 then + grav = 0.1 + else -- vel.y > 0 + grav = 0.5 + end end + player:set_physics_override({gravity = grav}) end end end @@ -51,8 +142,13 @@ minetest.register_entity("hangglider:glider", { player:set_physics_override({ gravity = 1, jump = 1, + speed = 1, }) - hangglider.use[player:get_player_name()] = false + hangglider.use[pname] = false + if HUD_Overlay then + player:hud_change(hangglider.id[pname], "text", "blank.png") + end + hangglider.airbreak[pname] = false end end end @@ -73,42 +169,84 @@ end) minetest.register_on_joinplayer(function(player) + local pname = player:get_player_name() player:set_physics_override({ gravity = 1, jump = 1, }) - hangglider.use[player:get_player_name()] = false + hangglider.use[pname] = false + if HUD_Overlay then + hangglider.id[pname] = player:hud_add({ + hud_elem_type = "image", + text = "blank.png", + position = {x=0, y=0}, + scale = {x=-100, y=-100}, + alignment = {x=1, y=1}, + offset = {x=0, y=0} + }) end + if debug then + hangglider.debug[pname] = {id = player:hud_add({hud_elem_type = "text", + position = {x=0.5, y=0.1}, + text = "-", + number = 0xFF0000}), -- red text + -- ht = {50,50,50}, + } + end + hangglider.airbreak[pname] = false end) minetest.register_on_leaveplayer(function(player) - hangglider.use[player:get_player_name()] = nil + local pname = player:get_player_name() + hangglider.use[pname] = nil + if HUD_Overlay then hangglider.id[pname] = nil end + if debug then hangglider.debug[pname] = nil end + hangglider.airbreak[pname] = nil end) -minetest.register_craftitem("hangglider:hangglider", { +minetest.register_tool("hangglider:hangglider", { description = "Glider", inventory_image = "glider_item.png", - + stack_max=1, on_use = function(itemstack, user, pointed_thing) if not user then return end local pos = user:get_pos() - if minetest.get_node(pos).name == "air" and not hangglider.use[user:get_player_name()] then --Equip + local pname = user:get_player_name() + if minetest.get_node(pos).name == "air" and not hangglider.use[pname] then --Equip minetest.sound_play("bedsheet", {pos=pos, max_hear_distance = 8, gain = 1.0}) - user:set_physics_override({ - gravity = 0.02, - jump = 0, - }) - local stopper = minetest.add_entity(pos, "hangglider:airstopper") - stopper:get_luaentity().attach = user - user:set_attach( stopper, "", {x=0,y=0,z=0}, {x=0,y=0,z=0}) - hangglider.use[user:get_player_name()] = true + if HUD_Overlay then user:hud_change(hangglider.id[pname], "text", "glider_struts.png") end + local vel = user:get_player_velocity().y + if vel < -2 then -- engage mid-air, falling fast, so stop but ramp velocity more quickly + hangglider.airbreak[pname] = true + user:set_physics_override({ + gravity = 1, + jump = 0, + speed = 1.75, + }) + local stopper = minetest.add_entity(pos, "hangglider:airstopper") + stopper:get_luaentity().attach = user + user:set_attach( stopper, "", {x=0,y=0,z=0}, {x=0,y=0,z=0}) + else + user:set_physics_override({ + gravity = 0.02, + jump = 0, + speed = 1.75, + }) + end + hangglider.use[pname] = true + -- if minetest 0.4.x use this: minetest.add_entity(user:get_pos(), "hangglider:glider"):set_attach(user, "", {x=0,y=0,z=0}, {x=0,y=0,z=0}) - - elseif hangglider.use[user:get_player_name()] then --Unequip - hangglider.use[user:get_player_name()] = false + -- if minetest 5.x use this: + -- minetest.add_entity(user:get_pos(), "hangglider:glider"):set_attach(user, "", {x=0,y=10,z=0}, {x=0,y=0,z=0}) + itemstack:set_wear(itemstack:get_wear() + 255) + return itemstack + elseif hangglider.use[pname] then --Unequip + if HUD_Overlay then user:hud_change(hangglider.id[pname], "text", "blank.png") end + hangglider.use[pname] = false end - end + end, + sound = {breaks = "default_tool_breaks"}, }) minetest.register_craft({ diff --git a/textures/blank.png b/textures/blank.png new file mode 100644 index 0000000..de728ad Binary files /dev/null and b/textures/blank.png differ diff --git a/textures/glider_struts.png b/textures/glider_struts.png new file mode 100644 index 0000000..da71a8a Binary files /dev/null and b/textures/glider_struts.png differ diff --git a/textures/glider_struts.png~ b/textures/glider_struts.png~ new file mode 100644 index 0000000..55dd0d2 Binary files /dev/null and b/textures/glider_struts.png~ differ -- cgit v1.2.3