BBC BASIC for Windows
Programming >> Graphics and Games >> Sub-processes
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1354380259

Sub-processes
Post by Usama Amin on Dec 1st, 2012, 3:44pm

Hi,
I am currently working on a 2d sidescrolling shooter.
Does anyone know a way so that i can still make my character move around and at the same time, fire a projectile?
Also im a newbie coder can someone upload example code of a bullet being fired to the right of the screen until it is out of view then another can be fired?
Thanks
Usama grin
Re: Sub-processes
Post by admin on Dec 1st, 2012, 9:53pm

on Dec 1st, 2012, 3:44pm, Usama Amin wrote:
can someone upload example code of a bullet being fired to the right of the screen until it is out of view then another can be fired?

The very simple program below illustrates a common way of achieving that. Use the cursor keys to move the 'gun', and the space bar to fire:

Code:
      MODE 9
      ORIGIN 0,512
      GCOL 128+4
      CLG
      
      VDU 23,128,&C0,&F0,&FC,&FF,&FF,&FC,&F0,&C0
      GunX% = 0
      GunY% = 0
      BulletX% = 1280
      BulletY% = 0
      VDU 5
      
      REPEAT
        GCOL 3,9
        MOVE GunX%, GunY% : VDU 128
        GCOL 3,11
        PLOT BulletX%, BulletY%
        
        WAIT 2
        
        GCOL 3,9
        MOVE GunX%, GunY% : VDU 128
        GCOL 3,11
        PLOT BulletX%, BulletY%
        
        CASE INKEY(0) OF
          WHEN 32:
            IF BulletX% >= 1280 THEN
              BulletX% = GunX% + 32
              BulletY% = GunY% - 16
            ENDIF
          WHEN 136: GunX% -= 4
          WHEN 137: GunX% += 4
          WHEN 138: GunY% -= 4
          WHEN 139: GunY% += 4
        ENDCASE
        IF BulletX% < 1280 BulletX% += 8
      UNTIL FALSE 

For some more sophisticated examples you can look in the Games folder on the Yahoo group and on the BB4WGAMES web site:

http://tech.groups.yahoo.com/group/bb4w/files/Games/
http://bb4wgames.com/

Richard.
Re: Sub-processes
Post by Usama Amin on Dec 1st, 2012, 10:05pm

Thank You! grin
Re: Sub-processes
Post by David Williams on Dec 4th, 2012, 5:54pm

The GFXLIB package comes with a little mini-game called 'Cowboy' which happens to be all about shooting bullets!

Take a look at the code, it might give you some useful ideas.


Regards,

David.


Re: Sub-processes
Post by Usama Amin on Dec 4th, 2012, 7:12pm

Yes, i have seen it and implemented it in my game