仿minecraft游戏 linux,【图片】【Codea制作仿MineCraft3D游戏】Craft Ver. 0.1发布(开源)【codea吧】_百度贴吧...
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
function AABB:clipYcollide(c,y)
if ((c.x1 <= self.x0) or (c.x0 >= self.x1)) then return y end
if ((c.z1 <= self.z0) or (c.z0 >= self.z1)) then return y end
if ((y > 0.0) and (c.y1 <= self.y0)) then
local max = self.y0 - c.y1
if (max < y) then y = max end
end
if ((y < 0.0) and (c.y0 >= self.y1)) then
local max = self.y1 - c.y0
if (max > y) then y = max end
end
return y
end
function AABB:clipZcollide(c,z)
if ((c.y1 <= self.y0) or (c.y0 >= self.y1)) then return z end
if ((c.x1 <= self.x0) or (c.x0 >= self.x1)) then return z end
if ((z > 0.0) and (c.z1 <= self.z0)) then
local max = self.z0 - c.z1
if (max < z) then z = max end
end
if ((z < 0.0) and (c.z0 >= self.z1)) then
local max = self.z1 - c.z0
if (max > z) then z = max end
end
return z
end
function AABB:intersects(c)
if ((c.x1 <= self.x0) or (c.x0 >= self.x1)) then return false end
if ((c.y1 <= self.y0) or (c.y0 >= self.y1)) then return false end
if ((c.z1 <= self.z0) or (c.z0 >= self.z1)) then return false end
return true
end
--# Tile
Tile = class()
function Tile:init(id,tex)
-- you can accept and set parameters here
self.id = id
self.tex = tex
table.insert(Tile.tiles,id,self)
end
function Tile:render(t,level,x,y,z)
c1 = 1.0
c2 = 0.8
c3 = 0.6
if self:shouldRenderFace(level,x - 1,y,z) then
t:brightf(c2)
self:renderFace(t,x,y,z,Left)
end
if self:shouldRenderFace(level,x + 1,y,z) then
t:brightf(c2)
self:renderFace(t,x,y,z,Right)
end
if self:shouldRenderFace(level,x,y - 1,z) then
t:brightf(c3)
self:renderFace(t,x,y,z,Bottom)
end
if self:shouldRenderFace(level,x,y + 1,z) then
t:brightf(c1)
self:renderFace(t,x,y,z,Top)
end
if self:shouldRenderFace(level,x,y,z - 1) then
t:brightf(c2)
self:renderFace(t,x,y,z,Back)
end
if self:shouldRenderFace(level,x,y,z + 1) then
t:brightf(c2)
self:renderFace(t,x,y,z,Front)
end
end
function Tile:shouldRenderFace(level,x,y,z)
return level:isLightBlock(x,y,z)
end
function Tile:renderFace(t,x,y,z,face)
local tex = self:getTex(face)
local u0 = math.fmod(tex,16) / 16
local u1 = u0 + 14.99 / 256
local v0 = math.floor(tex/16)
local v1 = v0 + 14.99 / 256
local x0 = x
local x1 = x + 1
local y0 = y
local y1 = y + 1
local z0 = z
local z1 = z + 1
if face == Front then
t:vertexUV(x0,y0,z1,u0,v0)
t:vertexUV(x1,y0,z1,u1,v0)
t:vertexUV(x1,y1,z1,u1,v1)
t:vertexUV(x1,y1,z1,u1,v1)
t:vertexUV(x0,y1,z1,u0,v1)
t:vertexUV(x0,y0,z1,u0,v0)
elseif face == Back then
t:vertexUV(x1,y0,z0,u0,v0)
t:vertexUV(x0,y0,z0,u1,v0)
t:vertexUV(x0,y1,z0,u1,v1)
t:vertexUV(x0,y1,z0,u1,v1)
t:vertexUV(x1,y1,z0,u0,v1)
t:vertexUV(x1,y0,z0,u0,v0)
elseif face == Top then
t:vertexUV(x0,y1,z1,u0,v0)
t:vertexUV(x1,y1,z1,u1,v0)
t:vertexUV(x1,y1,z0,u1,v1)
t:vertexUV(x1,y1,z0,u1,v1)
t:vertexUV(x0,y1,z0,u0,v1)
t:vertexUV(x0,y1,z1,u0,v0)
elseif face == Bottom then
t:vertexUV(x0,y0,z0,u0,v0)
t:vertexUV(x1,y0,z0,u1,v0)
t:vertexUV(x1,y0,z1,u1,v1)
t:vertexUV(x1,y0,z1,u1,v1)
t:vertexUV(x0,y0,z1,u0,v1)
t:vertexUV(x0,y0,z0,u0,v0)
elseif face == Left then
t:vertexUV(x0,y0,z0,u0,v0)
t:vertexUV(x0,y0,z1,u1,v0)
t:vertexUV(x0,y1,z1,u1,v1)
t:vertexUV(x0,y1,z1,u1,v1)
t:vertexUV(x0,y1,z0,u0,v1)
t:vertexUV(x0,y0,z0,u0,v0)
else
t:vertexUV(x1,y0,z1,u0,v0)
t:vertexUV(x1,y0,z0,u1,v0)
t:vertexUV(x1,y1,z0,u1,v1)
t:vertexUV(x1,y1,z0,u1,v1)
t:vertexUV(x1,y1,z1,u0,v1)
t:vertexUV(x1,y0,z1,u0,v0)
end
end
function Tile:getTex(face)
return self.tex
end
function Tile.getAABB(x,y,z)
return AABB(x,y,z,x + 1,y + 1,z + 1)
end
--# GrassTile
GrassTile = class(Tile)
function GrassTile:init(id,tex)
Tile.init(self,id,tex)
end
function GrassTile:getTex(face)
if face==Top then return 0 end
if face==Bottom then return 2 end
return 1
end
--# TileConst
Tile.tiles = {}
Tile.air = Tile(0,0)
Tile.grass = GrassTile(1,1)
Tile.soil = Tile(2,2)
Tile.stone = Tile(3,3)
Tile.cobbleStone = Tile(4,4)
Tile.bedRock = Tile(5,5)
--# Entity
Entity = class()
function Entity:init(level)
-- you can accept and set parameters here
self.level = level
self.x,self.y,self.z = 0,0,0
self.xd,self.yd,self.zd = 0,0,0
self.xo,self.yo,self.zo = 0,0,0
self.xRot,self.yRot = 0,0
self.onGround = false
end
function Entity:setSize(width,height)
self.width = width
self.height = height
self.heightOffset = height / 2
self:resetPos()
end
function Entity:setPos(x,y,z)
self.x,self.y,self.z = x,y,z
local w,h = self.width / 2,self.height / 2
self.aabb = AABB(x - w,y - h,z - w,x + w,y + h,z + w)
end
function Entity:resetPos()
local x = math.random(self.level.x0,self.level.x1)
local y = level.h + 2
local z = math.random(self.level.z0,self.level.z1)
self:setPos(x,y,z)
end
function Entity:turn(xo,yo)
self.yRot = self.yRot + yo
if self.yRot > 180 then
self.yRot = self.yRot - 360
elseif self.yRot < 180 then
self.yRot = self.yRot + 360
end
self.xRot = self.xRot + xo
if self.xRot > 90 then
self.xRot = 90
elseif self.xRot < -90 then
self.xRot = -90
end
end
function Entity:tick()
self.xo = self.x
self.yo = self.y
self.zo = self.z
end
function Entity:moveRelative(xa,za,speed)
local dist = xa * xa + za * za
if dist < 0.01 then return end
dist = speed / math.sqrt(dist)
xa = xa * dist
za = za * dist
local sin = math.sin(self.yRot * math.pi / 180.0)
local cos = math.cos(self.yRot * math.pi / 180.0)
self.xd = self.xd + xa * cos - za * sin
self.zd = self.zd + za * cos + xa * sin
end
function Entity:move(xa,ya,za)
local xaOrg = xa
local yaOrg = ya
local zaOrg = za
local aabbs = self.level:getCubes(self.aabb:expend(xa,ya,za))
for i,aabb in ipairs(aabbs) do
ya = aabb:clipYcollide(self.aabb,ya)
end
self.aabb:move(0.0,ya,0.0)
for i,aabb in ipairs(aabbs) do
xa = aabb:clipXcollide(self.aabb,xa)
end
self.aabb:move(xa,0.0,0.0)
for i,aabb in ipairs(aabbs) do
za = aabb:clipZcollide(self.aabb,za)
end
self.aabb:move(0.0,0.0,za)
self.horizontalCollision = ((xaOrg ~= xa) or (zaOrg ~= za))
self.onGround = ((yaOrg ~= ya) and (yaOrg < 0.0))
if xaOrg ~= xa then self.xd = 0.0 end
if yaOrg ~= ya then self.yd = 0.0 end
if zaOrg ~= za then self.zd = 0.0 end
self.x = (self.aabb.x0 + self.aabb.x1) / 2.0
self.y = self.aabb.y0 + self.heightOffset
self.z = (self.aabb.z0 + self.aabb.z1) / 2.0
end
function Entity:render()
end
function Entity:touched(touch)
end
總結
以上是生活随笔為你收集整理的仿minecraft游戏 linux,【图片】【Codea制作仿MineCraft3D游戏】Craft Ver. 0.1发布(开源)【codea吧】_百度贴吧...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【一】Git 安装
- 下一篇: 【三】Java运算符