Liberty BASIC Community Forum
« pong : sprite version »

Welcome Guest. Please Login or Register.
Sep 21st, 2017, 7:55pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: pong : sprite version  (Read 186 times)
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 908
xx pong : sprite version
« Thread started on: Dec 22nd, 2015, 06:30am »

error
- runtime error : index 6 outof colertionbounds
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , hx,hy,hp , cx,cy,cp
global balx , baly , baldx , baldy , speed
winx = WindowWidth
winy = WindowHeight
speed = 5
baldx = speed
baldy = speed
nomainwin
open "pong" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp bmp 0 0 " ; winx ; " 60"
  #m "addsprite top bmp"
  #m "addsprite bottom bmp"
  #m "getbmp bmp 0 0 30 200"
  #m "addsprite human bmp"
  #m "addsprite comp bmp"
  #m "getbmp 0 0 30 60"
  #m "addsprite bal bmp"
  #m "fill white"
  #m "spritexy top 0 70"
  #m "spritexy bottom 0 " ; winy - 70
  hx = winx - 70
  hy = winy / 2
  #m "spritexy human " ; hx ; " " ; hy - 50
  cx = 40
  cy = winy / 2
  #m "spritexy comp " ; cx ; " " ; cy - 50
  balx = winx / 2
  baly = winy / 2
  #m "spritexy bal " ; balx - 15 ; " " ;  baly - 15
  #m "when mouseMove [move]"
  #m "setfocus"
  #m "font Courier_new 40 bold"
  timer 40 , [timer]
wait
[timer]
  #m "cls"
  #m "goto 0 0"
  #m "down"
  #m "\" ; nr$( cp ) ; " - " ; nr$( hp )
  #m "up"
  ''ai
  if cy < baly then cy = cy + speed
  if cy > baly then cy = cy - speed
  #m "spritecollides bal list$"
  if instr( list$ , "top" ) then
    baldy = abs( baldy )
  end if
  if instr( list$  , "bottom" ) then
    baldy = 0 - abs( baldy )
  end if
  if instr( list$ , "human" ) then
    baldx = 0 - abs( baldx )
    baldy = baly - hy
  end if
  if instr( list$ , "comp" ) then
    baldx = abs( baldx )
    baldy = baly - cy
  end if
  if balx < 0 then hp = hp + 1
  if balx > winx then cp = cp + 1
  if hp > 12 then
    timer 0
    notice "You have won !!"
    close #m
    end
  end if
  if cp > 12 then
    timer 0
    notice "You lost ."
    close #m
    end
  end if
  #m "spritexy human " ; hx ; " " ; hy - 50
  #m "spritexy comp " ; cx ; " " ; cy - 50
  #m "spritexy bal " ; balx - 15 ; " " ;  baly - 15
  #m "drawsprites"

wait
function nr$( x )
  nr$ = right$( "00" ; x , 2 )
end function
[move]
  hy = MouseY
wait
[quit]
  close #m
end

 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
cundo
Guru
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 626
xx Re: pong : sprite version
« Reply #1 on: Dec 22nd, 2015, 08:29am »

There is a bitmap name missing, line:
Code:
  #m "getbmp 0 0 30 60" 
change that to
Code:
  #m "getbmp BMPNAME 0 0 30 60"  
. I don't know what name to use, so change the bitmap name to one you will use later in your code.
User IP Logged

cundo
bluatigro
Guru
ImageImageImageImageImage


member is offline

Avatar

cxiu diversas el tio respondas cxiu samvaloras [ thats esperanto for : we are al different therefore we are al equal ]


PM

Gender: Male
Posts: 908
xx Re: pong : sprite version
« Reply #2 on: Dec 23rd, 2015, 08:20am »

@ cundo :
- thanks for spotting that

next error :
- sprites top , botom , human and comp not viseble
Code:
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , hx,hy,hp , cx,cy,cp
global balx , baly , baldx , baldy , speed
winx = WindowWidth
winy = WindowHeight
speed = 5
baldx = speed
baldy = speed
nomainwin
open "pong" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp bmp 0 0 " ; winx ; " 60"
  #m "addsprite top bmp"
  #m "addsprite bottom bmp"
  #m "getbmp bmp 0 0 30 200"
  #m "addsprite human bmp"
  #m "addsprite comp bmp"
  #m "getbmp bmp 0 0 30 60"
  #m "addsprite bal bmp"
  #m "fill white"
  #m "spritexy top 0 70"
  #m "spritexy bottom 0 " ; winy - 70
  hx = winx - 70
  hy = winy / 2
  #m "spritexy human " ; hx ; " " ; hy - 50
  cx = 40
  cy = winy / 2
  #m "spritexy comp " ; cx ; " " ; cy - 50
  balx = winx / 2
  baly = winy / 2
  #m "spritexy bal " ; balx - 15 ; " " ;  baly - 15
  #m "when mouseMove [move]"
  #m "setfocus"
  #m "font Courier_new 40 bold"
  timer 40 , [timer]
wait
[timer]
  #m "fill white"
  #m "goto "; winx / 2 - 80 ; " 30"
  #m "down"
  #m "\" ; nr$( cp ) ; " - " ; nr$( hp )
  #m "up"
  ''ai
  if cy < baly then cy = cy + speed
  if cy > baly then cy = cy - speed
  #m "spritecollides bal list$"
  if instr( list$ , "top" ) then
    baldy = abs( baldy )
  end if
  if instr( list$  , "bottom" ) then
    baldy = 0 - abs( baldy )
  end if
  if instr( list$ , "human" ) then
    baldx = 0 - abs( baldx )
    baldy = baly - hy
  end if
  if instr( list$ , "comp" ) then
    baldx = abs( baldx )
    baldy = baly - cy
  end if
  balx = balx + baldx
  baly = baly + baldy
  if balx < 0 then
    hp = hp + 1
    balx = winx / 2
    baly = winy / 2
    baldx = 0 - speed
    baldy = speed
  end if
  if balx > winx then
    cp = cp + 1
    balx = winx / 2
    baly = winy / 2
  end if
  if hp > 12 then
    timer 0
    notice "You have won !!"
    close #m
    end
  end if
  if cp > 12 then
    timer 0
    notice "You lost ."
    close #m
    end
  end if
  #m "spritexy human " ; hx ; " " ; hy - 50
  #m "spritexy comp " ; cx ; " " ; cy - 50
  #m "spritexy bal " ; balx - 15 ; " " ;  baly - 15
  #m "drawsprites"

wait
function nr$( x )
  nr$ = right$( "00" ; x , 2 )
end function
[move]
  hy = MouseY
wait
[quit]
  close #m
end
 
User IP Logged

basic's : C64 Simons C128 Amiga Amos quick4.5 Visual5 Visual6 Visual2005 Visual2008 just and last but not least liberty
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls