LUA-字符的屏幕限制
我有一个问题,我的角色不断出现在屏幕上。
如何解决此问题?我知道我需要放置一个功能,以防止角色熄灭屏幕并设法在圆圈的半径上进行。
if love.keyboard.isDown("right") then
player.x = player.x + 4
elseif love.keyboard.isDown("left") then
player.x = player.x - 4
elseif love.keyboard.isDown("up") then
player.y = player.y - 4
elseif love.keyboard.isDown("down") then
player.y = player.y + 4
end
if AABB(player.x, player.y, player.w, player.h, target.x, target.y, target.raduis) then
score = score + 1
target.x = math.random(target.raduis, love.graphics.getWidth() - target.raduis)
target.y = math.random(target.raduis, love.graphics.getHeight()- 100)
end
I have a problem where my character keeps going out of my screen.
How do I fix this problem? I know I need to put in a function to prevent the character from going out of the screen and managed to do it on the radius of the circle.
if love.keyboard.isDown("right") then
player.x = player.x + 4
elseif love.keyboard.isDown("left") then
player.x = player.x - 4
elseif love.keyboard.isDown("up") then
player.y = player.y - 4
elseif love.keyboard.isDown("down") then
player.y = player.y + 4
end
if AABB(player.x, player.y, player.w, player.h, target.x, target.y, target.raduis) then
score = score + 1
target.x = math.random(target.raduis, love.graphics.getWidth() - target.raduis)
target.y = math.random(target.raduis, love.graphics.getHeight()- 100)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请同时执行玩家和目标
我不确定“角色”是什么,所以如果您希望角色不脱离屏幕,
,请尝试:如果您希望目标留在屏幕上,请尝试:
希望这会有所帮助
im not sure what the "character" is, so im going to do both the player and the target
if you want the character to not go off screen, try:
if you want the target to stay on screen, try:
hopefully this helps