another newbie question...
Blitz3D Forums/Blitz3D Beginners Area/another newbie question...
| ||
well , ive been studying , and i finally made a program that i think is kinda good , but I have a problem , I want it to have a secondary weapon and what happens is that I cant get it to work!! )+== any help please??? everything works like I want it to , but the weapons dont work)+ ive been trying very hard by the way ....just so u dont think im some noobie idiot looking for help . +) well thx ! Graphics 600,800,0,2 Const LEFTKEY = 203 , RIGHTKEY = 205, SPACEBAR = 57 , ENTER = 156, DEL = 211 Global counter = 0 Type luis Field x,y Field image Field dirx Field diry End Type Type ship Field x,y Field image Field life End Type Type bullets Field x,y Field image End Type Type pb Field x,y End Type Type bullets2 Field x,y End Type Global change = 0 Global pinguilife = 100 Global a = LoadImage("stars.bmp") Global bullet2image = LoadImage("bullet2.jpg") Global pbimage = LoadImage("playerbullet.bmp") Global explosion = LoadSound("tan.wav") Global scream2 = LoadSound("scream2.wav") Global player.luis = New luis Global ship.ship = New ship player\image = LoadImage ("pingui.bmp") ship\image = LoadImage("felicidad.bmp") Global bulletimage = LoadImage ("image1.jpg") MaskImage (bulletimage,0,0,0) Global jaja = LoadSound("jaja.wav") ScaleImage ship\image,.1,.1 player\x = 100 player\y = 100 player\dirx = Rnd(-1,1) player\diry = Rnd(-1,1) If player\dirx = 0 player\dirx = Rnd(-1,1) EndIf If player\diry = 0 player\diry = Rnd(-1,1) EndIf ScaleImage player\image,.1,.1 ship\x = 150 ship\y = 380 scrolly = 0 ;main loop ;main loop While Not KeyDown(1) Cls TileImage a,0,scrolly scrolly = scrolly + 1 If scrolly >= ImageHeight(a) scrolly = 0 EndIf player\x = player\x + player\dirx player\y = player\y + player\diry DrawImage player\image,player\x,player\y DrawImage ship\image,ship\x,ship\y testpingui() testbullets() testkeys() lifes() pinguibullet() secondaryweap() pinguilife() Delay 15 Flip Wend Function testpingui() If player\x < 0 Or player\x > 300 - ImageWidth(player\image) player\dirx = -player\dirx EndIf If player\y < 0 Or player\y > 400 - ImageHeight(player\image) player\diry = -player\diry EndIf End Function Function testkeys() If KeyDown(LEFTKEY) ship\x = ship\x - 3 EndIf If KeyDown(RIGHTKEY) ship\x = ship\x + 3 EndIf If KeyHit(SPACEBAR) If change = 0 bullet.bullets = New bullets bullet\x = ship\x bullet\y = ship\y EndIf If change = 1 bullet2.bullets2 = New bullets2 bullet2\x = ship\x bullet2\y = ship\y EndIf EndIf End Function Function testbullets() ; If change = 1 ; For bullet.bullets = Each bullets bullet\y = bullet\y - 5 DrawImage bulletimage,bullet\x,bullet\y ; If ImagesOverlap(bulletimage,bullet\x,bullet\y,player\image,player\x,player\y) PlaySound scream2 pinguilife = pinguilife - 2 ; EndIf If bullet\y < 0 Delete bullet ; EndIf ; Next ; EndIf ; If change = 0 ; For bullet2.bullets2 = Each bullets2 bullet2\y = bullet2\y - 3 DrawImage bullet2image , bullet2\x,bullet2\y If ImagesCollide(bullet2image,bullet2\x,bullet2\y,0,player\image,player\x,player\y,0) PlaySound Tan pinguilife = pinguilife - 3 EndIf ; ; Next EndIf End Function Function pinguibullet() For pbs.pb = Each pb pbs\x = player\x + ImageWidth((player\image)/2) pbs\y = player\y pbs\y = pbs\y + 5 If pbs\y > GraphicsHeight Delete pbs Else DrawImage pbimage,pbs\x,pbs\y EndIf If ImagesCollide (pbimage,pbs\x,pbs\y,0,ship\image,ship\x,ship\y,0) lifes = lifes - 1 PlaySound jaja EndIf Next End Function Function pinguilife() If pinguilife < 0 Cls Delay 2000 ClsColor 255,0,0 Cls Delay 100 Text 200,100,"YOU WON!!!" Delay 3000 End End If End Function Function lifes() lifes = 3 If lifes < 1 End EndIf End Function Function secondaryweap() If KeyHit(ENTER) change = change + 1 EndIf If change > 1 Or change < 0 Text 200,200,"What?" change = 0 EndIf If KeyHit(DEL) change = change - 1 EndIf End Function |
| ||
You're using the numpad enter key... is that right? If not, you might want to add some text or debug messages to your code which output the current function and the values of certain variables (in this case 'change') plus the last keyhit. |
| ||
I'm not exactly sure what you are trying to achive, but my guess is that you want the global variable change to toggle between two values when pressing ENTER or DEL. Right now it toggles quite randomly between 0-2. The main reason for this is that the logic in the secandaryweap() function is somewhat messy. If you want a simple toggle function for the change variable, replace all your code in secaondaryweap() with this:If KeyHit(ENTER) Or KeyHit(DEL) change = Not change EndIf This will toggle change between 0 and 1 with each keypress If it is something else you want help with, you'll need to specify your question //PetBom |
| ||
"....just so u dont think im some noobie idiot looking for help" Two out of three statements seems to fit, but it's not wrong being a noob, and neither it's wrong to look for help. Nobody here think you are dumb because you ask a (to some people) stupid question :) You could be more exact though, is it the changeing of weapons that don't work, or can't you make it fire, or... Anyway, "PlaySound Tan" will not give you any sort of sound, you forgot to alter, right? Hope it will help, and try posting a codebox for your code, end it with a [/codebox], start it with [codebox] and have the code inbetween. Edit: No that does work, at least when you press enter, though I agree it's a bit messy |
| ||
Okay thx for the tips guys +) but I still have the same problem , I cant shoot more than 1 bullet at a time and sometimes 3 or more of them go out. I also want it to shoot when I press the space bar, not when I shoot the del , intro keys like it actually happens well thx a lot I really appreciate it// |
| ||
It would be a lot easier to debug if I could run the code. If you email me your content I can probably find what bugs might be there. |
| ||
OKay |
| ||
I hope it's not too much for my inbox, only got 700 kB left. |