Liberty BASIC Community Forum
« negative number »

Welcome Guest. Please Login or Register.
Jan 23rd, 2018, 7:27pm


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


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: negative number  (Read 292 times)
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx negative number
« Thread started on: Jul 4th, 2016, 10:27am »

quite a long time ago i came across a command in the help file to change a positive number into a negative number
its a built in function but i don't seem to quite remember it at this very second does someone know or remember it?

Kevin
User IP Logged

KEVIN
robmcal
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 400
xx Re: negative number
« Reply #1 on: Jul 4th, 2016, 10:52am »

I don't recall seeing a built-in function but it is an easy one to create.

Code:
    x=15
    print NegNum(x)
    end

function NegNum(x)
    NegNum=x*-1
end function 

User IP Logged

Definition of an Upgrade: Take old bugs out, put new ones in.
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx Re: negative number
« Reply #2 on: Jul 4th, 2016, 11:08am »

thank you rob
User IP Logged

KEVIN
CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2834
xx Re: negative number
« Reply #3 on: Jul 4th, 2016, 12:53pm »

You can also simply subtract from 0.

num = 15
print 0-num
« Last Edit: Jul 4th, 2016, 12:53pm by CarlGundel » User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx Re: negative number
« Reply #4 on: Jul 5th, 2016, 03:18am »

thank you very much Mr Carl
kevin
User IP Logged

KEVIN
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx Re: negative number
« Reply #5 on: Jul 5th, 2016, 04:56am »

Here are my findings

Code:
    'SPRGETXY.BAS  - demonstrate spritexy?
    nomainwin

    'load the bitmaps we'll use as sprites & background
    loadbmp "smiley1", "sprites\smiley.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"

    'open a window and graphicbox

    open "sprite test" for graphics_fs  as #w
    print #w, "trapclose [quit]"
'__________________________________________________________________________________________________________


    hndl = hwnd(#w)
    struct winRect, orgX as long, orgY as long, cornerX as long, cornerY as long
    calldll #user32, "GetClientRect", hndl as ulong, winRect as struct, result as boolean
    x=winRect.cornerX.struct-winRect.orgX.struct
    y=winRect.cornerY.struct-winRect.orgY.struct
    'notice "inside of window frame width = "; x; " height = "; y
    'wait
'______________________________________________________________________________________________________________
    'add a background and sprite
    print #w, "background landscape";
    print #w, "addsprite smiley smiley1 smiley2 smiley3 smiley4";

    'tell the sprite to cycle one frame at a time, and move x5, y5
    print #w, "cyclesprite smiley 1"

        print #w, "spritemovexy smiley 5 5"


    timer 0, [a]
    wait
    [a]
 n =  int(rnd(1)*50) + 1
      scan
 'draw the next frame of animation
        print #w, "drawsprites";
        'get the x and y position of our sprite and print it out
        print #w, "spritexy? smiley spX spY"
       if spX > x then moveByX = -5
       if spX < 10 then moveByX = n
       if spY > y then moveByY = -5
       if spY < 10 then moveByY = n
        #w, "spritemovexy smiley "; moveByX; " "; moveByY


   wait
   for b = 1 to 20
        print #w, "backgroundxy -25 20";
        print #w, "drawsprites";
        next b
wait
[quit]
timer 0
close #w
end
end

 


Kevin
« Last Edit: Jul 5th, 2016, 04:57am by kevin » User IP Logged

KEVIN
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx Re: negative number
« Reply #6 on: Jul 5th, 2016, 06:03am »

Sorry wrong one here it is
Code:
   'SPRGETXY.BAS  - demonstrate spritexy?
    nomainwin

    'load the bitmaps we'll use as sprites & background
    loadbmp "smiley1", "sprites\smiley.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"

    'open a window and graphicbox

    open "sprite test" for graphics_fs  as #w
    print #w, "trapclose [quit]"
'__________________________________________________________________________________________________________


    hndl = hwnd(#w)
    struct winRect, orgX as long, orgY as long, cornerX as long, cornerY as long
    calldll #user32, "GetClientRect", hndl as ulong, winRect as struct, result as boolean
    x=winRect.cornerX.struct-winRect.orgX.struct
    y=winRect.cornerY.struct-winRect.orgY.struct
    'notice "inside of window frame width = "; x; " height = "; y
    'wait
'______________________________________________________________________________________________________________
    'add a background and sprite
    print #w, "background landscape";
    print #w, "addsprite smiley smiley1 smiley2 smiley3 smiley4";

    'tell the sprite to cycle one frame at a time, and move x5, y5
    print #w, "cyclesprite smiley 1"

        print #w, "spritemovexy smiley 5 5"


    timer 0, [a]
    wait
    [a]
 n =  int(rnd(1)*50) + 1
 nu = 0 - n -20
      scan
 'draw the next frame of animation
        print #w, "drawsprites";
        'get the x and y position of our sprite and print it out
        print #w, "spritexy? smiley spX spY"
       if spX > x then moveByX = nu
       if spX < 10 then moveByX = n
       if spY > y then moveByY = nu
       if spY < 10 then moveByY = n
        #w, "spritemovexy smiley "; moveByX; " "; moveByY


   wait
   for b = 1 to 20
        print #w, "backgroundxy -25 20";
        print #w, "drawsprites";
        next b
wait
[quit]
timer 0
close #w
end
end
 


Kevin
User IP Logged

KEVIN
kevin
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 418
xx Re: negative number
« Reply #7 on: Jul 7th, 2016, 05:54am »

hi guys here are my new Findings
what i am trying to do is ad at least 2 sprites that are not dependant of each other in there directions but when ever one sprit comes in contact with any other they multiply or a new one is added to the screen and so on
Code:
    'SPRGETXY.BAS  - demonstrate spritexy?
    nomainwin

    'load the bitmaps we'll use as sprites & background
    loadbmp "smiley1", "sprites\smiley.bmp"
    loadbmp "smiley2", "sprites\smiley2.bmp"
    loadbmp "smiley3", "sprites\smiley3.bmp"
    loadbmp "smiley4", "sprites\smiley4.bmp"
    loadbmp "landscape", "sprites\bg1.bmp"

    'open a window and graphicbox

    open "sprite test" for graphics_fs  as #w
    print #w, "trapclose [quit]"
'__________________________________________________________________________________________________________


    hndl = hwnd(#w)
    struct winRect, orgX as long, orgY as long, cornerX as long, cornerY as long
    calldll #user32, "GetClientRect", hndl as ulong, winRect as struct, result as boolean
    x=winRect.cornerX.struct-winRect.orgX.struct
    y=winRect.cornerY.struct-winRect.orgY.struct
    'notice "inside of window frame width = "; x; " height = "; y
    'wait
'______________________________________________________________________________________________________________
    'add a background and sprite
    print #w, "background landscape";
    print #w, "addsprite smiley smiley1 smiley2 smiley3 smiley4";

    print #w, "addsprite s2 smiley1 smiley2 smiley3 smiley4";
    print #w, "addsprite s3 smiley1 smiley2 smiley3 smiley4";

    'tell the sprite to cycle one frame at a time, and move x5, y5
    print #w, "cyclesprite smiley 1"
     direction =  int(rnd(1)*50) + 1
    sp = 0-s1
        print #w, "spritemovexy smiley 5 direction"
        print #w, "spritemovexy s2 3 3"
              #w, "spritemovexy s3 1 1"


    timer 0, [a]
    wait
    [a]
 n =  int(rnd(1)*50) + 1
' +++++++++++++++
  n2 =  int(rnd(1)*50) + 1
 o2 = 0-n
 '++++++++++++++
 o = 0-n
      scan
 'draw the next frame of animation
        print #w, "drawsprites";
        'get the x and y position of our sprite and print it out
        print #w, "spritexy? smiley spX spY"
       if spX > x then moveByX = o
       if spX < 10 then moveByX = n
       if spY > y then moveByY = o
       if spY < 10 then moveByY = n
        #w, "spritemovexy smiley "; moveByX; " "; moveByY
        '----------------------------------------s2------------------------------------------------------------------
         print #w, "spritexy? s2 s2X s2Y"
       if s2X > x then moveB2X = o2
       if s2X < 10 then moveB2X = n
       if s2Y > y then moveB2Y = -3
       if s2Y < 10 then moveB2Y = n*2
        #w, "spritemovexy s2 "; moveB2X; " "; moveB2Y
          '----------------------------------------s3------------------------------------------------------------------
                 print #w, "spritexy? s2 s3X s3Y"
       if s3X > x then moveB3X = -3
       if s3X < 10 then moveB3X = n
       if s3Y > y then moveB3Y = -3
       if s3Y < 10 then moveB3Y = n*2
        #w, "spritemovexy s3 "; moveB3X; " "; moveB3Y
       ' print #w, "spritexy? s2 s2X s2Y"



   wait
   for b = 1 to 20
        print #w, "backgroundxy -25 20";
        print #w, "drawsprites";
        next b
wait
[quit]
timer 0
close #w
end
end
 


Kevin
User IP Logged

KEVIN
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