TGC Codebase Backup



Simple PONG game by Colella

23rd Feb 2004 12:33
Summary

A little PONG game clone.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` Pong

veloc# = 1
direcao# = 0
fracao# = 0.5
pontos1 = 0
pontos2 = 0

autocam off
make camera 1
position camera 1,0,0,0
sync on
sync

set display mode 800,600,16

make object box 4,400,2,1
position object 4,0,50,100
set object collision to boxes 4

make object box 5,400,2,1
position object 5,0,-60,100
set object collision to boxes 5

make object box 1,5,25,2
set object collision to boxes 1
make object box 2,5,25,2
set object collision to boxes 2

make object sphere 3,3
set object collision to spheres 3

position object 3,0,0,+100
position object 1,-70,0,+100
position object 2,+70,0,+100

set text size 40

repeat

 set cursor 0,0
 print "Jogador 1: ", pontos1

 set cursor 500,0
 print "Jogador 2: ", pontos2

   `jogador 1
   if upkey() = 1
      if object collision (1,4) = 0
         move object up 1,1
      endif
   endif
   if downkey() = 1
      if object collision (1,5) = 0
         move object down 1,1
      endif
   endif
   `jogador 2
   if inkey$() = "W" or inkey$() = "w"
      if object collision(2,4) = 0
         move object up 2,1
      endif
   endif
   if inkey$() = "S" or inkey$() = "s"
      if object collision (2,5) = 0
         move object down 2,1
      endif
   endif

    if object collision(3,2) = 1
      fracao# = fracao# * -1
      y2#      = object position y(2)
      yBola#   = object position y(3)
      direcao# = object position y(3)
   endif

    if object collision(3,1) = 1
         fracao# = fracao# * -1
         y1#      = object position y(1)
         yBola#   = object position y(3)
         direcao# = object position y(3)
   endif

   veloc# = veloc# + fracao#

   if object hit (3,4)
      direcao# = object position y(3)
      y1#    = 1
      y2#    = 0
      yBola# = 0
   endif

   if object hit (3,5)
      direcao# = object position y(3)
      y1#    = 0
      y2#    = 1
      yBola# = 1
   endif

   if y1# > yBola#
      direcao# = direcao# - 0.1
   endif
   if y1# < yBola#
      direcao# = direcao# + 0.1
   endif
   if y2# > yBola#
      direcao# = direcao# - 0.1
   endif
   if y2# < yBola#
      direcao# = direcao# + 0.1
   endif

   if object position x(3) > 100
      pontos1 = pontos1 + 1
      position object 3,0,0,+100
      position object 1,-70,0,+100
      position object 2,+70,0,+100
      gosub limpa_variaveis
      wait 1000
   endif
   if object position x(3) < -100
      pontos2 = pontos2 + 1
      position object 3,0,0,+100
      position object 1,-70,0,+100
      position object 2,+70,0,+100
      gosub limpa_variaveis
      wait 1000
   endif

   position object 3,veloc#,direcao#,100

sync

until escapekey() = 1

limpa_variaveis:

      veloc# = 1
      direcao# = 0
      fracao# = 0.5
      y1# = object position y(1)
      yBola# = object position y(3)
      y2# = object position y(2)

return