horizontal Shoot em up in Object Oriented

BlitzMax Forums/BlitzMax Beginners Area/horizontal Shoot em up in Object Oriented

Hotshot2005(Posted 2015) [#1]
I cant seem get working for some reason and does anyone know what wrong with the code blow?

Global SX       ' Position the Player X
Global SY       ' Position the Player Y
Global X        ' X for moving the background otherwise it wouldnt move!

Graphics 640,480,0

Global Level_1:TImage=LoadImage("Level1.png")
Global Spaceship:TImage =LoadImage("SPACESHIP.png")

Global TPlayer:Player
Global TBackground:Background_Level

SX=100
SX=100

Type Player
     Field SX,SY

     Method Move()

          ' Move Up
          If KeyDown(KEY_UP)
             SY=SY-1
          EndIf

          ' Move Down
          If KeyDown(KEY_DOWN)
             SY=SY+1
          EndIf

         ' Move Right
         If KeyDown(KEY_RIGHT)
            SX=SX+1
         EndIf

         If KeyDown(KEY_LEFT)
            SX=SX-1
         EndIf

         DrawImage Spaceship,SX,SY
     End Method
End Type


Type Background_Level
     Field X

     Method Move()
        
         DrawImage Level_1,X,0
         X=X-1
    
    End Method
End Type


While Not KeyDown(1)
      Cls
      TBackground.Move()
      Tplayer.Move()
      Flip
Wend



Floyd(Posted 2015) [#2]
Global TPlayer:Player
Global TBackground:Background_Level

That declares variables, but does not create anything.
The Language Reference has a section on user defined types.

One way to do this:

Global TPlayer:Player
Global TBackground:Background_Level

TPlayer = New Player
TBackGround = New Background_level



Hotshot2005(Posted 2015) [#3]
It is work :)

Thank you so much!

I need to added shooter end of the spaceship.

For Enemys? IF the Enemys come on screen and I do need timer Enemys waves so often?

IF Enemys go off(for example passing me then off the screen) the screen then I have delete them otherwise it would slow the game.


Hotshot2005(Posted 2015) [#4]
Why isnt the Bullets isnt working?

Global SX   ' Position the Player X
Global SY   ' Position the Player Y
Global X    ' X for moving the background otherwise it wouldnt move!
Global bullet_x, bullet_y
Global bullet_Enabled

Graphics 640,480,0

Global Level_1:TImage=LoadImage("Level1.png")
Global Spaceship:TImage =LoadImage("SPACESHIP.png")

Global TPlayer:Player
Global TBackground:Background_Level


TPlayer = New Player
TBackGround = New Background_level


Type Player
     Field SX=100,SY=100
     Field Bullet_X=SX
     Field Bullet_Y=SY
     Field Bullet_Enabled=False
     Field SIZE=10

     Method Move()

          ' Move Up
          If KeyDown(KEY_UP)
             SY=SY-1
          EndIf

          ' Move Down
          If KeyDown(KEY_DOWN)
             SY=SY+1
          EndIf

         ' Move Right
         If KeyDown(KEY_RIGHT)
            SX=SX+1
         EndIf

         If KeyDown(KEY_LEFT)
            SX=SX-1
         EndIf

         DrawImage Spaceship,SX,SY
     End Method

     Method Update()
            If KeyHit(57) Then
               bullet_Enabled = True
               bullet_X = SX + 10
               bullet_Y = SY + 10
            EndIf

            If bullet_Enabled = True Then
               bullet_X = bullet_X + 15
               SetColor 255,0,0
               DrawRect bullet_X,bullet_Y,SIZE,SIZE
            EndIf

    End Method
End Type


Type Background_Level
     Field X

     Method Move()
        
         DrawImage Level_1,X,0
         X=X-1
    
    End Method
End Type



While Not KeyDown(KEY_ESCAPE)
      Cls

      ' Move the Background Scrolling
      TBackground.Move()

      ' Move the Player by using Keyboards
      Tplayer.Move()
      Tplayer.Update()

      ' Draw Everyhings!
      Flip
Wend



Hotshot2005(Posted 2015) [#5]
I got the shooter working now :-)

Next up...Time to put some Enemys in here and there


Hotshot2005(Posted 2015) [#6]
Would be better if I used Link Lists for enemys and if the enemys get killed then I can remove them easily.


Matty(Posted 2015) [#7]
If it works then why not?

If there is an easy solution that does the job then use that one. Seems you've found it.


Hotshot2005(Posted 2015) [#8]
I am trying to create link lists with bullets which make easier for me to remove them if shoot enemys or go off the screen but I got error saying
Listremove not found.

It is also good things to have Attacking enemys waves in link lists too if player kill some enemys then I can remove them when they been killed?

Global Bullet:TList

 Method Update()
            If KeyHit(KEY_SPACE) Then
               bullet_Enabled = True
               bullet_X = SX + 15
               bullet_Y = SY + 10
               Bullet = CreateList() 
            EndIf

            If bullet_Enabled = True Then
               bullet_X = bullet_X + 15
               DrawRect bullet_X,bullet_Y,SIZE,SIZE
               Bullet.ListRemove()
            EndIf
 end method



Brucey(Posted 2015) [#9]
You normally don't (re)create your bullet list every time you fire a bullet.

What you'd do instead is have a persistent List which you then add "bullets" to when fired, and when they are finished, remove them from the list.

You can use list.AddLast(bullet object) and list.Remove(bullet object), although the Remove() method is not very efficient for large lists (not a problem if you only have a few bullets).