3D魔方游戏制作lua迷你世界

--3D魔方

--星空露珠工作室

--核心脚本来自负负

--1:xy 2:yx 3:xz 4:zx 5:yz 6:zy

--4000,0-3 3995-0,3

local trn={

{{5,2},{3,1},{1,2},{1,3},{4,0},{2,2}},

{{3,0},{5,3},{1,3},{1,2},{2,3},{4,1}},

{{4,2},{2,1},{1,1},{1,0},{3,3},{5,1}},

{{2,0},{4,3},{1,0},{1,1},{5,0},{3,2}},

{{6,0},{1,3},{2,2},{2,3},{5,2},{3,0}},

{{1,2},{6,1},{2,3},{2,2},{3,1},{5,3}},

{{5,1},{3,2},{2,1},{2,0},{1,0},{6,2}},

{{3,3},{5,0},{2,0},{2,1},{6,3},{1,1}},

{{6,2},{1,1},{3,2},{3,3},{2,0},{4,2}},

{{1,0},{6,3},{3,3},{3,2},{4,3},{2,1}},

{{2,2},{4,1},{3,1},{3,0},{1,3},{6,1}},

{{4,0},{2,3},{3,0},{3,1},{6,0},{1,2}},

{{5,0},{3,3},{4,2},{4,3},{6,2},{1,0}},

{{3,2},{5,1},{4,3},{4,2},{1,1},{6,3}},

{{6,1},{1,2},{4,1},{4,0},{3,0},{5,2}},

{{1,3},{6,0},{4,0},{4,1},{5,3},{3,1}},

{{2,3},{4,0},{5,2},{5,3},{6,1},{1,3}},

{{4,1},{2,2},{5,3},{5,2},{1,2},{6,0}},

{{6,3},{1,0},{5,1},{5,0},{4,2},{2,0}},

{{1,1},{6,2},{5,0},{5,1},{2,1},{4,3}},

{{4,3},{2,0},{6,2},{6,3},{5,1},{3,3}},

{{2,1},{4,2},{6,3},{6,2},{3,2},{5,0}},

{{5,3},{3,0},{6,1},{6,0},{2,2},{4,0}},

{{3,1},{5,2},{6,0},{6,1},{4,1},{2,3}}}

1.上面-黄

2.左面-绿

3.后面-红

4.右面-蓝

5.前面-橙

6.下面-白

模型快速制作,请阅读下一篇
local ids={4000,3999,3998,3997,3996,3995}

local x0,y0,z0=0,9,0--起点坐标

--黄,绿,红,蓝,橙,白

--魔方数据

local cft={{

{{1,0},{1,0},{1,0}},

{{1,0},{1,0},{1,0}},

{{1,0},{1,0},{1,0}}}

,{

{{1,0},{1,0},{1,0}},

{{1,0},{1,0},{1,0}},

{{1,0},{1,0},{1,0}}}

,{

{{1,0},{1,0},{1,0}},

{{1,0},{1,0},{1,0}},

{{1,0},{1,0},{1,0}}}}

local x,y,z=0,0,0

--游戏开始,生成魔方

local function Go(e)

for x=0,2 do

for y=0,2 do

for z=0,2 do

Block:destroyBlock(Px0+x,y0+y,z0+z,false)

Block:setBlockAll(x0+x,y0+y,z0+z,ids[1],0)

end

end

end

end

ScriptSupportEvent:registerEvent([=[Game.Start]=],Go)

--刷新魔方

local function Re()

local str=''

for x=1,3 do

str=str..'\n'

for y=1,3 do

str=str..'\n'

for z=1,3 do

str=str..'('..cft[x][4-y][z][1]..','.. cft[x][4-y][z][2]..'),'

Block:setBlockAll(x0+z-1,y0+x-1,z0+y-1,ids[cft[x][4-y][z][1]],cft[x][4-y][z][2])

end

end

end

print("打印\n"..str)

end

--旋转

local rc={1,0}

local function Ton(a,e,b)

rc[1]=cft[a[1]][a[2]][a[3]][1]

rc[2]=cft[a[1]][a[2]][a[3]][2]

cft[a[1]][a[2]][a[3]][1]=trn[cft[a[4]][a[5]][a[6]][1]*4+cft[a[4]][a[5]][a[6]][2]-3][b][1]

cft[a[1]][a[2]][a[3]][2]=trn[cft[a[4]][a[5]][a[6]][1]*4+cft[a[4]][a[5]][a[6]][2]-3][b][2]

cft[a[4]][a[5]][a[6]][1]=trn[cft[a[7]][a[8]][a[9]][1]*4+cft[a[7]][a[8]][a[9]][2]-3][b][1]

cft[a[4]][a[5]][a[6]][2]=trn[cft[a[7]][a[8]][a[9]][1]*4+cft[a[7]][a[8]][a[9]][2]-3][b][2]

cft[a[7]][a[8]][a[9]][1]=trn[cft[a[10]][a[11]][a[12]][1]*4+cft[a[10]][a[11]][a[12]][2]-3][b][1]

cft[a[7]][a[8]][a[9]][2]=trn[cft[a[10]][a[11]][a[12]][1]*4+cft[a[10]][a[11]][a[12]][2]-3][b][2]

cft[a[10]][a[11]][a[12]][1]=trn[rc[1]*4+rc[2]-3][b][1]

cft[a[10]][a[11]][a[12]][2]=trn[rc[1]*4+rc[2]-3][b][2]


rc[1]=cft[e[1]][e[2]][e[3]][1]

rc[2]=cft[e[1]][e[2]][e[3]][2]

cft[e[1]][e[2]][e[3]][1]=trn[cft[e[4]][e[5]][e[6]][1]*4+cft[e[4]][e[5]][e[6]][2]-3][b][1]

cft[e[1]][e[2]][e[3]][2]=trn[cft[e[4]][e[5]][e[6]][1]*4+cft[e[4]][e[5]][e[6]][2]-3][b][2]

cft[e[4]][e[5]][e[6]][1]=trn[cft[e[7]][e[8]][e[9]][1]*4+cft[e[7]][e[8]][e[9]][2]-3][b][1]

cft[e[4]][e[5]][e[6]][2]=trn[cft[e[7]][e[8]][e[9]][1]*4+cft[e[7]][e[8]][e[9]][2]-3][b][2]

cft[e[7]][e[8]][e[9]][1]=trn[cft[e[10]][e[11]][e[12]][1]*4+cft[e[10]][e[11]][e[12]][2]-3][b][1]

cft[e[7]][e[8]][e[9]][2]=trn[cft[e[10]][e[11]][e[12]][1]*4+cft[e[10]][e[11]][e[12]][2]-3][b][2]

cft[e[10]][e[11]][e[12]][1]=trn[rc[1]*4+rc[2]-3][b][1]

cft[e[10]][e[11]][e[12]][2]=trn[rc[1]*4+rc[2]-3][b][2]

end

--d m: 0左中右 1上中下 2前中后

--m: 0顺时针 1逆时针 从左后下方

local function Re0(d,i,m)

if (d==0)and(m==0) then

Ton({1,3,1+i,3,3,1+i,3,1,1+i,1,1,1+i},{1,2,1+i,2,3,1+i,3,2,1+i,2,1,1+i},6)

elseif (d==0)and(m==1) then

Ton({1,1,1+i,3,1,1+i,3,3,1+i,1,3,1+i},{2,1,1+i,3,2,1+i,2,3,1+i,1,2,1+i},5)

elseif (d==1)and(m==0) then

Ton({3-i,3,1,3-i,3,3,3-i,1,3,3-i,1,1},{3-i,2,1,3-i,3,2,3-i,2,3,3-i,1,2},4)

elseif (d==1)and(m==1) then

Ton({3-i,1,1,3-i,1,3,3-i,3,3,3-i,3,1},{3-i,1,2,3-i,2,3,3-i,3,2,3-i,2,1},3)

elseif (d==2)and(m==0) then

Ton({1,3-i,1,1,3-i,3,3,3-i,3,3,3-i,1},{1,3-i,2,2,3-i,3,3,3-i,2,2,3-i,1},2)

else

Ton({3,3-i,1,3,3-i,3,1,3-i,3,1,3-i,1},{2,3-i,1,3,3-i,2,2,3-i,3,1,3-i,2},1)

end

Re()

end

--d m: 0左中右 1上中下 2前中后

--m: 0顺时针 1逆时针 从左后下方

local function input(e)

if e.content=="0" then Go(e) --复原

elseif e.content=="1" then Re0(1,0,0) --上

elseif e.content=="2" then Re0(1,2,0) --下

elseif e.content=="3" then Re0(0,0,0) --前

elseif e.content=="4" then Re0(0,2,0) --后

elseif e.content=="5" then Re0(2,2,0) --左

elseif e.content=="6" then Re0(2,0,0) --右

elseif e.content=="7" then Re0(1,0,1) --上

elseif e.content=="8" then Re0(1,2,1) --下

elseif e.content=="9" then Re0(0,0,1) --前

elseif e.content=="10" then Re0(0,2,1) --后

elseif e.content=="11" then Re0(2,2,1)--左

elseif e.content=="12" then Re0(2,0,1) --右

elseif e.content=="13" then Re0(0,1,0) --中_前后

elseif e.content=="14" then Re0(1,1,0) --中_上下

elseif e.content=="15" then Re0(2,1,0) --中_左右

elseif e.content=="16" then Re0(0,1,1) --中_前后

elseif e.content=="17" then Re0(1,1,1) --中_上下

elseif e.content=="18" then Re0(2,1,1) --中_左右

end

end

ScriptSupportEvent:registerEvent([=[Player.InputContent]=], input)

相关推荐
如竟没有火炬40 分钟前
LRU缓存——双向链表+哈希表
数据结构·python·算法·leetcode·链表·缓存
爱吃生蚝的于勒1 小时前
【Linux】零基础学会Linux之权限
linux·运维·服务器·数据结构·git·算法·github
爱编程的化学家2 小时前
代码随想录算法训练营第27天 -- 动态规划1 || 509.斐波那契数列 / 70.爬楼梯 / 746.使用最小花费爬楼梯
数据结构·c++·算法·leetcode·动态规划·代码随想录
2501_918126914 小时前
使用HTML和Python开发街霸游戏
python·游戏·html
一只鱼^_5 小时前
力扣第470场周赛
数据结构·c++·算法·leetcode·深度优先·动态规划·启发式算法
Univin12 小时前
C++(10.4)
开发语言·数据结构·c++
AA陈超15 小时前
虚幻引擎UE5专用服务器游戏开发-33 在上半身播放组合蒙太奇
c++·游戏·ue5·游戏引擎·虚幻
AA陈超17 小时前
虚幻引擎5 GAS开发俯视角RPG游戏 P05-05 游戏效果委托
c++·游戏·ue5·游戏引擎·虚幻
m0_5522008218 小时前
《UE5_C++多人TPS完整教程》学习笔记62 ——《P63 多人游戏中的开火特效(Fire Effects in Multiplayer)》
c++·游戏·ue5