I have been trying to use Deux's example to get my guy to be able to fire his weapon , but it uses a created and grabimage approach, my hopes are to use a loaded bitmap image. I can get it to fire and you see it for a second inside my sprite of a guy, but then it disappears and doesnt go any farther, can't get it to extend its range no matter what I do. Also it seems that Deux's example is extensive , is there a shorter easier version using a loaded bitmap. Any help would be appreciated, been trying for 2 days now, I am about as green as they come to programming.
need help on a bullet coding using a bitmap image
BlitzMax Forums/BlitzMax Beginners Area/need help on a bullet coding using a bitmap image can you describe what you are trying to accomplish?
hey delbar, how was my example extensive ? :)
cant you just replace the bullet with an image ?
can you post your code here ?
cant you just replace the bullet with an image ?
can you post your code here ?
Hello Deux
I tried to just replace the code where the dynamic image was with a .bmp image that i made but it didn't seem to work, the best i could get was when I hit the left mouse( I changed the space bar on yours to it ) was to get 1 or 2 buttlets to show up inside my sprite but not go across the screen. I changed your originX&Y to my sprite image to get it to shoot from there. If I knew how to post code here I would , for now let me check out how I can. But that is the end result I got trying to convert your code to an image, I also took out scale_factor and alpha_factor , not sure if I should have , I used life where alpha_factor<0 to delete from the bulletlist.
I tried to just replace the code where the dynamic image was with a .bmp image that i made but it didn't seem to work, the best i could get was when I hit the left mouse( I changed the space bar on yours to it ) was to get 1 or 2 buttlets to show up inside my sprite but not go across the screen. I changed your originX&Y to my sprite image to get it to shoot from there. If I knew how to post code here I would , for now let me check out how I can. But that is the end result I got trying to convert your code to an image, I also took out scale_factor and alpha_factor , not sure if I should have , I used life where alpha_factor<0 to delete from the bulletlist.
Test trying to post my code. Am trying to get an bullet image(bmp) to shoot from my sprites gun and travel across the screen either to a certain distance or off the screen or stop when it hits something( collision to come later)
SetMaskColor 244,21,241' Magenta Global Player_1:Timage = LoadImage("gfx\player1.bmp") Global Player1bullet:TImage = LoadImage("gfx\bullet.bmp") Global player1X = 400 Global player1Y = 500 Global RunSpeed = 2 While Not KeyDown(KEY_ESCAPE) Cls TileMap() Player1() Player1Input() Bullets() Flip FlushMem Wend Function TileMap() SetScale .2,.2 Local Grass = LoadImage("gfx\Grass2.bmp") TileImage Grass End Function Function Player1() MidHandleImage Player_1 SetScale .4,.4 DrawImage Player_1,player1X,player1Y End Function Function Player1Input() If KeyDown(Key_Left) player1X:- RunSpeed 'Decrease X <-- Go left If KeyDown(Key_Right) player1X:+ RunSpeed 'Increase X --> Go Right If KeyDown(Key_Down) player1Y:+ RunSpeed 'Increase Y Go Down \/ If KeyDown(Key_Up) player1Y:- RunSpeed 'Decrease Y Go Up /\ If KeyHit(Key_Space) player1X=400;player1Y=500 'Set poss End Function AutoMidHandle True Global bulletList:TList Type bullet Field x# Field y# Field origin_x# Field origin_y# Field life# Field scale_factor# Field alpha_factor# Method draw() SetMaskColor 244,21,241 ' Magenta SetScale 1,1 DrawImage Player1bullet,x,y+(scale_factor*5),0 SetAlpha alpha_factor DrawImage Player1bullet,origin_x,origin_y,0 End Method Method update() y:-1 life:-1 scale_factor:-3 alpha_factor:-0.03 If(alpha_factor+10 <0) ListRemove bulletList,Self End Method End Type Function UpdateBullets() For Local b:bullet = EachIn bulletList b.Draw() b.Update() Next End Function Function Bullets() bulletList = CreateList() If KeyHit(KEY_MOUSELEFT) Local mybullet:bullet = New bullet mybullet.life = 100 mybullet.alpha_factor=1 mybullet.x = Player1X mybullet.y = Player1Y myBullet.origin_x = mybullet.x myBullet.origin_y = mybullet.y bulletList.addLast(mybullet) End If UpdateBullets() End Function End
hiya , guess my posting the code didnt work to well other then posting it like text, didn't use one of those cool windows ffor it but there it is. This version I put back in the scale_factor and alpha_factor thinking that somehow it made the bullet go across the screen but it didnt help either. I am sure I am missing something that is probly real easy for most programmers with some experience. If someone could nudge me in the right direction I would appreciate it. Being a newbie to this is ruff.
delbar - i've put your code in a codebox. If you edit that post you will be able to see how I did it.
where in the code archives did you put it ?
Hi Delbar:
I have modified your code abit and it should work now. I have changed the imagenames to my needs and bring all bulletfunctions together to the bullet type to make it more OOP. Its not working well (short time to test) but it should show you how to make it.
I have modified your code abit and it should work now. I have changed the imagenames to my needs and bring all bulletfunctions together to the bullet type to make it more OOP. Its not working well (short time to test) but it should show you how to make it.
Global Player_1:Timage = LoadImage("gfx\raumschiff1.png") Global Player1bullet:TImage = LoadImage("gfx\rocket.bmp") Global player1X = 400 Global player1Y = 500 Global RunSpeed = 2 Global bulletList:TList Graphics 800,600,0,-1 While Not KeyDown(KEY_ESCAPE) Cls TileMap() Player1() Player1Input() If bulletlist <> Null Then bullet.Draw2() EndIf Flip FlushMem Wend Function TileMap() SetScale .2,.2 Local Grass = LoadImage("gfx\grass.bmp") TileImage Grass End Function Function Player1() MidHandleImage Player_1 SetScale .4,.4 DrawImage Player_1,player1X,player1Y End Function Function Player1Input() If KeyDown(Key_Left) player1X:- RunSpeed 'Decrease X <-- Go left If KeyDown(Key_Right) player1X:+ RunSpeed 'Increase X --> Go Right If KeyDown(Key_Down) player1Y:+ RunSpeed 'Increase Y Go Down \/ If KeyDown(Key_Up) player1Y:- RunSpeed 'Decrease Y Go Up /\ If KeyHit(Key_Space) player1X=400;player1Y=500 'Set poss If KeyHit(Key_Mouseleft) Then bb:Bullet = bullet.create() EndIf End Function AutoMidHandle True Type bullet Field x# Field y# Field origin_x# Field origin_y# Field life# Field scale_factor# Field alpha_factor# Function Create:Bullet() If Bulletlist = Null Then bulletlist = New Tlist Local mybullet:bullet = New bullet mybullet.life = 100 mybullet.alpha_factor=1 mybullet.x = Player1X mybullet.y = Player1Y myBullet.origin_x = Player1X myBullet.origin_y = Player1Y bulletList.addLast(mybullet) Return MyBullet End Function Method draw() ' SetMaskColor 244,21,241 ' Magenta SetScale 1,1 DrawImage Player1bullet,x,y+(scale_factor*5),0 SetAlpha alpha_factor DrawImage Player1bullet,origin_x,origin_y+(scale_factor*4),0 End Method Method update() y:-1 life:-1 scale_factor:-3 alpha_factor:-0.03 If(alpha_factor+10 <0) ListRemove bulletList,Self End Method Function Draw2() SetBlend(AlphaBlend) For Local b:bullet = EachIn bulletList b.Draw() b.Update() Next SetAlpha 1 End Function End Type
Hello everyone
Thanks Beaker for showing me the [codebox] command. Thanks Klepto2 for showing me what I was doing wrong, I have tested your code and it does just what I was wanting it to do, thanks a million! Thanks Deux for helping, although we seemed to be on at different times and I couldn't respond too quickly , I am not sure what you mean by the post " where in the code archives did I put it", nonetheless your code got me going on what I wanted to try and do. The Blitz community seems to be as they advertised when I bought the Blitz+, very helpful and I thank you all for helping out a "newbie".
Thanks Beaker for showing me the [codebox] command. Thanks Klepto2 for showing me what I was doing wrong, I have tested your code and it does just what I was wanting it to do, thanks a million! Thanks Deux for helping, although we seemed to be on at different times and I couldn't respond too quickly , I am not sure what you mean by the post " where in the code archives did I put it", nonetheless your code got me going on what I wanted to try and do. The Blitz community seems to be as they advertised when I bought the Blitz+, very helpful and I thank you all for helping out a "newbie".
no probs man, hopefully we can play your game soon :)
I just wanted to see your updated code :)
I just wanted to see your updated code :)