
-----------------------------------
chaos
Mon Aug 15, 2011 4:08 pm

Shooting Multiple Shots
-----------------------------------
I want to be able to fire multiple shots, but I can only figure out how to shoot one shot at a time. I was wondering what ways there are to do this (ie. a particle engine)?

-----------------------------------
crossley7
Mon Aug 15, 2011 4:22 pm

RE:Shooting Multiple Shots
-----------------------------------
a simple way is to duplicate your variables or convert them to arrays and have an array of boolean that will say whether it is in the air or not.  Then just loop around your array and depending on how you do it, you can have up to n shots if n is the size of the array.

It really depends how you have it set up to help you much with getting multiples

-----------------------------------
Insectoid
Mon Aug 15, 2011 5:01 pm

RE:Shooting Multiple Shots
-----------------------------------
You'll want an array of bullets, yeah. I suggest you calculate the maximum possible number of bullets on the screen at a time. This is how big your array should be.

-----------------------------------
chaos
Mon Aug 15, 2011 5:09 pm

Re: Shooting Multiple Shots
-----------------------------------
I want to limit it to about 10 bullets on screen at a time. Also, is it possible to do this using a particle engine for bullets?

-----------------------------------
Insectoid
Mon Aug 15, 2011 5:23 pm

RE:Shooting Multiple Shots
-----------------------------------
Uh, why? Bullets move just like characters. Particle engines are for like, smoke & stuff like that.

-----------------------------------
chaos
Mon Aug 15, 2011 5:28 pm

Re: Shooting Multiple Shots
-----------------------------------
So, is creating an array each for the number if bullets, the bullet's x-coordinate, and the bullet's y-coordinate the correct way to go?

-----------------------------------
Insectoid
Mon Aug 15, 2011 6:08 pm

RE:Shooting Multiple Shots
-----------------------------------
Have a look at records. There should be something about them in the Turing Walkthrough.

-----------------------------------
chaos
Tue Aug 16, 2011 8:08 pm

Re: Shooting Multiple Shots
-----------------------------------
I took a look at records and this is what I have come up with. I have one problem. The error message says there is no value for the variable  in the line where the bullet is drawn.


setscreen("offscreenonly")
var x:int:=0
var y:int:=maxy div 2

var ship:int:=Pic.FileNew("G:/Turing Game/SpaceShip.bmp")
var bullet:int:=Pic.FileNew("G:/Turing Game/Bullet.bmp")
var count:int:=0
type Bullet:
record
x,y,speed:real
bullet:boolean
end record

var Shoot:array 1..10 of Bullet

for a:1..10
    Shoot(a).bullet:=false
end for
var chars:array char of boolean
loop    
Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) and y+270 then
        y-=1
    end if
    if chars (' ') then
        count+=1
        if count=11 then
            count:=1
        end if
        for bulletcheck:1..10
            if bulletcheck=count then
                Shoot(bulletcheck).bullet:=true
            end if
            if Shoot(bulletcheck).bullet=true then
                Shoot(bulletcheck).x:=67
                Shoot(bulletcheck).y:=y+8
            end if
            Pic.Draw(bullet,round(Shoot(bulletcheck).x),round(Shoot(bulletcheck).y),picCopy)
            Shoot(bulletcheck).x+=5
        end for
        
        
        
    end if
    
    
    Pic.Draw(ship,x,y,picCopy)
    View.Update
    delay(10)
    cls
end loop



-----------------------------------
mirhagk
Wed Aug 17, 2011 7:43 am

RE:Shooting Multiple Shots
-----------------------------------
You have this organized very strangely. When you shoot you want to do all that setting of it's values and stuff in one section, and in a different section you check if it's alive and draw it if it is.

Right now your drawing all the bullets that don't exist as soon as you hit the space bar.

-----------------------------------
chaos
Wed Aug 17, 2011 11:14 am

Re: Shooting Multiple Shots
-----------------------------------
@mirhagk: Thanks. I fixed the problem.

Here is the fixed code. Though I need some help on delaying the movement of the bullet from the movement of the ship. 



setscreen("offscreenonly")
var x:int:=0
var y:int:=maxy div 2

var ship:int:=Pic.FileNew("G:/Turing Game/SpaceShip.bmp")
var bullet:int:=Pic.FileNew("G:/Turing Game/Bullet.bmp")
var count:int:=0
type Bullet:
record
x,y,speed:real
bullet:boolean
end record

var Shoot:array 1..10 of Bullet

for a:1..10
    Shoot(a).bullet:=false
    Shoot(a).speed:=5
end for
var chars:array char of boolean
loop    
Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) and y+270 then
        y-=1
    end if
    if chars (' ') then
        count+=1
        if count=11 then
            count:=1
        end if
        for check:1..10 
            if check=count then
                Shoot(check).bullet:=true
                Shoot(check).x:=67
                Shoot(check).y:=y+8
            end if
        end for    
    end if
    for firing:1..10
        if Shoot(firing).bullet=true then
            Shoot(firing).x+=Shoot(firing).speed
            if Shoot(firing).x>maxx then
                Shoot(firing).bullet:=false
            else
                Pic.Draw(bullet,round(Shoot(firing).x),round(Shoot(firing).y),picCopy)
            end if
        end if
    end for
    
    
    Pic.Draw(ship,x,y,picCopy)
    View.Update
    delay(50)
    cls
end loop



-----------------------------------
mirhagk
Wed Aug 17, 2011 12:10 pm

RE:Shooting Multiple Shots
-----------------------------------
I might be confused as to what you want, but couldn't you just decrease the speed?

-----------------------------------
Raknarg
Sat Aug 27, 2011 7:43 pm

Re: Shooting Multiple Shots
-----------------------------------

for check:1..10 
     if check=count then 
          Shoot(check).bullet:=true 
          Shoot(check).x:=67 
          Shoot(check).y:=y+8 
     end if 
end for 


This xan be shortened to:

Shoot(count).bullet:=true 
Shoot(count).x:=67 
Shoot(count).y:=y+8 

since that's whats going to happen anyways.

And as for your most recent quetion, there's no need to delya them seperately. Just move them at different speeds.

Also, you're going to encounter one more problem in the future, depending on how you do it. But to make it easier, I'd move every dead bullet to a ludicrous position so they do not get in the way. When I did my spaceship game, it took me a while to figure out why ships were disappearing at random, and its because (again, depending on how you do it) the dead bullets kill ships though they dont move and are not drawn.

-----------------------------------
chaos
Mon Aug 29, 2011 10:24 pm

Re: Shooting Multiple Shots
-----------------------------------
I have now included enemies and collision detection (somewhat). The problem is that after you kill the enemy and shoot bullets again in the same location, the bullets disappear without the the presence of an enemy for some time--about less than a second, but noticeable. How can I fix this? Any help is appreciated. I have attached the enemy ship below. Here is my code:


setscreen("offscreenonly")
var x:int:=0
var y:int:=maxy div 2

var ship:int:=Pic.FileNew("G:/Turing Game/SpaceShip.bmp")   %Spaceship pic (68x27 pixels)
var bullet:int:=Pic.FileNew("G:/Turing Game/Bullet.bmp")   %Bullet pic (20x8 pixels)
var count:int:=0
var EnemyShip:int:=Pic.FileNew("G:/Turing Game/EnemyShip.bmp")  %EnemyShip pic (77x39 pixels)
var background:int:=Pic.FileNew("G:/Turing Game/scrollingBackground.bmp")  %Background pic (2,110x300 pixels)
const screenx:=640
const picx:=2110
var backx:int:=0

const eships:=5 %Max # of enemy ships

type Enemy:     %Record of variables for enemy ships
    record
        ex,ey,espeed:real
        onoff:boolean
    end record

var BadGuys:array 1..eships of Enemy %Array for enemy ships

for i:1..eships         %Assigning initial values of enemy ships
    BadGuys(i).ex:=maxx                 %EnemyShip x-coordinate
    BadGuys(i).ey:=Rand.Int(39,maxy-39) %EnemyShip y-coordinate
    BadGuys(i).espeed:=Rand.Int(3,5)    %EnemyShip speed
    BadGuys(i).onoff:=false
end for

const shots:=10 %Max # of bullets

type Bullet:    %Record of variables for bullets
    record
        x,y,speed:real
        bullet:boolean
    end record

var Shoot:array 1..shots of Bullet %Array for bullets

for a:1..shots          %Assigning unitial values of bullets
    Shoot(a).bullet:=false         %Bullet is off("false"=off;"true"=on)
    Shoot(a).speed:=5              %Bullet speed
end for
var chars:array char of boolean
loop                                %Main loop
    %Drawing the Background
    Pic.Draw(background,-backx,0,picCopy)
    if backx=picx then
        backx:=0
    elsif backx+screenx>=picx then
        Pic.Draw(background,picx-backx,0,picCopy)
    end if
    
    %Spawning the Bad Guys
    for e:1..eships
        BadGuys(e).ex-=BadGuys(e).espeed
        var num:int:=Rand.Int(1,3)
        if BadGuys(e).ex