So finally back to working on a program, "Astrosmash", and it is moving right along. However I find myself in a situation that is boggling my primitive little monkey brain. In this game I have 4 main types of objects to deal with(at the moment); Small Asteroids, Big Asteroids, Small Bombs and Big Bombs. Now when you blow up a Big Asteroid, it has a chance to split into 2 Small Asteroids. And everything seems to be working properly, save when you shoot a Big Bomb. This causes a pause in the games execution. I have yet to be able to identify why.
At first I thought maybe my numbers were off and the code was trying to split the Big Bomb into 2 Small Asteroids, which would have caused some issues somewhere due to the rather primative way I split the Big Asteroids. Another reason I thought it might be doing that is when the Big Asteroid splits it doesn't leave an "Explosion" sprite behind, and when the code pauses the Big Bomb that was hit doesn't leave one either. but that could just be because the explosion animation is only 6 frames and lasts a very short time, less time than the pause I believe.
If the SplitObject routine was running at this time there should be an associated output to the Debug.txt file when it happens, however there is not, the Object hit value outputs to show what was hit and thats it(this is a single BYTE value followed by &HFF). So where is this seemingly random pause coming from? It doesn't pause every time you hit a Big Bomb, just sometimes. Big Asteroids have a ~75% chance of splitting in two, yet another reason I thought the SplitObject would be a root cause.
this line determines a split;
IF (O
(Hit%%
).Kind
>= 6 AND O
(Hit%%
).Kind
<= 9) AND (RND * 100) > 25 THEN '~75%chance of split if large object is hit
Player's ship is 1
Small Asteroids have values 2-5(4 variations)
Big Asteroids have values 6-9 (4 variations)
Bombs have value 10
These are all defined in the CONSTs so.. no accidental changing should be happening.
And, debuging as I do, if I remove(aka Comment out) that line and subsequent lines the issue no longer happens. so why is that line trying to execute on a Bomb value of 10? or is it something completely different going on?
I have added prints here and there to try and catch the issue but alas, I am defeated.
I have removed all the subs, save for the MovePlayerShot and SplitObject, and placed them in an include file. Hopefully to make the code(that I think contributes to the issue anyway) more concise. may or may not need the font file, attached it anyway.
Now I have not added the RANDOMIZE TIMER yet as to make things more repeatable, (maybe) if you shoot the small bomb then the large yellow asteroid(which should split) then wait for a large bomb to enter the screen, shooting one should cause the pause.
Video demonstrating the pause issue.
Tracking
AS _BYTE 'tells whether its a tracker and which direction its moving
Movement
AS _BYTE 'How fast player moves ShotSpeed
AS _BYTE 'how fast player shots move GameOver
AS _BYTE 'has player lost all lives CurrentBG
AS _BYTE 'current background color
'Load sprites--------------------------------
SpriteData:
DATA 311,16,16,16,56,124,238,254,68,16,84,56,108,56,124,254,170,76,124,118,174,252,127,90,48,118,255,122,47,15,60,126,44,104,252,124,62,122,222,252,56,124,126,126,55,63,250,239,102,32,120,236,254,120,95,47,58,124,127,253,218,110,126,58,16,12,60,126,118,127,255,250,60,124,126,111,255,254,126,108,32,24,24,60,36,36,60,24,24,0,6,30,36,36,120,96,0,0,0,60,231,231,60,0,0,0,96,120,36,36,30,6,0,0,0,36,24,24,36,0,0,0,66,60,36,36,60,66,0,0,60,102,90,90,102,60,0,60,0,153,165,165,153,0,60,66,153,36,66,66,36,153,66,153,66,0,129,129,0,66,153,0,0,0,16,16,124,16,16,0,0,0,16,56,124,56,16,0,0,0,56,124,124,124,56,0,0,0,16,56,124,56,16,16,16,16,16,16,16,16,56,56,124,108,238,254,254,68,68,128,128,64,64,64,32,112,112,60,108,110,126,120,32,32,32,128,128,64,64,48,48,62,62,23,23,28,28,24,24,8,8,0,0,128,192,108,127,63,22,22,28,28,28,8,8,8,0,0,0,0,2,7,15,30,250,250,30,15,7,2,0,0,0,0,0,24,60,60,24,0,0,60,126,255,213,255,60,0,0,24,90,255,171,126,153,0,0,153,90,255,171,126,90,0,0,0,0,84,42,84,42,0 'Load Main & Title screens
MainScreenData:
DATA 205,0,487,15,1,0,194,15,1,0,12,15,1,0,115,15,1,0,106,15,1,0,275,15,1,0,71,15,1,0,174,15,1,0,480,15,1,0,39,15,1,0,455,15,1,0,123,15,2,0,786,15,1,0,32,15,1,0,18,15,1,0,7,15,1,0,367,15,2,0,30,15,2,0,14,15,2,0,775,15,1,0,31,15,1,0,1170,15,1,0,195,15,1,0,36,15,1,0,354,15,2,0,591,15,1,0,162,15,1,0,7,15,1,0,20,15,1,0,39,15,1,0,394,15,1,0,31,15,1,0,294,15,1,0,317,15,1,0,151,15,1,0,110,15,1,0,347,15,1,0,83,15,2,0,257,15,1,0,365,15,1,0,42,15,1,0,192,15,1,0,103,15,1,0,31,15,1,0,135,15,1,0,138,15,2,0,305,15,1,0,1063,5,4,0,160,5,4,0,149,5,3,0,8,5,3,0,143,5,3,0,14,5,3,0,129,5,2,0,7,5,2,0,20,5,3,0,14,5,1,0,39,5,2,0,67,5,3,0,2,5,3,0,29,5,3,0,8,5,3,0,37,5,3,0,2,5,3,0,34,5,4,0,23,5,3,0,8,5,3,0,29,5,3,0,2,5,3,0,4,5,2,0,31,5,3,0,8,5,3,0,29,5,2,0,4,5,2,0,10,5,4,0,6,5,1,0,14,5,1,0,31,5,2,0,9,5,2,0,10,5,4,0,12,5,3,0,14,5,3,0,12,5,4,0,8,5,2,0,8,5,2,0,5,5,3,0,4,5,3,0,63,5,2,0,5,5,3,0,4,5,3,0,6,5,3,0,20,5,3,0,6,5,3,0,4,5,3,0,3,5,2,0,12,5,5,0,10,5,3,0,62,5,5,0,10,5,6,0,26,5,6,0,10,5,3,0,960,5,320,0,1600 TitleScreenData:
DATA 129,4,1617,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,32,15,4,4,12,7,4,4,12,6,4,4,12,5,4,4,24,3,4,4,12,2,4,4,12,1,4,4,12,0,4,4,13136
'Color CONSTs
CONST Black
= 0, Blue
= 1, Red
= 2, Tanc
= 3, Olive
= 4, DkGreen
= 5 CONST BGGreen
= 6, Yellow
= 7, Grey
= 8, SkyBlue
= 9, Orange
= 10 CONST Pink
= 11, Purple
= 12, FadeGreen
= 13, Maroon
= 14, White
= 15 'Zoom CONSTs
CONST None
= 0, H4
= 128, H2
= 64, H12
= 32, H14
= 16, V4
= 8, V2
= 4 CONST V12
= 2, V14
= 1, HF
= 512, VF
= 256, COLLISION
= 8192 '4-x4, 2-x2, 12-x1/2, 14-x1/4, HF-Flip Horizontal, VF-Flip Vertical
'Sprite CONSTs
CONST NullShip
= 0, Ship
= 1, SmallA
= 2, SmallB
= 3, SmallC
= 4, SmallD
= 5 CONST LargeA
= 6, LargeB
= 7, LargeC
= 8, LargeD
= 9, Bomb
= 10, Tracker
= 11 CONST SpaceShip
= 12, SmallE
= 13, SmallF
= 14, SmallG
= 15, SmallH
= 16 CONST Blast
= 17, SpaceShipShot
= 18 'Game Scores CONSTs
Layer
(1) = _NEWIMAGE(640, 480, 32) 'Composite layerLayer
(3) = _NEWIMAGE(640, 480, 32) 'Title Screen LayerLayer
(4) = _NEWIMAGE(640, 480, 32) 'Background sheet layerLayer
(5) = _NEWIMAGE(640, 480, 32) 'Sprite draw layerLayer
(6) = _NEWIMAGE(64, 64, 32) 'temp sprite layer for transparencyLayer
(7) = _NEWIMAGE(640, 480, 32) 'collision shadow layer OidsLayer
(8) = _NEWIMAGE(640, 480, 32) 'background colorLayer
(9) = _NEWIMAGE(640, 480, 32) 'collision shadow layer Player
FFX
(1) = _LOADFONT("PixelIntv.ttf", 40, "monospace")
Colors
(0) = _RGB32(0, 0, 0) ' BlackColors
(1) = _RGB32(0, 45, 255) ' BlueColors
(2) = _RGB32(255, 61, 16) ' RedColors
(3) = _RGB32(201, 207, 171) ' TanColors
(4) = _RGB32(84, 110, 0) ' Olive GreenColors
(5) = _RGB32(56, 107, 63) ' DkGreenColors
(6) = _RGB32(0, 167, 86) ' BGGreenColors
(7) = _RGB32(250, 234, 80) ' YellowColors
(8) = _RGB32(189, 172, 200) ' Purpleish GreyColors
(9) = _RGB32(36, 184, 255) ' Sky BlueColors
(10) = _RGB32(255, 180, 31) ' OrangeColors
(11) = _RGB32(255, 78, 87) ' PinkishColors
(12) = _RGB32(164, 150, 255) 'PurplishColors
(13) = _RGB32(117, 204, 128) 'Faded GreenColors
(14) = _RGB32(181, 26, 88) ' MaroonColors
(15) = _RGB32(255, 255, 255) 'White
'Start Values
P.Ypos = 321
P.Xpos = 300
G.Movement = 4
G.ShotSpeed = 8
G.Lives = 4
G.level = 1
G.MaxShot = 2
G.Score = 0
G.ObjectCount = 5
FOR i%%
= 0 TO G.ObjectCount
- 1 MakeObject i%%
DrawSpriteSheet Layer(2)
DrawScreen 4
DrawScreen 3
TitleScreen
ClearLayer 7
Controls
CompositeBackGroundPlate
'-------Draw the objects-------
FOR i%%
= 0 TO G.ObjectCount
- 1 DrawObject (i%%)
'------------------------------
IF G.BlastCount
THEN DrawExplosions
DrawPlayer
'--------Place the player shots on the screen--------
FOR i%%
= 0 TO P.ShotCount
- 1 MovePlayerShot i%%
DrawPlayerShot i%%
'----------------------------------------------------
DisplayStats
ClearLayer 1
FOR i%%
= 0 TO G.ObjectCount
- 1 MoveObject i%% 'move the objects
'PRINT _RGB32(32, 0, 0) - Colors(Black)
SUB MovePlayerShot
(id~%%
) s(id~%%).Ypos = s(id~%%).Ypos - G.ShotSpeed
IF s
(id~%%
).Ypos
> 0 THEN Hit%%
= ShotCollision
(id~%%
) ELSE Hit%%
= -1 s(id~%%).Ypos = -32 'move shot for removal
ScoreShot Hit%% 'increase score
Nul~%% = 255
IF (O
(Hit%%
).Kind
>= 6 AND O
(Hit%%
).Kind
<= 9) AND (RND * 100) > 25 THEN '~75%chance of split if large object is hit a$ = "Splitting object"
SplitObject Hit%% '
MakeBlast G.BlastCount, Hit%%
G.BlastCount = G.BlastCount + 1 'add a new blast
MakeObject Hit%% 'replace the oid with a new one
P.ShotCount = P.ShotCount - 1
FOR i%%
= id~%%
TO P.ShotCount
s(i%% - 1).Xpos = -10: s(i%% - 1).Ypos = 0
'some big Oids will split into two smaller Oids moving at sharper angles
'object 1 -uses original objects id
O
(id~%%
).Angle
= O
(id~%%
).Angle
- (RND * .25) O(id~%%).Rotation = 1
O
(id~%%
).Kind
= INT(RND * 4) + 2 O
(id~%%
).Speed
= O
(id~%%
).Speed
+ (RND * 1 + .25) 'small objects move faster O
(id~%%
).Colr
= INT(RND * 5) + 6 O(id~%%).Zoom = V12
'object 2 -uses next availible id
id2~%% = G.ObjectCount 'instead of having to use a long varible name.
O(id2~%%).Xpos = O(id~%%).Xpos + 8
O(id2~%%).Ypos = O(id~%%).Ypos
O
(id2~%%
).Angle
= O
(id~%%
).Angle
+ (RND * .25) O(id2~%%).Rotation = 1
O
(id2~%%
).Kind
= INT(RND * 4) + 2 O
(id2~%%
).Speed
= O
(id~%%
).Speed
+ (RND * 1 + .25) 'small objects move faster O
(id2~%%
).Colr
= INT(RND * 5) + 6 O(id2~%%).Zoom = V12
G.ObjectCount = G.ObjectCount + 1 'add a new object to the list
'$include:'AstroAllSubs.bi'