Microsoft Small Basic

Program Listing: VLJ457
'Kollisions Snippet
GraphicsWindow.KeyDown = TasteGedrueckt
Fenster()
Shape()

Sub Fenster
GraphicsWindow.Height = 500
GraphicsWindow.Width = 500
GraphicsWindow.Title = "Kollisions Snippet"
GraphicsWindow.Left = Desktop.Width/2 - GraphicsWindow.Width/2
GraphicsWindow.Top = Desktop.Height/2 - GraphicsWindow.Height/2
GraphicsWindow.ShowMessage("Mit den Pfeiltasten wird gesteuert.", "Steuerung")
EndSub

Sub Shape
GraphicsWindow.PenColor = "Red"
GraphicsWindow.BrushColor = "Red"
Shape[1][1][0] = Shapes.AddEllipse(25, 25)
Shape[1][1][1] = 25 'Breite
Shape[1][1][2] = 25 'Höhe
GraphicsWindow.PenColor = "Yellow"
GraphicsWindow.BrushColor = "Blue"
Shape[2][1][0] = Shapes.AddRectangle(60, 70)
Shape[2][1][1] = 60 'Breite
Shape[2][1][2] = 70 'Höhe
GraphicsWindow.PenColor = "Yellow"
GraphicsWindow.BrushColor = "Green"
Shape[2][2][0] = Shapes.AddTriangle(40, 5, 10, 55, 70, 55)
Shape[2][2][1] = 60 'Breite
Shape[2][2][2] = 50 'Höhe
GraphicsWindow.PenColor = "Yellow"
GraphicsWindow.BrushColor = "Brown"
Shape[2][3][0] = Shapes.AddRectangle(130, 20)
Shape[2][3][1] = 130 'Breite
Shape[2][3][2] = 20 'Höhe
GraphicsWindow.PenColor = "Yellow"
GraphicsWindow.BrushColor = "Black"
Shape[2][4][0] = Shapes.AddRectangle(30, 250)
Shape[2][4][1] = 30 'Breite
Shape[2][4][2] = 250 'Höhe

Shapes.Move(Shape[1][1][0], GraphicsWindow.Width/2-12.5, GraphicsWindow.Height/2-12.5)
Shapes.Move(Shape[2][1][0], 400, 30)
Shapes.Move(Shape[2][3][0], 310, 430)
Shapes.Move(Shape[2][4][0], 60, 140)
EndSub

Sub Kollisionscheck
xPosPlayer1 = Shapes.GetLeft(Shape[1][1][0])
yPosPlayer1 = Shapes.GetTop(Shape[1][1][0])
xPosPlayer2 = Shapes.GetLeft(Shape[1][1][0])+12.5
yPosPlayer2 = Shapes.GetTop(Shape[1][1][0])+12.5

For i = 1 To Array.GetItemCount(Shape[2])
TextWindow.WriteLine(Array.GetItemCount(Shape[2])) 'This should be 4, because there are 4 different Arrays
xPosKol1 = Shapes.GetLeft(Shape[2][i][0])
yPosKol1 = Shapes.GetTop(Shape[2][i][0])
xPosKol2 = Shapes.GetLeft(Shape[2][i][0])+Shape[2][i][1]
yPosKol2 = Shapes.GetTop(Shape[2][i][0])+Shape[2][i][2]
If xPosPlayer1 = xPosKol2 Or xPosPlayer1 < xPosKol2 And xPosPlayer1 > xPosKol1 Then
Rechts()
ElseIf xPosPlayer2 = xPosKol1 Or xPosPlayer2 > xPosKol1 And xPosPlayer1 < xPosKol2 Then
Links()
ElseIf yPosPlayer1 = yPosKol2 Or yPosPlayer1 < yPosKol2 And yPosPlayer1 > yPosKol1 Then
Runter()
ElseIf yPosPlayer2 = yPosKol1 Or yPosPlayer2 > yPosKol1 And yPosPlayer1 < yPosKol2 Then
Hoch()
EndIf
EndFor
EndSub

Sub TasteGedrueckt
GT = GraphicsWindow.LastKey
If GT = "Up" Then
Hoch()
ElseIf GT = "Down" Then
Runter()
ElseIf GT = "Left" Then
Links()
ElseIf GT = "Right" Then
Rechts()
EndIf
EndSub

Sub Hoch
xPos = Shapes.GetLeft(Shape[1][1][0])
yPos = Shapes.GetTop(Shape[1][1][0])
Shapes.Move(Shape[1][1][0], xPos, yPos-2)
Kollisionscheck()
EndSub

Sub Runter
xPos = Shapes.GetLeft(Shape[1][1][0])
yPos = Shapes.GetTop(Shape[1][1][0])
Shapes.Move(Shape[1][1][0], xPos, yPos+2)
Kollisionscheck()
EndSub

Sub Links
xPos = Shapes.GetLeft(Shape[1][1][0])
yPos = Shapes.GetTop(Shape[1][1][0])
Shapes.Move(Shape[1][1][0], xPos-2, yPos)
Kollisionscheck()
EndSub

Sub Rechts
xPos = Shapes.GetLeft(Shape[1][1][0])
yPos = Shapes.GetTop(Shape[1][1][0])
Shapes.Move(Shape[1][1][0], xPos+2, yPos)
Kollisionscheck()
EndSub