Code: Select all
;- Klassen
Class GetFrameRate
FPS.l
lFPS.l
sFPS.l
Public Method Get()
This\FPS + 1
If ElapsedMilliseconds() - This\lFPS >= 1000
This\sFPS = This\FPS
This\FPS = 0
This\lFPS = ElapsedMilliseconds()
EndIf
MethodReturn This\sFPS
EndMethod
EndClass
Class ScreenSize
Public Width.l
Public Height.l
Public Method Init(ScreenWidth.l, ScreenHeight.l)
This\Width = ScreenWidth
This\Height = ScreenHeight
EndMethod
EndClass
Class WindowScreen
*Screen.ScreenSize
WindowID.l
Public Method Init(*ScreenSize)
This\Screen = *ScreenSize
If InitSprite() = 0
MessageRequester("Fehler","Konnte Sprite nicht initialisieren!",0)
EndIf
If InitSound() = 0
MessageRequester("Fehler","Konnte Sound nicht initialisieren!",0)
EndIf
If InitKeyboard()=0
MessageRequester("Fehler","Konnte Keyboard nicht initialisieren!",0)
EndIf
This\WindowID = OpenWindow(#PB_Any, 0, 0, This\Screen\Width, This\Screen\Height, "SimpleOOP - DrawExample1", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(This\WindowID), 0, 0, This\Screen\Width, This\Screen\Height, 1, 0, 0) = 0
MessageRequester("Fehler","Konnte Screen nicht initialisieren!",0)
EndIf
EndMethod
Public Method Event(WindowEvent.l)
If EventWindow() <> This\WindowID
MethodReturn 0
EndIf
Select WindowEvent
Case #PB_Event_CloseWindow
End
EndSelect
EndMethod
Public Method UpdateScreen()
FlipBuffers()
ClearScreen(RGB(0,0,0))
EndMethod
EndClass
Class Line
*Screen.ScreenSize
xStart.l
yStart.l
xEnd.l
yEnd.l
Direction.l
Color.l
Public Method Init(*ScreenSize)
This\Screen = *ScreenSize
This\xStart = 0
This\yStart = 0
This\xEnd = Random(This\Screen\Width) ;This\ScreenWidth-50
This\YEnd = This\Screen\Height
This\Direction = 1
This\Color = RGB(Random(255),Random(255),Random(255))
EndMethod
Public Method Move()
This\xEnd+This\Direction
If This\xEnd > This\Screen\Width
This\xEnd = This\Screen\Width
This\Direction = -This\Direction
EndIf
If This\xEnd < 0
This\xEnd = 0
This\Direction = -This\Direction
EndIf
EndMethod
Public Method Draw()
Line(This\xStart, This\yStart, This\xEnd, This\yEnd , This\Color)
EndMethod
EndClass
;- Schleife
Define *FrameRate.GetFrameRate = NewObject.GetFrameRate
Define *ScreenSize.ScreenSize = NewObject.ScreenSize(800, 600)
Define *WindowScreen.WindowScreen = NewObject.WindowScreen(*ScreenSize)
NewList *Lines.Line()
For I=0 To 10
AddElement(*Lines())
*Lines() = NewObject.Line(*ScreenSize)
Next
Repeat
ExamineKeyboard()
WindowEvent = WindowEvent()
*WindowScreen\Event(WindowEvent)
StartDrawing(ScreenOutput())
ForEach *Lines()
*Lines()\Move()
*Lines()\Draw()
Next
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, Str(*FrameRate\Get())+" FPS")
DrawingMode(#PB_2DDrawing_Default)
StopDrawing()
*WindowScreen\UpdateScreen()
ForEver
Add CLASS syntax
And it can automatically prompt
And FreeClass
CLass is often used to
In order to join the official function convenient please
He has
Default property
default member
Can be destroyed
Similar to the VB CLass