horizontal Shoot em up in Object Oriented
BlitzMax Forums/BlitzMax Beginners Area/horizontal Shoot em up in Object Oriented
| ||
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
|
| ||
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 |
| ||
| 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. |
| ||
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
|
| ||
| I got the shooter working now :-) Next up...Time to put some Enemys in here and there |
| ||
| Would be better if I used Link Lists for enemys and if the enemys get killed then I can remove them easily. |
| ||
| 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. |
| ||
| 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
|
| ||
| 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). |