游戏区域设置:
function love.conf(t)
t.window.width = 400
t.window.height = 700
有一段主要代码:
function love.load()
-- Left wall
w1 = {
m = "fill",
x = 0,
y = 0,
w = 50,
h = love.graphics.getHeight()
}
-- Right wall
w2 = {
m = "fill",
x = love.graphics.getWidth() - 50,
y = 0,
w = 50,
h = love.graphics.getHeight()
}
stone = {
m = "fill",
x = 200,
y = 0,
w = 80,
h = 20,
speed = 600
}
end
function love.update(dt)
if stone.y > love.graphics.getHeight() then
stone.y = 0
stone.x = math.random(50,300)
stone.w = math.random(25,100)
stone.h = math.random(10,25)
else
stone.y = stone.y + (dt * stone.speed)
end
end
并且右墙的右边界有一个交集,我认为可以这样解决:
- 确定右侧墙壁和石质物体之间的像素差异
- 如果纬度(stone.w)大于1点的结果,则减去
- Stone.x 减去 2 分的结果
- 将3点的结果分配给stone.x
我想这样就不会有交集了,我是这样写的:
difference = stone.x - (love.graphics.getWidth() - 50)
if stone.w > difference then
stone.x = stone.w - difference
如果我的想法正确的话,那么我不知道在哪里注册这张支票:-D
如有错误,请帮忙指正。...
需要确定正确的 x 范围并从中生成随机数