Ball_X[i] = Ball_X[i] + Nx * (Ball_Diameter - Distance)
Ball_Y[i] = Ball_Y[i] + Ny * (Ball_Diameter - Distance)
Ball_X[j] = Ball_X[j] - Nx * (Ball_Diameter - Distance)
Ball_Y[j] = Ball_Y[j] - Ny * (Ball_Diameter - Distance)
EndIf
EndFor
EndFor
EndSub
Sub DumpObstacle
For i = 1 To Obstacle_Number
TextWindow.WriteLine("obstacle[" + i + "]=" + WQ + obstacle[i] + WQ)
EndFor
TextWindow.Pause()
EndSub
Sub Gravity
For i = 1 To Ball_Number
' ax = 0
ay = g
vy = Ball_vY[i]
Ball_vY[i] = vy + dt * ay
Ball_X[i] = Ball_X[i] + Ball_vX[i] * dt
Ball_Y[i] = Ball_Y[i] + (vy + Ball_vY[i]) * dt / 2
EndFor
EndSub
Sub Jump
If keyDown Then
key = GraphicsWindow.LastKey
If Not[jumping] And ((key = "Up") Or (key = "NumPad8")) Then
Ball_vY[1] = Ball_vY[1] - 400
running = "True"
jumping = "True"
EndIf
If Not[running] And ((key = "Left") Or (key = "NumPad4")) Then
Ball_vY[1] = Ball_vY[1] - 100
Ball_vX[1] = Ball_vX[1] - 100
right = "False"
running = "True"
ElseIf Not[running] And ((key = "Right") Or (key = "NumPad6")) Then
Ball_vY[1] = Ball_vY[1] - 100
Ball_vX[1] = Ball_vX[1] + 100
right = "True"
running = "True"
EndIf
keyDown = "False"
EndIf
EndSub
Sub LoadScene
' param i - scene index (0..4)
' param offset["x"], offset["y"] - offset in GW [pixel]
' param size - size of cell [pixel]
pathS = Program.Directory + "/Scenery/scen" + i + ".bb"
line = 0
For row = 0 To rowMax - 1
y = offset["y"] + row * size
obs = ""
colLastObs = -2
For col = 0 To colMax - 1
x = offset["x"] + col * size
line = line + 1
' The following line could be harmful and has been automatically commented.
' j = File.ReadLine(pathS, line)
cell[row][col] = j
isObstacle = "False"
If 0 < j Then
If (textures[j] <> "green") And (textures[j] <> "water") Then
isObstacle = "True"
If obs = "" Then
obs["x"] = x
obs["y"] = y
obs["height"] = size
EndIf
obs["width"] = obs["width"] + size
colLastObs = col
EndIf
EndIf
If ((col = colMax - 1) Or Not[isObstacle]) And (obs <> "") Then
Obstacle_Number = Obstacle_Number + 1
obstacle[Obstacle_Number] = obs
obs = ""
EndIf
EndFor
EndFor
EndSub
Sub MoveObjects
For i = 1 To Ball_Number
If right Then
Shapes.HideShape(Ball_ObjL[i])
If (scen + 1) * gw < Ball_X[1] Then
scen = scen + 1
ShowScene()
EndIf
Shapes.Move(Ball_Obj[i], (Ball_X[i] - scen * gw) * scale - offset, Ball_Y[i] * scale - offset)
Shapes.ShowShape(Ball_Obj[i])
Else
Shapes.HideShape(Ball_Obj[i])
If Ball_X[1] < scen * gw Then
scen = scen - 1
ShowScene()
EndIf
Shapes.Move(Ball_ObjL[i], (Ball_X[i] - scen * gw) * scale - offset, Ball_Y[i] * scale - offset)
Shapes.ShowShape(Ball_ObjL[i])
EndIf
EndFor
EndSub
Sub ObstacleCheck
For i = 1 To Ball_Number
x = Ball_X[i]
y = Ball_Y[i]
For j = 1 To Obstacle_Number
obs = obstacle[j]
x1 = obs["x"]
x2 = obs["x"] + obs["width"]
y1 = obs["y"]
y2 = obs["y"] + obs["height"]
If ((x1 - r) < x) And (x < (x2 + r)) And ((y1 - r) < y) And (y < (y2 + r)) Then
found = "False"
' find a point (px, py) of the collision
If Not[found] And (0 < Ball_vX[i]) Then
' find the point in left edge of the wall
dx = x - (x1 - r)
dy = dx / Math.Abs(Ball_vX[i]) * Ball_vY[i]
py = y - dy
If ((y1 - r) < py) And (py < (y2 + r)) Then
px = x1
x = x - ((x + r) - x1) * (1 + e * e)
Ball_X[i] = x
Ball_vX[i] = -Ball_vX[i] * e ' e: coefficent of restitution
Ball_vY[i] = 0
found = "True"
EndIf
EndIf
If Not[found] And (Ball_vX[i] < 0) Then
' find the point in right edge of the wall
dx = (x2 + r) - x
dy = dx / Math.Abs(Ball_vX[i]) * Ball_vY[i]
py = y - dy
If ((y1 - r) < py) And (py < (y2 + r)) Then
px = x2
x = x + (x2 - (x - r)) * (1 + e * e)
Ball_X[i] = x
Ball_vX[i] = -Ball_vX[i] * e ' e: coefficent of restitution
Ball_vY[i] = 0
found = "True"
EndIf
EndIf
If Not[found] And (0 < Ball_vY[i]) Then
' find the point in top edge of the wall
dy = y - (y1 - r)
dx = dy / Math.Abs(Ball_vY[i]) * Ball_vX[i]
px = x - dx
If ((x1 - r) < px) And (px < (x2 + r)) Then
py = y1
y = y - ((y + r) - y1) * (1 + e * e)
Ball_Y[i] = y
Ball_vY[i] = -Ball_vY[i] * e ' e: coefficent of restitution
Ball_vX[i] = 0
jumping = "False"
running = "False"
found = "True"
EndIf
EndIf
If Not[found] And (Ball_vY[i] < 0) Then
' find the point in bottom edge of the wall
dy = (y2 + r) - y
dx = dy / Math.Abs(Ball_vY[i]) * Ball_vX[i]
px = x - dx
If ((x1 - r) < px) And (px < (x2 + r)) Then
py = y2
y = y + (y2 - (y - r)) * (1 + e * e)
Ball_Y[i] = y
Ball_vY[i] = -Ball_vY[i] * e ' e: coefficent of restitution
Ball_vX[i] = 0
found = "True"
EndIf
EndIf
EndIf
EndFor
EndFor
EndSub
Sub OnKeyDown
keyDown = "True"
EndSub
Sub ShowScene
' param scen - scene index (0..4)
' param offset["x"], offset["y"] - offset in GW [pixel]
' param size - size of cell [pixel]
pathS = Program.Directory + "/Scenery/scen" + scen + ".bb"
pathT = Program.Directory + "/Textures/"
line = 0
GraphicsWindow.BrushColor = "LightBlue"
GraphicsWindow.FillRectangle(0, 0, gw, gh)
For row = 0 To rowMax - 1
y = offset["y"] + row * size
For col = 0 To colMax - 1
x = offset["x"] + col * size
line = line + 1
' The following line could be harmful and has been automatically commented.
' j = File.ReadLine(pathS, line)
If 0 < j Then
GraphicsWindow.DrawResizedImage(pathT + textures[j] + ".png", x * scale, y * scale, size * scale, size * scale)
EndIf
EndFor
EndFor
EndSub