Page 1 of 1

negating a value

Posted: Fri Feb 06, 2004 11:16 am
by RaverDave
Hello again!!
I was wondering, is there a command to negate a value,that is to say,I want to start off at a random speed, which i have done, but when it hits the edge of the screen i want it to totally negate its speed, so lets say the speed was a value of 4, I want it to hit the edge of the screen and make it -4, but bare in mind it could be any value,as it is initially given a random speed as I said!

Code: Select all

new_face:
  AddElement(face())
  face()\xb=Random(640)
  face()\yb=Random(480)
  face()\xspeed=1
  face()\yspeed=Random(3)+1
Return
like so!!

And this is the movement, but i dont want face()\yspeed=-3 or 3,I want the negative of what it was originally assigned in the new_face routine!

Code: Select all

draw_sprites:
 ResetList(face())
While NextElement(face())

      DisplaySprite(#fcs,face()\xb,face()\yb)
      face()\yb=face()\yb+face()\yspeed
      face()\xb=face()\xb+face()\xspeed
      
      If face()\xb>=640-64
        face()\xspeed=-1
      EndIf
      If face()\xb<=0
        face()\xspeed=1
      EndIf
      If face()\yb<=0
        face()\yspeed=3
      EndIf
       If face()\yb>=480-64
        face()\yspeed=-3
      EndIf
  Wend
Return
Thanks 4 any help! P.S... this PureBasic is well CooL!! ;)

Posted: Fri Feb 06, 2004 11:25 am
by Pupil
?? Why not just use:

Code: Select all

face()\xspeed = -face()\xspeed
face()\yspeed = -face()\yspeed

Posted: Fri Feb 06, 2004 11:33 am
by RaverDave
hehe,man that was simple,i didnt think you could do that,i have done it that same way b4 in a c++ style language!!LoL...ok thanks..Works fine