1
Programs / Assassins 64: Blast from the past
« on: April 12, 2022, 09:39:22 pm »
This is a QB 64 version of the first-person shooter game that I made in QB 4.5 back in 2001. It was impressive back then simply because it was such a fast engine for QB 4.5; that's not really an issue anymore. The sprites are rather basic (no pun intended?), but this version features improved gameplay compared to the original, and a third weapon. The look of the game is otherwise the same, and most of the code is unchanged.
Code: QB64: [Select]
- '1PSA64-2.BAS by Dr. Jacques Mallah (jackmallah@yahoo.com)
- 'Compile with QB64
- main: raycast: keys: yourshot: time: yourmove: badguys: showhealth: medkit.etc
- spritedata:
- 'Map: each character (>"0") is a color or texture
- '0 is empty space. Outer walls must not contain any 0's, ?'s, or r's
- '1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, +, >, @, A are wall textures
- '4 is the map, A is the rainbow
- '? is an ice block "door"
- 'r is random: 50% chance of ice, else texture @
- '. = empty, B = bad guy, R = robot, M = medkit, L = ammo, P = the President / player
- mapdata:
- Data "666666667546C66666666666666666666666666666666666666666666666"
- Data "6.R..?.......6....M6L..................RR?................L6"
- Data "6....1.......A.....?...................BB3................M6"
- Data "6....1.......@.....6662?266666662526666666666664?766666666?6"
- Data "6....1.......?.....6.....................6.................6"
- Data "6....1.......>.....6.....................?.................6"
- Data "6....1.......=.....6.....................6.................1"
- Data "6....?.......<.....666666666444666666666?6.................1"
- Data "6....2.......;.....6.........1...........6.......BBBB......1"
- Data "6....2.......:.....6..BBBB...2......B....?.................6"
- Data "6....2.......9.....6..BBBB...3...........6.................6"
- Data "6....2.......8.....6.........4...........6.................6"
- Data "6....?.......7.....6.........A777777777776666664?76666666666"
- Data "6....3.......6.....6.......................................6"
- Data "6....3.......5.....6.......................................6"
- Data "6....3.......4.....7.......................................6"
- Data "6....?.......3.....6.......................................6"
- Data "6....4BBB....2..R..6.......................................6"
- Data "6....4BBB....1LMMM612?45633?333333333333?33336.............6"
- Data "6....4BBB....6657666.....6...................6.............6"
- Data "6....4BBB....?.LLL.6.....6...................6.............6"
- Data "6....4BBB....?.MMM.6.....6.......BBB.........?.............6"
- Data "6....555555555555556.....r...................6.............6"
- Data "6.........?.....M..6.....6...................6666666466666?6"
- Data "6.........r........6.....6AAAAAAA?AAAAAAAAAA46.............3"
- Data "6.........r........A.........................6.............4"
- Data "6..B......r........A..BBBB...................?.............1"
- Data "6.........r.....P..A.........................6...RRRR......2"
- Data "6.........r.....L..A.............LLLLMMMM....6.............6"
- Data "6155555555555556AAA66666666666666AAA666656666666666656666666"
- Sub badguys
- 'bad guys: Note: I want to add some AI!
- active%(x%) = 1: lastx(x%) = bx: lasty(x%) = by
- bbgx = px - bgx(x%): bbgy = py - bgy(x%)
- chase = 2 * delta.t * (1 + robo%(x%)) * -(active%(x%) > 0)
- bbgx = lastx(x%) - bgx(x%): bbgy = lasty(x%) - bgy(x%)
- vbx(x%) = vbx(x%) - bbgx / dis(x%) * fdt
- vby(x%) = vby(x%) - bbgy / dis(x%) * fdt
- vx = vx + bbgx / dis(x%) * fdt
- vy = vy + bbgy / dis(x%) * fdt
- crashtest bgx(x%) + .15 * svx%, bgy(x%) + .15 * svy%, vbx(x%), vby(x%)
- crashtest bgx(x%) - .15 * svx%, bgy(x%) + .15 * svy%, vbx(x%), vby(x%)
- crashtest bgx(x%) + .15 * svx%, bgy(x%) - .15 * svy%, vbx(x%), vby(x%)
- bgx(x%) = bgx(x%) + vbx(x%) * delta.t: bgy(x%) = bgy(x%) + vby(x%) * delta.t
- scbg(x%) = 2 / (dis(x%) + .01)
- bgang%(x%) = atan2(bgy(x%) - by, bgx(x%) - bx) * 5
- x(x%) = delba% - scbg(x%) * 20: y(x%) = 100 - 25 * scbg(x%)
- 'bad guy's shot
- bgshtx(x%) = bgx(x%): bgshty(x%) = bgy(x%)
- bgvshx(x%) = ct(bgsta%) * 7
- bgvshy(x%) = st(bgsta%) * 7
- 'bad guy's shot
- crashtest bgshtx(x%), bgshty(x%), bgvshx(x%), bgvshy(x%)
- k% = map%(inx%, iny%)
- bgshosht%(x%) = 0
- map%(inx%, iny%) = 0
- testin%(4, inx% + 2, iny% + 19) = 0
- bgshtx(x%) = bgshtx(x%) + bgvshx(x%) * delta.t
- bgshty(x%) = bgshty(x%) + bgvshy(x%) * delta.t
- bbx = bgshtx(x%) - bx: bby = bgshty(x%) - by
- bgshtang% = atan2(bby, bbx) * 5
- dis(x% + nbguys%) = bgshtdis(x%)
- 'fix damage test
- ph% = ph% - bgsht(x%) / 4 - 2.5 * (1 + robo%(x%)): bgshosht%(x%) = 0
- vx = vx + bgvshx(x%) * .05: vy = vy + bgvshy(x%) * .05
- 'kill each other?
- bgh%(y%) = bgh%(y%) - bgsht(x%) / 2 - 1: bgshosht%(x%) = 0
- vbx(y%) = vbx(y%) + bgvshx(x%) * .5: vby(y%) = vby(y%) + bgvshy(x%) * .5
- bgshtht%(x%) = 30 / bgshtdis(x%)
- Next x%
- px = bx + vx * delta.t: py = by + vy * delta.t
- chn2% = (inx% - oinx%) * xsign% + (iny% - oiny%) * ysign%
- k% = map%(inx%, iny%)
- ys% = (1 + ysign%) \ 2: xs% = (1 + xsign%) \ 2
- kx% = map%(oinx%, iny%): ky% = map%(inx%, oiny%)
- tst% = xsign% * ysign% * tstang%
- horz% = 1
- vert% = 1
- lx = px: ly = py: delx = delx / delmag / delta.t: dely = dely / delmag / delta.t: lt% = 0
- lt% = lt% + 1
- lsight% = (map%(inx%, iny%) = 0)
- Sub endit
- goon% = 2
- goon% = goon% - 1
- Print "You die"
- sb1%(x%, y%) = ccc%
- Print "You, President Sal Snore of the United Snows of Antarctica,"
- Print "are trapped in the Wight House with a bunch of guys trying to kill you. "
- Print "Luckily, you have your trusty plasma gun (press 1) and machine gun (press 2)"
- Print "and plas-cannon (press 3; uses plasma gun ammo)."
- Print "Hiding's not your style. You'll show them who's the boss!"
- Print "use arrow forward, back to move; use arrow left, right to rotate"
- Print "Alt to strafe with arrow left, right"
- Print "Ctrl to shoot"
- Print "To fight, try getting some distance and using strafe"
- Print "Try shooting out some ice blocks"
- Print "After starting, press Esc to take the easy way out - suicide!"
- Print "The # at the top left corner is frames per second"
- Print "The bar at the bottom is your health."
- Print "j to toggle cheat mode";
- Sub maketables
- Next tmp1%
- st(0) = 10 ^ -9: st(900) = 10 ^ -9: st(1800) = st(0)
- stt(0) = 10 ^ -7: stt(900) = 10 ^ -7
- ct(450) = 10 ^ -9: ct(1350) = 10 ^ -9
- ctt(450) = 10 ^ -7: ctt(1350) = 10 ^ -7
- xb%(t%) = ct(t%) * nn: yb%(t%) = st(t%) * nn
- yb%(0) = 0: yb%(900) = 0
- xb%(450) = 0: xb%(1350) = 0
- hicol%(c%) = &H100 * (c% + &H100 * (c% > &H7F))
- lowcol%(c% - 128) = c% - 128 - &H100 * ((c% - 128) < 0)
- bicol%(c%) = &H100 * (c% + &H100 * (c% > &H7F)) + c%
- Sub readmap
- DefInt N
- maxshots% = 9: nbguys% = nb: nbguysm1% = nbguys% - 1: nbguyst2% = nbguys% * 2
- nshots% = maxshots%: nspr% = maxshots% + nbguyst2% + nmeds% + nammo%
- Sub makeworld
- nshots% = 1: weap$ = " plasma gun": ammo%(0) = 24: ammo%(1) = 200
- map%(x, y) = 0: bgx(nb) = x + .5: bgy(nb) = y + .5: robo%(nb) = 1: nb = nb + 1
- medx(nm) = x + .5: medy(nm) = y + .5: map%(x, y) = 0: med%(nm) = 1: nm = nm + 1 'meds
- medx(nam) = x + .5: medy(nam) = y + .5: map%(x, y) = 0: med%(nam) = 1: nam = nam + 1 'ammo
- fmap%(39, 15) = -7: fmap%(24, 10) = -2: fmap%(17, 25) = 0
- randloc:
- Sub medkit.etc: 'medkits and ammo boxes
- dis(x% + nbguyst2% + maxshots% + 1) = medis(x%)
- scmed(x%) = 3 / (dis(x% + nbguyst2% + maxshots% + 1) + .01)
- bgang% = atan2(medy(x%) - by, medx(x%) - bx) * 5
- mx(x%) = delba% - scmed(x%) * 10: my(x%) = 100 + 15 * scmed(x%)
- med%(x%) = 0: ammo%(0) = ammo%(0) + 16: ammo%(1) = ammo%(1) + 100
- bsdis = (bgx(y%) - medx(x%)) * (bgx(y%) - medx(x%)) + (bgy(y%) - medy(x%)) * (bgy(y%) - medy(x%))
- Sub onscreen
- bitex% = 1: t% = (fire > 0) * 15: hLINE 155, 166, 100, -t%
- vline 160, 96, 104, 15 + t%: bitex% = 0
- 'draw on screen
- sb2%(2 + x% + 160 * (y% - 8)) = sb1%(x%, y%)
- Sub paintsprites
- 'This uses the painter's algorithm with an exchange sort to show sprites
- showbadguy spord%(xx%)
- showbadshot spord%(xx%) - nbguys%
- showurshot spord%(xx%) - nbguyst2%
- showmed spord%(xx%) - nbguyst2% - maxshots% - 1
- xb% = x% - R% + 1: xt% = x% + R% - 1
- vline xx%, y% - shthtx%, y% + shthtx%, col%
- vline xx%, y% - shthtx%, y% + shthtx%, col%
- Sub raycast
- sizexf% = sizex% * 256: sizeyf% = sizey% * 256
- rxx% = bxx%: ryy% = byy%: oinx% = rxx% \ 256: oiny% = ryy% \ 256
- ys% = (1 - ysign%) \ 2: xs% = (1 - xsign%) \ 2
- yss& = ys% * 256 - byy%: xss& = xs% * 256 - bxx%
- 'find dis & col
- oinx% = inx%: oiny% = iny%
- inx% = rxx% \ &H100: iny% = ryy% \ &H100
- k% = map%(inx%, iny%)
- chn2% = (inx% - oinx%) * xsign% + (iny% - oiny%) * ysign%
- kx% = map%(oinx%, iny%)
- ky% = map%(inx%, oiny%)
- tst% = xsign% * ysign% * Sgn((rxx% - bxx%) * (iny% * 256 + yss&) - (ryy% - byy%) * (inx% * 256 + xss&))
- wdis(x%) = (iny% * 256 + yss&) / stt(t%)
- xfrac = bx + wdis(x%) * ct(t%)
- wdis(x%) = (inx% * 256 + xss&) / ctt(t%)
- xfrac = by + wdis(x%) * st(t%)
- dd% = dsfc(x%) / wdis(x%): odd%(x%) = dd%
- 'load view to buffer
- afx% = ctt(t%) * dsfc(x%): afy% = stt(t%) * dsfc(x%): yt% = dd% + 1
- fixfloor:
- fcxp% = (bxx% + afx% \ yt%): fcyp% = (byy% + afy% \ yt%)
- fcxp% = (bxx% + afx% \ y%): fcx% = fcxp% \ &H100
- fcyp% = (byy% + afy% \ y%): fcy% = fcyp% \ &H100
- flor% = fmap%(fcx%, fcy%)
- sb1%(xx%, y% + 99) = bicol%(flor%)
- flor% = -flor% - ntx% - 1
- sb1%(xx%, 100 - y%) = bicol%(cmap%(fcx%, fcy%))
- hmd% = 100 - dd%: df% = (dd% + 4) \ 32: dof& = dd%: kx% = k% - ntx% - 1
- yb% = 2 * dd% - 1: hmd% = 100 - dd%
- kx% = k% - ntx% - 1
- obcc% = bcc%: Next
- xt% = x(b%) + scbg(b%) * 40
- putbox x(b%) + scbg(b%) * 16, y(b%) + 0, x(b%) + scbg(b%) * 24, y(b%) + scbg(b%) * 2, F0%, dis(b%)
- putbox x(b%) + scbg(b%) * 15, y(b%) + scbg(b%) * 2, x(b%) + scbg(b%) * 25, y(b%) + scbg(b%) * 10, F1%, dis(b%)
- putbox x(b%) + scbg(b%) * 10, y(b%) + scbg(b%) * 10, x(b%) + scbg(b%) * 30, y(b%) + scbg(b%) * 40, b%, dis(b%)
- putbox x(b%), y(b%) + scbg(b%) * 11, x(b%) + scbg(b%) * 10, y(b%) + scbg(b%) * 20, b%, dis(b%)
- putbox x(b%) + scbg(b%) * 30, y(b%) + scbg(b%) * 11, x(b%) + scbg(b%) * 40, y(b%) + scbg(b%) * 20, b%, dis(b%)
- putbox x(b%), y(b%) + scbg(b%) * 20, x(b%) + scbg(b%) * 5, y(b%) + scbg(b%) * 40, b%, dis(b%)
- putbox x(b%) + scbg(b%) * 35, y(b%) + scbg(b%) * 20, x(b%) + scbg(b%) * 40, y(b%) + scbg(b%) * 40, b%, dis(b%)
- putbox x(b%) + scbg(b%) * 10, y(b%) + scbg(b%) * 40, x(b%) + scbg(b%) * 18, y(b%) + scbg(b%) * 70, F3%, dis(b%)
- putbox x(b%) + scbg(b%) * 22, y(b%) + scbg(b%) * 40, x(b%) + scbg(b%) * 30, y(b%) + scbg(b%) * 70, F3%, dis(b%)
- putbox x(b%) + scbg(b%) * 18, y(b%) + scbg(b%) * 40, x(b%) + scbg(b%) * 22, y(b%) + scbg(b%) * 50, F3%, dis(b%)
- putbox x(b%) + scbg(b%) * 7, y(b%) + scbg(b%) * 70, x(b%) + scbg(b%) * 18, y(b%) + scbg(b%) * 75, F4%, dis(b%)
- putbox x(b%) + scbg(b%) * 22, y(b%) + scbg(b%) * 70, x(b%) + scbg(b%) * 33, y(b%) + scbg(b%) * 75, F4%, dis(b%)
- putbox x(b%) + scbg(b%) * 5, y(b%) + scbg(b%) * 35, x(b%) + scbg(b%) * 15, y(b%) + scbg(b%) * 40, F1%, dis(b%)
- putbox x(b%) + scbg(b%) * 25, y(b%) + scbg(b%) * 35, x(b%) + scbg(b%) * 35, y(b%) + scbg(b%) * 40, F1%, dis(b%)
- putbox x(b%) + scbg(b%) * 15, y(b%) + scbg(b%) * 25, x(b%) + scbg(b%) * 25, y(b%) + scbg(b%) * 35, F5%, dis(b%)
- putbox x(b%) + scbg(b%) * 16, y(b%) + scbg(b%) * 3, x(b%) + scbg(b%) * 18, y(b%) + scbg(b%) * 4, 0, dis(b%)
- putbox x(b%) + scbg(b%) * 22, y(b%) + scbg(b%) * 3, x(b%) + scbg(b%) * 24, y(b%) + scbg(b%) * 4, 0, dis(b%)
- putbox x(b%) + scbg(b%) * 16, y(b%) + scbg(b%) * 4, x(b%) + scbg(b%) * 18, y(b%) + scbg(b%) * 4, 7, dis(b%)
- putbox x(b%) + scbg(b%) * 22, y(b%) + scbg(b%) * 4, x(b%) + scbg(b%) * 24, y(b%) + scbg(b%) * 4, 7, dis(b%)
- putbox x(b%) + scbg(b%) * 17, y(b%) + scbg(b%) * 4, x(b%) + scbg(b%) * 17, y(b%) + scbg(b%) * 4, 0, dis(b%)
- putbox x(b%) + scbg(b%) * 23, y(b%) + scbg(b%) * 4, x(b%) + scbg(b%) * 23, y(b%) + scbg(b%) * 4, 0, dis(b%)
- putbox x(b%) + scbg(b%) * 20, y(b%) + scbg(b%) * 5, x(b%) + scbg(b%) * 20, y(b%) + scbg(b%) * 6, 114, dis(b%)
- putbox x(b%) + scbg(b%) * 18, y(b%) + scbg(b%) * 8, x(b%) + scbg(b%) * 22, y(b%) + scbg(b%) * 8, 4, dis(b%)
- F1% = 6
- putcircle bgdela%(x%), 100, bgshtht%(x%), 4 + robo%(x%), bgshtdis(x%)
- Sub showhealth
- hLINE 0, 319 * ph% / 100, y%, 1 + 14 * gm%
- hLINE 319 * ph% / 100 + 1, 319, y%, 4
- ' Print b%, nmeds%
- c% = (b% < nmeds%)
- putbox mx(b%) + 0, my(b%) + 0, mx(b%) + scmed(b%) * 20, my(b%) + scmed(b%) * 20, 2 - 13 * c%, medis(b%)
- putbox mx(b%) + scmed(b%) * 8, my(b%) + scmed(b%) * 3, mx(b%) + scmed(b%) * 13, my(b%) + scmed(b%) * 17, 2 - 2 * c%, medis(b%)
- putbox mx(b%) + scmed(b%) * 3, my(b%) + scmed(b%) * 8, mx(b%) + scmed(b%) * 17, my(b%) + scmed(b%) * 13, -4 * c%, medis(b%)
- Sub time
- fram% = fram% + 1
- afram% = afram% + 1
- fdt = 14 * delta.t
- Static y%, xx%
- Sub yourmove
- vx = vx + ct(efa%) * shift * delta.t
- vy = vy + st(efa%) * shift * delta.t
- vx = vx - ct(efa%) * shift * delta.t
- vy = vy - st(efa%) * shift * delta.t
- crashtest px + .15 * svx%, py + .15 * svy%, vx, vy
- crashtest px - .15 * svx%, py + .15 * svy%, vx, vy
- crashtest px + .15 * svx%, py - .15 * svy%, vx, vy
- px = px + vx * delta.t: py = py + vy * delta.t
- damp = 2 ^ -fdt
- vx = vx * damp: vy = vy * damp: va = va * damp
- Sub yourshot
- Static kk%
- vshx(kk%) = ct(efa%) * 10: vshy(kk%) = st(efa%) * 10
- crashtest shtx(x%), shty(x%), vshx(x%), vshy(x%)
- k% = map%(inx%, iny%)
- shtx(x%) = shtx(x%) + vshx(x%) * delta.t: shty(x%) = shty(x%) + vshy(x%) * delta.t
- map%(inx%, iny%) = 0
- testin%(4, inx% + 2, iny% + 19) = 0
- shtang%(x%) = atan2(shty(x%) - by, shtx(x%) - bx) * 5
- dis(x% + nbguys% * 2) = shtdis(x%)
- shtht%(x%) = 30 / shtdis(x%)
- 'damage test
- bsdis = (shty(x%) - bgy(y%)) * (shty(x%) - bgy(y%)) + (shtx(x%) - bgx(y%)) * (shtx(x%) - bgx(y%))
- 'vbx(y%) = vbx(y%) + vshx(x%) * .1: vby(y%) = vby(y%) + vshy(x%) * .1
- bgh%(y%) = bgh%(y%) - sht(x%) * 1.5 - 50: shosht%(x%) = 0
- 'vbx(y%) = vbx(y%) + vshx(x%) * .5: vby(y%) = vby(y%) + vshy(x%) * .5
- 'If sht(0) < 0 Then fb% = 0
- Sub keys