How To

How do your shoot multiple bullets at once

0

Tinycloud778 2019-03-23 19:54

Question: how to shoot multiple bullets at once?


Timo 2019-03-23 21:17

Please explain some more details. What exactly do you want to do? Like in what other game?


Tinycloud778 2019-03-23 22:52

Like a shooter, I know I have to use DIM but I don’t know how to


Tinycloud778 2019-03-23 22:52

Like Galaga or galaxians


was8bit 2019-03-24 05:31

There are two approaches...

1: Use sprites.... this yields a nice look, detection of hitting is easy, and is the same as with original LowRes.... you and your enemies should be sprites too.. you will need to use arrays to track all position of everything ...

2: use cell block animation, like i did with my game Buzy Battle Game.... movement is jerkey as you actually move image characters from one cell block to a nearby empty cell block... this has advantages and disadvantages ...
Advantage, no need for arrays, as the background is used to store things... this then become the disadvantage as you have to scan the entire background, cell by cell, and be very clever in image character usage to help create the code ...

The SPRITE method is going to be the easier method to code.. it's straight forward, looks nicer, and is much easier to do.... the only disadvantage is that you are limited to a total of 64 sprites total,,, that means, the player, the enemies, and each buller shot, cannot exceed 64.. i usually make the player Sprite #0,enemies #1-19, then bullets #20-60, leaving Sprite #61-63 open just in case in want them for some reason later...

That gives you 19 enemies, and about 40 bullets at once flying around, yours and enemy bullets... you can adjust the ranges of course...

The cell block method is harder to do, but lets you have as many things as can fit on the screen... the background is 32x32 which means you could have as many as 900 things moving about... albeit jerky and jumping from cell to cell... but it's a lot more complicated to pull off..

... let me know what interests you :)


was8bit 2019-03-24 05:37

This game uses multiple bullets,,,

https://lowresnx.inutilis.com/topic.php?id=161


was8bit 2019-03-24 05:38

This game only uses one bullet per player, but shows how to set up a simple Sprite game...

https://lowresnx.inutilis.com/topic.php?id=52


was8bit 2019-03-24 05:54

I my game "Twobit saves Bitville" I actually use both methods..

I use Sprite #0 for my main player .. Sprites #1-60 for all bullets, and then I use the background cell #'s that the player can interact with. Such as for pickups, searching inside doors, etc..

I am slowly gathering ideas for my ultimate format, a GAME MAKER series where all a person has to do is design a background, and my GAME MAKER would automatically let the player play the background.... all enemies, pickups, etc. are placed on the background, these then "come to life" and can be interacted with during gameplay :)


was8bit 2019-03-24 05:58

The advanatage of a GAME MAKER format is this... once made, you can totally create tons of different layouts, arrangements, use different quantities, etc, and won't have to do ANY adjustments to any code.... all you have to do is design the background, adding in all the different elements you want, where you want them... THATS IT, the GAME MAKER game would make the background come alive and become interactive with the player :)


was8bit 2019-03-24 06:00

I am entertaining the idea for my first Game Maker... PITFALL... whatcha think? :)


was8bit 2019-03-24 06:05

I'm fleshing out the necessary moves here

https://lowresnx.inutilis.com/topic.php?id=302

Need to get back to that... when I get the time to.....


was8bit 2019-03-24 06:46

OK ..
I made you an example program for multiple bullets.. even lets you SEE how the memory is working in real time :)

https://lowresnx.inutilis.com/topic.php?id=334


was8bit 2019-03-24 06:54 (Edited)

I use S(I) to indicate that this bullet isn't being used (=0) or IS being used (=1) ..

but if you want to get fancy, you can use any number >0 so that it can indicate what KIND of bullet it is... yours, an enemy bullet, etc, OR, maybe you want to animate the bullet, so the number indicates the animation cell to use, so when you update the bullet position you can also update the sprites image as well... LOTS of different ways to use this number when it's >0 ;)

as long as =0 means this bullet isn't being used, any number >0 means the bullet is being used, so update or move the bullet..


Timo 2019-03-24 08:46

Definitely use arrays (DIM) to handle the bullets. I'm writing the chapter for arrays now for my BASIC tutorial, I hope I can finish it today.
In any case, you can start to program a single bullet. When you got this working, it's easy to extend it using arrays.


Tinycloud778 2019-03-24 13:05

Thank you very much


Tinycloud778 2019-03-24 13:16

This is an example code, please help me it’s not working

DIM BX(40)
DIM BY(40)
I=0
X=64
Y=120
GAMEPAD 1

DO
CLS
BY(I)=BY(I)-2

SPRITE 2,X,Y,2
SPRITE 1,BX(I),BY(I),1

IF LEFT(0) THEN X=X-1.5
IF RIGHT(0) THEN X=X+1.5

IF BUTTON(0,0) THEN GOSUB SHOOT

WAIT VBL
LOOP

SHOOT:
BX(I)=X
BY(I)=Y
I=I+1
RETURN


#2:MAIN CHARACTERS
00000000000000000000000000000000
183C3C3C3C000000000000003C000000
3C6666C3810000000000000000000000


Timo 2019-03-24 15:01

Here you go. Basically I added a FOR loop, so each bullet gets updated. There are some more little changes.

DIM BX(40)
DIM BY(40)
N=0
X=64
Y=120
GAMEPAD 1

DO
FOR I=0 TO 40
IF BY(I)>-8 THEN
BY(I)=BY(I)-2
SPRITE 2+I,BX(I),BY(I),1
ELSE
SPRITE OFF 2+I
END IF
NEXT I

SPRITE 1,X,Y,2

IF LEFT(0) THEN X=X-1.5
IF RIGHT(0) THEN X=X+1.5

IF BUTTON TAP(0,0) THEN GOSUB SHOOT

WAIT VBL
LOOP

SHOOT:
BX(N)=X
BY(N)=Y
N=N+1
IF N>40 THEN N=0
RETURN


#2:MAIN CHARACTERS
00000000000000000000000000000000
183C3C3C3C000000000000003C000000
3C6666C3810000000000000000000000


was8bit 2019-03-24 16:37

Think of each bullet has having its own reference number.. in your code I is always 0, so you are only moving bullet #0

TIMO's code loops thru all bullet #'s, so then all bullets are getting moved :)

The tricky is (unless you always want all bullets being used all the time) making your code smart enough to figure out which bullets are in use, and which bullets are not being used... otherwise, if you reuse the same bullet over and over, your last shot disappears and gets reused as the next shot...

Reference my bullet example program for how I make my code smarter so it can find an unused bullet then put it into use... then of course your code must know that a bullet is done and needs to be reset as being unused again...


Tinycloud778 2019-03-24 17:53

Thanks


was8bit 2019-03-24 18:01

:)


Log in to reply.