Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Array Setup for Weapon Blasts- on spot

Author
Message
CrayZemon
23
Years of Service
User Offline
Joined: 16th Jun 2003
Location: United States
Posted: 20th Jun 2003 18:08
Well, I'm back with another question for a simple tile-based engine demo I'm working on to teach be DB. So far, I've got the tile-based background to work, the ship displayed and moving, but when I code to have the ship fire a weapon something just isn't right.

Here's code that initializes arrays for weapon blast sprites:


max_num=100
Dim Blasts_Xpos(max_num)
Dim Blasts_Ypos(max_num)
object_num=1


Here's code that reads the space key:


if spacekey()=1
if rapidity=0
rapidity=50
Blasts_Xpos(object_num)=player_x+10
Blasts_Ypos(object_num)=player_y+10
object_num=object_num+1
endif
endif

rem make sure the weapon takes time to fire again
if rapidity > 0 then rapidity=rapidity-1


All we did above was set the array so that it had one object to take care of, which should be taken care of here:


rem this shouldn't concern the player sprite
update = object_num

`make sure we have an additional sprite(s) to take care of
if update > 0
FOR object_num = 1 to update
todo = Blasts_Ypos(object_num)
todo=todo-10
sprite object_num+2,Blasts_Xpos(object_num),todo,2
if todo
"I need gopher-chucks!!"
CrayZemon
23
Years of Service
User Offline
Joined: 16th Jun 2003
Location: United States
Posted: 20th Jun 2003 18:53
Somehow my code in the third example didn't display fully. It goes:



My last part of the message didn't display either. The spacebar doesn't even respond. Instead, the plasma sprites continuously multiply on the top left part of the screen until the trial version runs out of object. Could someone please help?!?

"I need gopher-chucks!!"
CrayZemon
23
Years of Service
User Offline
Joined: 16th Jun 2003
Location: United States
Posted: 21st Jun 2003 02:20
Ok, I fixed 90% of it but there is still an annoying bug.

Every time you press the space bar a weapon fires. This causes object_num to increment itself every time the weapon is fired. However, when it comes time for me to clean up after myself, I have a block of code that faithfully deletes each sprite that wanders outside the screen. However, when I want to decrement (subtract from) object_num for every weapon blast deleted I get a host of problems. Either this causes the weapon to not fire at all, or the blast positions itself constantly on the ship's nose .

Ignoring all the above posts. Could someone tell me what I can do to make it happen based on this piece of code:



And this code that processes the sprites



And this code that is supposed to decrement the value off of object_num



The third piece of code seems to have no effect on the overall loop, and the firing weapon continues to push to the max that I set on the arrays until it is all used up. Could someone please help.

"I need gopher-chucks!!"
CrayZemon
23
Years of Service
User Offline
Joined: 16th Jun 2003
Location: United States
Posted: 22nd Jun 2003 01:48
Ok- this is the last time I'm going to attempt to keep this post alive unless anyone answers - yes, it's probably my fault for posting such stupendously messy code above.

I've built to weapon firing engine to the point where I can get it to fire appropriately until the spacebar is released. If the space bar is released, the live plasma blasts pause in place until the spacebar is pressed again. I do not understand this, since the code for increasing the blast's y-value is not in the same code block as pressing the space key to initilize a new blast. This time, I've left my source code in a bare-bones format demo below. Keep in mind, the variable "object_num" should maintain a minimal value throughout the loop. There is a reason for this (ie, the preset maximum on the arrays). The reason for the variable being "number" instead of "object_num" in the for loop is because I do not want object_num to be the "screen_num" when done.

"I need gopher-chucks!!"
Scorpyo
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 22nd Jun 2003 19:35
can t you post a stand alone part of the code that does that? (so we just put an image sprite for the plasma.bmp and we run it)?
CrayZemon
23
Years of Service
User Offline
Joined: 16th Jun 2003
Location: United States
Posted: 22nd Jun 2003 21:34
Not easily said when you've got dozens of sprites on the screen to update with constantly changing objects. Unfortunately, those sprite numbers have to pool, delete, decrement, or recycle somewhere in the code to keep the number to a minimum. Otherwise, the "for" loops will be processing numbers incredible massive by the end of a level.

"I need gopher-chucks!!"

Login to post a reply

Server time is: 2026-07-05 22:37:33
Your offset time is: 2026-07-05 22:37:33