Liberty BASIC Help Online

Simple Demo Program
 
This simple demo draws a background and sprites on the screen, using GETBMP to set up the bitmaps for sprite animation.  The program scrolls the background, moves the sprites automatically, checks for collisions and acts when the sprites collide.
 
nomainwin
WindowWidth=410
WindowHeight=450
UpperLeftX=50
UpperLeftY=5
 
graphicbox #w.g, 0,0,400,300
graphicbox #w.s, 0,301,100,100
open "Animation" for window_nf as #w
 
print #w, "trapclose [quit]"
 
'draw background:
print #w.g, "down;fill blue"
print #w.g, "color red;backcolor red"
print #w.g, "boxfilled 200 150"
print #w.g, "getbmp landscape 0 0 399 299";
 
'set background:
print #w.g, "background landscape";
 
'draw sprite and mask:
print #w.s, "down; fill white;backcolor black"
print #w.s, "color black;place 0 40"
print #w.s, "boxfilled 80 80"
 
'masks:
print #w.s, "place 20 20;circlefilled 18"
print #w.s, "place 60 20;circlefilled 18"
 
'sprite 1:
print #w.s, "color yellow;backcolor yellow"
print #w.s, "place 20 60;circlefilled 18"
print #w.s, "color black;backcolor black;size 4"
print #w.s, "set 12 55;set 28 55;size 1"
print #w.s, "place 20 67"
print #w.s, "ellipsefilled 20 5"
print #w.s, "Getbmp ball1 0 0 40 80"
 
'add sprite, set auto-move
print #w.g, "addsprite guy ball1"
print #w.g, "spritemovexy guy 3 2"
 
'sprite 2:
print #w.s, "color pink;backcolor pink"
print #w.s, "place 60 60;circlefilled 18"
print #w.s, "color blue;size 4"
print #w.s, "set 54 55;set 66 55"
print #w.s, "color darkpink;backcolor darkpink;size 1"
print #w.s, "place 60 67"
print #w.s, "ellipsefilled 20 7"
print #w.s, "Getbmp ball2 40 0 40 80"
 
'add sprite2, set auto-move
print #w.g, "addsprite girl ball2"
print #w.g, "spritexy girl 380 280"
print #w.g, "spritemovexy girl -2 -2"
 
'move sprites, scroll background,
'check for collisions:
 
ms = timerScroll(100)
 
wait
 
[scroll]
    if ms = 0 then wait   'this causes any extra ticks to be ignored
    x=x-5:y=y+5
    print #w.g, "backgroundxy ";x;" ";y
    print #w.g, "drawsprites"
    print #w.g, "spritecollides guy list$"
 
    if list$="girl" then
        print #w.g, "color black;font arial 14"
        print #w.g, "place 140 280;|Boy meets girl!"
        ms = timerScroll(0)
    end if
    wait
 
function timerScroll(ms)
    timer ms, [scroll]
    timerScroll = ms
end function
 
[quit]
    close #w:end
 
 


Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/