Lua删除货箱
2015-4-17 10:33:49
收藏:0
阅读:133
评论:1
我正在尝试制作一个简单的游戏,但是我遇到了一些问题。 我有一个游戏,在其中有一层由6个方块组成,5秒后会出现另一层由6个方块组成的图层,以此类推。 我的问题是,我想从每层中随机删除2个方块。在第一层中将会有某种可以在方块上跳跃的对象,所以我想从第一层中删除2个方块,并放置一个动物之类的对象。这是我拥有的代码(仅适用于第一层方块,但当我知道如何处理第一层时它也将适用于第二层)
local physics = require("physics")
physics.start()
display.setDrawMode("hybrid")
local sky = display.newImage("bkg_clouds.png")
sky.x = display.contentWidth/2
sky.y = display.contentHeight/2-60
local ground = display.newImage("ground.png")
ground.x = display.contentWidth/2
ground.y = sky.y + display.contentHeight/2 + 80
ground.rotation = 0.7
local image_outline = graphics.newOutline( 2, "ground.png" )
physics.addBody( ground , "static", {friction = 0.5, bounce = 0.2, outline = image_outline})
local leftwall = display.newRect(0,0,1,display.contentHeight*2+100)
local rightwall = display.newRect(display.contentWidth,0,1,display.contentHeight*2+100)
physics.addBody(leftwall, "static",{bounce=0.1})
physics.addBody(rightwall, "static", {bounce = 0.1})
for i = 27, display.contentWidth-20, display.contentWidth/6 do
local crate = display.newImage("crate.png")
crate.x = i
crate.width = display.contentWidth/6.5
crate.y = 50
crate.height = display.contentWidth/6.5
physics.addBody(crate, {density = 3.0, friction = 0.5, bounce = 0.1})
end
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
这可能是一个非常基本的解决方案,但是首先想到的是生成 2 个随机的指标来替换木箱。
所以当循环计数器匹配索引时,你会绘制一个动物代替创建物品。
我想的是这样的:
local physics = require("physics") local math = require("math") -- 不确定是否需要加载。 physics.start() display.setDrawMode("hybrid") local sky = display.newImage("bkg_clouds.png") sky.x = display.contentWidth/2 sky.y = display.contentHeight/2-60 local ground = display.newImage("ground.png") ground.x = display.contentWidth/2 ground.y = sky.y + display.contentHeight/2 + 80 ground.rotation = 0.7 local image_outline = graphics.newOutline( 2, "ground.png" ) physics.addBody( ground , "static", {friction = 0.5, bounce = 0.2, outline = image_outline}) local leftwall = display.newRect(0,0,1,display.contentHeight*2+100) local rightwall = display.newRect(display.contentWidth,0,1,display.contentHeight*2+100) physics.addBody(leftwall, "static",{bounce=0.1}) physics.addBody(rightwall, "static", {bounce = 0.1}) -- 生成 2 个随机指标,落在循环边界内。 local index_1 = math.random(27, display.contentWidth-20) local index_2 = math.random(27, display.contentWidth-20) for i = 27, display.contentWidth-20, display.contentWidth/6 do -- 为匹配的索引绘制动物,否则绘制一个木箱。 if (i == index_1 or i == index_w) then -- 绘制动物 else local crate = display.newImage("crate.png") crate.x = i crate.width = display.contentWidth/6.5 crate.y = 50 crate.height = display.contentWidth/6.5 physics.addBody(crate, {density = 3.0, friction = 0.5, bounce = 0.1}) end end就像我说的那样,这是一个非常基本的实现,但应该可以让你的层正常工作。
未解决的问题:
但是我会留给你去处理这些检查。