【发布时间】:2018-02-09 01:24:49
【问题描述】:
我想为游戏制作一个可控制的角色,但我不希望地板是一种形状。它将由多种形状组成,并具有不同的 y 和 x 位置。每个形状被称为 rectangle[x][y] x 和 y 范围从 1 到 40 以构成一个 20x20 的网格。我唯一能做到的是一种带有碰撞检测的形状。但我真的很想一次拥有所有的形状,我必须做 1600 种不同的 If 语句还是有更简单的选择?最终的程序希望能够创建关卡,然后能够玩这个关卡,但是我现在只创建了关卡。 下面是使用一种形状的示例重力程序。
GraphicsWindow.Show()
player = Shapes.AddEllipse(10,10)
Shapes.Move(player, 100, 5)
For i = 1 To 2
rec[i] = Shapes.AddRectangle(100,10)
Shapes.Move(rec[i], 100*i, 500)
EndFor
GraphicsWindow.MouseDown = OnMouse
main:
playertop = Shapes.GetTop(player)
shapetop = Shapes.GetTop(rec[1])
Sub OnMouse
Shapes.Move(player, Shapes.GetLeft(player), playertop-5)
upvel = 0.5
EndSub
If playertop+12 > shapetop Then
upvel = 0
Else
upvel = upvel - 0.0004
EndIf
Shapes.Move(player, Shapes.GetLeft(player), playertop-upvel)
Program.Delay(1)
Goto main
到目前为止的代码:https://pastebin.com/mFuy2Prd 提前致谢
【问题讨论】:
标签: collision-detection game-physics shapes smallbasic