mehrere bmx dateien...

Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Neue Antwort erstellen

 

played2often

Betreff: mehrere bmx dateien...

BeitragSo, Sep 21, 2008 13:21
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo, ich bin mich grade am einarbeiten in BMax und ihrgendwie klapt das nicht so ganz wie ich das will. Also ich möchte den Code in 2 Dateien aufteilen, aber das klappt nicht... in einer Datei gehts in 2 nicht, was mach ich falsch?

ALS FEHLER MELDUNG KOMMT
Unhandled Exception:Attempt to access field or method of Null object

################################################
So gehts nicht...

********BASIC2D.BMX
Code: [AUSKLAPPEN]

'IMPORT - TYPES, ATTRIBUTES AND BEHAVIOURS
Import "basic2d_types.bmx"

' -----------------SETUP GAME CONDITIONS--------------------
Global GameObjectList:TList=CreateList()
Graphics 640,480,0

Local Player:TSpaceShip = TSpaceShip.Create("blobship_1-1.png",320,420)
Local Alien:TAlienShip = TAlienShip.Create("cartoonufo_1-1.png",320,0)

 ' ---------------------MAIN LOOP-------------------------
Repeat
        Cls
        For o:TGameObject=EachIn GameObjectList
               o.DrawSelf()
               o.UpdateState()
         Next
         Flip
Until KeyDown(KEY_ESCAPE) Or AppTerminate()
End

********BASIC2D_TYPES.BMX
Code: [AUSKLAPPEN]

' ---------------------TYPES, ATTRIBUTES AND BEHAVIOURS-------------------------
Type TGameObject
   Field X:Int = 320
   Field Y:Int = 420
   Field Speed:Int = 3
   Field Image:TImage

   Method DrawSelf()
      DrawImage Image,X,Y
   End Method     

   Method UpdateState() Abstract
End Type

Type TSpaceShip Extends TGameObject
   Function Create:TSpaceShip(File:String,xstart:Int,ystart:Int)
      Local Ship:TSpaceShip=New TSpaceShip
      Ship.X=xstart
      Ship.Y=ystart
      Ship.Image=LoadImage(LoadBank(File))

      If Ship.Image=Null
         Print "Not able to load image file. Program aborting"
         End
      EndIf

   ListAddLast GameObjectList, Ship
   Return Ship
   End Function

   Method UpdateState()
      If KeyDown(KEY_LEFT)
         X :- Speed
      EndIf   
      If KeyDown(KEY_RIGHT)
      X :+ Speed
      EndIf

      If X < 0 Then X = 0
      If X > 620 Then X = 620
   End Method
End Type

Type TAlienShip Extends TGameObject
   Function Create:TAlienShip(File:String, xstart:Int, ystart:Int)
      Local Ship:TAlienShip = New TAlienShip
      Ship.X = xstart
      Ship.Y = ystart
      Ship.Image = LoadImage(LoadBank(File) )

      If Ship.Image = Null
         Print "Not able to load image file. Program aborting"
         End
      EndIf

   ListAddLast GameObjectList, Ship
   Return Ship
   End Function

   Method UpdateState()
      X :- Speed
      If X < - ImageWidth(Image) Then X = 620
   End Method
End Type


################################################
So gehts...

Code: [AUSKLAPPEN]

' -----------------SETUP GAME CONDITIONS--------------------
Global GameObjectList:TList=CreateList()
Graphics 640,480,0

Local Player:TSpaceShip = TSpaceShip.Create("blobship_1-1.png",320,420)
Local Alien:TAlienShip = TAlienShip.Create("cartoonufo_1-1.png",320,0)

 ' ---------------------MAIN LOOP-------------------------
Repeat
        Cls
        For o:TGameObject=EachIn GameObjectList
               o.DrawSelf()
               o.UpdateState()
         Next
         Flip
Until KeyDown(KEY_ESCAPE) Or AppTerminate()
End

' ---------------------TYPES, ATTRIBUTES AND BEHAVIOURS-------------------------
Type TGameObject
   Field X:Int = 320
   Field Y:Int = 420
   Field Speed:Int = 3
   Field Image:TImage

   Method DrawSelf()
      DrawImage Image,X,Y
   End Method     

   Method UpdateState() Abstract
End Type

Type TSpaceShip Extends TGameObject
   Function Create:TSpaceShip(File:String,xstart:Int,ystart:Int)
      Local Ship:TSpaceShip=New TSpaceShip
      Ship.X=xstart
      Ship.Y=ystart
      Ship.Image=LoadImage(LoadBank(File))

      If Ship.Image=Null
         Print "Not able to load image file. Program aborting"
         End
      EndIf

   ListAddLast GameObjectList, Ship
   Return Ship
   End Function

   Method UpdateState()
      If KeyDown(KEY_LEFT)
         X :- Speed
      EndIf   
      If KeyDown(KEY_RIGHT)
      X :+ Speed
      EndIf

      If X < 0 Then X = 0
      If X > 620 Then X = 620
   End Method
End Type

Type TAlienShip Extends TGameObject
   Function Create:TAlienShip(File:String, xstart:Int, ystart:Int)
      Local Ship:TAlienShip = New TAlienShip
      Ship.X = xstart
      Ship.Y = ystart
      Ship.Image = LoadImage(LoadBank(File) )

      If Ship.Image = Null
         Print "Not able to load image file. Program aborting"
         End
      EndIf

   ListAddLast GameObjectList, Ship
   Return Ship
   End Function

   Method UpdateState()
      X :- Speed
      If X < - ImageWidth(Image) Then X = 620
   End Method
End Type
  • Zuletzt bearbeitet von played2often am So, Sep 21, 2008 13:34, insgesamt einmal bearbeitet

Lunatix

BeitragSo, Sep 21, 2008 13:28
Antworten mit Zitat
Benutzer-Profile anzeigen
Probiers mal mit include anstatt import - import ist für Module vorgesehen.
Und das nächste mal benutz bitte die [ code][ /code] tags Wink
[size=9]Pro|gram|mier|er: Ein Organismus, der Koffein in Software umwandelt.
Geben Sie eine beliebige 11-stellige Primzahl ein, um fortzusetzen...

Xeres

Moderator

BeitragSo, Sep 21, 2008 13:29
Antworten mit Zitat
Benutzer-Profile anzeigen
1. Editiere in deinen Post mal code-Tags, so kann man schwer was erkennen.
2. "Klappt nicht" ist keine adäquate Fehlerbeschreibung, welche Meldung kommt denn?
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)
 

played2often

BeitragSo, Sep 21, 2008 13:35
Antworten mit Zitat
Benutzer-Profile anzeigen
danke Smile mit include gehts...

Neue Antwort erstellen


Übersicht BlitzMax, BlitzMax NG Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group