Post by Anteater on Dec 17, 2004 10:26:02 GMT -5
I have created a full FPS engine! However, for a better 3D engine and more options, check out Xeno8's "Easy 3D Envirements"
The code:
The code:
' Alien Assault
'
'Core engine written BASIC4GL community :)
'Game designed and created by Josh Stevens
'2004 DECAPITATION GAMES
'
' A simple 3D engine
dim BGSND, LASSND
BGSND = LOADSOUND ("SND\BGSND.wav")
LASSND = LOADSOUND ("SND\LASSND.wav")
PLAYSOUND (BGSND)
dim soundtoloop, strafe, guns, gunt, shooting, cockpitt, cockpits
dim bulletactive, bulletlife, dead
dead = LOADSOUND ("SND\DEAD.wav")
gunt = LoadTexture ("data\gun01.bmp")
guns = NewSprite (gunt)
cockpitt = LoadTexture ("data\cockpit01.bmp")
cockpits = NewSprite (cockpitt)
Struc SCam
Dim X#
Dim Y#
Dim PosX
Dim PosY
Dim Z#
Dim TestX#
Dim TestZ#
Dim Angle
Dim Look#
Dim Lean#
EndStruc
Struc Sbullet
Dim X#
Dim Y#
Dim Z#
Dim Angle#
EndStruc
Struc Sbaddie
Dim X#
Dim Y#
Dim Z#
Dim Angle#
Dim MDead#
Dim PosX
Dim PosY
Dim TestX#
Dim TestZ#
Dim AI#
EndStruc
Dim Sbaddie Baddie(99)
Dim SCam Cam
Cam.X# = 40 ' 4 units over from top left corner of tilemap.
Cam.Z# = 20 ' 2 units down from top left corner of tilemap.
Cam.Y# = 0
Cam.Lean# = 0
Dim Sbullet Bullet
Dim I, Speed#, Opp, Fogmode, Angle#, Tex(11), FogColor# (3) , lightambient# (3) , lightdiffuse# (3) , lightpos1# (2) , lightpos2# (2), lightpos3# (2) , gun1tex, gun1spr , lightambient2# (3), b, Bspeed#
fogColor# = vec4(0.2, 0, 0, 0)
lightambient# = vec4 (1.0,1.0,1.0,1.0)
lightambient2# = vec4 (0.9,0.1,0.1,0.1)
lightdiffuse# = vec4 (0.1,0.1,0.1,0.1)
lightpos1# = vec3 (0,Cam.Y#,0)
lightpos2# = vec3 (150,Cam.Y#,156)
lightpos3# = vec3 (30,Cam.Y#,300)
Tex(1) = LoadMipMapTexture ("textures\00001.jpg")
Tex(2) = LoadMipMapTexture ("textures\00002.jpg")
Tex(3) = LoadMipMapTexture ("textures\00003.jpg")
Tex(4) = LoadMipMapTexture ("textures\00004.jpg")
Tex(5) = LoadMipMapTexture ("textures\wall01.jpg")
Tex(6) = LoadMipMapTexture ("textures\ceil01.jpg")
Tex(7) = LoadMipMapTexture ("textures\001.jpg")
Tex(8) = LoadMipMapTexture ("Data\cube.bmp")
Tex(9) = LoadMipMapTexture ("Data\water1.bmp")
Tex(10) = LoadMipMapTexture ("Data\water2.bmp")
Tex(11) = LoadMipMapTexture ("textures\laswall.jpg")
dim MapsX, MapsY
data 25, 16
data 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0
data 3,0,6,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0
data 3,0,0,0,0,2,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0
data 3,0,0,0,0,0,0,0,0,7,0,7,0,0,3,0,0,0,0,0,0,0,0,0,0,0
data 3,0,0,0,0,0,11,0,0,0,0,0,0,0,3,4,4,4,4,4,4,4,4,4,4,4
data 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4
data 3,0,1,1,0,0,0,4,0,4,0,0,0,0,3,4,4,4,4,4,4,4,4,0,4,4
data 3,0,1,1,0,0,0,4,0,4,0,8,0,0,3,0,0,0,0,0,0,0,4,0,4,0
data 3,0,0,0,0,0,0,4,0,4,0,0,0,0,3,0,0,0,0,0,0,0,4,0,4,0
data 3,0,0,0,0,0,0,4,4,4,0,0,0,0,3,0,0,0,4,4,4,4,4,0,4,0
data 3,0,0,5,0,0,0,0,0,0,0,0,0,0,3,0,0,0,4,0,0,0,0,0,4,0
data 3,0,0,0,0,0,0,0,0,3,0,7,0,0,3,0,0,0,4,0,4,4,4,4,4,0
data 3,0,0,0,0,2,0,0,0,3,0,0,0,0,3,3,3,3,4,0,4,0,0,0,0,0
data 3,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0
data 3,0,0,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,4,0,4,0,0,0,0,0
data 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,0,0,0,4,0,4,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,4,4,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
read MapsX, MapsY
dim X,Y, Map (MapsX)(MapsY), Type
for Y = 0 to MapsY
for X = 0 to MapsX
read Type
Map(X)(Y) = Type
next
next
dim fogfilter, count
fogfilter = 0
glEnable (GL_TEXTURE_2D)
TextMode (TEXT_OVERLAID) 'When using both text and opengl, use text overlaid.
glClearColor(0.0,0.0,0.0,0.0)
glfogi (gl_fog_mode, GL_LINEAR)
glfogfv(gl_fog_color, fogcolor#)
glfogf (gl_fog_density, 1)
glhint (gl_fog_hint, gl_dont_care)
glfogf (gl_fog_start,5)
glfogf (gl_fog_end,60)
glenable (gl_fog)
glenable (gl_lighting)
glenable (GL_LIGHT1)
glenable (GL_LIGHT2)
glenable (GL_LIGHT3)
gllightfv (GL_LIGHT1,GL_AMBIENT,lightambient# )
gllightfv (GL_LIGHT1,GL_DIFFUSE,lightdiffuse# )
gllightfv (GL_LIGHT1,GL_POSITION, lightpos1# )
gllightfv (GL_LIGHT2,GL_AMBIENT,lightambient# )
gllightfv (GL_LIGHT2,GL_DIFFUSE,lightdiffuse# )
gllightfv (GL_LIGHT2,GL_POSITION, lightpos2# )
gllightfv (GL_LIGHT3,GL_AMBIENT,lightambient2# )
gllightfv (GL_LIGHT3,GL_DIFFUSE,lightdiffuse# )
gllightfv (GL_LIGHT3,GL_POSITION, lightpos3# )
'This next section creates baddies up to a max of 99 of them.
Bspeed# = 0.1
'Bspeed only needs to be set once.
b = 0 ' The "B" var makes the array of the baddie in question be the correct baddie
Baddie(b).X# = 60
Baddie(b).Y# = 0
Baddie(b).Z# = 30
Baddie(b).Angle# = 90
b = 1 ' The "B" var makes the array of the baddie in question be the correct baddie
Baddie(b).X# = 124
Baddie(b).Y# = 0
Baddie(b).Z# = 45
Baddie(b).Angle# = 30
'This section has ended here
while true
Cls
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity ()
'hey, thats not bad! when I was adding look up\down, I put the look after
'the angle rotate (not thinking, as usuall!). then when you looked up or
'down while the turn angle wasn't 180 or 0, the camera would tip all over
'the place. So to fix it, I did the following--
'GlRotatef (Cam.AngleX * Sind (Cam.Angle), 0, 0, -1)
'GlRotatef (Cam.AngleX * Cosd (Cam.Angle), 1, 0, 0)
'Needless to say, your way is MUCH simpler. lol! Thx for showing me a better way!
' You're welcome! -Josh :)
glRotated (Cam.Lean#, 0, 0, 1)
glRotatef (-Cam.Look#, 1, 0, 0)
glRotated (-Cam.Angle, 0, 1, 0)
glTranslatef (-Cam.X#, -Cam.Y#, -Cam.Z#)
if bulletactive = 0 then
Bullet.X# = Cam.X#
Bullet.Z# = Cam.Z#
bulletlife = 0
endif
' I modified this part-
for Y = 0 to MapsY
for X = 0 to MapsX
GlPushMatrix ()
GlTranslatef (10*X, 0, 10*Y)
' Draw a ceiling and a floor, but no walls.
if Map (X)(Y)= 0 then
glBindTexture (GL_TEXTURE_2D, tex (1))
GoSub DrawFloor
GlBindTexture (GL_TEXTURE_2D, Tex (3))
GoSub DrawCeiling
endif
' Draw another ceiling and floor, but no walls.
if Map (X)(Y)= 1 then
GlBindTexture (GL_TEXTURE_2D, Tex (9))
GoSub DrawFloor
GlBindTexture (GL_TEXTURE_2D, Tex (10))
GoSub DrawCeiling
endif
for I = 1 to 11
' Draw another cube with different texture.
if Map (X)(Y) = I then
GlBindTexture (GL_TEXTURE_2D, Tex(I))
gosub DrawCube
endif
next
GlPopMatrix ()
next
next
while SyncTimer (1)