I've changed the way the levels are set-up; now each level is a set of
numbers (rather than a string) in the DATA statements at the bottom of
the main program section. This lets you use numbers like 12 for wall
colors (before, 12 would have been interpreted as a single wall of color
1, then another single wall of color 2). Plus, I put in a different
level, now 12x12, to demonstrate the new range of colors.
I've changed the obelisk added by Nick Cangiani to an office building,
complete with lights. There are also clouds in the background, now,
which look pretty neat, I think. I'm thinking of adding a bit of
shading to them, too.
You can no longer walk through walls, either. Though, of course, you
can change that in the [SPACE] handling section.
I've tried implementing negative-number walls, with special handling
that creates a neat effect, but nothing works quite right. Raising the
walls just causes a problem when you have a wall between you and the
raised wall; the raised part disappears! Ditto inverted with lowered
walls. Using circles instead of straight line segments is a wash-out
(painting inside 'em is a problem, and it just looks strange). I guess
I'll just have to wait until the texture-mapped walls get coded. :-D
Oh, and I optimized Nick Cangiani's pixel-plotting thing for the ground
(though it didn't speed things up much). I just realized I could've
made 'em 2x2 squares instead of single pixels. Maybe some other time
(or just forget it 'till the texture mapping gets done!).
Enjoy!
---------- BEGIN INCLUDED CODE ----------
'=======================================================================
' RAY CASTER 3D sorta ENGINE thingymajig
'=======================================================================
' Wrote this about a month ago, it's a sort of wolfenstien\doom
' lookalike but all in native QBasic source! Uses an interesting ray
' tracing technique could be optimized x1000 Infact, it's being
' converted to ASM and stuff like textures will be added and maybe a bit
' of shading
'
' Anyway, this code is _public domain_, change it, modify it, whatever,
' it only took about 40 mins in total, So whatever.. you have fun with
' it <grin>
'
' Cheers, {:o) Peter Cooper
' Minor clean-up by Brent P. Newhall
' Left arrow == Move left
' Right arrow == Move right
' [SPACE] == Move
' [ESC] == Quit
' Ceilings/floors added by Nick Cangiani
' nic...@gnn.com
DECLARE SUB screensetup ()
DECLARE SUB makeworld ()
DECLARE SUB maketables ()
DIM SHARED st%(0 TO 360)
DIM SHARED ct%(0 TO 360)
DIM SHARED a$(1 TO 10)
DIM SHARED grid(1 TO 12, 1 TO 12)
px% = 15: py% = 35: sa% = 0
PRINT "Please wait...";
RANDOMIZE TIMER
makeworld
maketables
screensetup
m% = 1
DO
IF m% = 1 THEN
IF P = 2 THEN PCOPY 2, 0 ELSE PCOPY 3, 0
IF P = 2 THEN P = 3 ELSE P = 2
m% = 0
END IF
FOR t% = sa% TO sa% + 59 STEP 1
xb = st%(t% MOD 360) / 100 'get inc
yb = ct%(t% MOD 360) / 100 'get inc
bx = px% 'decimal copy
by = py% 'decimal copy
l% = 0 'reset length
DO
bx = bx + xb
by = by + yb
l% = l% + 1
'k% = ASC(MID$(a$(CINT(by / 10)), CINT(bx / 10), 1)) - 48
k% = grid(CINT(by / 10), CINT(bx / 10))
LOOP UNTIL k% <> 0
'LOCATE 1, 1
'PRINT l%; 'this would print the distance to wall from player
X% = (t% - sa%) * 5
dd% = (1000 / l%)
'LINE (X%, 1)-(X% + 5, 99 - dd%), 15, BF 'paint ceiling
'LINE (X%, 101 + dd%)-(X% + 5, 200), 2, BF 'paint floor
LINE (X%, 100 - dd%)-(X% + 5, 100 + dd%), k%, BF 'paint walls
LINE (X%, 100 - dd%)-(X% + 5, 100 - dd%), 0 'top lines
LINE (X%, 100 + dd%)-(X% + 5, 100 + dd%), 0 'bottom lines
NEXT t%
PCOPY 0, 1
DO: in$ = INKEY$: LOOP UNTIL in$ <> ""
SELECT CASE in$
CASE CHR$(0) + "M" ' [LEFT]
sa% = sa% + 3
m% = 1
CASE CHR$(0) + "K" ' [RIGHT]
sa% = (sa% + 357) MOD 360
m% = 1
CASE CHR$(27) ' [ESC]
quit = 1
CASE " " ' [SPACE]
Oldpx% = px%: Oldpy% = py% ' Save where you are
px% = px% + (st%(t% MOD 360) / 50)
py% = py% + (ct%(t% MOD 360) / 50)
IF grid(CINT(py% / 10), CINT(px% / 10)) > 0 THEN'Walking thru walls?
px% = Oldpx% ' Forget it! Don't move
py% = Oldpy%
END IF
m% = 1
END SELECT
LOOP UNTIL quit > 0
SCREEN 0
WIDTH 80, 25
SYSTEM
' Level data (this way you can have walls colored 10, 11, etc.)
' 12x12
DATA 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9
DATA 9, 0, 4, 0, 0, 0, 0, 0, 0, 5, 0, 1
DATA 1, 0,12, 0, 0, 0, 0, 0, 0,13, 0, 9
DATA 9, 0, 4, 0, 0, 0, 0, 0, 0, 5, 0, 1
DATA 1, 0,12, 0, 0, 0, 0, 0, 0,13, 0, 9
DATA 9, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1
DATA 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 9
DATA 9, 0,12, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 1, 0, 4, 0, 0, 0, 0, 0, 3,11, 0, 9
DATA 9, 0,12, 0, 0, 0, 0, 0,11, 3, 0, 1
DATA 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 9
DATA 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1
' Old level. If you want it, come and get it.
' 1, 9, 1, 9, 1, 9, 1, 9, 1, 9
' 9, 0, 0, 0, 0, 0, 0, 0, 0, 1
' 1, 0, 0, 0, 0, 0, 0, 4, 0, 9
' 9, 0, 1, 0, 0, 0, 5, 0, 0, 1
' 1, 0, 2, 0, 0, 4, 0, 0, 0, 9
' 9, 0, 3, 0, 0, 0, 0, 0, 0, 1
' 1, 0, 0, 0, 0, 7, 8, 0, 0, 9
' 9, 0, 5, 0, 0, 8, 7, 0, 0, 1
' 1, 0, 6, 0, 0, 0, 0, 0, 0, 9
' 9, 1, 9, 1, 9, 1, 9, 1, 9, 1
SUB maketables ()
' Peters boring _yawn_ table creation
FOR tmp1% = 0 TO 360
st%(tmp1%) = SIN(tmp1% * .0174) * 100
IF tmp1% MOD 100 = 0 THEN PRINT ; ".";
NEXT tmp1%
FOR tmp1% = 0 TO 360
ct%(tmp1%) = COS(tmp1% * .0174) * 100
IF tmp1% MOD 100 = 0 THEN PRINT ; ".";
NEXT tmp1%
END SUB
SUB makeworld ()
' Read in this level's data
FOR j = 1 TO 12
FOR i = 1 TO 12
READ grid(i, j)
NEXT i
NEXT j
' Peter Coopers demonstration level. Change it if you wish! Each number
' is a color number
'a$(1) = "1919191919"
'a$(2) = "9000000001"
'a$(3) = "1000000409"
'a$(4) = "9010005001"
'a$(5) = "1020040009"
'a$(6) = "9030000001"
'a$(7) = "1000078009"
'a$(8) = "9050087001"
'a$(9) = "1060000009"
'a$(10) = "9191919191"
END SUB
SUB screensetup ()
SCREEN 7, , 2, 0
CLS
'WINDOW SCREEN (1, 1)-(320, 200)
' Sky
LINE (0, 0)-(300, 99), 3, BF
FOR cnt = 1 TO 10 ' Clouds
a = INT(RND * 319)
b = INT(RND * 80 + 10)
c = INT(RND * 50)
d = INT(RND * 10): d = d / 100
CIRCLE (a, b), c, 1, , , d: PAINT (a, b), 1
CIRCLE (a, b), c, 15, , , d: PAINT (a, b), 15
NEXT cnt
LINE (301, 0)-(319, 199), 0, BF ' Erase clouds on right
' Obelisk
'LINE (200, 20)-(240, 99), 0, BF
'LINE (201, 21)-(239, 98), 8, BF
LINE (200, 20)-(220, 15), 8 ' Building (gray)
LINE (220, 15)-(240, 20), 8
LINE (200, 20)-(200, 99), 8
LINE (240, 20)-(240, 99), 8
LINE (200, 99)-(240, 99), 8
PAINT (220, 50), 8
FOR cnt = 1 TO 20 ' Lights
PSET (INT(RND * 38 + 201), INT(RND * 80 + 20)), 14
NEXT cnt
LINE (200, 20)-(220, 15), 0 ' Building (border)
LINE (220, 15)-(240, 20), 0
LINE (219, 15)-(219, 99), 0
LINE (200, 20)-(200, 99), 0
LINE (240, 20)-(240, 99), 0
' Sun
CIRCLE (50, 30), 10, 14: PAINT (50, 30), 14, 14
PCOPY 2, 3
FOR Y% = 100 TO 199
FOR X% = 0 TO 300
IF RND > .5 THEN c% = 6 ELSE c% = 0
PSET (X%, Y%), c%
NEXT X%
NEXT Y%
SCREEN 7, , 3, 0
FOR Y% = 100 TO 199
FOR X% = 0 TO 300
IF RND > .5 THEN c% = 6 ELSE c% = 0
PSET (X%, Y%), c%
NEXT X%
NEXT Y%
SCREEN 7, , 0, 1
END SUB
---------- END INCLUDED CODE ----------
Cheers to everyone who's worked on this thing so far. It's really
starting to look better.
Brent P. Newhall
------------------------------------------------------------------
"Our greatest weakness lies in giving up. The most certain way to
succeed is always to try just one more time." -- Thomas A. Edison
Pretty good! =) It's purely theory but its interesting the sun and
building are still in front of me even when I do a 180 degree turn..
<grin> =) But really, pretty good. I have adjusted it further. Removing
unnecessary bits, and I have corrected the walking problem! I have also
added using the UP arrow to go forwards, and the DOWN arrow to go back.
>I've changed the way the levels are set-up; now each level is a set of
>numbers (rather than a string) in the DATA statements at the bottom of
>the main program section. This lets you use numbers like 12 for wall
>colors (before, 12 would have been interpreted as a single wall of color
>1, then another single wall of color 2). Plus, I put in a different
>level, now 12x12, to demonstrate the new range of colors.
Not bad, just I'm not personally keen on DATA statements =) The string
method works better from file.. You can actually carry on with the
numbers using one digit past 9.. you can carry on up the ascii table..
see?
>I've tried implementing negative-number walls, with special handling
>that creates a neat effect, but nothing works quite right. Raising the
>walls just causes a problem when you have a wall between you and the
>raised wall; the raised part disappears! Ditto inverted with lowered
>walls. Using circles instead of straight line segments is a wash-out
>(painting inside 'em is a problem, and it just looks strange). I guess
>I'll just have to wait until the texture-mapped walls get coded. :-D
Texture mapping is no problem but this is going to turn into a full
program before soon. There's going to be lots of different versions and
we'll be flooded.. <laugh> Just as long as my name is credited once I
do not mind. :^)
Please note, the formula used to work out the distance from the wall
isnt too good in my opinion, I will try to correct this and change the
whole formula system. I will probably release any updates I think of as
'patches' for whatever versions all you people are tinkering with.. =)
there are a few now hehe
Cheers,
_/_/_/ e t e r C o o p e r pe...@trenham.demon.co.uk
_/ / ~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~
_/_/_/
_/ http://www.trenham.demon.co.uk/
_/ 'I'm lost in the sea of desire..'