CoderDunn Posted April 11, 2008 Posted April 11, 2008 (edited) Inspired from my last script, I made this one to see if I could make a ball bounce like it would in real life. I know there are probably much better ways at doing this so if you have a better way please show me! You can customize the gravity, bounce ratio, and time per tick by editing the first few variables in the script. I dunno why I'm still using a golf ball but who cares ... I have never taken a physics course and I'm not that great at math so grade lightly ~ Hallman Ball_Bounce_Test.au3 Edited April 11, 2008 by Hallman
Vindicator209 Posted April 11, 2008 Posted April 11, 2008 Thats really good, now use that in maybe a connon game and you might get somewhere with it! [center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]
BrettF Posted April 12, 2008 Posted April 12, 2008 Sweet! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
Achilles Posted April 12, 2008 Posted April 12, 2008 Good work... Based of my experience with golf balls (I actually have played a little bit) it actually seems somewhat accurate, especially the end. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Triblade Posted April 12, 2008 Posted April 12, 2008 Looks very good! But I'm very picky. (If that's the right English word..) Just the split second before the ball comes to a complete stop is moves one or two pixels down. My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
DexterMorgan Posted April 13, 2008 Posted April 13, 2008 wow.. really cool i opened like 10 of them at the same time very fun! code
Toady Posted April 14, 2008 Posted April 14, 2008 I was interested in this script so I played around with it a little. Heres what I got try it out. expandcollapse popup#include <GUIConstants.au3> ; Bounce Test by Hallman ; Change these variables to whatever you want Global $Gravity = 1.4 ; Has to be greater than 1 (1.4 = default) Global $Bounce_Ratio = 0.7 ; ; Should be >0 and <1 (0.7 = default). If you set it to 1, then the ball will bounce to the same height that it was dropped from. Global $TimePerTick = 30 ; How long each tick is in miliseconds. Bigger number = slower ball movement (30 = default) ; ----------------------------------------------------------------------------------------------------------------------------------- ; ----------------------------------------------------------------------------------------------------------------------------------- Dim $BallPos[4] $BallPos[0] = 30 $BallPos[1] = 0 $BallPos[2] = 50 $BallPos[3] = 50 Dim $Current_Tick[6] ;~ $Current_Tick[0] = Active? (0 or 1) ;~ $Current_Tick[1] = Timer ;~ $Current_Tick[2] = Movement So Far ;~ $Current_Tick[3] = Total Movement Global $Speed = 0 $Main_Window = GUICreate("Ball Test",$BallPos[2], $BallPos[3], 0, @DesktopHeight / 10, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOOLWINDOW) $Ball_Ctrl = GUICtrlCreatePic("Golf Ball.gif", 0, 0, $BallPos[2], $BallPos[3]) GuiSetState() WinSetOnTop($Main_Window, "", 1) $Win_Pos = WinGetPos($Main_Window, "") $BallPos[0] = $Win_Pos[0] $BallPos[1] = $Win_Pos[1] Sleep(2000) $Loop_Timer = TimerInit() $Time_Per_Loop = 1 $Speed = 1 $Current_Tick[0] = 0 While 1 $Time_Per_Loop = TimerDiff($Loop_Timer) $Loop_Timer = TimerInit() $BallPos[0] += 4 If $Current_Tick[0] = 1 Then $Current_Tick_Time = TimerDiff($Current_Tick[1]) If $Current_Tick_Time > $TimePerTick Then $BallPos[1] = $Current_Tick[3] WinMove($Main_Window, "", $BallPos[0], $BallPos[1], $BallPos[2], $BallPos[3]) $Current_Tick[0] = 0 Else If $Speed > 0 Then $int = ($TimePerTick - $Current_Tick_Time) / $Time_Per_Loop $Movement = ($Current_Tick[3] - $Current_Tick[2]) / $int $Current_Tick[2] += $Movement If $Current_Tick[2] >= $Current_Tick[3] Then $BallPos[1] = $Current_Tick[3] WinMove($Main_Window, "", $BallPos[0], $BallPos[1], $BallPos[2], $BallPos[3]) $Current_Tick[0] = 0 Else $BallPos[1] = $Current_Tick[2] WinMove($Main_Window, "", $BallPos[0], $BallPos[1], $BallPos[2], $BallPos[3]) EndIf Else $int = ($TimePerTick - $Current_Tick_Time) / $Time_Per_Loop $Movement = ($Current_Tick[3] - $Current_Tick[2]) / $int $Current_Tick[2] += $Movement If $Current_Tick[2] <= $Current_Tick[3] Then $BallPos[1] = $Current_Tick[3] WinMove($Main_Window, "", $BallPos[0], $BallPos[1], $BallPos[2], $BallPos[3]) $Current_Tick[0] = 0 Else $BallPos[1] = $Current_Tick[2] WinMove($Main_Window, "", $BallPos[0], $BallPos[1], $BallPos[2], $BallPos[3]) EndIf EndIf EndIf Else If $BallPos[1] = (@DesktopHeight - $BallPos[3]) Then $Speed = $Speed * -1 $Speed = $Speed * $Bounce_Ratio If $Speed > -0.2 and $Speed < 0.2 Then Sleep(2000) Exit EndIf Else If $Speed > 0 Then $Speed = $Speed * $Gravity ElseIf $Speed < 0 Then $Speed = $Speed / $Gravity If $Speed > -2 Then $Speed = $Speed * -1 EndIf EndIf $Current_Tick[2] = $BallPos[1] $Current_Tick[3] = $BallPos[1] + $Speed If $Current_Tick[3] > (@DesktopHeight - $BallPos[3]) Then $Current_Tick[3] = (@DesktopHeight - $BallPos[3]) EndIf $Current_Tick[1] = TimerInit() $Current_Tick[0] = 1 EndIf sleep(1) WEnd www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
Triblade Posted April 15, 2008 Posted April 15, 2008 Very nice Toady!! Hmm, why does the program keeps running when the ball is offscreen? Anyway, Can someone add a check in the program for the picture? I had twice that I where wondering why the program didn't do anything My active project(s): A-maze-ing generator (generates a maze) My archived project(s): Pong3 (Multi-pinger)
Toady Posted April 15, 2008 Posted April 15, 2008 (edited) Very nice Toady!! Hmm, why does the program keeps running when the ball is offscreen? Anyway, Can someone add a check in the program for the picture? I had twice that I where wondering why the program didn't do anything The program is running while ball goes off screen because the ball is still bouncing. I have multi-monitor so I can see if bounce to the other screen. To make it stay on your screen just change the line $BallPos[0] += 4oÝ÷ ÚÚºÚ"µÍÌÍÐ[ÜÖÌH ÏH Edited April 15, 2008 by Toady www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding
AdmiralAlkex Posted April 15, 2008 Posted April 15, 2008 I have tried this like five times but i never see any ball anywhere .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
monoceres Posted April 15, 2008 Posted April 15, 2008 You could make a nice little game out of this, just let the ball bounce up when you click on it and then your goal is to keep it in the air as long as possible Broken link? PM me and I'll send you the file!
mafioso Posted April 15, 2008 Posted April 15, 2008 @AdmiralAlex Same for me, and I have changed the path to the ball...
JustinReno Posted April 16, 2008 Posted April 16, 2008 Are you sure the picture is in the script directory and named "Golf Ball.gif" ?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now