该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

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吧】_百度贴吧...相关推荐

  1. python3小游戏代码教程_Python3制作仿“经典90坦克大战”小游戏|python3教程|python入门|python教程...

    https://www.xin3721.com/eschool/pythonxin3721/ 本文转载至知乎ID:Charles(白露未晞)知乎个人专栏 下载W3Cschool手机App,0基础随时随 ...

  2. c语言改u3d游戏,使用Unity3D怎么制作一个五子棋游戏

    使用Unity3D怎么制作一个五子棋游戏 发布时间:2021-04-17 17:56:36 来源:亿速云 阅读:106 作者:Leah 本篇文章为大家展示了使用Unity3D怎么制作一个五子棋游戏,内 ...

  3. scratch跳一跳游戏脚本_cocos creator制作微信小游戏「跳一跳」

    一.游戏的分析(之前没有接触过小游戏,制作的思维还停留在大型ARPG游戏大家共同协作的想法里,但是小游戏讲究小而全,大部分时间是一个人独立开发,所以需要迫使自己养成看到小游戏先拆分细化的思想) 二.一 ...

  4. html5坦克游戏ppt说明,HTML5制作的坦克游戏

    HTML5制作的坦克游戏 本游戏是基于HTML5开发的 网页游戏,js,css辅助开发 源码如下: 坦克大战 坦克大战(请使用IE浏览器) style="background-color:b ...

  5. linux系统适合什么游戏,Linux 系统不适合运行主流游戏?这是为何

    炎炎夏日,Steam正在进行能够让游戏爱好者们清凉一夏的夏日大促活动(Steam是一款布拉姆·科恩亲自开发设计的游戏平台,玩家可以在Steam上购买游戏.软件.下载.讨论.上传.分享).不过在众多玩家 ...

  6. php拼图游戏开发,原生javascript制作的拼图游戏实现方法详解

    本文实例讲述了原生javascript制作的拼图游戏实现方法.分享给大家供大家参考,具体如下: 实现方法 //1.让所有的li(在ul里)可以拖拽 //2.交换li的位置  计算背景图位置 //1.让 ...

  7. 接水果游戏代码 c语言,制作接水果游戏

    今天是儿童节,让老师教同学们做个接水果的小游戏吧. 我们新建一个项目,把小猫角色删除,然后选择一个碗的角色来接水果: 把碗移动到白色画布的下半部分,让它可以随着鼠标的移动而左右移动,但是不需要上下移动 ...

  8. 熟悉linux指令游戏,Linux指令初探之闯关游戏Bandit(上)

    开学季,Evan会带领小萌新们一点点接触安全领域,今天要给大家讲的是和Linux有关的一款游戏Bandit,通过Bandit你会学到Linux的一些基础指令,这对今后的学习有很大的帮助,准备好了吗让我 ...

  9. 游戏动漫角色模型制作方法,无偿分享工具0基础入门教程

    从复杂3D模型入手,你可能会备受打击.选一个简单的结构,然后开始学习.你不仅想要学会3D建模的基本知识,还需要慢慢学习掌握不同的工具.技巧. 瓶子一样的圆柱体是一个很好的入门模型. 或者你可以用更简单 ...

最新文章

  1. 【我看Hibernate】Hibernate 介绍及其简单应用
  2. python奇数和_请问python如何判断奇偶数?
  3. windows环境下安装nodeJS和express,一直提示command not found-配置环境变量
  4. union all会影响性能吗_哪些因素会影响悬臂式掘进机的性能?
  5. 用exists代替distinct
  6. keras提取模型中的某一层_Tensorflow笔记:高级封装——Keras
  7. PHP安全新闻早8点_1127
  8. 别双击闪存盘 惊醒病毒就不得了
  9. JS 操作 HTML 和 AJAX 请求后台数据
  10. IE8 SVG Viewer下一些对象属性和方法
  11. html中css字体颜色代码大全,css字体颜色的设置方法
  12. 【计算机网络】谢希仁笔记 数据链路层
  13. java uniapp旅游微信小程序的开发hbuilderx
  14. ps制作浮雕和投影效果
  15. 我看考研(一)——为什么考研之考研的理由的重要性
  16. ROS自定义消息类型,编译无法生成 msg/srv 文件产生的头文件
  17. [基础规范]JavaBeans规范
  18. linux文件夹缩略图不显示,在Linux终端中使用lsix显示缩略图图像
  19. K8S Runtime CRI OCI contained dockershim 理解
  20. 数字经济时代,数据中心供电系统如何助力实现双碳目标

热门文章

  1. 第1章 IO流概述及FileWriter类使用
  2. JavaScript的数据结构与算法(三) —— 单向链表
  3. 安装程序集'' policy.8.0.microsoft.vc80.atl,type=''win32-
  4. 深入Java核心:JVM中的栈和局部变量
  5. nutch源代码阅读心得
  6. API – MultiByteToWideChar的用法
  7. 利用Javascript的“函数重载”实现自定义Alert样式
  8. 程序员日记我们需要有条理的生活
  9. 每年的飞鸽传书5月21日都要进一位老师
  10. 又不能起床python好学吗