Thanks, but handwriting is on the wall... And it's a Brick one!

by Pete (no login)

 

NOte that when you begin collision detection and redrawing, even with some decent tricks, theaction begins to slow down. Mostly though, it is the INKEY$ or INP(96) in QB4.5 that are not suitable for such games. YOu cannot keep your fingers on the left/right keys and fie. Once yuo fire, yuo won't be able to move left or right until you release the key and then hold it down again.

Anyway, this is probably why I was never much interested in actions games made in QBasic.

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

REM Adds multiple bullets (5) max.
REM Adds firing delay and ship turns red while reloading.
REM Adds aliens.
REM Adds collision for bullets from base to aliens.
DEFINT I
SCREEN 0, 0, 0, 0
DIM bullet%(5), bulletcol%(5), bulletdelay%(5), alien$(6)
tank$ = CHR$(127): icolor = 7

REM Aliens
DIM a AS STRING * 68
a1$ = "-<" + CHR$(237) + ">- "
a$ = a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$ + a1$
ialiencol = 6
LOCATE 2, ialiencol
FOR i = 1 TO 6
IF i MOD 1 = 0 THEN PRINT
LOCATE , 6
IF i = 6 THEN ileadingrow = CSRLIN
alien$(i) = a$
PRINT a$
NEXT

REM Station
LOCATE 24, 40, 1, 7, 7
PRINT tank$; : LOCATE , POS(1) - 1: tanky% = CSRLIN: tankx% = POS(1)
DO
z1 = TIMER
key$ = INKEY$
SELECT CASE key$
CASE CHR$(0) + "K"
IF POS(1) > 1 THEN COLOR icolor: LOCATE , POS(1) - 1: PRINT tank$ + " "; : LOCATE , POS(1) - 2
tanky% = CSRLIN: tankx% = POS(1)
CASE CHR$(0) + "M"
IF POS(1) < 79 THEN COLOR icolor: PRINT " " + tank$; : LOCATE , POS(1) - 1
tanky% = CSRLIN: tankx% = POS(1)
CASE CHR$(32)
IF icolor = 7 THEN
FOR i2 = 1 TO 5
IF bullet%(i2) = 0 THEN
icolor = 12: COLOR icolor: GOSUB redraw
bullet%(i2) = -1: reload = TIMER: EXIT FOR
END IF
NEXT
END IF
CASE ""
IF ABS(z1 - reload) > 1 AND reload <> 0 THEN
GOSUB redraw
icolor = 7: reload = 0
END IF
CASE CHR$(27): SYSTEM
END SELECT

REM Fire
FOR i = 1 TO 5
SELECT CASE bullet%(i)
CASE -1: bullet%(i) = tanky% - 1: bulletcol%(i) = tankx%
CASE IS > 0
IF bulletdelay%(i) = -1 OR bullet%(i) = tanky% - 1 THEN
IF bullet%(i) <= ileadingrow THEN GOSUB checkcollision
z2bullet = TIMER: bulletdelay%(i) = 0
COLOR 7, 0: LOCATE bullet%(i), bulletcol%(i): PRINT CHR$(24)
IF CSRLIN <> 24 THEN LOCATE , bulletcol%(i): PRINT " ";
IF ihitaliens > 0 THEN GOSUB reprintaliens
LOCATE tanky%, tankx%
IF bullet%(i) > 1 THEN
bullet%(i) = bullet%(i) - 1
ELSE
GOSUB erasebullet
END IF
END IF
END SELECT
NEXT

REM Bullet timer delay
IF z2bullet <> 0 THEN
IF z1 < z2bullet THEN z2bullet = z2bullet - 86400
IF z1 - z2bullet >= .06 THEN
FOR i2 = 1 TO 5
IF bullet%(i2) <> 0 THEN bulletdelay%(i2) = -1
NEXT i2
END IF
END IF

LOOP
SYSTEM

erasebullet:
LOCATE ABS(bullet%(i)), bulletcol%(i): PRINT " ";
bullet%(i) = 0: bulletcol%(i) = 0: bulletdelay%(i) = 0
LOCATE tanky%, tankx%
RETURN

redraw:
LOCATE tanky%, tankx%: PRINT tank$; : LOCATE tanky%, tankx%: COLOR 7, 0
RETURN

checkcollision:
IF bulletcol%(i) - ialiencol + 1 > 0 AND bulletcol%(i) - ialiencol + 1 <= LEN(a) THEN
i4 = (ileadingrow - bullet%(i)) \ 2 + 1
IF i4 > 0 AND i4 < 7 THEN
ihitaliens = bulletcol%(i) - ialiencol + 1
a = alien$(i4)
IF MID$(a, bulletcol%(i) - ialiencol + 1, 1) > CHR$(32) THEN
i3 = ihitaliens - 7 + 1: IF i3 < 1 THEN i3 = 1: REM count from the "<" symbol.
MID$(a, INSTR(i3 + 1, a, "<") - 1, 7) = SPACE$(7)
alien$(i4) = a
ELSE
ihitaliens = 0
END IF
END IF
END IF
RETURN

reprintaliens:
LOCATE bullet%(i), ialiencol: PRINT a
ihitaliens = 0
bullet%(i) = -bullet%(i)
RETURN


Posted on Dec 2, 2009, 5:46 PM

Respond to this message   

Return to Index

Response TitleAuthor and Date
* use mouse its smooth and you can move while shootingBen on Dec 2
 Ben, you're a genius! Mouse + alien movement added...Pete on Dec 2
  Cool Pete! on Dec 2
Use INP(96) in a timer tick loop for multiple presses. LINK on Dec 2
 Pete hates INP(96)...Pete on Dec 3
  The read loop does cancel the keypress when not used. on Dec 3
   Ah, the num lock is screwing up the results...Pete on Dec 3
    The number pad does not send two press codes like the arrow keys do. on Dec 3

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement