Gruppe
Grafik
Problem
Wie kann ich Zeichnungselemente innerhalb eines Tabellenblattes so steuern, daß der Eindruck eines Pac-Man-Spiels entsteht?
ClassModule: Tabelle1
Private Sub cmdEnde_Click()
Set PacMan = Nothing
Set Vitamin = Nothing
Application.OnKey "{right}"
Application.OnKey "{left}"
Application.OnKey "{up}"
Application.OnKey "{down}"
End Sub
Private Sub cmdStart_Click()
Set PacMan = ActiveSheet.Shapes("PacMan")
Set Vitamin = ActiveSheet.Shapes("Vitamin")
Schalter = False
Tempo = 3
PacMan.Fill.ForeColor.SchemeColor = 7
PacMan.Top = 0
PacMan.Left = 0
Vitamin.Visible = True
Application.OnKey "{right}", "ToRight"
Application.OnKey "{left}", "ToLeft"
Application.OnKey "{up}", "ToTop"
Application.OnKey "{down}", "ToDown"
End Sub
StandardModule: basMain
Public PacMan As Shape
Public Vitamin As Shape
Public Schalter As Boolean
Public Tempo As Integer
Sub ToRight()
With PacMan
If .Left >= 300 Then
Beep
Exit Sub
End If
.Left = .Left + Tempo
End With
Call Pille
End Sub
Sub ToLeft()
With PacMan
.Left = .Left - Tempo
End With
Call Pille
End Sub
Sub ToTop()
With PacMan
.Top = .Top - Tempo
End With
Call Pille
End Sub
Sub ToDown()
With PacMan
If .Top >= 200 Then
Beep
Exit Sub
End If
.Top = .Top + Tempo
End With
Call Pille
End Sub
Sub Pille()
Dim dblPac As Double
Dim dblVit As Double
If Schalter = False Then
If Abs(PacMan.Left - Vitamin.Left) < 13 And Abs(PacMan.Top - Vitamin.Top) < 13 Then
Schalter = True
Vitamin.Visible = msoFalse
PacMan.Fill.ForeColor.SchemeColor = 12
Tempo = 5
Else
Schalter = False
End If
End If
End Sub
Sub VitaminZeigen()
ActiveSheet.Shapes("Vitamin").Visible = True
End Sub