This is my code:
But sometimes there an error : Unhandled Exception:Attempt to access field or method of Null object . In this function World.Update(Delta.time()). Who now, why, please help.
'=============INITIALIZATION SECTION=============== SuperStrict Framework brl.max2d Import brl.bmploader Import brl.jpgloader Import sas.spritebehaviors Import brl.math '==========Îñíîâà Èãðû============ SeedRnd MilliSecs() Const Window_Width:Int=800,Window_Height:Int=600 AppTitle="Spacer" Graphics (Window_Width,Window_Height,32,60) HideMouse() AutoMidHandle True Global World:GameWorld=GameWorld.Create(Window_Width,Window_Height) World.ToggleShowFPS() 'World.SetClientSize(Window_Width,Window_Height) '________________Èãðîâûå Ëèñòû__________________ Global EnemyLooserList:TList=CreateList() Global PulaList:TList=CreateList() Global ExpList:TList=CreateList() Global MothBullet:TList=CreateList() Global BombersList:TList=CreateList() 'Global Damage_List:TList=CreateList() Global Attackers_List:TList=CreateList() '================|000_ÏÀÐÀÌÅÒÐÛ_000|================= Parameters.CohesionWeight=55 ' óñòàíîâêà ïàðàìåòðîâ äëÿ ðåàëèñòè÷íîñòè ÈÈ Parameters.WanderWeight=90 Parameters.SeparationWeight=45 Parameters.AlignmentWeight=30 Parameters.EvadeWeight=150 Parameters.ArriveWeight=100 Rem Parameters.CohesionWeight=55 ' óñòàíîâêà ïàðàìåòðîâ äëÿ ðåàëèñòè÷íîñòè ÈÈ Parameters.WanderWeight=90 Parameters.SeparationWeight=65 Parameters.AlignmentWeight=30 Parameters.EvadeWeight=150 Parameters.FollowPathWeight=10 Parameters.ArriveWeight=100 End Rem 'World.ToggleRenderCollisionRadius ' Âêëþ÷åíèå îòîáðàæåíèÿ ÔÏÑ ' Äåëàåì àâòîöåíòðîâêó èçîáðàæåíèé '++++++++++++++++Splash Screen++++++++++++++ 'Incbin "images\main.png" 'Incbin "images\end.png" 'Global Splash_Screen:TImage=LoadImage("incbin::images\main.png",FILTEREDIMAGE) 'Global End_Scr:TImage=LoadImage("incbin::images\end.png",FilterEDIMAGE) '=========Images Section=============== Incbin "images\enemy.png" ' òóò èçîáðàæåíèÿ Incbin "images\bomber.png" ' âêëþ÷àþòñÿ â .åõå Incbin "images\stars1.jpg" Incbin "images\player2.png" Incbin "images\pula.png" Incbin "images\explos2.bmp" Incbin "images\1.bmp" Incbin "images\mothership.png" Incbin "images\mothership_bullet.png" Incbin "images\turret.png" Incbin "images\shield.png" ' Incbin "images\mini_explos.bmp" '===========Âñÿ Ìåäèà Ïðîåêòà Çäåñü=============== Global PlayerShield:TImage=LoadImage("Incbin::images\shield.png") Global EnemyLooserImage:TImage = LoadImage ("incbin::images\enemy.png") Global EnemyBomberImage:TImage=LoadImage("incbin::images\bomber.png") Global Stars:TImage=LoadImage("incbin::images\stars1.jpg") Global ExplImage2:TImage=LoadAnimImage ("incbin::images\explos2.bmp",128,128,0,20) Global ExplImage:TImage=LoadAnimImage ("incbin::images\1.bmp",128,128,0,20) Global MotherShip_Image:TImage=LoadImage("incbin::images\mothership.png") 'Global Damage_Image:TImage=LoadAnimImage("incbin::images\Mini_Explos.bmp",128,128,0,24) Global AttackBullet_IMG:TImage=LoadImage ("incbin::images\mothership_bullet.png") Global Pula_IMG:TImage=LoadImage ("incbin::images\pula.png") Global MOTHPULA_IMG:TImage=LoadImage ("incbin::images\mothership_bullet.png") Global Player_IMG:TImage=LoadImage("incbin::images\player2.png") Global Turret:TImage=LoadImage("incbin::images\turret.png") Type Pula ' Òèï Ïóëÿ, è âñå ÷òî ñ íåé ñâÿçàíî))) Field x#,y#,xspd#,yspd#,dir:Int Field entity:TImage=Pula_IMG Field List:TList=PulaList Field Alpha#=1 Function create(x#,y#,xspd#,yspd#,dir#) Local Unit:Pula=New Pula Local spd:Int=8 Unit.x = x Unit.y = y Unit.dir = dir Unit.Xspd = Cos(dir)*spd+Xspd Unit.Yspd = Sin(dir)*spd+YSpd ListAddLast (Unit.List,Unit) End Function Method update() x:+Xspd alpha:-0.015 Y:+Yspd If X<0 Or X>Window_Width Or Y<0 Or Y>Window_Height Or alpha<=0Then List.Remove(Self) SetAlpha alpha SetScale 0.5,0.5 SetRotation dir DrawImage entity,x,y SetRotation 0 SetScale 1,1 SetAlpha 1 End Method End Type Type MothPula ' Òèï Ïóëÿ, è âñå ÷òî ñ íåé ñâÿçàíî))) Field x#,y#,xspd#,yspd#,dir:Int Field entity:TImage=MOTHPULA_IMG Field Alpha#=1 Field List:TList=MothBullet Function create(x#,y#,xspd#,yspd#,dir#) Local Unit:MothPula=New MothPula Local spd:Int=8 Unit.x = x Unit.y = y Unit.dir = dir Unit.Xspd = Cos(dir)*spd+Xspd Unit.Yspd = Sin(dir)*spd+YSpd ListAddLast (Unit.List,Unit) End Function Method update() Alpha:-0.01 x:+Xspd Y:+Yspd If X<0 Or X>Window_Width Or Y<0 Or Y>Window_Height Or Alpha<=0 Then List.Remove(Self) SetAlpha alpha SetScale 0.4,0.4 SetHandle 0,5 SetRotation dir DrawImage entity,x,y SetRotation 0 SetHandle 0,0 SetScale 1,1 SetAlpha 1 End Method End Type Type AttackBullet ' Òèï Ïóëÿ, è âñå ÷òî ñ íåé ñâÿçàíî))) Field life:Int Field x#,y#,xspd#,yspd#,dir# Field entity:TImage=AttackBullet_IMG Field List:TList=Attackers_List Function create(x#,y#,xspd#,yspd#,dir#) Local Unit:AttackBullet=New AttackBullet Local spd:Int=8 Unit.x = x Unit.y = y Unit.dir = dir Unit.Xspd = Cos(dir)*spd+Xspd Unit.Yspd = Sin(dir)*spd+YSpd Unit.life=30 ListAddLast (Unit.List,Unit) End Function Method update() x:+Xspd Y:+Yspd life:-1 If X<0 Or X>Window_Width Or Y<0 Or Y>Window_Height Or life=0 Then List.Remove(Self) SetScale 0.4,0.2 SetRotation dir DrawImage entity,x,y SetRotation 0 SetScale 1,1 End Method End Type Type Explosion Field x#,y#,frame% Field Image:TImage Field Alpha#=1 Function Create(x#,y#,Image:Timage) Local c:Explosion=New Explosion c.x=x c.y=y c.frame=0 c.Image=Image ListAddLast (ExpList,c) End Function Method update(MAX_FRAME:Int) If frame<=MAX_FRAME And alpha>=0 SetAlpha alpha SetScale 0.5,0.5 DrawImage Image,x,y,frame SetScale 1,1 SetAlpha 1 Else ListRemove(ExpList,Self) End If frame:+1 alpha:-0.01 End Method End Type Rem Type Damage Field x#,y#,Frame:Int,Image:TImage,List:TList Field angle# Function Create(x#,y#,angle#,Image:timage,List:TList) Local C:Damage=New Damage C.angle=angle C.Image=Image C.List=List C.x=x C.y=y ListAddLast (List,C) End Function Method update(MaxFrame:Int) If Frame<=MaxFrame SetRotation angle SetScale 0.5,0.6 DrawImage Image,x,y,frame SetScale 1,1 SetRotation 0 Else List.Remove(Self) End If frame:+1 End Method End Type End Rem ' Ñîçäàíèå èãðîêà è ìèøåíè äÿ áîòîâ ' //////////////////////// Èñêóññòâåííûé Èíòåëëåêò /////////////////////////// Global Point:Sprite=New Sprite Global Shield_Active:Int=0 Global Player1:Player=New Player Global Num_LooserEnemies:Int=100 Global Num_Bombers:Int=5 ' ************MotherShip*************** Global MotherShip:Sprite=Sprite.CreateForSteering(MotherShip_Image,World,CreateVector(80,80),0,CreateVector(1,1),6,1,1,0.05,0.5) Global MotherShipLife:Int=100 MotherShip.GetSteering().WanderOn() MotherShip.GetSteering().EvadeOn() MotherShip.AddEvadeTarget(Point) MotherShip.SetWorldWrap(True) World.AddVehicle(MotherShip) '\\\\\\\\\\\\\\\\Turret\\\\\\\\\\\\\\\\ Global TurretGun:Sprite=Sprite.CreateForSteering(Turret,World,MotherShip.GetPosition(),0,CreateVector(0,0),1,0,0,1,0.45) World.AddVehicle(TurretGun) '\\\\\\\\\\\\\\\\Others\\\\\\\\\\\ Create_AI() ' ======== Äåëà Ïëåéðíûå ============= Type Player Field x#=Window_Width/2,y#=Window_Height/2,dir#,frict#=0.03,maxspd#=4.0,accel#=0.09,xspd#,yspd# Field turnfrict#=0.9,turnmax#=2.0,turnaccel#=2.0,spdvect#,turnspd# Field Life:Int=100 Field entity:TImage=Player_IMG Method Update() If KeyDown(KEY_UP) ' Ìàíèïóëèðîâàíèå âåêòîðàìè è ïåðåìåííûìè äëÿ XSpd:+Cos(dir)*accel ' äîñòèæåíèÿ äâèæåíèÿ, äëÿ èãðîêà YSpd:+Sin(dir)*accel EndIf If KeyDown(KEY_DOWN) XSpd:-Cos (dir) * accel YSpd:- Sin (dir) * accel End If spdvect=Sqr(xspd*xspd+yspd*yspd) ' âû÷èñëåíèå äëèíû âåêòîðà ñêîðîñòè ïî ò. Ïèôàãîðà If spdvect>0 xspd:-(xspd/spdvect)*frict yspd:-(yspd/spdvect)*frict End If If spdvect>maxspd xspd:+(xspd/spdvect)*(maxspd-spdvect) yspd:+(yspd/spdvect)*(maxspd-spdvect) End If x:+xspd y:+yspd ' Íó ýòî ÿñíî, êàê äåíü =) SetRotation dir DrawImage entity,x,y SetRotation 0 If KeyDown(Key_Left) Turnspd:-Turnaccel End If If KeyDown(Key_Right) turnspd:+TurnAccel End If If MouseDown(1) Or KeyDown(KEY_SPACE) And Time<MilliSecs() Then Pula.create(x,y,xspd,yspd,dir) time=MilliSecs()+100 EndIf If turnspd>turnmax turnspd=turnmax If turnspd<-turnmax turnspd=-turnmax dir:+turnspd If dir<0 dir:+360 If dir>360 dir:-360 If turnspd>turnfrict turnspd:-turnfrict If turnspd<-turnfrict turnspd:+turnfrict If turnspd<turnfrict And turnspd>-turnfrict Then turnspd=0 Point.SetPosition(x,y) If x>Window_Width Then x=0 ' Áóðæóè íàçûâàþò ýòî Wrapping'îì If x<0 Then x=Window_Width If y>Window_Height Then y=0 If y<0 Then y=Window_Height End Method End Type Type Shield Function Active_true(x#,y#,angle#) If Shield_Active=1 SetScale 1,1.45 SetRotation angle DrawImage PlayerShield,x,y SetRotation 0 SetScale 1,1 End If End Function End Type ' ----------------Òàéìåðû --------------------- Global MothTime:Int=MilliSecs() Global time:Int=MilliSecs() Global AttTime:Int=MilliSecs() Global ReLife:Int=MilliSecs() Global ReLife2:Int=MilliSecs() Global Mult#=1 Global ExtraTime:Int Global ShieldTime:Int Global ShieldPauseTime:Int=1000 ' =========== Main Cycle ========== While Not KeyHit(KEY_ESCAPE) Cls DrawImage Stars,450,370 ' îòðèñîâêà çàäíåãî ôîíà Player1.update() World.Update(Delta.time()) If ShieldPauseTime>300 If MouseDown(2) ShieldTime=500 ShieldPauseTime=0 EndIf EndIf If ShieldTime>0 ShieldTime:-1 Shield_Active=1 Else ShieldPauseTime:+1 Shield_Active=0 EndIf Shield.Active_true(Player1.x,Player1.y,Player1.dir) DrawText "Player Life:"+Player1.Life,660,10 DrawText "Mothership Life:"+MotherShipLife,640,22 DrawText "Num of Loosers:"+EnemyLooserList.Count(),640,34 DrawText "Num of Attackers:"+BombersList.Count(),640,46 Rem If Player1.Life<=0 Then Notify "You Die! And i'm cry..." End EndIf End Rem If MotherShipLife<=0 Then Notify "You Won! Well Done!" End EndIf If MotherShipLife<= 50 Then For Local k:Sprite = EachIn EnemyLooserList k.GetSteering().EvadeOff() k.ClearEvadeTargets() k.GetSteering().ArriveOn(MotherShip) Next EndIf Local Dlina#=Sqr((MotherShip.GetX()-Player1.x)^2+(Mothership.GetY()-Player1.y)^2) If dlina<=250 ExtraTime=50 Else ExtraTime=400 EndIf UpdateMothership() Fill_OUT() ' World.update(Delta.time()) World.render() World_Update() ' For Local boom:Damage=EachIn Damage_List ' boom.update(18) ' Next Flip ' Ðåíäåð èçîáðàæåíèé delta.update() Wend End Function UpdateMothership() If MotherShipLife<= 50 Then Mult=7 For Local k:Sprite = EachIn EnemyLooserList k.GetSteering().EvadeOff() k.ClearEvadeTargets() k.GetSteering().ArriveOn(MotherShip) Next EndIf If MotherShipLife<=70 Then Mult=4 If MotherShipLife<=40 Then Mult=10 If MotherShipLife<=20 Then Mult=15 If MotherShipLife<=10 Then Mult=25 Rem If (MothTime+ExtraTime)<MilliSecs() MothPula.create(MotherShip.GetX(),MotherShip.GetY(),MotherShip.GetSpeed(),MotherShip.GetSpeed(),Rnd(0,90)) MothPula.create(MotherShip.GetX(),MotherShip.GetY(),MotherShip.GetSpeed(),MotherShip.GetSpeed(),Rnd(90,180)) MothPula.create(MotherShip.GetX(),MotherShip.GetY(),MotherShip.GetSpeed(),MotherShip.GetSpeed(),Rnd(180,270)) MothPula.create(MotherShip.GetX(),MotherShip.GetY(),MotherShip.GetSpeed(),MotherShip.GetSpeed(),Rnd(270,360)) MothTime=MilliSecs() End If End Rem TurretGun.SetPosition(MotherShip.GetX(),MotherShip.GetY()) TurretGun.RotateHeadingToFacePosition(Point.GetPosition()) If (MothTime+ExtraTime)<MilliSecs() MothPula.create(TurretGun.GetX(),TurretGun.GetY(),0,0,-TurretGun.GetHeading()) MothTime=MilliSecs() EndIf End Function Function Fill_OUT() If Relife+(100*mult)<MilliSecs() If Num_LooserEnemies<20 For Local g:Int=1 To 1 Local enemylooserg:Sprite=Sprite.CreateForSteering(EnemyLooserImage,world,MotherShip.GetPosition(),0,createvector(1,1),1,7,5,5,0.6) enemylooserg.GetSteering().CohesionOn() ' Ñîçäàíèå è ïðèñâîåíèå ÈÈ íîðì ïîâåäåíèÿ enemylooserg.Setworldwrap(True) enemylooserg.GetSteering().AlignmentOn() enemylooserg.GetSteering().WanderOn() enemylooserg.TurnSmoothingOn() enemylooserg.AddEvadeTarget(MotherShip) enemylooserg.GetSteering().SeparationOn() enemylooserg.AddEvadeTarget(Point) enemylooserg.GetSteering().EvadeOn() enemylooserg.SetCollisionRadius(6) World.AddVehicle(enemylooserg) Num_LooserEnemies:+1 ' Äîáàâëåíèå ê ìèðó ListAddLast (EnemyLooserList,Enemylooserg) Next EndIf ReLife=MilliSecs() EndIf If ReLife2+(200*Mult)<MilliSecs() If Num_Bombers<5 For Local q:Int=1 To 1 Local Enemybomberq:Sprite=Sprite.CreateForSteering(EnemyBomberImage,World,MotherShip.GetPosition(),0,createvector(1,1),1,4,4,4,0.5) enemybomberq.ApplyAcceleration(1000,-enemybomberq.GetHeading()) enemybomberq.SetWorldWrap(True) enemybomberq.GetSteering().SeparationOn() Enemybomberq.SetCollisionRadius(4) enemybomberq.GetSteering().ArriveOn(Point) World.AddVehicle(enemybomberq) num_Bombers:+1 ListAddLast(BombersList,Enemybomberq) Next End If ReLife2=MilliSecs() EndIf End Function Function World_Update() For Local vzriv:Explosion=EachIn ExpList vzriv.update(18) Next For Local Pulka:Pula=EachIn PulaList Pulka.update() If ImagesCollide2(Pulka.Entity,Pulka.x,Pulka.y,0,Pulka.dir,0.1,0.1,MotherShip.GetImage(),MotherShip.GetX(),MotherShip.GetY(),0,-MotherShip.GetHeading(),MotherShip.GetScaleX(),MotherShip.GetScaleY()) Explosion.Create(Pulka.x,Pulka.y,ExplImage) ' Damage.Create(Pulka.X,Pulka.y,Pulka.dir,Damage_Image,Damage_List) PulaList.Remove(Pulka) MotherShipLife:-1 End If Next ' Òóò ïðîèñõîäèò êîíòðîëü êîëè÷åñòâà âðàãîâ For Local a:Sprite = EachIn EnemyLooserList For Local b:Pula = EachIn PulaList If ImagesCollide(b.entity,b.x,b.y,0,a.GetImage(),a.GetX(),a.GetY(),0) PulaList.Remove(b) EnemyLooserList.Remove(a) Explosion.Create(a.GetX(),a.GetY(),ExplImage) World.RemoveVehicle(a) Num_LooserEnemies:-1 EndIf Next Next For Local C:Sprite=EachIn BombersList For Local A:Pula=EachIn PulaList If ImagesCollide(A.entity,A.x,A.y,0,C.GetImage(),C.GetX(),C.GetY(),0) PulaList.Remove(A) Explosion.Create(C.GetX(),C.GetY(),ExplImage) BombersList.Remove(C) World.RemoveVehicle(C) Num_Bombers:-1 EndIf Next Next If AttTime+300<MilliSecs() For Local C:Sprite=EachIn BombersList Local Lenght#=Sqr((C.GetX()-Player1.x)^2+(C.GetY()-Player1.y)^2) If Lenght<200 C.TurnSmoothingOn() C.RotateHeadingToFacePosition(Point.GetPosition()) AttackBullet.create(C.GetX(),C.GetY(),0,0,-C.GetHeading()) EndIf If lenght<=100 End If Next AttTime=MilliSecs() EndIf For Local G:AttackBullet=EachIn Attackers_List g.update() If ImagesCollide(g.entity,g.x,g.y,0,player1.entity,player1.x,player1.y,0) Explosion.Create(Player1.x,Player1.y,ExplImage2) attackers_List.Remove(g) If Shield_Active=0 Player1.Life:-1 End If Next For Local MthPula:MothPula=EachIn MothBullet MthPULA.update() If ImagesCollide(MTHPULA.Entity,MTHPULA.X,MTHPULA.Y,0,Player1.Entity,Player1.x,Player1.y,0) MothBullet.Remove(MTHPULA) Explosion.Create(Point.Getx(),Point.Gety(),ExplImage2) If Shield_Active=0 Then Player1.Life:-1 End If Next TurretGun.Draw() End Function Function Create_AI() ' ----------------------Ëóçåðû----------------------- ' Âîçíÿ ñ ÈÈ , à âåðíåå, åãî íàñòðîéêà ' Òóò ñîçäàåòñÿ îïðåäåëåííûé òèï ÈÈ For Local i:Int=1 To Num_LooserEnemies Local enemylooseri:Sprite=Sprite.CreateForSteering(EnemyLooserImage,world,createvector(Rnd( Window_Width),Rnd(Window_Height)),0,createvector(1,1),1,7,5,5,0.6) enemylooseri.GetSteering().CohesionOn() ' Ñîçäàíèå è ïðèñâîåíèå ÈÈ íîðì ïîâåäåíèÿ enemylooseri.Setworldwrap(True) enemylooseri.GetSteering().AlignmentOn() enemylooseri.GetSteering().WanderOn() enemylooseri.AddEvadeTarget(MotherShip) enemylooseri.GetSteering().SeparationOn() enemylooseri.AddEvadeTarget(Point) enemylooseri.GetSteering().EvadeOn() enemylooseri.SetCollisionRadius(6) World.AddVehicle(enemylooseri) ' Äîáàâëåíèå ê ìèðó ListAddLast (EnemyLooserList,Enemylooseri) Next ' Òèï ÈÈ, êîòîðûé áóäóò ãîíÿòü çà ïëååðîì '-----------------------------Atackers------------------------- For Local l:Int=1 To Num_Bombers Local Enemybomberl:Sprite=Sprite.CreateForSteering(EnemyBomberImage,World,CreateVector(Rnd(Window_Width,Window_Height)),0,createvector(1,1),1,6,4,6,0.5) enemybomberl.SetWorldWrap(True) enemybomberl.GetSteering().SeparationOn() Enemybomberl.SetCollisionRadius(10) enemybomberl.GetSteering().ArriveOn(Point) World.AddVehicle(enemybomberl) ListAddLast(BombersList,Enemybomberl) Next End Function
But sometimes there an error : Unhandled Exception:Attempt to access field or method of Null object . In this function World.Update(Delta.time()). Who now, why, please help.