Move the mouse bellow the bouncing Sun and bounce it back into the sky.
Each bounce will give you 8 points, if the ball hits the wall or the top of the window instead of 8 points you get 8, 16, 24... points (8 * wall/top hits).
For full gameplay environment download Music/Sound files from here: BouncingSun+Music/Sound effects
The game doesn't use GDI, it was made with drawing and moving shapes/graphics.
If you feel like, you can post your best results here in this topic. Enjoy
Here's a TIP: keep the Sun bouncing in the area of clouds, don't let it go bellow the clouds area
Screen Shot of the game:

...and source: edit: added dynamic background
#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinApi.au3> #include <Sound.au3> Opt("MouseCoordMode", 2) Opt("TrayIconHide", 1) Global $Save_File = @ScriptDir & "\Data\DATA.ini" if NOT FileExists($Save_File) then _Create_ini() Global Const $WS_EX_COMPOSITED = 0x2000000 Global $PosX = 0, $PosY = 0, $VelX = 0, $VelY = 0 Global $Gravity Global $CurMusic = 1, $Music1, $Music2 Global $TheBallIsDown = True, $Score = 0, $Tap_Counter = 1 Global $BallWidth = Number(IniRead($Save_File, "Options", "BallSize", "56")) Global $SpringWidth = Number(IniRead($Save_File, "Options", "SpringSize", "76")) Global $Highscore_key = IniRead($Save_File, "Top score", "score", "0/0") Global $Score_Multip = Number(IniRead($Save_File, "Options", "Score multiplier", "8")) Global $BallBounceHeight = Number(IniRead($Save_File, "Options", "Bounce height", "22")) Global $XAccelerate = Number(IniRead($Save_File, "Options", "Acceleration X", "40")) Global $OverAllSpeed = Number(IniRead($Save_File, "Options", "GameSpeed", "16")) Global $dynamicBackground = Number(IniRead($Save_File, "Options", "dynamicBackground", "1")) Global $Counter = 0, $BestResult = Number(StringLeft($Highscore_key, StringInStr($Highscore_key, "/")-1)) Global $Grass_move_timer = Random(100, 800, 1), $Grass_Current = 1, $Grass_Timer, $Cloud_Timer, $Cloud_move_timer = Random(100, 300, 1) Dim $Cloud_movement[10] $Form1 = GUICreate("Bounce The SUN - Keep the Sun from falling from the sky - by sandin", 640, 480+40, -1, -1, -1, $WS_EX_COMPOSITED) GUISetBkColor(0xBFE3FE) $Clouds = _Create_Clouds() $TheSpring = _Create_Sphere(0, 0, $SpringWidth, 15, 0x00477D) $TheBall = _Create_Sphere(0, 0, $BallWidth, $BallWidth, 0xFFFF00) GUICtrlSetState($TheSpring, $GUI_HIDE) GUICtrlSetState($TheBall, $GUI_HIDE) $Start_Button = GUICtrlCreateButton("S&tart", 640/2-150/2, 430, 150, 35) GUICtrlSetFont(-1, 14, 800, 2, "Arial") $MusicButton = GUICtrlCreateButton("Stop Music", 5, 490, 80, 25) $Grass = _Draw_ground_and_grass() $Result_label = GUICtrlCreateLabel("Press Start to play the game", 0, 260, 640, 80, 0x01) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 26, 800, 2, "Arial") $Hits_Label = GUICtrlCreateLabel("Hits: 0", 100, 490, 160, 30) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 18, 800, 2, "Arial") GUICtrlSetColor(-1, 0xFFF2CB) $Score_Label = GUICtrlCreateLabel("Score: 0", 220, 490, 160, 30) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 18, 800, 2, "Arial") GUICtrlSetColor(-1, 0xFFF2CB) $BestResult_Label = GUICtrlCreateLabel("Highscore: " & $Highscore_key, 380, 490, 340, 30) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetFont(-1, 18, 800, 2, "Arial") GUICtrlSetColor(-1, 0xFFF2CB) $BounceSound = _SoundOpen(@ScriptDir & "\Data\Sound\Bounce.wav") $HitSound = _SoundOpen(@ScriptDir & "\Data\Sound\Hit.wav") $Music1 = _SoundOpen(@ScriptDir & "\Data\Music\Music01.mp3") $Music2 = _SoundOpen(@ScriptDir & "\Data\Music\Music02.mp3") GUISetState(@SW_SHOW) _SoundPlay($Music1) AdlibEnable("_The_Ball_Is_alive", $OverAllSpeed) While 1 Local $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _SoundClose($BounceSound) _SoundClose($HitSound) _SoundClose($Music1) _SoundClose($Music2) Exit Case $Start_Button $Score = 0 $Tap_Counter = 1 $Counter = 0 GUICtrlSetData($Score_Label, "Score: 0") GUICtrlSetData($Hits_Label, "Hits: 0") $TheBallIsDown = False _WinAPI_ShowCursor(False) $PosX = 640/2-$BallWidth/2 $PosY = 0 $VelX = Random(-22, 22, 1) $VelY = 0 $Gravity = Number(IniRead($Save_File, "Options", "Gravity", "1.0")) GUICtrlSetState($Result_label, $GUI_HIDE) GUICtrlSetState($TheSpring, $GUI_SHOW) GUICtrlSetState($Start_Button, $GUI_HIDE) GUICtrlSetState($TheBall, $GUI_SHOW) Case $MusicButton if GUICtrlRead($MusicButton) = "Stop Music" Then GUICtrlSetData($MusicButton, "Start Music") if $CurMusic = 1 Then _SoundStop($Music1) Else _SoundStop($Music2) EndIf Else GUICtrlSetData($MusicButton, "Stop Music") $CurMusic = Random(1, 2, 1) if $CurMusic = 1 Then _SoundPlay($Music1) Else _SoundPlay($Music2) EndIf EndIf EndSwitch Local $mouseMsg = GUIGetCursorInfo() if NOT @error then Local $Mouse_X = $mouseMsg[0]-$SpringWidth/2 Local $Mouse_Y = $mouseMsg[1]-15/2 _move_the_object_to($TheSpring, $Mouse_X, $Mouse_Y) EndIf if $dynamicBackground = 1 then if Random(0, 1, 1) = 0 then if TimerDiff($Grass_Timer) >= $Grass_move_timer Then if $Grass_Current = 1 then $Grass_Current = 2 _move_the_object_to($Grass, 1, 477) Else $Grass_Current = 1 _move_the_object_to($Grass, 0, 477) EndIf $Grass_move_timer = Random(100, 800, 1) $Grass_Timer = TimerInit() EndIf Else If TimerDiff($Cloud_Timer) >= $Cloud_move_timer Then $Cloud_move_timer = Random(100, 300, 1) $Cloud_Timer = TimerInit() _Move_Clouds() EndIf EndIf EndIf WEnd func _Create_ini() if NOT FileExists(@ScriptDir & "\Data") then DirCreate(@ScriptDir & "\Data") FileWrite($Save_File, "") IniWrite($Save_File, "Options", "Gravity", "1.0") IniWrite($Save_File, "Options", "Acceleration X", "40") IniWrite($Save_File, "Options", "Bounce height", "22") IniWrite($Save_File, "Options", "Score multiplier", "8") IniWrite($Save_File, "Options", "GameSpeed", "16") IniWrite($Save_File, "Options", "BallSize", "56") IniWrite($Save_File, "Options", "SpringSize", "76") IniWrite($Save_File, "Options", "dynamicBackground", "1") IniWrite($Save_File, "Top score", "Score", "0/0") EndFunc func _Create_Sphere($x, $y, $width, $height, $color) Local $sphere = GUICtrlCreateGraphic($x, $y, $width, $height) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, $color) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, $x, $y, $width, $height) Return $sphere EndFunc func _Create_Clouds() dim $Cloouuudd[10] for $i = 1 to 9 $Cloouuudd[$i] = GUICtrlCreateGraphic(Random(5, 505, 1), Random(5, 240, 1), 155, 35+25) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xFFFFFF, 0xFFFFFF) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, Random(10, 35, 1), Random(15, 25, 1), Random(40, 90, 1), Random(25, 35, 1)) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, Random(0, 15, 1), Random(10, 20, 1), Random(40, 70, 1), Random(25, 35, 1)) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, Random(50, 60, 1), Random(10, 20, 1), Random(40, 95, 1), Random(25, 35, 1)) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, Random(10, 35, 1), Random(0, 15, 1), Random(40, 95, 1), Random(25, 35, 1)) $Cloud_movement[$i] = Random(0, 1, 1) Next if $dynamicBackground = 1 then $Cloud_Timer = TimerInit() Return $Cloouuudd EndFunc func _Draw_ground_and_grass() Local $grass_graph1 = GUICtrlCreateGraphic(0, 479, 640, 1) Local $Grass_move = GUICtrlCreateGraphic(0, 477, 640, 2) for $i = 1 to 640 step 6 GUICtrlSetGraphic($grass_graph1, $GUI_GR_COLOR, 0x00570C) GUICtrlSetGraphic($Grass_move, $GUI_GR_COLOR, 0x00570C) GUICtrlSetGraphic($grass_graph1, $GUI_GR_RECT, $i, 0, 3, 1) GUICtrlSetGraphic($Grass_move, $GUI_GR_RECT, $i, 0, 2, 2) Next GUICtrlCreateGraphic(0, 480+5, 640, 40-5) GUICtrlSetBkColor(-1, 0x3E2300) GUICtrlCreateGraphic(0, 480, 640, 5) GUICtrlSetBkColor(-1, 0x00570C) if $dynamicBackground = 1 then $Grass_Timer = TimerInit() Return $Grass_move EndFunc func _The_Ball_Is_Alive() _Apply_Gravity() $PosX += $VelX $PosY += $VelY if $PosX > 640 - $BallWidth Then $PosX = 640 - $BallWidth _Apply_Rebound() ElseIf $PosX < 0 Then $PosX = 0 _Apply_Rebound() EndIf if $PosY > 480 - $BallWidth Then $PosY = 480 - $BallWidth _Apply_Bounce() ElseIf $PosY < 0 Then $PosY = 0 _Apply_Bounce() EndIf _move_the_object_to($TheBall, $PosX, $PosY) if GUICtrlRead($MusicButton) = "Stop Music" then _Change_Music() if $TheBallIsDown = False then _Collision() EndFunc func _Move_Clouds() Local $i = Random(1, 9, 1) Local $Cloud_Pos = ControlGetPos($Form1, "", $Clouds[$i]) if $Cloud_movement[$i] = 0 then ;left if $Cloud_Pos[0] <= -$Cloud_Pos[2] Then _move_the_object_to($Clouds[$i], 640, $Cloud_Pos[1]) Else _move_the_object_to($Clouds[$i], $Cloud_Pos[0]-2, $Cloud_Pos[1]) EndIf else ;right if $Cloud_Pos[0] >= 640+$Cloud_Pos[2] Then _move_the_object_to($Clouds[$i], -$Cloud_Pos[2], $Cloud_Pos[1]) Else _move_the_object_to($Clouds[$i], $Cloud_Pos[0]+2, $Cloud_Pos[1]) EndIf EndIf EndFunc func _Change_Music() if $CurMusic = 1 Then if _SoundPos($Music1, 2) >= _SoundLength($Music1, 2)-10 Then _SoundStop($Music1) $CurMusic = 2 _SoundPlay($Music2) EndIf Else if _SoundPos($Music2, 2) >= _SoundLength($Music2, 2)-10 Then _SoundStop($Music1) $CurMusic = 1 _SoundPlay($Music1) EndIf EndIf EndFunc func _Collision() Local $MousePos = MouseGetPos() Local $Mouse_X = $MousePos[0] Local $Mouse_Y = $MousePos[1] if ($Mouse_X+$SpringWidth/2 > $PosX) AND ($Mouse_X-$SpringWidth/2 < $PosX+$BallWidth) AND ($Mouse_Y+15/2 > $PosY) AND ($Mouse_Y-15/2 < $PosY+$BallWidth) then $Counter += 1 GUICtrlSetData($Hits_Label, "Hits: " & $Counter) _SoundPlay($HitSound) $VelY = -$BallBounceHeight $VelX = ((($PosX+$BallWidth/2)-$Mouse_X)/(100/$XAccelerate) * (2-(2-1)*($BallWidth-10)/(56-10))) ;the last should result with 1 unless shrinking ball starts working, and thus increase X speed of the ball if $VelX = 0 then $VelX = (Random(-10, 10, 1)/10) $Score += $Score_Multip*$Tap_Counter $Tap_Counter = 1 GUICtrlSetData($Score_Label, "Score: " & $Score) ;~ if $BallWidth > 10 then ;failed attemt to create ball and spring to shrink every 3 hits due to graphic display bug ;~ if Mod($Counter, 3) = 0 Then ;~ $BallWidth -= 1 ;~ $SpringWidth -= 1 ;~ GUICtrlSetGraphic($TheBall, $GUI_GR_ELLIPSE, 0, 0, $BallWidth, $BallWidth) ;~ GUICtrlSetGraphic($TheSpring, $GUI_GR_ELLIPSE, 0, 0, $SpringWidth, 15) ;~ GUICtrlSetData($BallSize_Label, "Size: " & $BallWidth) ;~ EndIf ;~ EndIf EndIf EndFunc func _Set_the_object_size($object, $dimension) GUICtrlSetGraphic($object, $GUI_GR_ELLIPSE, 0, 0, $dimension, $dimension) EndFunc func _move_the_object_to($object, $x, $y) GUICtrlSetPos($object, $x, $y) EndFunc func _Apply_Gravity() $VelY += $Gravity EndFunc func _Apply_Bounce() if Round($VelY) > 1 Then _SoundPlay($BounceSound) if $VelY > 0 Then $VelY *= (-0.85) if $TheBallIsDown = false Then _WinAPI_ShowCursor(True) $TheBallIsDown = True GUICtrlSetData($Start_Button, "&Try again") GUICtrlSetState($TheSpring, $GUI_HIDE) GUICtrlSetState($Start_Button, $GUI_SHOW) Local $show_result = "You score " & $Score & " points with " & $Counter & " hits" if $Score > $BestResult then $BestResult = $Score $show_result &= @CRLF & "AND You beat the highscore!" GUICtrlSetData($BestResult_Label, "Highscore: " & $Score & "/" & $Counter) IniWrite($Save_File, "Top score", "Score", $Score & "/" & $Counter) EndIf GUICtrlSetData($Result_label, $show_result) GUICtrlSetState($Result_label, $GUI_SHOW) EndIf Else $Tap_Counter += 1 _SoundPlay($BounceSound) $VelY *= (-1.0) EndIf $VelX *= 0.92 if Abs($VelX) < 1 Then $VelX = 0 if Abs($VelY) < 1 then $VelY = 0 EndFunc func _Apply_Rebound() $Tap_Counter += 1 _SoundPlay($BounceSound) $VelX *= (-0.9) if Abs($VelX) < 1 then $VelX = 0 EndFunc
Edited by sandin, 19 November 2009 - 05:07 PM.









