TGC Codebase Backup



MadSmash PCE (Badminton Game) 1 or 2 players by Glog

3rd Jun 2004 8:41
Summary

a complete badminton game , all is here , exept the final media (there is just WIP models textures and GFX ) and some code to allow user to change controls and graphic devices fun



Description

Its my first game in DBA , and there is no bugs , and its nearly fun ! i say nearly because its also quite repetitive and very basic game , but i'm happy of all the code
i had great moments working on it ( 3 weeks , 1 hour a day ) and it learn me a lot of things . I'm looking for teamates to make another small game in seven days , I'll begin code it in six day , so if you are interessed , please mail now!
francois-ruiz@caramail.com

##NOTES:
to make the game zork
-create a directory , where you will stock the game
-dowload data.zip from media section , and extract it in a directory called data
-copy all the PCE code here to your db editor , save it on the dir and compile
-please post comments ,even a small one , to make me see what you don't like , or
-ideas to add



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem ****************************************************************************************
rem                             MadSmash PCE release 1.0
rem                      Coded by Glog , francois-ruiz@caramail.com
rem ****************************************************************************************
rem           this code release is designed to be posted on the net and be a demo of what
rem           you could expect of me as a coder . it doesnt need  graphics material such as
rem           bitmaps , models , sounds etc...   there is all the game code exept
rem           - pc config code , to make the game run on every kind of machine
rem           - anim code , useless to copy because its the same in all games (loading a
rem            model , using that animation in that situation , etc....)
rem ****************************************************************************************

rem   PLEASE NOTE THAT YOU CAN SWITCH THE AI OFF IF YOU WANT TO DO SINGLE PLAYING



rem ****************************************************************************************
rem                              Game Vars
rem ****************************************************************************************
rem ********************************sys vars********************************
 game_loaded=0
 p1score=0
 p2score=0
 scene_scale=10
 Xres=screen height()
 Yres=screen width()

_setvars:
 rem ******************** ball********************
  rem position
  bpx#=10.0
  bpy#=100.0
  bpz#=100
  rem direction vectors
  bvx#=0;
  bvy#=1;
  bdir_1=1
  bdir_2=0
  rem propulsion vectors when the ball is bouncing
  bvpx#=1
  bvpy#=3;
  rem speed
  bspd#=  0.2
  rem misc
  jump_mode=0
  ball_mode=0
  strike_force#=0.05

 rem ************************** Player 1 vars *************
  rem position
  p1px#=1.0
  p1py#=1.0
  rem direction vectors
  p1vx#=0.0
  p1vy#=0.0
  rem speed
  p1spd#=  1
  rem direction triggers
  p1dh=0
  p1db=0
  p1dg=0
  p1dd=0

  rem **************************  Player 2 Vars ****************************
  rem position
  p2px#=300.0
  p2py#=1.0
  rem direction vectors
  p2vx#=0.0
  p2vy#=0.0
  rem speed
  p2spd#=  1
  rem direction triggers
  p2dh=0
  p2db=0
  p2dg=0
  p2dd=0

  rem ******************************** AI **********************************
  AI_mode = 0
  catch = 1
  gotball=0
  sendback = 2
  tvx#=0
  tvy#=0
  upd_time=0


  rem **************************camera********************
  rem position
  med_cam_x# = 250
  med_cam_y# = 50
  med_cam_z# = -200
  rem rotation
  rx#=0
  ry#=0
  rz#=0
  rem to reset camera angle after the ball was tracked
  save_cam_r#=  0
  timing = 0

  mode = 0
  intro = 1
  victory = 2
  idle  = 3
  p1focus = 4
  p2focus = 5

  rem when the cam follows the ball
  cam_up_glide=0
  down_mode = 0

  rem ******************** Global Vars  *********************
  game_start=1
  terrain_min_x#=1
  terrain_max_x#=500
  terrain_min_y#=1
  terrain_max_y#=500
  filet_p1#=240
  filet_p2#=250
  v_mode=150
  rem game state
  game_mode=00
  rem  available game states
  play=1
  p1point=2
  p2point=3
  quit=4
  pause=5

  rem ************************ Vars used for the begining of the game *********************
  cam_mode=intro;
  AI=1
  AI_mode=catch
  game_mode=pause
  jump_mode=1
  ball_mode=1
rem **************************************************************************************
rem                         Loading game data
rem **************************************************************************************

if game_loaded=0
 rem ************ball***************

   make object sphere 4,30
   position object 4,bpx#,pby#,bpz#
   make object collision box  4, -30,-30,-30,30,30,30,1
   set object collision on 4

   rem **************playground*******************


   rem  load object "Datazone1_1.3ds",5
   make object box 5,10000,100,10000
   position object 5,250,-20,570
   color object 5,20
   scale object 5,1*scene_scale,1*scene_scale,1*scene_scale
   rem   load image "Datagrass16.bmp",2
   rem load object "Datazone1_2.3ds",6




   rem **************players********************

   rem player 1
   make object cube 2,30
   yrotate object 2,180 : fix object pivot 2
   position object 2,1*scene_scale,1*scene_scale,1*scene_scale
   scale object 2,6*scene_scale,6*scene_scale,6*scene_scale
   make object collision box  2, 1,1,1,30,30,30,1
   set object collision on 2


   rem player 2
   make object cube 3,30
   yrotate object 3,180 : fix object pivot 2
   position object 3,p2px#,p2py#,1*scene_scale
   scale object 3,6*scene_scale,6*scene_scale,6*scene_scale
   make object collision box  3, 1,1,1,30,30,30,1
   set object collision on 3


   game_loaded=1
endif



rem **************************************************************************************
rem                         Game Main Loop
rem **************************************************************************************

  sync on
  sync rate 60
  position camera med_cam_x,med_cam_y,med_cam_z


  do
    rem *******************************camera**********************************************


    rem *************camera is shooting all the scene when it begins*******************
    if cam_mode=intro
    game_start=0
    if timing=0
       med_cam_x#=250
       med_cam_y#=50
       med_cam_z#=-200
       rx#=0
       rotate camera rx#,ry#,rz#
    endif

    med_cam_x#=med_cam_x#-1.5;
    med_cam_y#=med_cam_y#+3.5;
    med_cam_z#=med_cam_z#+1.5;
    rx#=rx#+0.7
    rotate camera rx#,ry#,rz#
    timing=timing+1
    if timing > 70
        cam_mode=idle
        game_mode=play
        timing=0
        endif
   endif

rem camera is also...
rem *************doing some travelings during the game***************
   if cam_mode=idle


 rem ******************** following ball when she goes too high***********

 if cam_up_glide=1
            if bpz#>20
                  rx#=rx#+(bvz#/20)
                  if med_cam_y#<1500 then med_cam_y#=med_cam_y#+12
                          if med_cam_y#>1300
                          set cursor Xres/2,Yres/2
                          print " Come On !!! "
                   endif
             endif
   rem change shot angle when the ball falls
               if bpz#<150
                  if bpz#>11
                    if down_mode=1
                         rx#=rx#-(bvz#/20)
                         med_cam_y#=med_cam_y#-12
                     endif
                  endif
             endif
             rem go to the standard angle when the ball hits the ground
             if bpz#<20
                if med_cam_y#>400 then med_cam_y#=med_cam_y#-40
                if med_cam_y#<400 then med_cam_y#=400
                rem exit upglide mode when the ball is not in the air anymore
                if med_cam_y#=400
                      if rx#>49.7 then rx#=rx#-40
                      if rx#<49.7 then rx#=49.7
                endif
                if rx#=49.7
                  if med_cam_y#=400 then cam_up_glide=0
                endif
             endif
           endif

    if timing=0

       med_cam_x#=250
       med_cam_y#=400
       med_cam_z#=-150
       ry#=0

    endif

    if timing < 200
    ry#=ry#+0.1
    med_cam_x#=med_cam_x#-1;
    rotate camera rx#,ry#,rz#
    endif

    if timing > 200
    med_cam_x#=med_cam_x#+1;
    if ry#>1 then ry#=ry#-0.1
    if ry#<1 then ry#=ry#+0.1
    rotate camera rx#,ry#,rz#
    endif

    if timing > 400 then  timing = 0
    timing=timing+1
    endif

    rem *************   if there is a victory *******************
    if cam_mode=victory
    if timing=0
       med_cam_x#=250
       med_cam_y#=50
       med_cam_z#=-200
       rx#=0
       timing=timing+1
       rotate camera rx#,ry#,rz#
    endif

    med_cam_x#=med_cam_x#-2.5;
    med_cam_y#=med_cam_y#+1.5;
    med_cam_z#=med_cam_z#+1.5;
    rx#=rx#+0.1
    rotate camera rx#,ry#,rz#
    timing=timing+1
    if timing > 70
        cam_mode=idle
        game_mode=play
        timing=0
        goto _setvars
        endif

    endif

 position camera med_cam_x#,med_cam_y#,med_cam_z#



    rem ****************************** Gameplay code *********************************

    if game_mode=play

    rem *******************************controls*****************************************


    rem used to get all the key codes
    rem set cursor 0,0
    rem key=scancode()
    rem print key

    rem *************************Player 1****************************

   if upkey()=1
    p1dh=1
    p1db=0
    p1vy#=p1vy#+ p1spd#
    endif

    if downkey()=1
    p1db=1
    p1dh=0
    p1vy#=p1vy#+ p1spd#
    endif

    if leftkey()=1
    p1dg=1
    p1dd=0
    p1vx#=p1vx#+ p1spd#
    p1s_force#=p1s_force#-0.5
   endif

    if rightkey()=1
    p1dd=1
    p1dg=0
    p1vx#=p1vx#+ p1spd#
    p1s_force#=p1s_force#+0.5
    endif


    rem *************************Player 2 ****************************

    if AI=0
    rem keypad= 72 80 75 77
    if keystate(72)=1
    p2dh=1
    p2db=0
    p2vy#=p2vy#+ p2spd#
    endif

    if keystate(80)=1
    p2db=1
    p2dh=0
    p2vy#=p2vy#+ p2spd#
    endif

    if keystate(75)=1
    p2dg=1
    p2dd=0
    p2vx#=p2vx#+ p2spd#
    p2s_force#=p2s_force-0.5
    endif

    if keystate(77)=1
    p2dd=1
    p2dg=0
    p2vx#=p2vx#+ p2spd#
    p2s_force#=force+0.5
    endif

    endif

    rem  AI control if player 1 is alone ( very crap but usefull to test all the game logic )
     if AI= 1
      if AI_mode= catch
             p2px#=bpx#
             p2py#=bpy#
              rem check if player 2 gots the ball
               upd_time=upd_time+1
               if upd_time=100
               AI_mode=sendback
               upd_time=0
               endif

       endif

      if AI_mode = sendback
             if upd_time<500
             p2dd=1
             p2dg=0
             p2vx#=p2vx#+ p2spd#
             p2s_force#=force+0.5
             endif
             if upd_time>500
             p2dd=0
             p2dg=1
             p2vx#=p2vx#+ p2spd#
             p2s_force#=force+0.5
          endif
        upd_time=upd_time+1
           if upd_time=1000
           AI_mode=catch
           upd_time=0
          endif
         endif
      endif


   rem ***************************** collisions  *****************************

    rem ********* with the filet ********

    if p1px#>filet_p1# then p1px#=filet_p1#
    if p2px#<filet_p2# then p2px#=filet_p2#

    rem **********with ball and players*************

    col_p1= object hit(2,4)
    col_p2= object hit(3,4)
    if col_p1=1
      bpz#=10
      jump_mode=1
      down_mode=0
      bdir_1=1
      bvx#=bvx#+1
      if p1dg=1 then bdir_2=1
      if p1dd=1 then bdir_2=2
      ball_mode=1
      c_jump#=0
      bvz#=0
    endif
   if col_p2=1
      jump_mode=1
      down_mode=0
      bdir_1=2
      bvx#=bvx#+1
      if p2dg=1 then bdir_2=1
      if p2dd=1 then bdir_2=2
      ball_mode=1
      c_jump#=0
      bvz#=0
    endif


    rem ********* with the ground********

    rem ball

    if bpx#<terrain_min_x# then bdir_1 = 1
    if bpx#>terrain_max_x# then bdir_1 = 2
    if bpy#<terrain_min_y# then bdir_2 = 1
    if bpy#>terrain_max_y# then bdir_2 = 2

  if bpz#<-10
     bpz#=10
     bvz#=0
     c_jump#=0
     b_jump#=0
     jump_mode=0
     if bpx#<250
     p2score=p2score+1
      game_mode=p2point
         v_mode=0
         timing=0
     endif
     if bpx#>250
     p1score=p1score+1
        game_mode=p1point
         v_mode=0
         timing=0
     endif
    endif


    rem Player 1
    if p1px#<terrain_min_x# then p1dg=0
    if p1px#>terrain_max_x# then p1dd=0
    if p1py#<terrain_min_y# then p1db=0
    if p1py#>terrain_max_y# then p1dh=0
    rem Player 2
    if AI=0
    if p2px#<terrain_min_x# then p2dg=0
    if p2px#>terrain_max_x# then p2dd=0
    if p2py#<terrain_min_y# then p2db=0
    if p2py#>terrain_max_y# then p2dh=0
    endif
    if AI=1
    if p2px#<terrain_min_x# then p2px#=terrain_min_x#
    if p2px#>terrain_max_x# then p2px#=terrain_max_x#
    if p2py#<terrain_min_y# then p2py#=terrain_min_y#
    if p2py#>terrain_max_y# then p2py#=terrain_max_y#
    endif


    rem ***************************** Moving all the objects*******************************

    rem comuting ball trajectory

    rem  direction

    if jump_mode=1

     if bdir_1= 1 then bpx#=bpx#+bvx#
      if bdir_1= 2 then bpx#=bpx#-bvx#
      if bdir_2= 1 then bpy#=bpy#+2
      if bdir_2= 2 then bpy#=bpy#-2

      rem distance to the ground
      if ball_mode=1
      down_mode=0
      bvx#=bvx#+1
      c_jump#=c_jump#+strike_force#
      rem if the ball goes too high , camera follows her to the skies...
                  if bvz#>3

                    cam_up_glide=1
                    save_cam_r#=rx#
                       if bvz#>7.2
                          ball_mode=2
                          down_mode=1
                       endif
                  endif
       endif

       if ball_mode=2
          down_mode=1
          bvx#=bvx#+2
          c_jump#=c_jump#-strike_force#
          endif
      bvz#=bvz#+c_jump#
    endif

    rem calculate all the object directions

    viscosity# = 0.2

    rem ball
    bvx# = bvx# - viscosity#
    bvy# = bvy# - viscosity#
    if bvx# < 0 then bvx# = 0
    if bvx# > 5 then bvx# = 5
    if bvy# < 0 then bvy# = 0
    if bvy# > 5 then bvy# = 5


    rem player1
    p1vx# = p1vx# - viscosity#
    p1vy# = p1vy# - viscosity#
    if p1vx# < 0 then p1vx# = 0
    if p1vx# > 5 then p1vx# = 5
    if p1vy# < 0 then p1vy# = 0
    if p1vy# > 5 then p1vy# = 5

    rem player2
    p2vx# = p2vx# - viscosity#
    p2vy# = p2vy# - viscosity#
    if p2vx# < 0 then p2vx# = 0
    if p2vx# > 5 then p2vx# = 5
    if p2vy# < 0 then p2vy# = 0
    if p2vy# > 5 then p2vy# = 5


    rem add all the direction vectors to objects

    rem ball ( mainly done when computed the distance to the ground )
    bpz#=bpz#+bvz#


    rem player1
    if p1dh=1 then p1py# = p1py# + p1vy#
    if p1db=1 then p1py# = p1py# - p1vy#
    if p1dg=1 then p1px# = p1px# - p1vx#
    if p1dd=1 then p1px# = p1px# + p1vx#

    rem player2
    if p2dh=1 then p2py# = p2py# + p2vy#
    if p2db=1 then p2py# = p2py# - p2vy#
    if p2dg=1 then p2px# = p2px# - p2vx#
    if p2dd=1 then p2px# = p2px# + p2vx#

    rem moving objects...
    position object 2,p1px#,1,p1py#
    position object 3,p2px#,1,p2py#
    if b_stop=0 then  position object 4,bpx#,bpz#,bpy#

  endif

   rem ********************************other game states*******************************

   if game_mode=p1point
   cam_mode=victory
   rem player can jump all the cine stuff if boring
   if scancode()>0 then goto _setvars
   endif

   if game_mode=p2point
   if scancode()>0 then goto _setvars
   cam_mode=victory
   endif

    rem ********************************* displaying text stuff***************************
    if game_mode=play
    set cursor 0,0
    print "P1score   ", p1score
    print "P2score   ", p2score
    endif
    set cursor Xres/2,Yres/2
    if game_mode=p1point then print " Player 1 wins !!!! "
    if game_mode=p2point then print " Player 2 wins !!!! "

 sync
   loop

rem thats all folks !!