Main Menu

they lose height

Started by RaverDave, October 16, 2006, 03:55:11 PM

Previous topic - Next topic

RaverDave

ok a very good friend of mine has been learning me gravity and stuff, he has been using one language and showing me the code, i have been translating it to playbasic, now then the problem is that when i run mine,they seem to lose height after every bounce, but with his they retain the same heighth, could someone look at the code and explain why??

; PROJECT : gravity
; AUTHOR  : Raverdave
; CREATED : 16/10/2006
; EDITED  : 16/10/2006
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
ScreenVsync On
Mouse Off
Global numofp=100
Global amg#=0.05
Type tpumpkin
bally#
ballx#
newspeed#
oldspeed#
gravity#
angle#
state
EndType
Dim pumpkin(numofp) As tpumpkin
makegfx()
For n=1 To numofp
pumpkin(n).gravity#=0.05
pumpkin(n).angle#=180
pumpkin(n).ballx#=Rnd(640)
pumpkin(n).bally#=Rnd(260)+10
Next
Do
Cls 0
SetCursor 0,0
Print pumpkin(n).bally#
For n=1 To numofp
DrawImage 1,pumpkin(n).ballx#,pumpkin(n).bally#,1
Select pumpkin(n).angle#
Case 180.0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#+pumpkin(n).gravity#
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).bally#>=380
pumpkin(n).angle#=0
pumpkin(n).bally#=380
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
ContCase
Case 0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#-(pumpkin(n).gravity#+amg#)
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).newspeed#<=0
pumpkin(n).angle#=180
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
EndSelect

Next
Sync
Loop
Function makegfx()
Cls 0
Circle 15,15,15,0
TempImage=GetFreeImage()
GetImage TempImage,0,0,32,32
EndFunction




RaverDave

hmmm..changing
Global amg#=0.00005
makes them gain height,but i dont want em to gain or lose!

RaverDave

ahaaaa..... this works!

; PROJECT : gravity
; AUTHOR  : Raverdave
; CREATED : 16/10/2006
; EDITED  : 16/10/2006
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
ScreenVsync On
Mouse Off
Global numofp=1
Global amg#=0.000002
Type tpumpkin
bally#
ballx#
newspeed#
oldspeed#
gravity#
angle#
state
EndType
Dim pumpkin(numofp) As tpumpkin
makegfx()
For n=1 To numofp
pumpkin(n).gravity#=0.05
pumpkin(n).angle#=180
pumpkin(n).ballx#=Rnd(640)
pumpkin(n).bally#=Rnd(260)+10
ly=pumpkin(n).bally#
Next

Do
Cls 0
SetCursor 0,0
Line 0,ly,640,ly
Print pumpkin(n).newspeed#
For n=1 To numofp
DrawImage 1,pumpkin(n).ballx#,pumpkin(n).bally#,1
Select pumpkin(n).angle#
Case 180
pumpkin(n).newspeed#=pumpkin(n).oldspeed#+pumpkin(n).gravity#
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).bally#>=380
pumpkin(n).angle#=0
pumpkin(n).bally#=375
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
ContCase
Case 0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#-(pumpkin(n).gravity#+amg#)
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).newspeed#<=0
pumpkin(n).angle#=180
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
EndSelect

Next
Sync
Loop
Function makegfx()
Cls 0
Circle 15,15,15,0
TempImage=GetFreeImage()
GetImage TempImage,0,0,32,32
EndFunction





dunno why yet,but hell...maybe someone can explain it! :D:D


stef

this is similar




; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
;SetFPS 60
;ScreenVsync On
Mouse Off
Global numofp=100
Global amg#=0.0499
Type tpumpkin
bally#
ballx#
newspeed#
oldspeed#
gravity#
angle#
state
EndType
Dim pumpkin(numofp) As tpumpkin
makegfx()
For n=1 To numofp
pumpkin(n).gravity#=0.05
pumpkin(n).angle#=180
pumpkin(n).ballx#=Rnd(640)
pumpkin(n).bally#=Rnd(260)+10
Next
Do
Cls 0
SetCursor 0,0
Print pumpkin(n).bally#
For n=1 To numofp
DrawImage 1,pumpkin(n).ballx#,pumpkin(n).bally#,1
Select pumpkin(n).angle#
Case 180.0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#+pumpkin(n).gravity#
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).bally#>=380
pumpkin(n).angle#=0
pumpkin(n).bally#=380
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
;ContCase
Case 0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#-amg#
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).newspeed#<=0
pumpkin(n).angle#=180
pumpkin(n).newspeed#=0
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
EndSelect

Next
Sync
Loop
Function makegfx()
Cls 0
Circle 15,15,15,0
TempImage=GetFreeImage()
GetImage TempImage,0,0,32,32
EndFunction





RaverDave

damnit i should have tested more..some runs its ok..some it aint..this is all rather odd

stef

Don' know if you have noticed:
I added the line

   pumpkin(n).newspeed#=0



RaverDave

ah right..yeh seems to work..thanks!! well i had to unrem the fps setting..i mean really!!

ok i have added x speed now and they seem to be rebounding nicely all over the place


couldyou explain what was wrong then..i need to learn this fully

stef

Nothing was wrong!

It is all an approach to the real physical solution
It is a system of elasticity (the real solution must be quite complicated)

I think it is important to set the speed at the ground to zero (to have always same conditions)
and change experimentally the "elasticity/resistance-factor"  (amg#) to a fitting value with desired result (spooky pumpkins :))


RaverDave

well yeh my goal is to do something for halloween1 :D:D just for fun really

They bounce around nicely now... here is the code for anyone whom may find it handy...
; PROJECT : gravity
; AUTHOR  : Raverdave
; CREATED : 16/10/2006
; EDITED  : 17/10/2006
; ---------------------------------------------------------------------
OpenScreen 640,480,32,2
SetFPS 60
;ScreenVsync On
Mouse Off
Global numofp=2
Global amg#=0.0499
Type tpumpkin
bally#
ballx#
speedx#
newspeed#
adx#
oldspeed#
gravity#
angle#
state
EndType
Dim pumpkin(numofp) As tpumpkin
makegfx()
For n=1 To numofp
pumpkin(n).adx#=Rnd(2)+1
pumpkin(n).speedx#=pumpkin(n).adx#
pumpkin(n).gravity#=0.05
pumpkin(n).angle#=180
pumpkin(n).ballx#=Rnd(640)
pumpkin(n).bally#=Rnd(260)+10
ly=pumpkin(n).bally
Next
Do
Cls 0
SetCursor 0,0
m=RGB(255,255,255)
Ink m
Line 0,ly,640,ly
c=RGB(200,0,0)
Ink c
Line 0,410,640,410
Print pumpkin(n).bally#
For n=1 To numofp
DrawImage 1,pumpkin(n).ballx#,pumpkin(n).bally#,1
pumpkin(n).ballx#=pumpkin(n).ballx#+pumpkin(n).speedx#

If pumpkin(n).ballx#>=640
pumpkin(n).speedx#=-pumpkin(n).adx#
EndIf
If pumpkin(n).ballx#<=0
pumpkin(n).speedx#=pumpkin(n).adx#
EndIf
Select pumpkin(n).angle#
Case 180.0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#+pumpkin(n).gravity#
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).bally#>=380
pumpkin(n).angle#=0
pumpkin(n).bally#=380
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
;ContCase
Case 0
pumpkin(n).newspeed#=pumpkin(n).oldspeed#-amg#
pumpkin(n).bally#=pumpkin(n).bally#-(Cos(pumpkin(n).angle#)*pumpkin(n).newspeed#)
If pumpkin(n).newspeed#<=0
pumpkin(n).angle#=180
pumpkin(n).newspeed#=0
EndIf
pumpkin(n).oldspeed#=pumpkin(n).newspeed#
EndSelect

Next
Sync
Loop
Function makegfx()
Cls 0
Circle 15,15,15,0
TempImage=GetFreeImage()
GetImage TempImage,0,0,32,32
EndFunction


A couple of lines are drawn simply for some visualnesssss

stef

Quotewell yeh my goal is to do something for halloween1 :D just for fun really

Great idea!

I must do something too!

That will be a Just-for-fun-competition :)

13 nights to halloween