_Title "Turkey Shoot" 'b+ 2021-12-29 translate from BlitzMax to QB64 and modify, source: ' https://www.syntaxbomb.com/tutorials/learning-basic-for-total-beginners-blitzmax-ng/msg347053898/#msg347053898
' from MidiMaster tutorial on BlitzMax started Dec 22, 2021
' single comments are BlitzMax code
'' double comments are added notes by bplus
'SuperStrict
'' current default type is single suffix ! not needed which is low precision float
'Graphics 800,600
'' land.png the background is 1347 X 600 so let's use a screen in same proportion shrink by 1.1225 so no distorion of background
Screen _NewImage(1200, 534, 32) ' << the 32 allows RGBA color, this sets up customized graphics screen
'Global Land:TImage = LoadImage("land.png") '' dims 1347 x 600
'Global Chicken:TImage = LoadImage("chicken.png")
'' for Global use Shared keyword with Dim (or ReDim or Static for Subs to preserve values)
''Dim Shared Turkey&: Turkey& = _LoadImage("turkey run.jpg")
'' remove background color OK this isn't the cleanest removal , BlizMax just drew a rectangle
''_Source Turkey&
''_ClearColor Point(10, 10), Turkey&
''_ClearColor Point(64, 22), Turkey&
''_ClearColor Point(86, 133), Turkey&
''_PutImage (0, 0), Turkey&, 0
''Do ' find points to make transparent
'' While _MouseInput: Wend
'' Locate 1, 1: Print Space$(40)
'' Locate 1, 1: Print _MouseX, _MouseY, Point(_MouseX, _MouseY) \ 256, (Point(_MouseX, _MouseY) \ 256) \ 256, ((Point(_MouseX, _MouseY) \ 256) \ 256) \ 256
'' _Display
'' _Limit 100
''Loop
''End
''_ClearColor Point(10, 10), Turkey&
''_Source 0
' the above block was replaced with a Custom Image Load
Dim Shared Turkey&: Turkey&
= LoadCustomImage&
("Test Save Turkey Run") _PutImage (100, 100), Turkey&
, 0 ' I want to see how our image looks from custom load Print "Here is our target, press any to continue..."
Dim Shared TurkeyWidth&: TurkeyWidth&
= 100 ' proportional to image
'Global Shot:TSound=LoadSound("fire.ogg")
'Global cX:Int, cY:Int=300
'Global mX:Int, mY:Int
'Global Points:Int
' in QB64 you can Dim with suffix or say Type in DIM ststement
'Since we are using a Turkey instead of a Chicken:
TurkeyY = 350 ' for now the other values are at 0
'start turkey on right side of screen, this image can only run left
'Repeat
' default drawing color is already white
'Cls '' not needed in QB64
'DrawImage Land , 0 , 0
_PutImage , Land&
, 0 ' stretch/shrink image to fit screen This already CLS screen
'DrawImage Chicken , cX , cY
' comment out the original command, and use DrawRect instead:
' SetColor 111,0,0
' DrawRect cX, cY, 60,40
_PutImage (TurkeyX
, TurkeyY
)-Step(TurkeyWidth&
, TurkeyHeight&
), Turkey&
, 0 ' shrink image into Box
' cX = cX +2
TurkeyX
= TurkeyX
- Rnd * 20
'if turkey lives to run outside of screen replace it on left side
'If GunFire() =True Then
' QB64 Bonus display turkey upside down!!!
_PutImage , Land&
, 0 ' stretch/shrink image to fit screen
' cX=-100
TurkeyX
= _Width ' reset turkey to left side of screen
Points = Points + 1 'same for both for next loop
'SetColor 255,255,255
'DrawRect mX-25, mY-1,50,3
'DrawRect mX-1, mY-25,3,50
' This is for mouse scope (the gunFire call updates mouse info in loop)
Line (MX
- 20, MY
)-Step(40, 0), &HFF000000 Line (MX
, MY
- 20)-Step(0, 40), &HFF000000 ''HideMouse
'did this before starting loop
'DrawText "Points: " + points, 700,550
'Flip
_Limit 60 ' 30 frames per second at most!
'Until AppTerminate()
Loop Until _KeyDown(27) 'quit with escape, top right x click will also close window no matter what 'ShowMouse
'_MouseShow not really needed
'Function GunFire:Int()
' mX=MouseX()
' mY=MouseY()
' If MouseHit(1)
' PlaySound Shot
' If (mX>cX) And (mx<cX+60)
' If (mY>cY) And (mY<cY+40)
' ' collision
' Return True
' EndIf
' EndIf
' EndIf
' Return False
'End Function
Function GunFire&
() ' Long integer Type While _MouseInput:
Wend ' poll mouse updates the mouse information in keyWords starting with _Mouse... If _MouseButton(1) Then ' Left mouse button is down, might want to wait until released but we delay in main loop if hit If (MX
> TurkeyX
) And (MX
< TurkeyX
+ TurkeyWidth&
) Then If (MY
> TurkeyY
) And (MY
< TurkeyY
+ TurkeyHeight&
) Then ' collision
' return True value with Function name
GunFire& = -1 ' anything not 0 is true
'else function returns 0
' Function returns Image Handle& (like _LoadFile)
Function LoadCustomImage&
(fileLoadBaseName$
) ' reverse the Save Open fileLoadBaseName$
+ ".CI_DIM" For Input As #1 ' get dimensions of custom image Dim imgHdl&: imgHdl&
= _NewImage(w
, h
, 32) 'setup space and handle for it Dim screenGrab$: screenGrab$
= Space$(M.SIZE
) LoadCustomImage& = imgHdl& ' finally assign the function