PONG [ sprite verie ]

Vragen en suggesties over het programmeren van spelletjes, sprites en dergelijke in Liberty BASIC

Moderator: anthonio

PONG [ sprite verie ]

Berichtdoor bluatigro » zo jun 26, 2011 12:36 pm

eerst de sprite code :
Code: Selecteer alles
call clear 10 , 100
call boxfil 0 , 45 , 10 , 55 , green , black
call save "pong-bal"
call boxfil 0 , 0 , 10 , 100 , green , black
call save "pong-bat"

main sprite code :
http://www.basic.wikispaces.com/Draw+Bool+Sprites
LET OP : path's
en dan nu het spel
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , humanx , humany , humanpoint
global compx , compy , comppoint , balx , baly , baldx , baldy
winx = WindowWidth
winy = WindowHeight
humanx = winx * 3 / 4 - 5
humany = winy / 2 - 50
compx = winx / 4 - 5
compy = winy / 2 - 50
balx = winx / 2 - 5
baly = winy / 2 - 50
baldx = 5
baldy = 5
nomainwin
loadbmp "bat" , DefaultDir$ + "\BMP\pong-bat.bmp"
loadbmp "ball" , DefaultDir$ + "\BMP\pong-bal.bmp"

open "pong" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "down"
  #m "color green"
  #m "size 7"
  #m "line " ; winx / 4 ; " " ; winy / 4 ; " " ; winx * 3 / 4 ; " " ; winy / 4
  #m "line " ; winx / 4 ; " " ; winy * 3 / 4 ; " " ; winx * 3 / 4 ; " " ; winy * 3 / 4
  #m "size 1"
  #m "line " ; winx / 2 ; " " ; winy / 4 ; " " ; winx / 2 ; " " ; winy * 3 / 4
  #m "up"
  #m "getbmp back 0 0 " ; winx ; " " ; winy
  #m "background back"
  #m "addsprite human bat"
  #m "addsprite comp bat"
  #m "addsprite bal ball"
  #m "backcolor green"
  #m "font Courier_new 50 bold"
  #m "when mouseMove [MMove]"
  timer 40 , scene
wait
[MMove]
  humany = MouseY - 50
wait
sub scene
  if baly < winy / 4 - 50 then baldy = abs( baldy )
  if baly > winy * 3 / 4 - 50 then baldy = 0-abs( baldy )
  if balx < winx / 5 - 5 then
    balx = winx / 2 - 5
    baly = winy / 2 - 50
    baldy = 5
  end if
  if balx > winx * 4 / 5 - 5 then
    balx = winx / 2 - 5
    baly = winy / 2 - 50
    baldy = 5
  end if
  if baly < compy then compy = compy - 4
  if baly > compy then compy = compy + 4
  #m "spritecollides bal list$"
  if instr( list$ , "human" ) then
    baldy = ( baly - humany ) / 3
    baldx = -5
  end if
  if instr( list$ , "comp" ) then
    baldy = ( baly - compy ) / 3
    baldx = 5
  end if
  balx = balx + baldx
  baly = baly + baldy
  #m "spritexy human " ; humanx ; " " ; humany
  #m "spritexy comp " ; compx ; " " ; compy
  #m "spritexy bal " ; balx ; " " ; baly
  #m "drawsprites"
end sub
[quit]
  close #m
end

nog nodig : geluid en puntentelling en ...(?)...
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: PONG [ sprite verie ]

Berichtdoor bluatigro » zo jun 26, 2011 1:19 pm

update :
nu met geluid en puntentelling

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , humanx , humany , humanpoint
global compx , compy , comppoint , balx , baly , baldx , baldy
winx = WindowWidth
winy = WindowHeight
humanx = winx * 3 / 4 - 5
humany = winy / 2 - 50
compx = winx / 4 - 5
compy = winy / 2 - 50
balx = winx / 2 - 5
baly = winy / 2 - 50
baldx = 5
baldy = 5
nomainwin
loadbmp "bat" , DefaultDir$ + "\BMP\pong-bat.bmp"
loadbmp "ball" , DefaultDir$ + "\BMP\pong-bal.bmp"

open "pong" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "down"
  #m "color green"
  #m "size 7"
  #m "line " ; winx / 4 ; " " ; winy / 4 ; " " ; winx * 3 / 4 ; " " ; winy / 4
  #m "line " ; winx / 4 ; " " ; winy * 3 / 4 ; " " ; winx * 3 / 4 ; " " ; winy * 3 / 4
  #m "size 1"
  #m "line " ; winx / 2 ; " " ; winy / 4 ; " " ; winx / 2 ; " " ; winy * 3 / 4
  #m "up"
  #m "getbmp back 0 0 " ; winx ; " " ; winy
  #m "background back"
  #m "addsprite human bat"
  #m "addsprite comp bat"
  #m "addsprite bal ball"
  #m "backcolor black"
  #m "font Courier_new 100 bold"
  #m "when mouseMove [MMove]"
  timer 40 , scene
wait
[MMove]
  humany = MouseY - 50
wait
function nr$( x )
   nr$ = right$( "00" ; x , 2 )
end function
sub scene
  if baly < winy / 4 - 50 then
    baldy = abs( baldy )
    playwave DefaultDir$+"\WAV\beep-1.wav" , async
  end if
  if baly > winy * 3 / 4 - 50 then
    baldy = 0-abs( baldy )
    playwave DefaultDir$+"\WAV\beep-1.wav", async
  end if
  if balx < winx / 5 - 5 then
    balx = winx / 2 - 5
    baly = winy / 2 - 50
    baldy = 5
    playwave DefaultDir$+"\WAV\beep-1.wav" , async
    humanpoint = humanpoint + 1
  end if
  if balx > winx * 4 / 5 - 5 then
    balx = winx / 2 - 5
    baly = winy / 2 - 50
    baldy = 5
    playwave DefaultDir$+"\WAV\beep-1.wav" , async
    comppoint = comppoint + 1
  end if
  if baly < compy then compy = compy - 4
  if baly > compy then compy = compy + 4
  #m "spritecollides bal list$"
  if instr( list$ , "human" ) then
    baldy = ( baly - humany ) / 3
    baldx = -5
    playwave DefaultDir$+"\WAV\beep-1.wav" , async
  end if
  if instr( list$ , "comp" ) then
    baldy = ( baly - compy ) / 3
    baldx = 5
    playwave DefaultDir$+"\WAV\beep-1.wav" , async
  end if
  balx = balx + baldx
  baly = baly + baldy
  #m "spritexy human " ; humanx ; " " ; humany
  #m "spritexy comp " ; compx ; " " ; compy
  #m "spritexy bal " ; balx ; " " ; baly
  #m "drawsprites"
  #m "goto " ; winx / 2 - 250 ; " " ; winy / 5
  #m "down"
  #m "\" ; nr$( comppoint ) ; "-" ; nr$( humanpoint )
  #m "up"
  #m "flush"
end sub
[quit]
  close #m
end


have fun playing
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar Games

Wie is er online

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

cron