Posted: 27th Jun 2007 0:19
I am new to dark basic Pro and i am starting a FPS i was wondering what would be a good code to use for creating the level...adding collision into the walls and object and not letting me go through the ground like free clip...adding AI...adding enemies...and adding the hand and gun type first person view...please someone help!!!with using this code...

+ Code Snippet
REM Set Client Options

SYNC ON
SYNC RATE 0
HIDE MOUSE


REM Make Floor
MAKE OBJECT PlAIN 6,1000,1000
XROTATE OBJECT 6,-90
COLOR OBJECT 6,RGB(50,55,55)


REM Make Main Character
MAKE OBJECT SPHERE 1,50
COLOR OBJECT 1,RGB(0,255,0)
POSITION OBJECT 1,0,2,0
HIDE OBJECT 1

REM Make Enemy Character
MAKE OBJECT SPHERE 2,50
COLOR OBJECT 2,rgb(255,0,0)
POSITION OBJECT 2,130,0,0

REM Make WallS
MAKE OBJECT BOX 3,1000,100,5
POSITION OBJECT 3,0,0,250
MAKE OBJECT BOX 7,1000,100,5
POSITION OBJECT 7,0,0,-250
MAKE OBJECT BOX 8,5,100,1000
POSITION OBJECT 8,250,0,0
MAKE OBJECT BOX 9,5,100,1000
POSITION OBJECT 9,-250,0,0

REM Make Ammo CLip
MAKE OBJECT BOX 4,20,50,20
COLOR OBJECT 4,RGB(255,0,255)
POSITION OBJECT 4,-40,0,0

REM Make Ammo Crate
MAKE OBJECT BOX 5,20,30,70
COLOR OBJECT 5,RGB(255,0,200)
POSITION OBJECT 5,150,0,-200

REM Set Up Shooting Limb
MAKE OBJECT TRIANGLE 9999,0,0,0,0,0,0,0,0,0
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,0,500

HIDE LIMB 1,1


REM  nEW LIMB

ADD LIMB 1,2,1
OFFSET LIMB 1,2,0,0,OBJECT SIZE Z(1)/2
HIDE LIMB 1,2
ADD LIMB 1,3,1
OFFSET LIMB 1,3,0,0,-OBJECT SIZE Z(1)/2
HIDE LIMB 1,3
ADD LIMB 1,4,1
OFFSET LIMB 1,4,0,0,OBJECT SIZE X(1)/2
HIDE LIMB 1,4
ADD LIMB 1,5,1
OFFSET LIMB 1,5,0,0,-OBJECT SIZE X(1)/2
HIDE LIMB 1,5
DELETE MESH 1

REM Move objects up
   FOR OBJECT =1 TO 5
      POSITION OBJECT object,Object position x(OBJECT),OBJECT SIZE Y(OBJECT)/2,OBJECT POSITION Z(OBJECT)
   NEXT OBJECT
   FOR OBJECT =7 TO 9
      POSITION OBJECT object,Object position x(OBJECT),OBJECT SIZE Y(OBJECT)/2,OBJECT POSITION Z(OBJECT)
   NEXT OBJECT

REM Define Some Variables
EnemyHP=5000
Ammo=1000
MaxAmmo=1000
Clips=3
MaxClips=10
reload=0
time#=0









REM Start Main Loop
Do
REM Set Up Player Location
   X#=OBJECT POSITION X(1)
   Y#=OBJECT POSITION Y(1)
   Z#=OBJECT POSITION Z(1)
REM Display HUD
   REM Display FPS
    `  TEXT 0,0, "FPS: " + STR$(SCREEN FPS())
   REM Display Ammo
     ` TEXT 0,SCREEN HEIGHT()-50, "Ammo: " + STR$(ammo) + "/" + STR$(Clips)
   REM Enemy HP
      IF OBJECT EXIST(2)=1
         CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-70, "Enemy HP: " + STR$(enemyhp)
      ENDIF

   REM crosshair
      CIRCLE SCREEN WIDTH()/2,SCREEN HEIGHT()/2,20
   REM Clip Label
      IF Object Exist(4) Then CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-70,"Ammo Clip"
   REM Crate Label
      IF Object Exist(5) Then CENTER TEXT OBJECT SCREEN X(5),OBJECT SCREEN Y(5)-70,"Ammo Crate"


   REM Set Up Character Controls
   REM Movement
      IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,0.5
      IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-0.5
      IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,0.3
      IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,0.3

   REM Jumping
      IF SPACEKEY()=1 and JUMPING#=0 THEN JUMP#=1
      REM Jump Condition
         IF JUMP#=1
            GROUND#=Y#
            JUMP_SPEED#=1
            JUMPING#=1
            JUMP#=0
         ENDIF

      REM Jump Calculation
         IF JUMPING#=1
            DEC JUMP_SPEED#,0.01


            y#=y#+JUMP_SPEED#
            POSITION OBJECT 1,X#,Y#+JUMP_SPEED#,Z#


            IF Y#<=GROUND#
               JUMPING#=0
               Y#=ground#
            endif

         ENDIF

   REM Set Up Camera Controls
      CAMY#=CAMY#+MOUSEMOVEX()*0.1
      CAMX#=CAMX#+MOUSEMOVEY()*0.1
      IF CAMX#>90 AND CAMX#<135 THEN CAMX#=90
      IF CAMX#>270 AND CAMX#<225 THEN CAMX#=90
      ROTATE CAMERA CAMX#,CAMY#,0
      `XROTATE CAMERA CAMX#
      ROTATE OBJECT 1,CAMX#,CAMY#,0
      `XROTATE OBJECT 1,CAMX#


      REM Camera
         POSITION CAMERA X#,Y#,Z#
   REM Reload
      IF KEYSTATE(19)=1 and MOUSECLICK()=0 AND Clips>0 AND AMMO<MaxAmmo THEN reload=1
      IF reload=1 THEN INC time#,0.001
      IF Time#>1 Then Ammo=MaxAmmo:DEC Clips,1:Time#=0:reload=0
      IF Reload=1 THEN CENTER TEXT SCREEN WIDTH()/2,SCREEN HEIGHT()/2,"Reloading..."


      REM Pickup ammo CLIP
         IF Object Exist(4)
            IF Clips<MaxClips AND INTERSECT OBJECT (4, X#,Y#-50,Z#,X#,Y#,Z#)>0
               IF Clips<MaxClips
                  INC Clips,1
                  Delete Object 4
         ENDIF
         ENDIF
         ENDIF
      REM Pickup Ammo crate
         IF Object Exist(5)
            IF Clips<MaxClips AND INTERSECT OBJECT (5,Z#,Y#-50,Z#,X#,Y#,Z#)>0
               IF Clips<MaxClips
                  Clips=MaxClips
                  Ammo=MaxAmmo
                  Delete Object 5
         ENDIF
         ENDIF
         ENDIF
   REM Shooting
      IF MOUSECLICK()=1 AND KEYSTATE(19)=0
      REM Decrease Ammo
         IF Ammo>0
            DEC Ammo,1
            Wait 100
         ENDIF
      REM Check Object Exists
         IF OBJECT EXIST(2)=1
         REM Check the player has ammo
            IF Ammo>0
            REM Check if player is aiming at enemy
                IF INTERSECT OBJECT(2,LIMB POSITION X(1,1),LIMB POSITION Y(1,1),LIMB POSITION Z(1,1),X#,Y#,Z#)>0
               REM Decrease Enemy Health
                  DEC EnemyHP,1
      ENDIF
         ENDIF
            ENDIF
               ENDIF
      REM Kill enemy if HP is zero
         IF enemyhp=0
            IF OBJECT EXIST(2)=1
               DELETE OBJECT 2
         ENDIF
            ENDIF
REM Floor Collision
   while INTERSECT OBJECT (6,X#,(Y#-26),Z#,X#,Y#,Z#)>0
      inc y#
      POSITION OBJECT 1,X#,Y#,Z#
      JUMPING=0
   endwhile

   REM WALL COLLISIONS
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,2),LIMB POSITION Y(1,2),LIMB POSITION Z(1,2),X#,Y#,Z#)
   MOVE OBJECT 1,-1
   ENDIF
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,3),LIMB POSITION Y(1,3),LIMB POSITION Z(1,3),X#,Y#,Z#)
   MOVE OBJECT 1,1
   ENDIF
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,4),LIMB POSITION Y(1,4),LIMB POSITION Z(1,4),X#,Y#,Z#)
   MOVE OBJECT LEFT 1,1
   ENDIF
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,5),LIMB POSITION Y(1,5),LIMB POSITION Z(1,5),X#,Y#,Z#)
   MOVE OBJECT RIGHT 1,1
   ENDIF

   FOR OBJECT =7 TO 9
   IF INTERSECT OBJECT (OBJECT,LIMB POSITION X(1,2),LIMB POSITION Y(1,2),LIMB POSITION Z(1,2),X#,Y#,Z#)
   MOVE OBJECT 1,-1
   ENDIF
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,3),LIMB POSITION Y(1,3),LIMB POSITION Z(1,3),X#,Y#,Z#)
   MOVE OBJECT 1,1
   ENDIF
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,4),LIMB POSITION Y(1,4),LIMB POSITION Z(1,4),X#,Y#,Z#)
   MOVE OBJECT LEFT 1,1
   ENDIF
   IF INTERSECT OBJECT (3,LIMB POSITION X(1,5),LIMB POSITION Y(1,5),LIMB POSITION Z(1,5),X#,Y#,Z#)
   MOVE OBJECT RIGHT 1,1
   ENDIF
   NEXT OBJECT

SYNC
LOOP


[mod edit]You need to close your code tag for it to work!
Posted: 27th Jun 2007 0:49
lol...no comment
Posted: 27th Jun 2007 0:55
You need to put code in code blocks:



(Top right of post message box)

And post snippets instead of the whole code. Also, you may get a better use of these forums by posting in the "Newcomers" section
Posted: 30th Jun 2007 19:50
Sigh, another person who has given themself a username based on their first problem
Posted: 30th Jun 2007 21:00
sigh, another person who wants us to make his game for him
Posted: 30th Jun 2007 23:47
Sigh, another person who has given themself a username based on their first problem

That's how I came up with my name, isn't that normal?
Posted: 1st Jul 2007 1:01
Sigh, another person who has given themself a username based on their first problem

I know, I can't stand it when people do that. Are they too stupid to realize that the username is the name that will forever be displayed everytime they post?
Posted: 1st Jul 2007 2:44
and down into the fiery darkness this goes

@ DBP FPS HELP NEEDED : have you checked the fps tutorial in the help menus?
Posted: 1st Jul 2007 3:56
the provided tutorial is awful... it assumes that the world still runs on old quake bsp maps...

honnestly... if you are a beginner then forget the game project... it will consume your brain with pain and shame. Instead, make a bunch of various projects... such as an interface one, one where you run about on geometry and other such things. After a while you will have enough functions to chuck togethor as a game.

For collision you should get the free Sparky Collision DLL 2.0. It is amazing and fast. Also, study raycasting vectors, they are good things to have grocked.

all the best for your FPS... BTW checkout my WIP, I'm nearly done on my FPS engine, I'd happily share tips tricks and code.

http://forum.thegamecreators.com/?m=forum_view&t=109256&b=8&p=0