The QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 
 Return to Index  

NewGuy's Program

April 21 2008 at 4:20 PM
Pete  (Login The-Universe)
Admin

DEFINT A-Z
SCREEN 13

CONST MAXBULLETS = 16
AMBX = 199
DIM bullets(MAXBULLETS - 1, 1) AS INTEGER
DIM a(30, 30)'pixel array -- make it bigger for a bigger sprite
delay% = 8

RESTORE shooterdata
FOR J = 0 TO 30
FOR I = 0 TO 30
READ a(I, J)
NEXT
NEXT

RESTORE blooddata
FOR y = 0 TO 9
FOR x = 0 TO 8
READ blood
PSET (x, y), blood
NEXT x
NEXT y

DIM blood%(90)
GET (0, 0)-(9, 10), blood%

FOR y = 0 TO 9
FOR x = 0 TO 8
READ needle
PSET (x, y), needle
NEXT x
NEXT y

DIM needle%(90)
GET (0, 0)-(9, 10), needle%


FOR y = 0 TO 9
FOR x = 0 TO 8
READ cross
PSET (x, y), cross
NEXT x
NEXT y

DIM cross%(90)
GET (0, 0)-(9, 10), cross%


FOR y = 0 TO 9
FOR x = 0 TO 17
READ barrier
PSET (x, y), barrier
NEXT x
NEXT y

DIM barrier%(153)
GET (0, 0)-(17, 10), barrier%
CLS
ex = -24: REM start 24 spaces to the left
inc = 2

DO
GOSUB drawenemies
IF ex = 48 OR ex = -24 AND inc < 0 THEN ey = ey + 2: inc = -inc
ex = ex + inc
IF ey = 66 THEN STOP: REM hits base
GOSUB delay
CLS
GOSUB redrawbase
GOSUB shooter
LOOP

drawenemies:
PUT (ex + 85, ey + 0), needle
PUT (ex + 100, ey + 0), needle
PUT (ex + 115, ey + 0), needle
PUT (ex + 130, ey + 0), needle
PUT (ex + 145, ey + 0), needle
PUT (ex + 160, ey + 0), needle
PUT (ex + 175, ey + 0), needle
PUT (ex + 190, ey + 0), needle
PUT (ex + 205, ey + 0), needle
PUT (ex + 220, ey + 0), needle

PUT (ex + 75, ey + 15), cross
PUT (ex + 90, ey + 15), cross
PUT (ex + 105, ey + 15), cross
PUT (ex + 120, ey + 15), cross
PUT (ex + 135, ey + 15), cross
PUT (ex + 150, ey + 15), cross
PUT (ex + 195, ey + 15), cross
PUT (ex + 210, ey + 15), cross

PUT (ex + 85, ey + 30), blood
PUT (ex + 100, ey + 30), blood
PUT (ex + 115, ey + 30), blood
PUT (ex + 130, ey + 30), blood
PUT (ex + 145, ey + 30), blood
PUT (ex + 160, ey + 30), blood
PUT (ex + 175, ey + 30), blood
PUT (ex + 190, ey + 30), blood
PUT (ex + 205, ey + 30), blood
PUT (ex + 220, ey + 30), blood

PUT (ex + 75, ey + 45), needle
PUT (ex + 90, ey + 45), needle
PUT (ex + 105, ey + 45), needle
PUT (ex + 120, ey + 45), needle
PUT (ex + 135, ey + 45), needle
PUT (ex + 150, ey + 45), needle
PUT (ex + 165, ey + 45), needle
PUT (ex + 180, ey + 45), needle
PUT (ex + 195, ey + 45), needle
PUT (ex + 210, ey + 45), needle

PUT (ex + 85, ey + 60), cross
PUT (ex + 100, ey + 60), cross
PUT (ex + 115, ey + 60), cross
PUT (ex + 130, ey + 60), cross
PUT (ex + 145, ey + 60), cross
PUT (ex + 160, ey + 60), cross
PUT (ex + 175, ey + 60), cross
PUT (ex + 190, ey + 60), cross
PUT (ex + 205, ey + 60), cross
PUT (ex + 220, ey + 60), cross

PUT (ex + 75, ey + 75), blood
PUT (ex + 90, ey + 75), blood
PUT (ex + 105, ey + 75), blood
PUT (ex + 120, ey + 75), blood
PUT (ex + 135, ey + 75), blood
PUT (ex + 150, ey + 75), blood
PUT (ex + 165, ey + 75), blood
PUT (ex + 180, ey + 75), blood
PUT (ex + 195, ey + 75), blood
PUT (ex + 210, ey + 75), blood
RETURN

shooter:
'Setup program and data

'Make each slot empty (set both coordinates to -1)
FOR bul = 0 TO UBOUND(bullets, 1)
bullets(bul, 0) = -1
bullets(bul, 1) = -1
NEXT bul

'Main loop
DO
IF OLDAMBX <> AMBX THEN
LINE (OLDAMBX, 150)-(OLDAMBX + 35, 170 + 35), 0, BF
END IF
OLDAMBX = AMBX
'Update objects
'For each bullet
FOR bul = 0 TO UBOUND(bullets, 1)
'If it's not an empty slot
IF NOT (bullets(bul, 0) = -1 AND bullets(bul, 1) = -1) THEN
'Erase the bullet from it's old position
PSET (bullets(bul, 0), bullets(bul, 1)), 0

'Move the bullet up one pixel
bullets(bul, 1) = bullets(bul, 1) - 1

'If it's off the screen, make it an empty slot again
IF bullets(bul, 1) < 0 THEN
bullets(bul, 0) = -1
bullets(bul, 1) = -1
'Otherwise, draw it in it's new spot
ELSE
'Draw the bullet
PSET (bullets(bul, 0), bullets(bul, 1)), 15
END IF
END IF
NEXT bul
FOR J = 0 TO 30
FOR I = 0 TO 30
PSET (I + AMBX, 170 + J), a(I, J)
NEXT
NEXT
'Get user input
a$ = INKEY$
IF a$ <> "" THEN
REM allows a redraw even when key is held down
nodelay = 1
switchvar = switchvar + 1: IF switchvar > 1 THEN switchvar = 0: a$ = "": nodelay = 0
END IF
SELECT CASE a$
'Fire a bullet
CASE CHR$(32)
FOR bul = 0 TO UBOUND(bullets, 1)
'Create a new bullet if it's an empty slot
IF (bullets(bul, 0) = -1 AND bullets(bul, 1) = -1) THEN
bullets(bul, 0) = INT(AMBX + 9)
bullets(bul, 1) = 170
EXIT FOR
END IF
NEXT bul
CASE CHR$(27)
SYSTEM
CASE CHR$(0) + CHR$(75)
IF AMBX > 0 THEN AMBX = AMBX - 5
CASE CHR$(0) + CHR$(77)
IF AMBX < 320 THEN AMBX = AMBX + 5
CASE "": RETURN
END SELECT

'Delay for 1/10th of a second
''''''''IF switchvar = 0 THEN RETURN
STime! = TIMER
WHILE TIMER - STime! < .01: WEND
LOOP
'End program
RETURN

redrawbase:
'***PUT***
CLS
PUT (75, 150), barrier
PUT (125, 150), barrier
PUT (175, 150), barrier
PUT (225, 150), barrier
RETURN

delay:
IF nodelay = 1 THEN nodelay = 0: RETURN
FOR Reps% = 1 TO delay%
WAIT &H3DA, 8
WAIT &H3DA, 8, 8
NEXT Reps%
RETURN

shooterdata:
DATA 00,00,00,00,00,00,00,00,00,04,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,04,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,15,00,00,04,00,04,00,04,00,00,15,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,15,15,00,04,15,04,15,04,00,15,15,00,00,00,14,04,14,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,15,15,15,04,04,04,04,04,15,15,15,00,00,00,04,14,04,00,00,00,00,00,00,00,00,00,00
DATA 00,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,00,00,00,00,00,00,00,00,00,00
DATA 00,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,03,17,03,15,00,00,00,00,00,00,00,00,00
DATA 00,15,15,15,15,15,15,04,04,04,04,04,15,15,15,15,15,15,03,17,03,15,00,00,00,00,00,00,00,00,00
DATA 00,15,15,15,15,15,15,04,04,04,04,04,15,15,15,15,15,15,03,17,17,15,00,00,00,00,00,00,00,00,00
DATA 00,15,15,15,15,15,15,04,04,04,04,04,15,15,15,15,15,15,03,17,03,15,00,00,00,00,00,00,00,00,00
DATA 00,15,15,15,15,15,15,04,04,04,04,04,15,15,15,15,15,15,15,15,15,15,15,15,15,15,12,12,00,00,00
DATA 00,15,15,04,04,04,04,04,04,04,04,04,04,04,04,04,15,15,15,15,15,15,15,15,15,15,12,12,12,00,00
DATA 00,15,15,04,04,04,04,04,04,04,04,04,04,04,04,04,15,15,15,15,15,15,15,15,15,15,12,12,12,00,00
DATA 00,15,15,04,04,04,04,04,04,04,04,04,04,04,04,04,15,15,15,15,15,15,15,15,15,15,12,12,12,00,00
DATA 00,15,15,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,08,08,00,00
DATA 00,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,08,00,00
DATA 00,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,04,08,08,00,00
DATA 00,15,15,15,15,15,15,04,04,04,04,04,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,08,00,00
DATA 00,15,15,15,15,15,15,04,04,04,04,04,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,08,08,00,00
DATA 00,15,15,15,17,17,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,17,15,15,15,00,00
DATA 00,06,06,17,08,08,17,06,06,06,06,06,06,06,06,06,06,06,06,06,06,04,06,17,08,08,17,06,00,00,00
DATA 00,15,17,08,08,08,08,17,15,15,15,15,15,15,15,15,15,15,15,15,15,15,17,08,08,08,08,17,00,00,00
DATA 00,00,00,08,08,08,08,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,08,08,08,08,00,00,00,00
DATA 00,00,00,00,08,08,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,08,08,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00


'**BLOOD**
blooddata:
DATA 17,17,17,17,04,17,17,17,17
DATA 17,17,17,04,04,04,17,17,17
DATA 17,17,04,04,04,04,04,17,17
DATA 17,04,04,04,04,04,04,04,17
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,04,04,04,04,04,04,04
DATA 04,04,04,04,04,04,04,04,04
DATA 17,04,04,04,04,04,04,04,17
DATA 17,17,17,04,04,04,17,17,17

'**NEEDLE**
needledata:
DATA 00,00,00,00,00,00,00,00,15
DATA 00,00,00,00,15,00,15,15,00
DATA 00,00,00,00,00,15,04,15,00
DATA 00,00,00,00,15,04,15,00,00
DATA 00,15,00,15,04,15,00,15,00
DATA 00,00,15,04,15,00,00,00,00
DATA 00,00,04,15,00,00,00,00,00
DATA 00,04,00,00,15,00,00,00,00
DATA 04,00,00,00,00,00,00,00,00
DATA 00,00,00,00,00,00,00,00,00

'**CROSS**
crossdata:
DATA 15,15,15,15,15,15,15,15,15
DATA 15,15,15,04,04,04,15,15,15
DATA 15,15,15,04,04,04,15,15,15
DATA 15,04,04,04,04,04,04,04,15
DATA 15,04,04,04,04,04,04,04,15
DATA 15,04,04,04,04,04,04,04,15
DATA 15,15,15,04,04,04,15,15,15
DATA 15,15,15,04,04,04,15,15,15
DATA 15,15,15,04,04,04,15,15,15
DATA 15,15,15,15,15,15,15,15,15

'*** Barrier
barrierdata:
DATA 00,00,00,02,02,02,02,02,02,02,02,02,02,02,02,00,00,00
DATA 00,00,02,02,02,02,02,02,02,02,02,02,02,02,02,02,00,00
DATA 00,02,02,09,09,09,09,09,09,09,09,09,09,09,09,02,02,00
DATA 02,02,02,09,02,02,12,12,12,12,12,12,02,02,09,02,02,00
DATA 02,02,02,09,02,02,12,00,00,00,00,12,02,02,09,02,02,02
DATA 02,02,02,09,02,02,12,00,00,00,00,12,02,02,09,02,02,02
DATA 02,02,02,09,02,02,00,00,00,00,00,00,02,02,09,02,02,02
DATA 02,02,02,09,02,00,00,00,00,00,00,00,00,02,09,02,02,02
DATA 02,02,02,09,00,00,00,00,00,00,00,00,00,00,09,02,02,02
DATA 02,02,02,00,00,00,00,00,00,00,00,00,00,00,00,02,02,02

---------------------------------------------

Pete

Here's the deal. Combining just takes making the new addition into a SUB. Then, you have to do things like RESTORE to tell the program which data to read. I like to stack all data statements at the end. OK, you do have to take out extra CLS and screen statements and it alos helps to move constant variables to the top of the program.

Most importantly is to make the program cycle through everything. I included a new case in INKEY for this. If no key is selected, it cycles. If a key is held down, the cycle is still possible because of a new variable, called SWITCHVAR.

Now your part is to concentrate on the next task, which is trying to figure out how to keep that bullet going!

- Notice that it is in a for loop and to make it functional, it has to cycle out of that loop every time to redraw the rest of the screen.

Good luck,

Pete



    
This message has been edited by The-Universe on Apr 21, 2008 5:46 PM


 
 Respond to this message   
Response TitleAuthor and Date
An example of Page flipping in SCREEN 9 (View Thread) on Apr 21
   How would we page flip thisNew Guy on Apr 22
      You will need to use Screen 7 on Apr 22
         I did as you said but Its not working properly!New Guy on Apr 22
            You are confusing DATA with PUT on Apr 22
               I don't know what to say! (I'm stuck)New Guy on Apr 23
                  Try this and see what happensroy on Apr 23
                     As it is in Big Programs I have done it for youroy on Apr 23
                        Thank YouNew Guy's Helper on Apr 23
O my! Ok I'll try. (View Thread)New Guy on Apr 21
   *Sry Clippy I didn't see you thread when I asked that!New Guy on Apr 21
      *No problem. I forgot to add the Image Array anyhow....fixed on Apr 21
Ok so we have page flipping in effect. BUT now what? (View Thread)New Guy on Apr 25
   I will help again as you still have a lot of work to do butroy on Apr 25
      *This alteration will preserve barriers,run smoother and fire bullets.roy on Apr 25
      Nice work roy!Pete on Apr 25
      I am in your debt! Thank you. One question though?New Guy on Apr 28
         You will need to use POINT(x , y)roy on Apr 28
            If you are stuck again, here is a rough example.roy on May 1
               Ok ima work with thatNew Guy's Helper on May 1
                  IS ANYONE ON AT THE MOMENT? I have a questionNew Guy's Helper on May 1
                     This is not a chat roomroy on May 1
                        * How quickly we turn on our buddies LOLClippy on May 2
               Re: If you are stuck again, here is a rough example.New Guy on May 2
                  I was getting you there step by step.roy on May 2
                  The reason for the discrepancy when hitting the enemyroy on May 2
                     The drawenemies sub example was to show you how to blank out PUTSroy on May 2
                  This may be easier for youroy on May 3
                     Added a firing delay called... bulletaway! on May 4
                        The pairs dissapearing is still a little unreliable!New Guy on May 8
                           We are trying to help you.roy on May 8
                              Sry about that! What do you mean by dead variable range.New Guy on May 8
                                 dead is a variable just like a can be a variableroy on May 8
                                    The drawenemies sub is a bit tedious to typeroy on May 8
                                       *Ok so what do we have to do from here?New Guy on May 9
                                       Without making drastic changes this will workroy on May 9
                                          * That's why I hate making games on May 9
   * The Black box is erasing your barriers. Move down some on Apr 25
Ok here is what we have right now! Its not working! Anyone know how to fix it? (View Thread)New Guy on May 7
   Remove END and INPUT k just after the looproy on May 7

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums