#150930 - 2005-11-03 11:42 AM
First 3D game in KiX
cj
MM club member
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
This is (finally) my 1000th post and what better way than some of my finest (non COM) code. Here is KiXmaze3D - the first 3D game written in KiX... enjoy... again... Code: ;
; KiXmaze
;
; a 3D maze game
; by cj
;
; version 1.4
;
break on ; allow CTRL +C and setup vars
$ =setascii ("on" ) $x =chr (219 ) $x3 =$x +$x +$x $up =chr (223 ) $dn =chr (220 ) $up3 =$up +$up +$up $dn3 =$dn +$dn +$dn
$xup1 =chr (220 )+chr (223 )+chr (223 ) $xup2 =chr (220 )+chr (220 )+chr (223 )
$xdn1 =chr (223 )+chr (220 )+chr (220 ) $xdn2 =chr (223 )+chr (223 )+chr (220 )
dim $d [8 ] $i =0 do $d [$i ]=0 $i =$i +1 until $i =8 ; dim arrays for maze
dim $maze [10 ]
$startR =1 $startC =1 ; setup initial conditions
$endR =5 $endC =10
$face =1 ; 0 =up , 1 =right , 2 =down , 3 =left
$width =11
$height =9
; define maze
; you can change this all you like
; 1=wall, 0=space
; ensure the $endR and $endC are on a space
; all R/C vars are zero based
$maze [0 ]="11111111111"
$maze [1 ]="10000010001"
$maze [2 ]="11111010101"
$maze [3 ]="10000000001"
$maze [4 ]="10101111111"
$maze [5 ]="10101000100"
$maze [6 ]="10100010101"
$maze [7 ]="10011000001"
$maze [8 ]="11111111111"
$currentR =$startR ; starting point
$currentC =$startC
;$kixlib=olecreateobject("kixlib32.library") ; this library had a 'hide cursor' routine
;if $kixlib< >0 $=olecallfunc($kixlib,"SetConsoleCursorVisible","s","0") endif
cls ; clear screen and draw bounding box
box (0 , 0 , 20 , 56 , single )
:start
do
gosub calculate ; calculate walls
gosub draw ; draw walls 1 , 1 , 19 , 55
if $kixlib =0 at (0 , 0 ) endif get $ans ; move cursor out if the way if visible
select
case $ans ="h" ; forward (Up arrow )
if $d [4 ]< >3
select ; determine the movement based on direction faced
case $face =0 $currentR =$currentR -1 ; North /up - reduce Row var
case $face =1 $currentC =$currentC +1 ; East /right - inc Column
case $face =2 $currentR =$currentR +1 ; South /down
case $face =3 $currentC =$currentC -1 ; West /left
case 1
endSelect
endif
case $ans ="p" ; backward (Down arrow )
select
case $face =0 if substr ($maze [$currentR +1 ], $currentC +1 , 1 )=0 $currentR =$currentR +1 endif
case $face =1 if substr ($maze [$currentR ], $currentC +0 , 1 )=0 $currentC =$currentC -1 endif
case $face =2 if substr ($maze [$currentR -1 ], $currentC +1 , 1 )=0 $currentR =$currentR -1 endif
case $face =3 if substr ($maze [$currentR ], $currentC +2 , 1 )=0 $currentC =$currentC +1 endif
endSelect
case $ans ="k" ; turn left (Left arrow )
$face =$face -1
if $face =-1 $face =3 endif
case $ans ="m" ; turn right (Right arrow )
$face =$face +1
if $face =4 $face =0 endif
case 1
endSelect
if $currentC <0 $currentC =0 endif ; constrain to array bounds
if $currentR <0 $currentR =0 endif
if $currentC >$width -1 $currentC =$width -1 endif
if $currentR >$height -1 $currentC =$height -1 endif
until $ans ="q" ; press Q to quit
at (22 ,0 ) color w +/n ; goodbye
"Goodbye!" ?
;if $kixlib< >0 $=olecallfunc($kixlib,"SetConsoleCursorVisible","s","1") endif ; Cursor visible again
quit ; we outta here
:calculate ; calculate visible walls from location and orientation
if $currentR =$endR and $currentC =$endC ; you reached the 'end' point
at (22 ,0 ) color w +/n
"You did it!" ?
if $kixlib < >0 $ =olecallfunc ($kixlib ,"SetConsoleCursorVisible" ,"s" ,"1" ) endif ; Cursor on
quit
endif
select
case $face =0 ; north /up
$oneR =$currentR -0 $sevenR =$currentR -0
$oneC =$currentC -1 $sevenC =$currentC +1
$twoR =$currentR -1 $sixR =$currentR -1
$twoC =$currentC -1 $sixC =$currentC +1
$threeR =$currentR -2 $fiveR =$currentR -2
$threeC =$currentC -1 $fiveC =$currentC +1
if substr ($maze [$currentR -1 ], $currentC +1 , 1 )=1 $d [4 ]=3
else if substr ($maze [$currentR -2 ], $currentC +1 , 1 )=1 $d [4 ]=2
else if substr ($maze [$currentR -3 ], $currentC +1 , 1 )=1 $d [4 ]=1
else $d [4 ]=0
endif
endif
endif
case $face =1 ; east /right
$oneR =$currentR -1 $sevenR =$currentR +1
$oneC =$currentC +0 $sevenC =$currentC +0
$twoR =$currentR -1 $sixR =$currentR +1
$twoC =$currentC +1 $sixC =$currentC +1
$threeR =$currentR -1 $fiveR =$currentR +1
$threeC =$currentC +2 $fiveC =$currentC +2
if substr ($maze [$currentR ], $currentC +2 , 1 )=1 $d [4 ]=3
else if substr ($maze [$currentR ], $currentC +3 , 1 )=1 $d [4 ]=2
else if substr ($maze [$currentR ], $currentC +4 , 1 )=1 $d [4 ]=1
else $d [4 ]=0
endif
endif
endif
case $face =2 ; south /down
$oneR =$currentR +0 $sevenR =$currentR +0
$oneC =$currentC +1 $sevenC =$currentC -1
$twoR =$currentR +1 $sixR =$currentR +1
$twoC =$currentC +1 $sixC =$currentC -1
$threeR =$currentR +2 $fiveR =$currentR +2
$threeC =$currentC +1 $fiveC =$currentC -1
if substr ($maze [$currentR +1 ], $currentC +1 , 1 )=1 $d [4 ]=3
else if substr ($maze [$currentR +2 ], $currentC +1 , 1 )=1 $d [4 ]=2
else if substr ($maze [$currentR +3 ], $currentC +1 , 1 )=1 $d [4 ]=1
else $d [4 ]=0
endif
endif
endif
case $face =3 ; west /left
$oneR =$currentR +1 $sevenR =$currentR -1
$oneC =$currentC -0 $sevenC =$currentC -0
$twoR =$currentR +1 $sixR =$currentR -1
$twoC =$currentC -1 $sixC =$currentC -1
$threeR =$currentR +1 $fiveR =$currentR -1
$threeC =$currentC -2 $fiveC =$currentC -2
if substr ($maze [$currentR ], $currentC -0 , 1 )=1 $d [4 ]=3
else if substr ($maze [$currentR ], $currentC -1 , 1 )=1 $d [4 ]=2
else if substr ($maze [$currentR ], $currentC -2 , 1 )=1 $d [4 ]=1
else $d [4 ]=0
endif
endif
endif
case 1
endSelect
; this walls up holes in the map
if $oneR >-1 and $oneR <$height -1 and $oneC >-1 and $oneC <$width -1
$d [1 ]=substr ($maze [$oneR ], $oneC +1 , 1 )
else
$d [1 ]=1
endif
if $twoR >-1 and $twoR <$height -1 and $twoC >-1 and $twoC <$width -1
$d [2 ]=substr ($maze [$twoR ], $twoC +1 , 1 )
else
$d [2 ]=1
endif
if $threeR >-1 and $threeR <$height -1 and $threeC >-1 and $threeC <$width -1
$d [3 ]=substr ($maze [$threeR ], $threeC +1 , 1 )
else
$d [3 ]=1
endif
if $fiveR >-1 and $fiveR <$height -1 and $fiveC >-1 and $fiveC <$width -1
$d [5 ]=substr ($maze [$fiveR ], $fiveC +1 , 1 )
else
$d [5 ]=1
endif
if $sixR >-1 and $sixR <$height -1 and $sixC >-1 and $sixC <$width -1
$d [6 ]=substr ($maze [$sixR ], $sixC +1 , 1 )
else
$d [6 ]=1
endif
if $sevenR >-1 and $sevenR <$height -1 and $sevenC >-1 and $sevenC <$width -1
$d [7 ]=substr ($maze [$sevenR ], $sevenC +1 , 1 )
else
$d [7 ]=1
endif
return
:draw ; render calulated walls to screen
; 1
if $d [1 ]=0
; remove 1 < >0
at (2 , 2 ) " " at (3 , 5 ) " " at (4 , 8 ) " " at (18 , 2 ) " " at (17 , 5 ) " " at (16 , 8 ) " "
; draw 1 =0
color w +/n
at (5 , 1 ) $up3 $up3 $up3 at (15 , 1 ) $dn3 $dn3 $dn3
$i =5 do at ($i , 10 ) $x $i =$i +1 until $i =16
else
; remove 1 =0
at (5 , 1 ) " " at (15 , 1 ) " "
; draw 1 < >0
color w +/n
at (2 , 2 ) $xdn1 at (3 , 5 ) $xdn2 at (4 , 8 ) $xdn1 at (18 , 2 ) $xup1 at (17 , 5 ) $xup2 at (16 , 8 ) $xup1
$i =5 do at ($i , 10 ) if $d [2 ]=0 $x else " " endif $i =$i +1 until $i =16
endif
; 7
if $d [7 ]=0
; remove 7 < >0
at (2 , 52 ) " " at (3 , 49 ) " " at (4 , 46 ) " " at (18 , 52 ) " " at (17 , 49 ) " " at (16 , 46 ) " "
; draw 7 =0
color w +/n
at (5 , 46 ) $up3 $up3 $up3 at (15 , 46 ) $dn3 $dn3 $dn3
$i =5 do at ($i , 46 ) $x $i =$i +1 until $i =16
else
; remove 7 =0
at (5 , 46 ) " " at (15 , 46 ) " "
; draw 7 < >0
color w +/n
at (2 , 52 ) $xup1 at (3 , 49 ) $xup2 at (4 , 46 ) $xup1 at (18 , 52 ) $xdn1 at (17 , 49 ) $xdn2 at (16 , 46 ) $xdn1
$i =5 do at ($i , 46 ) if $d [6 ]=0 $x else " " endif $i =$i +1 until $i =16
endif
;2
if $d [4 ]< >3
if $d [2 ]=0
; remove 2 < >0
at (5 , 11 ) " " at (6 , 14 ) " " at (7 , 17 ) " " at (15 , 11 ) " " at (14 , 14 ) " " at (13 , 17 ) " "
; draw 2 =0
color w /n
at (8 , 11 ) $up3 $up3 $up3 at (12 , 11 ) $dn3 $dn3 $dn3
$i =8 do at ($i , 19 ) $x $i =$i +1 until $i =13
else
; remove 2 =0
at (8 , 11 ) " " at (12 , 11 ) " "
; draw 2 < >0
color w /n
at (5 , 11 ) $xdn1 at (6 , 14 ) $xdn2 at (7 , 17 ) $xdn1 at (15 , 11 ) $xup1 at (14 , 14 ) $xup2 at (13 , 17 ) $xup1
$i =8 do at ($i , 19 ) if $d [3 ]=0 $x else " " endif $i =$i +1 until $i =13
endif
;6
if $d [6 ]=0
; remove 6 < >0
at (5 , 43 ) " " at (6 , 40 ) " " at (7 , 37 ) " " at (15 , 43 ) " " at (14 , 40 ) " " at (13 , 37 ) " "
; draw 6 =0
color w /n
at (8 , 37 ) $up3 $up3 $up3 at (12 , 37 ) $dn3 $dn3 $dn3
$i =8 do at ($i , 37 ) $x $i =$i +1 until $i =13
else
; remove 6 =0
at (8 , 37 ) " " at (12 , 37 ) " "
; draw 6 < >0
color w /n
at (5 , 43 ) $xup2 at (6 , 40 ) $xup1 at (7 , 37 ) $xup2 at (15 , 43 ) $xdn2 at (14 , 40 ) $xdn1 at (13 , 37 ) $xdn2
$i =8 do at ($i , 37 ) if $d [5 ]=0 $x else " " endif $i =$i +1 until $i =13
endif
endif
if $d [4 ]=1 or $d [4 ]=0
;3
if $d [3 ]=0
; remove 3 < >0
at (8 , 20 ) " " at (9 , 23 ) " " at (12 , 20 ) " " at (11 , 23 ) " "
; draw 3 =0
color n +/n
at (9 , 20 ) $up3 $up3 at (11 , 20 ) $dn3 $dn3
at (9 , 25 ) $x at (10 , 25 ) $x at (11 , 25 ) $x
else
; remove 3 =0
at (9 , 20 ) " " at (11 , 20 ) " "
; draw 3 < >0
color n +/n
at (8 , 20 ) $xdn1 at (9 , 23 ) $xdn2 at (12 , 20 ) $xup1 at (11 , 23 ) $xup2
at (9 , 25 ) $dn at (10 , 25 ) $x at (11 , 25 ) $up
endif
;5
if $d [5 ]=0
; remove 5 < >0
at (8 , 34 ) " " at (9 , 31 ) " " at (12 , 34 ) " " at (11 , 31 ) " "
; draw 5 =0
color n +/n
at (9 , 31 ) $up3 $up3 at (11 , 31 ) $dn3 $dn3
at (9 , 31 ) $x at (10 , 31 ) $x at (11 , 31 ) $x
else
; remove 5 =0
at (9 , 31 ) " " at (11 , 31 ) " "
; draw 5 < >0
color n +/n
at (8 , 34 ) $xup2 at (9 , 31 ) $xup1 at (12 , 34 ) $xdn2 at (11 , 31 ) $xdn1
at (9 , 31 ) $dn at (10 , 31 ) $x at (11 , 31 ) $up
endif
endif
;4
select
case $d [4 ]=0
; remove 4 =1
at (9 , 26 ) " " at (11 , 26 ) " "
; remove 4 =2 horizontal
at (8 , 23 ) " "
at (12 , 23 ) " "
; remove 4 =3 horizontal
at (5 , 14 ) " "
at (15 , 14 ) " "
case $d [4 ]=1
; remove 4 =2 horizontal
at (8 , 23 ) " "
at (12 , 23 ) " "
; remove 4 =3 horizontal
at (5 , 14 ) " "
at (15 , 14 ) " "
; draw 4 =1
color n +/n
; at (9 , 25 ) $x at (11 , 25 ) $x at (9 , 31 ) $x
Top
#150931 - 2005-11-03 11:44 AM
Re: First 3D game in KiX
cj
MM club member
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
hmmm, code too big? Here's the rest...Code: at (9 , 26 ) $up3 $up $up at (11 , 26 ) $dn3 $dn $dn
case $d [4 ]=2
; remove 4 =1
box (9 , 20 , 11 , 36 , " " )
; remove 4 =3 horizontal
at (5 , 14 ) " "
at (15 , 14 ) " "
; draw 4 =2
color w /n
at (8 , 19 ) $up3 $up3 $up3 $up3 $up3 $up3
at (12 , 19 ) $dn3 $dn3 $dn3 $dn3 $dn3 $dn3
$i =8 do at ($i , 19 ) $x at ($i , 37 ) $x $i =$i +1 until $i =13
case $d [4 ]=3
; draw 4 =3
color w +/n
at (5 , 11 ) $up3 $up3 $up3 $up3 $up3 $up3 $up3 $up3 $up3 $up3 $up3 $up3
at (15 , 11 ) $dn3 $dn3 $dn3 $dn3 $dn3 $dn3 $dn3 $dn3 $dn3 $dn3 $dn3 $dn3
$i =5 do at ($i , 46 ) $x $i =$i +1 until $i =16
$i =5 do at ($i , 10 ) $x $i =$i +1 until $i =16
; remove 4 =1 and 4 =2
box (6 , 11 , 14 , 45 , " " )
case 1
endSelect
return
cj p.s. Please put PostPrep somewhere (like a sticky) so it's easier to find...
Top
#150933 - 2005-11-03 12:41 PM
Re: First 3D game in KiX
cj
MM club member
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
lol, indeed, but it wouldn't have been so pretty I should have cleaned up the PP output. cj
Top
#150935 - 2005-11-03 05:22 PM
Re: First 3D game in KiX
Kdyer
KiX Supporter
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Reminds me of Castle Wolfenstein! Kent
Top
#150936 - 2005-11-04 01:05 AM
Re: First 3D game in KiX
cj
MM club member
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Quote: I think this is one of my favorite Kixtart scripts of all time. Still keep getting lost in the friggin thing. lol, the exit is not apparent until you are right next to it. Here's a hint, it's right at the end of an apparent dead-end. I should have included some info about it... Use the arrows to navigate (up=forward etc) and q to Quit. The system is quite simple really and I should make it smarter, but it works. There are 7 'strips' of images, 1 and 7 are the walls directly in front of you, 2 and 6 are a little further away and a shade darker, 3 and 5 are further and darker and 4 is the middle piece. let's say you are at the xCode: maze code 11011 x0000 11111 strip used 123 x 4 567 then you'll see a wall, door, wall to your left (1, 2, 3) and to your right (5, 6, 7) will be all wall. In front of you(4), and down the 'hall' a bit, will be nothing - it appears to continue into the distance. For each strip there will be either a wall or a space/door, so there are 2 different 'images' constructed of ascii chars that could be drawn there.Code: ┌───────────────────────────────────────────────────────┐ │ │ │ ▀▄▄ ▄▀▀ │ │ ▀▀▄ ▄▄▀ │ │ ▀▄▄ ▄▀▀ │ │ █ ▄▄▀ │ │ █ ▄▀▀ │ │ █ ▄▄▀ │ │ █▀▀▀▀▀▀▀▀█▀▄▄ ▄▄▀ │ │ █ █ ▀▀▄ ▄▀▀ │ │ █ █ █ █ │ │ █ █ ▄▄▀ ▀▄▄ │ │ █▄▄▄▄▄▄▄▄█▄▀▀ ▀▀▄ │ │ █ ▀▀▄ │ │ █ ▀▄▄ │ │ █ ▀▀▄ │ │ ▄▀▀ ▀▄▄ │ │ ▄▄▀ ▀▀▄ │ │ ▄▀▀ ▀▄▄ │ │ │ └───────────────────────────────────────────────────────┘ (hey, that worked!!) I was going to do a KiXBGI version at one stage but never got around to it. cj
Top
#150939 - 2005-11-16 07:08 AM
Re: First 3D game in KiX
sixdoubleo
Starting to like KiXtart
Registered: 2004-02-06
Posts: 118
Loc: California, US
How do I switch to the shotgun? Nice job man!
Edited by sixdoubleo (2005-11-16 07:08 AM )
Top
#150940 - 2005-11-24 02:25 PM
Re: First 3D game in KiX
roedie
Getting the hang of it
Registered: 2005-11-15
Posts: 52
Loc: balk friesland/holland
Top
Moderator: Glenn Barnas , NTDOC , Arend_ , Jochen , Radimus , Allen , ShaneEP , Ruud van Velsen , Mart
0 registered
and 525 anonymous users online.