Return to Index

# As it is in Big Programs I have done it for you

April 23 2008 at 1:21 PM
roy  (no login)

Response to Try this and see what happens

DEFINT A-Z
SCREEN 7, , 1, 0

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 + 165, ey + 15), cross
PUT (ex + 180, 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
PCOPY 1, 0
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)
5 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,04,14,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,14,04,14,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,04,14,04,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,14,04,14,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,08,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,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,08,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,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,08,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 08,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 08,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,08,08,08,08,08,08,08,08,08,08,08,08,08,08,00,00
DATA 00,08,02,67,02,67,02,67,08,67,02,67,08,67,02,67,08,00
DATA 08,02,67,02,67,08,67,02,67,02,67,02,67,02,67,08,67,08
DATA 08,67,08,67,02,67,08,67,02,67,08,67,02,67,02,67,02,08
DATA 08,02,67,08,67,02,67,08,08,08,08,02,67,08,67,02,67,08
DATA 08,67,02,67,02,67,08,00,00,00,00,08,02,67,02,67,02,08
DATA 08,02,67,02,67,08,00,00,00,00,00,00,08,02,67,08,67,08
DATA 08,67,08,67,08,00,00,00,00,00,00,00,00,08,02,67,02,08
DATA 08,02,67,02,08,00,00,00,15,15,00,00,00,08,67,02,67,08
DATA 08,08,08,08,00,00,00,15,15,15,15,00,00,00,08,08,08,08

 Respond to this message
 Response Title Author and Date Thank You (View Thread) New Guy's Helper on Apr 23

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