Code Update - Changes
If you've tried running the
Thesius XIII source/demo in early PlayBasicFX revisions, you've no doubt run into an odd sprite doesn't exist problem. I'd assumed this was from some difference with how the sprite list is traversed in PB1.7x, but it turned out that older editions of the PB (1.63 and bellow) let you to attempt to detect impacts against sprites that didn't exist without raising an error. This is not the case in PB1.7x editions however.
Anyway, So in order to get this demo running in newer editions of PB you'll need to replace the
UpdatePlayerBullets() function (found in the Player source Tab) with one provided bellow. Effectively what was happening was when a bullet left the screen, it was being deleted but rather than continuing the loop, it was falling through and hitting the SpriteHit command. There was another logic error which would occur when bullet hit an alien. Rather than grabbing the Next Sprite in the list prior to subtracting damage from the hit alien, it was doing it after it. This is no problem when the alien wasn't destroyed, by if it was, the code would end up reading a none existent sprite and popping a runtime error.
Moreover, the original source code used the
SpriteImageRGB command which is obsolete in PB1.7x revisions. While it's not actually used in the demo, it's present within the source code, so you can just delete or comment out any such instances from the source and it should compile and run. When I get some time, I'll build a version of the source that will work in both editions, Which is just a matter of adding optional compilation tags.
Function UpdatePLayerBullets()
For Bullet=0 To GetArrayElements(PlayerBullets().tPLayerBullet,1)
If PlayerBullets(Bullet).status
x# =playerbullets(bullet).x#
y# =playerbullets(bullet).Y#
Spr =PlayerBullets(bullet).sprite
Select PlayerBullets(Bullet).Brain
Case PlayerBullet_Directional
Angle#=PlayerBUllets(Bullet).angle#
x#=CosNewValue(x#,angle#,10)
y#=SinNewValue(y#,angle#,10)
; Case PlayerBullet_Homer
EndSelect
playerbullets(bullet).x#=x#
playerbullets(bullet).y#=y#
PositionSprite spr,x#,y#
If SpriteInCamera(spr,Screen.camera)=False
Delete_PlayerBullet(Bullet)
continue
EndIf
; Check If Bullet hit ALienBullet
; Constant CollisionClass_Player =1
; Constant CollisionClass_PlayerBullet =2
; Constant CollisionClass_Alien =4
; Constant CollisionClass_AlienBullet =8
KillBullet=False
CheckSprite=GetFirstSprite()
Repeat
HitAlienSprite=SpriteHit(spr,CheckSprite,CollisionClass_Alien)
; or CollisionClass_AlienBullet)
If HitALienSprite>0
CheckSprite=GetNextSprite(HitALienSprite)
SpriteDrawMode HitALienSprite,2+4096
SpriteAlphaAddColour HitAlienSprite,RndRGB()
CreateExplosionAnim(ExplosionAnim_Small,x#,y#,z#,rnd(360),rnd#(5),rndRange#(0.5,1.5))
if GetSpriteCollisionClass(HitAlienSprite)=CollisionClass_Alien
; handle Damnage on alien LAST..
; get the player that fired this shot
player=PlayerBullets(bullet).player
; handle damage alien and return score (if any)
Score=HandleAlienDamageFromSprite(HitAlienSprite,1)
if Score
Players(player).score=Players(player).score+score
Players(player).ScoreRefresh=true
endif
endif
KillBullet=True
EndIf
Until HitAlienSprite<1
If KillBullet
DeleteArrayObject(PlayerBullets().tplayerbullet,Bullet)
else
Inc NumberOfPlayerBullets
EndIf
EndIf // end of Status check
Next
// The Number Activate PLayers bullets this update
Game.Stats.ActivePlayerBullets=NumberOfPlayerBullets
EndFunction
http://www.playbasic.com