'tvscreen43& = _NEWIMAGE(1920, 1080, 32) 'Optional to test
SCREEN tvscreen43&
' Set tvscreen& as the screen where we will display everything in the end. The active screen.
'Making stuff easier to adjust
CONST ScreenEndRight
= 320 '1920 CONST ScreenEndBottom
= 240 '1080 CONST ScreenWidth
= 320 '1920 CONST ScreenHeight
= 240 '1080 CONST ScreenCenterX
= (ScreenWidth
/ 2) CONST ScreenCenterY
= (ScreenHeight
/ 2)
'THIS HAS SOME LEFT OVERS BUT THEY SHOULD NOT MATTER...
TYPE Shot
' PlayerShot definition. alive
AS _BYTE ' Is the shot alive on screen or not. Can be set to false if it goes off screen or if it collides with like an enemy. speed
AS SINGLE ' The speed of the shot. Could be adjusted according to the shot speed of different cannons etc. if needed. spriteheight
AS INTEGER ' The height of the shot sprite. A bit overkill but used for calculating when the shot is completely off the screen. dir
AS _BYTE ' What direction is the shot travelling in? stepy
AS SINGLE ' These are used for trig stuff to aim etc. etc. sprite
AS INTEGER ' What sprite is used for the shot 'maxshots AS SINGLE ' How many of this particular shot can be fired on screen at the same time.
'dmg AS SINGLE Damage value of the shot. Targets HP is reduced by this when hit.
REDIM SHARED Shots
(0) AS Shot
' Make it a dynamic array. Can be redimmed later to accomodate different amounts of shots.
'Shot sprite
'8x8px
'(Part of code is borrowed from somewhere like a tutorial or something...).
ShotSpriteData:
DATA &HFFFC00FC,&HFFFC00FC,&HFF000000,&HFF000000,&HFF000000,&HFF000000,&HFFFC00FC,&HFFFC00FC DATA &HFFFC00FC,&HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFF000000,&HFFFC00FC DATA &HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFFF7D8A5,&HFF000000 DATA &HFF000000,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFF000000 DATA &HFF000000,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFF000000 DATA &HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFFFFEFF,&HFFFFFEFF,&HFFF7D8A5,&HFFF7D8A5,&HFF000000 DATA &HFFFC00FC,&HFF000000,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFFF7D8A5,&HFF000000,&HFFFC00FC DATA &HFFFC00FC,&HFFFC00FC,&HFF000000,&HFF000000,&HFF000000,&HFF000000,&HFFFC00FC,&HFFFC00FC
'Set some properties of the shot
Shots(0).x! = 0
Shots(0).y! = 100
Shots(0).spritewidth% = 8
Shots(0).spriteheight% = 8
Shots(0).dir%% = 0
Shots(0).sprite% = shotsprite%
DO ' Start of the "game loop".
_LIMIT 60 ' Limit fps to 60 fps...
'LoopStartTime## = TIMER(0.001) ' Instead of _LIMIT one can do it manually
' Get time in milliseconds at start of game loop.
Shots(0).x! = (Shots(0).x! + 2) ' If done with dynamic fps this line would instead be:
'Shots(0).x! = Shots(0).x! + 2 * (delta## * 60)
'If the shot as gone off the right side screen edge, reset its position to the left side of screen.
IF Shots
(0).x!
>= (ScreenEndRight
+ Shots
(0).spritewidth%
) THEN Shots
(0).x!
= (ScreenEndLeft
- Shots
(0).spritewidth%
)
_PUTIMAGE (Shots
(0).x!
, Shots
(0).y!
), Shots
(0).sprite%
'Put the sprite on screen
_DISPLAY ' Display it hopefully flicker less...
'delta## = (TIMER(0.001) - LoopStartTime##) ' Calculate time that has passed during the loop.
'SECTION FOR USING A "FIXED" FPS INSTEAD OF USING _LIMIT (UNCOMMENT _LIMIT AT TOP OF LOOP)
'Comment out _LIMIT 60 at top of loop
'Uncomment: LoopStartTime## = TIMER(0.001)
'Uncomment: delta## = (TIMER(0.001) - LoopStartTime##)
'
'Uncomment the code lines below:
'-------------------------------------------------------------------------------------------
'IF delta## < 0.0167 THEN ' 'If the time it took to complete the loop is less than 1 / 60...
' 0.0167 could be replaced with (1/60)
'DO ' '...enter a mini loop and check the time again and again until it is 1/60 or more.
'delta## = (TIMER(0.001) - LoopStartTime##)
'
'LOOP UNTIL delta## >= (0.0167) ' 'Again its possible to use (1 / 60) instead of 0.0167...
'END IF
'-------------------------------------------------------------------------------------------
'FOR DYNAMIC FPS (LOOP CAN BE AS FAST AS IT WANT BUT SHOT MOVES THE SAME DISTANCE):
'Replace: Shots(0).x! = (Shots(0).x! + 2) with: Shots(0).x! = Shots(0).x! + 2 * (delta## * 60)
'
'Comment out _LIMIT 60 in the loop
'Uncomment: LoopStartTime## = TIMER(0.001)
'Uncomment: delta## = TIMER(0.001) - LoopStartTime##
'VARIANTS OF _PUTIMAGE LINE:
'-------------------------------------------------------------------------------------------
'_PUTIMAGE (INT(Shots(0).x!), INT(Shots(0).y!)), Shots(0).sprite% 'Putting it at integer values of the single type x and y values
' that can potentially have decimals (because it cant be put between pixels...).
'PSET ((Shots(0).x!), Shots(0).y!), &HFFF7D8A5 ' Its the same if we only put a single pixel on the screen...
'-------------------------------------------------------------------------------------------