can someone help me?
Code :
Code: Select all
Declare GameThread(*mem)
DeclareModule MOUSE
;MOUSE MODULE DRAFT
;BY MIJIKAI
;PB 5.62 x64 (Windows 10)
Structure MOUSE_VECTOR_STRUCT
X.f
Y.f
EndStructure
Structure MOUSE_STRUCT
Window.i
WindowHandle.i
Task.MSG
Pos.MOUSE_VECTOR_STRUCT
Factor.MOUSE_VECTOR_STRUCT
Area.MOUSE_VECTOR_STRUCT
Resize.b
LeftButton.b
LeftButtonDouble.b
RightButton.b
RightButtonDouble.b
EndStructure
Declare.i Init(Window.i)
Declare.b Update()
Declare.i Window()
Declare.i WindowHandle()
Declare.i Resize()
Declare.f AreaX()
Declare.f AreaY()
Declare.f PosX()
Declare.f PosY()
Declare.f FactorX()
Declare.f FactorY()
Declare.b LeftButton()
Declare.b RightButton()
Declare.b LeftButtonDouble()
Declare.b RightButtonDouble()
EndDeclareModule
Module MOUSE
Global Mouse.MOUSE_STRUCT
Procedure.w LoWord(Value.l)
ProcedureReturn (Value & $FFFF)
EndProcedure
Procedure.w HiWord(Value.l)
ProcedureReturn ((Value >> 16) & $FFFF)
EndProcedure
Procedure.i Init(Window.i)
Protected Style.i
If IsWindow(Window)
ClearStructure(@Mouse,MOUSE_STRUCT)
Mouse\Window = Window
Mouse\WindowHandle = WindowID(Window)
Mouse\Area\X = WindowWidth(Window)
Mouse\Area\Y = WindowHeight(Window)
Mouse\Factor\X = 1
Mouse\Factor\Y = 1
Style = GetClassLongPtr_(Mouse\WindowHandle,#GCL_STYLE)
If Style
SetClassLongPtr_(Mouse\WindowHandle,#GCL_STYLE,Style|#CS_DBLCLKS)
EndIf
ProcedureReturn @Mouse;returns pointer to MOUSE_STRUCT
EndIf
EndProcedure
Procedure.b Update()
If PeekMessage_(@Mouse\Task,Mouse\WindowHandle,#Null,#Null,#PM_NOREMOVE)
Mouse\LeftButtonDouble = #False
Mouse\RightButtonDouble = #False
If Mouse\Resize = #True
Mouse\Factor\X = Mouse\Area\X / WindowWidth(Mouse\Window)
Mouse\Factor\Y = Mouse\Area\Y / WindowHeight(Mouse\Window)
Mouse\LeftButton = #False
Mouse\RightButton = #False
EndIf
Select Mouse\Task\message
Case #WM_MOUSEMOVE
Mouse\Pos\X = LoWord(Mouse\Task\lParam) * Mouse\Factor\X
Mouse\Pos\Y = HiWord(Mouse\Task\lParam) * Mouse\Factor\Y
Mouse\Resize = #False
Case #WM_LBUTTONDOWN
Mouse\LeftButton = #True
Case #WM_LBUTTONUP
Mouse\LeftButton = #False
Case #WM_LBUTTONDBLCLK
Mouse\LeftButtonDouble = #True
Case #WM_LBUTTONDOWN
Mouse\RightButton = #True
Case #WM_RBUTTONUP
Mouse\RightButton = #False
Case #WM_RBUTTONDBLCLK
Mouse\RightButtonDouble = #True
Case #WM_NCMOUSEMOVE
Mouse\Resize = #True
EndSelect
ProcedureReturn #True
EndIf
EndProcedure
Procedure.i Window()
ProcedureReturn Mouse\Window
EndProcedure
Procedure.i WindowHandle()
ProcedureReturn Mouse\WindowHandle
EndProcedure
Procedure.i Resize()
PostMessage_(Mouse\WindowHandle,#WM_NCMOUSEMOVE,#Null,#Null)
EndProcedure
Procedure.f AreaX()
ProcedureReturn Mouse\Area\X
EndProcedure
Procedure.f AreaY()
ProcedureReturn Mouse\Area\Y
EndProcedure
Procedure.f PosX()
ProcedureReturn Mouse\Pos\X
EndProcedure
Procedure.f PosY()
ProcedureReturn Mouse\Pos\Y
EndProcedure
Procedure.f FactorX()
ProcedureReturn Mouse\Factor\X
EndProcedure
Procedure.f FactorY()
ProcedureReturn Mouse\Factor\Y
EndProcedure
Procedure.b LeftButton()
ProcedureReturn Mouse\LeftButton
EndProcedure
Procedure.b RightButton()
ProcedureReturn Mouse\RightButton
EndProcedure
Procedure.b LeftButtonDouble()
Protected State.b = Mouse\LeftButtonDouble
Mouse\LeftButtonDouble = #False
ProcedureReturn State
EndProcedure
Procedure.b RightButtonDouble()
Protected State.b = Mouse\RightButtonDouble
Mouse\RightButtonDouble = #False
ProcedureReturn State
EndProcedure
EndModule
Procedure.i Render(Sprite.i);lazy example...
Static OldX.f
Static OldY.f
Static Take = #True
If MOUSE::RightButtonDouble()
MessageBox_(#Null,"RightButtonDouble()","Test!",#Null)
EndIf
; If MOUSE::LeftButtonDouble()
; ResizeWindow(MOUSE::Window(),#PB_Ignore,#PB_Ignore,Random(800),Random(800))
; MOUSE::Resize()
; EndIf
If MOUSE::LeftButton()
If MOUSE::PosX() > OldX And MOUSE::PosX() < (OldX + 32)
If MOUSE::PosY() > OldY And MOUSE::PosY() < (OldY + 32)
Take = #True
EndIf
EndIf
Else
Take = #False
EndIf
If Take = #True
OldX = MOUSE::PosX() - 16
OldY = MOUSE::PosY() - 16
EndIf
DisplayTransparentSprite(Sprite,OldX,OldY)
EndProcedure
Procedure.i Screen(Width.i,Height.i,Title.s)
Protected Event.i
Protected Style.i
Protected Sprite.i
Protected Exit.b
Global direction = 1
Global playerX = 1
Global playerY = 1
Style|#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget
Style|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget
If OpenWindow(0,0,0,Width,Height,Title,Style) & InitSprite()
If OpenWindowedScreen(WindowID(0),0,0,Width,Height,#True,0,0)
WindowBounds(0,320,320,#PB_Ignore,#PB_Ignore)
CreateThread(@GameThread(),0)
Repeat
MOUSE::Update()
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = #True
EndIf
EndIf
EndProcedure
Procedure GameThread(*mem)
SetFrameRate(60)
LoadSprite(1, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")
Sprite = CatchSprite(#PB_Any,?SPRITEDATA,#PB_Sprite_AlphaBlending)
If Sprite And MOUSE::Init(0)
Debug "working"
Repeat
ClearScreen($FFFFFF)
Render(Sprite)
ClipSprite(1, 0, 0, x, x/8)
DisplaySprite(1, x, 100)
DisplaySprite(1, x, x)
DisplaySprite(1, 300-x, x)
DisplaySprite(1, playerX, playerY)
x + direction
If x > 300 : direction = -1 : EndIf ; moving back to the left with negative value
If x < 0 : direction = 1 : EndIf
FlipBuffers()
Until Exit = #True
EndIf
EndProcedure
UsePNGImageDecoder()
Screen(1024,768,#Null$)
DataSection
SPRITEDATA:
;{ Size: 204 Bytes
!dw 05089h, 0474Eh, 00A0Dh, 00A1Ah, 00000h, 00D00h, 04849h, 05244h, 00000h
!dw 02000h, 00000h, 02000h, 00208h, 00000h, 0FC00h, 0ED18h, 000A3h, 00000h
!dw 04993h, 04144h, 04854h, 0EDC7h, 0C156h, 0800Dh, 00830h, 00DA4h, 0D023h
!dw 0DC05h, 0267Fh, 0C017h, 0FC21h, 0A219h, 0D0B5h, 02622h, 0F29Ah, 038E6h
!dw 00A38h, 01134h, 04411h, 0021Ah, 0AF00h, 0505Bh, 0B2F4h, 08650h, 00B60h
!dw 0C027h, 0AA81h, 06E2Dh, 0EC87h, 04468h, 03ECAh, 0B331h, 04492h, 0F529h
!dw 0EE0Ah, 01290h, 02E10h, 0CA91h, 0CA77h, 0FD12h, 0CAC9h, 05788h, 06E78h
!dw 05523h, 05DB9h, 01912h, 069ABh, 07DBBh, 0D07Fh, 0B7FEh, 0AA2Ah, 0C6CFh
!dw 06833h, 056EFh, 0C9E0h, 02754h, 09FB0h, 0AE9Dh, 07BE9h, 0177Eh, 00979h
!dw 0EF7Ah, 01CEBh, 091B4h, 0181Eh, 0AEAFh, 04FB1h, 007B3h, 0C093h, 0296Fh
!dw 0FBFAh, 003BEh, 0AE4Bh, 0B92Ah, 0EC0Fh, 0B1D8h, 00000h, 00000h, 04549h
!dw 0444Eh, 042AEh, 08260h, 0AE4Bh
;}
EndDataSection