diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c7fb713 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,26 @@ +License for Code +---------------- + +Copyright (C) 2016 Birgit Lachner + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +License for Textures, Models and Sounds +--------------------------------------- +... will be added after there are some textures that are under a License that need that. Till then, everything is licensed CC-0. + + +CC-BY-SA 3.0 UNPORTED. Created by Birgit Lachner \ No newline at end of file diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/description.txt b/description.txt new file mode 100644 index 0000000..4df0715 --- /dev/null +++ b/description.txt @@ -0,0 +1 @@ +A Mod to let Kids start programming with a turtle that can move around in the world, and dig and build what the user wants. diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..db3c8f6 --- /dev/null +++ b/init.lua @@ -0,0 +1,165 @@ + +minetest.register_craftitem("turtle_miner:remotecontrol", { + description = "A remote control for Miner-Turtles", + inventory_image = "turtle_miner_remotecontrol.png", +}) + +local turtle_formspec_positions = {} + +minetest.register_node("turtle_miner:firstturtle", { + description = "First Turtle for Trials", + tiles = {"turtle_miner_firstturtle_top.png", "turtle_miner_firstturtle_buttom.png", "turtle_miner_firstturtle_right.png", "turtle_miner_firstturtle_left.png", "turtle_miner_firstturtle_back.png", "turtle_miner_firstturtle_front.png"}, + groups={oddly_breakable_by_hand=1}, + paramtype2 = "facedir", + + on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local wielditem = clicker:get_wielded_item() + local wieldname = wielditem:get_name() + if wieldname ~= "turtle_miner:remotecontrol" then + minetest.chat_send_player(clicker:get_player_name(), "Nimm die Fernbedienung!") + else + -- When the player does a right click on this node + local player_name = clicker:get_player_name() + -- Save the last turtle in a table + turtle_formspec_positions[player_name] = pos + + minetest.show_formspec(player_name, "turtle_miner:control_formspec", + "size[9,4]" .. + "label[0,0;Click buttons to move the turtle around!]" .. + "button_exit[5,1;2,1;exit;Exit]" .. + "image_button[1,1;1,1;arrow_up.png;up;]" .. + "image_button[2,1;1,1;arrow_fw.png;forward;]" .. + "image_button[1,2;1,1;arrow_left.png;turnleft;]".. + "image_button[3,2;1,1;arrow_right.png;turnright;]" .. + "image_button[1,3;1,1;arrow_down.png;down;]" .. + "image_button[2,3;1,1;arrow_bw.png;backward;]" + ) + return itemstack + + end + + end, +}) + +-- image_button[X,Y;W,H;image;name;label] + +local function nextrangeright(x) + x = x + 1 + if x > 3 then + x = 0 + end + return x +end + +local function nextrangeleft(x) + x = x - 1 + if x < 0 then + x = 3 + end + return x +end + +-- Catch user inputs from the formspec +minetest.register_on_player_receive_fields(function(sender, formname, fields) + if formname ~= "turtle_miner:control_formspec" then + return -- Not a turtle formspec + end + local player_name = sender:get_player_name() + local pos = turtle_formspec_positions[player_name] + + if not pos then + return -- Something went wrong. No position found for this player + end + + local node = minetest.get_node(pos) + + if node.name ~= "turtle_miner:firstturtle" then + turtle_formspec_positions[player_name] = nil + return -- Data invalid. There's no turtle at the given position + end + + local new_pos = vector.new(pos) + + if fields.up then + new_pos.y = new_pos.y + 1 + end + + if fields.down then + new_pos.y = new_pos.y - 1 + end + + if fields.forward then + new_pos.z = new_pos.z + 1 + end + + if fields.backward then + new_pos.z = new_pos.z - 1 + end + + if fields.turnright then + local ndef = minetest.registered_nodes[node.name] + + -- Compute param2 + local rotationPart = node.param2 % 32 -- get first 4 bits + local preservePart = node.param2 - rotationPart + local axisdir = math.floor(rotationPart / 4) + local rotation = rotationPart - axisdir * 4 + rotationPart = axisdir * 4 + nextrangeright(rotation) + + local new_param2 = preservePart + rotationPart + + node.param2 = new_param2 + minetest.swap_node(pos, node) + minetest.sound_play("moveokay", {to_player = player_name,gain = 1.0,}) + return + end + + if fields.turnleft then + local ndef = minetest.registered_nodes[node.name] + + -- Compute param2 + local rotationPart = node.param2 % 32 -- get first 4 bits + local preservePart = node.param2 - rotationPart + local axisdir = math.floor(rotationPart / 4) + local rotation = rotationPart - axisdir * 4 + rotationPart = axisdir * 4 + nextrangeleft(rotation) + + local new_param2 = preservePart + rotationPart + + node.param2 = new_param2 + minetest.swap_node(pos, node) + minetest.sound_play("moveokay",{to_player = player_name,gain = 1.0,}) + return + end + + + -- Check new position if empty + local newposchecktable = minetest.get_node(new_pos) + local newposcheck = newposchecktable.name + local walkable = minetest.registered_nodes[newposcheck].walkable + local dir = minetest.facedir_to_dir(node.param2) + + minetest.chat_send_all(newposcheck) + minetest.chat_send_all(tostring(dir.x)) + minetest.chat_send_all(tostring(walkable)) + + if not walkable then + if not vector.equals(pos, new_pos) then + -- Move node to new position + minetest.remove_node(pos) + minetest.set_node(new_pos, node) --move node to new position + minetest.get_meta(new_pos):from_table(meta) --set metadata of new node + + -- Update formspec reference position, wait for next instructions + turtle_formspec_positions[player_name] = new_pos + + minetest.sound_play("moveokay", {to_player = player_name,gain = 1.0,}) + end + else + minetest.sound_play("moveerror", { + to_player = player_name, + gain = 1.0, + }) + end +end) + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c297e16 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +Installation as always for Mods in Minetest: Extract the downloaded ZIP-Master file and move ot to mods folfer of Minetest. Enable the Mod in the settings for the world. \ No newline at end of file diff --git a/sounds/moveerror.ogg b/sounds/moveerror.ogg new file mode 100644 index 0000000..9cf3817 Binary files /dev/null and b/sounds/moveerror.ogg differ diff --git a/sounds/moveokay.ogg b/sounds/moveokay.ogg new file mode 100644 index 0000000..730dc47 Binary files /dev/null and b/sounds/moveokay.ogg differ diff --git a/textures/arrow_bw.png b/textures/arrow_bw.png new file mode 100644 index 0000000..142f349 Binary files /dev/null and b/textures/arrow_bw.png differ diff --git a/textures/arrow_down.png b/textures/arrow_down.png new file mode 100644 index 0000000..facbf4e Binary files /dev/null and b/textures/arrow_down.png differ diff --git a/textures/arrow_fw.png b/textures/arrow_fw.png new file mode 100644 index 0000000..98ad5fc Binary files /dev/null and b/textures/arrow_fw.png differ diff --git a/textures/arrow_left.png b/textures/arrow_left.png new file mode 100644 index 0000000..f186db7 Binary files /dev/null and b/textures/arrow_left.png differ diff --git a/textures/arrow_right.png b/textures/arrow_right.png new file mode 100644 index 0000000..9ddb16d Binary files /dev/null and b/textures/arrow_right.png differ diff --git a/textures/arrow_up.png b/textures/arrow_up.png new file mode 100644 index 0000000..1ecb330 Binary files /dev/null and b/textures/arrow_up.png differ diff --git a/textures/turtle_miner_firstturtle_back.png b/textures/turtle_miner_firstturtle_back.png new file mode 100644 index 0000000..b71f53f Binary files /dev/null and b/textures/turtle_miner_firstturtle_back.png differ diff --git a/textures/turtle_miner_firstturtle_buttom.png b/textures/turtle_miner_firstturtle_buttom.png new file mode 100644 index 0000000..cc4fbd0 Binary files /dev/null and b/textures/turtle_miner_firstturtle_buttom.png differ diff --git a/textures/turtle_miner_firstturtle_front.png b/textures/turtle_miner_firstturtle_front.png new file mode 100644 index 0000000..55b0892 Binary files /dev/null and b/textures/turtle_miner_firstturtle_front.png differ diff --git a/textures/turtle_miner_firstturtle_left.png b/textures/turtle_miner_firstturtle_left.png new file mode 100644 index 0000000..fc49e6b Binary files /dev/null and b/textures/turtle_miner_firstturtle_left.png differ diff --git a/textures/turtle_miner_firstturtle_right.png b/textures/turtle_miner_firstturtle_right.png new file mode 100644 index 0000000..c77156c Binary files /dev/null and b/textures/turtle_miner_firstturtle_right.png differ diff --git a/textures/turtle_miner_firstturtle_top.png b/textures/turtle_miner_firstturtle_top.png new file mode 100644 index 0000000..0e08fab Binary files /dev/null and b/textures/turtle_miner_firstturtle_top.png differ diff --git a/textures/turtle_miner_remotecontrol.png b/textures/turtle_miner_remotecontrol.png new file mode 100644 index 0000000..2fd38a9 Binary files /dev/null and b/textures/turtle_miner_remotecontrol.png differ