PONG

Start hier uw open source projecten

PONG

Berichtdoor bluatigro » zo jan 31, 2010 5:12 pm

nog te doen :
punten [ tellen en laten zien ]
geluid
van plaats wisselen
sprites ?
dubbelbuffering
Code: Selecteer alles
dim zone( 100 , 9 )
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global black  , red     , green  , yellow
global blue   , magenta , cyan   , white
global orange , gray    , purple , pink
black   = rgb(   0 ,   0 ,   0 )
red     = rgb( 255 ,   0 ,   0 )
green   = rgb(   0 , 255 ,   0 )
yellow  = rgb( 255 , 255 ,   0 )
blue    = rgb(   0 ,   0 , 255 )
magenta = rgb( 255 ,   0 , 255 )
cyan    = rgb(   0 , 255 , 255 )
white   = rgb( 255 , 255 , 255 )
pink    = rgb( 255 , 127 , 127 )
orange  = rgb( 255 , 127 ,   0 )
gray    = rgb( 127 , 127 , 127 )
purple  = rgb( 127 ,   0 , 127 )
global visible , enable
visible = 1
enable = 2
''end zone & color declarations
''==============================================
''begin game stuf
global wallup , walldown , human , comp , ball
wallup = 0 : walldown = 1
human = 2 : comp = 3 : ball = 4
global balldx , balldy
balldx = 2
balldy = 2
call zoneblock wallup   ,   0 , 250 , 0 , 250,20,50,orange
call zoneblock walldown ,   0 ,-220 , 0 , 250,20,50,orange
call zoneblock human    , 250 ,   0 , 0 ,  10,20,50,yellow
call zoneblock comp     ,-250 ,   0 , 0 ,  10,20,50,red
call zonesphere ball    ,   0 ,   0 , 0 ,  10,blue
nomainwin
timer 40 , [tmr]
open "Colision detection" for graphics as #m
  #m "trapclose [quit]"
  #m "when mouseMove [mouseMove]"
wait
end
[tmr]
  if zonehit( ball , wallup ) then
    balldy = 0 - abs( balldy )
  end if
  if zonehit( ball , walldown ) then
    balldy = abs( balldy )
  end if
  if zonehit( ball , human ) then
    balldx = 0 - abs( balldx )
    balldy = zone( ball , 1 ) - zone( human , 1 )
    balldy = balldy / 10
  end if
  if zonehit( ball , comp ) then
    balldx = abs( balldx )
    balldy = zone( ball , 1 ) - zone( comp , 1 )
    balldy = balldy / 10
  end if
  zone( ball , 0 ) = zone( ball , 0 ) + balldx
  zone( ball , 1 ) = zone( ball , 1 ) + balldy
  if zone( ball , 0 ) < -250 then
    notice "You won !!"
    goto [quit]
  end if
  if zone( ball , 0 ) > 250 then
    notice "You lost !!"
    goto [quit]
  end if
  if zone( comp , 1 ) < zone( ball , 1 ) then
    zone( comp , 1 ) = zone( comp , 1 ) + 2
  end if
  if zone( comp , 1 ) > zone( ball , 1 ) then
    zone( comp , 1 ) = zone( comp , 1 ) - 2
  end if
  #m "cls"
  call zonedraw wallup
  call zonedraw walldown
  call zonedraw human
  call zonedraw comp
  call zonedraw ball
  #m "flush"
wait
''end game stuf
''============================================
end
[mouseMove]
  qy = WindowHeight
  zone( human , 1 ) = ( qy / 2 - MouseY ) * 500 / qy
wait
''start zone functions and subs
sub zoneblock no , x , y , z , dx , dy , dz , clr
  zone( no , 0 ) = x
  zone( no , 1 ) = y
  zone( no , 2 ) = z
  zone( no , 3 ) = dx
  zone( no , 4 ) = dy
  zone( no , 5 ) = dz
  zone( no , 6 ) = -1
  zone( no , 7 ) = clr
  zone( no , 8 ) = visible + enable
end sub
sub zonesphere no , x , y , z , r , clr
  zone( no , 0 ) = x
  zone( no , 1 ) = y
  zone( no , 2 ) = z
  zone( no , 3 ) = 0
  zone( no , 4 ) = 0
  zone( no , 5 ) = 0
  zone( no , 6 ) = abs( r )
  zone( no , 7 ) = clr
  zone( no , 8 ) = visible + enable
end sub
sub zonedraw no
  if not( zone( no , 8 ) and visible ) then
    exit sub
  end if
  mx = WindowWidth / 2
  my = WindowHeight / 2
  tx = mx / 50
  ty = my / 50
  clr = zone( no , 7 )
  r = int( clr and 255 )
  g = int( clr / 256 ) and 255
  b = int( clr / 256 / 256 ) and 255
  #m "color " ; r ; " " ; g ; " " ; b
  #m "backcolor " ; r ; " " ; g ; " " ; b
  x = 0 : y = 1 : z = 2
  dx = 3 : dy = 4 : dz = 5 : r = 6
  if zone( no , r ) < 0 then
    #m "up"
    #m "goto " _
    ; mx + zone( no , x ) + zone( no , dx ) ; " " _
    ; my - zone( no , y ) + zone( no , dy )
    #m "down"
    #m "boxfilled " _
    ; mx + zone( no , x ) - zone( no , dx ) ; " " _
    ; my - zone( no , y ) - zone( no , dy )
    #m "up"
  else
    #m "goto " ; mx + zone( no , x ) _
         ; " " ; my - zone( no , y )
    #m "down"
    #m "circlefilled " ; zone( no , r )
    #m "up"
  end if
end sub
function zonehit( no1 , no2 )
  if not( zone( no1 , 8 ) and enable ) _
  or not( zone( no2 , 8 ) and enable ) then
    zonehit = 0
  end if
''zone 1 and zone 2 = block
  if zone( no1 , 6 ) < 0 _
  and zone( no2 , 6 ) < 0 then
    dx = abs( zone( no1 , 0 ) - zone( no2 , 0 ) )
    dy = abs( zone( no1 , 1 ) - zone( no2 , 1 ) )
    dz = abs( zone( no1 , 2 ) - zone( no2 , 2 ) )
    ax = zone( no1 , 3 ) + zone( no2 , 3 )
    ay = zone( no1 , 4 ) + zone( no2 , 4 )
    az = zone( no1 , 5 ) + zone( no2 , 5 )
    zonehit = dx < ax and dy < ay and dz < ay
  end if
''zone 1 and zone 2 = sphere
  if zone( no1 , 6 ) > 0 _
  and zone( no2 , 6 ) > 0 then
    x1 = zone( no1 , 0 )
    y1 = zone( no1 , 1 )
    z1 = zone( no1 , 2 )
    d1 = zone( no1 , 6 )
    x2 = zone( no2 , 0 )
    y2 = zone( no2 , 1 )
    z2 = zone( no2 , 2 )
    d2 = zone( no2 , 6 )
    dis = sqr( ( x1 - x2 ) ^ 2 _
    + ( y1 - y2 ) ^ 2 _
    + ( z1 - z2 ) ^ 2 )
    zonehit = dis < ( d1 + d2 )
  end if
''zone 1 = sphere  zone 2 = block
  if zone( no1 , 6 ) > 0 _
  and zone( no2 , 6 ) < 0 then
    h = no1
    no1 = no2
    no2 = h
  end if
''zone 1 = block  zone 2 = sphere
  diss = 0
  x = 0 : y = 1 : z = 2 : dx = 3 : dy = 4 : dz = 5 : r = 6
  if zone( no2 , x ) _
  < ( zone( no1 , x ) - zone( no1 , dx ) ) then
    diss = diss + ( zone( no2 , x ) _
    - ( zone( no1 , x ) - zone( no1 , dx ) ) ) ^ 2
  else
    if zone( no2 , x ) _
    > ( zone( no1 , x ) + zone( no1 , dx ) ) then
      diss = diss + ( zone( no2 , x ) _
      - ( zone( no1 , x ) + zone( no1 , dx ) ) ) ^ 2
    end if
  end if
  if zone( no2 , y ) _
  < ( zone( no1 , y ) - zone( no1 , dy ) ) then
    diss = diss + ( zone( no2 , y ) _
    - ( zone( no1 , y ) - zone( no1 , dy ) ) ) ^ 2
  else
    if zone( no2 , y ) _
    > ( zone( no1 , y ) + zone( no1 , dy ) ) then
      diss = diss + ( zone( no2 , y ) _
      - ( zone( no1 , y ) + zone( no1 , dy ) ) ) ^ 2
    end if
  end if
  if zone( no2 , z ) _
  < ( zone( no1 , z ) - zone( no1 , dz ) ) then
    diss = diss + ( zone( no2 , z ) _
    - ( zone( no1 , z ) - zone( no1 , dz ) ) ) ^ 2
  else
    if zone( no2 , z ) _
    > ( zone( no1 , z ) + zone( no1 , dz ) ) then
      diss = diss + ( zone( no2 , z ) _
      - ( zone( no1 , z ) + zone( no1 , dz ) ) ) ^ 2
    end if
  end if
  zonehit = diss < zone( no2 , 6 ) ^ 2
end function
function rgb( r , g , b )
  rgb = ( r and 255 ) _
  + ( g and 255 ) * 256 _
  + ( b and 255 ) * 256 * 256
end function
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar OPEN SOURCE PROJECTEN

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron