my attempt at space invaders
BlitzPlus Forums/BlitzPlus Beginners Area/my attempt at space invaders
| ||
This is my first attempt at coding anything and I just seem to be having problems with the bullets. It just pops up. it doesn't travel up the screen. Just wondering why that is. ;set graphics Graphics 640, 480, 16, 2 ;creat timer timer=CreateTimer(30) ;loading player images img_object = LoadImage("object.png") img_bullet = LoadImage("bullet.png") ; bullet type Type bullet Field x Field y End Type ;setting start coords x = 320 y = 340 ;set drawing buffer to back buffer SetBuffer BackBuffer() ;Start main loop While Not KeyDown(1) ;Clear screen Cls ;Draw player DrawImage img_object,x,y ;Update player positioin If KeyDown(203) Then x = x - 3 If KeyDown(205) Then x = x + 3 ; firing bullets If KeyHit(57) Then b.bullet = New bullet b\x = x b\y = - 5 EndIf ;update bullets and draw them For b.bullet = Each bullet b\y = b\y - 5 DrawImage img_bullet, b\x,b\y If b\y < 0 Then Delete b Next ;waite timer WaitTimer(timer) ;Flip drawing screen to monitor Flip ;end main loop Wend End |
| ||
You create your bullet on y = -5 and in your update-routine you delete it if its position is lower then 0. |
| ||
did i not do that? b\y = -5? and If b\y < 0 then delete b? im sure your right i am just trying to understand. its actually pretty cool it works..... kinda haha |
| ||
Sorry what I wanted to say is: If you set the bullets y-position to -5 the result of the condition is always true because you check if y is lower than 0 (-5 < 0) so the bullet will be deleted just after being created. Set the y-position for expample to 400 and it will work. An other way is that you increase the bullets y-position and check if the position is (for expample) greater than 400 and delete it (the bullet) only then when this condition (y > 400) is true Last edited 2012 |
| ||
you should try setting the y position of the bullet when it's created to the y position of the object, so you'd have: ; firing bullets If KeyHit(57) Then b.bullet = New bullet b\x = x b\y = y EndIf or to make it look like it starts just above the object so it's coming out of the ships gun, use b\y = y-5 |