Kistendingsi
Übersicht

CodeMasterBetreff: Kistendingsi |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Inspiriert durch das Kästchenspiel hier aus dem CodeArchiv. Der Ansatz ist sehr früh, wird jedoch vermutlich nicht mehr weiterentwickelt. Kleine Lockerungsübung für die Finger ![]() Code: [AUSKLAPPEN] Const MaxPoints = 20
Global TestMode = 0 Global DB_CurrentPoint = 0 Type TPoint Field X# Field Y# End Type Function TPoint_Create.TPoint( pX#, pY# ) Local lPoint.TPoint = New TPoint lPoint\X = pX lPoint\Y = pY Return lPoint End Function Function TPoint_Destroy( pPoint.TPoint ) Delete pPoint End Function Type TFigure Field Constr_.TPoint[ MaxPoints ] Field Point_.TPoint[ MaxPoints ] Field Acc_.TPoint[ MaxPoints ] Field PointCount% End Type Function TFigure_Create.TFigure () Local lFigure.TFigure = New TFigure lFigure\PointCount = 0 Return lFigure End Function Function TFigure_AddPoint( pFigure.TFigure, pX#, pY# ) If pFigure\PointCount < MaxPoints Then pFigure\PointCount = pFigure\PointCount + 1 pFigure\Constr_[ pFigure\PointCount - 1 ] = TPoint_Create( pX, pY ) pFigure\Point_[ pFigure\PointCount - 1 ] = TPoint_Create( pX, pY ) pFigure\Acc_[ pFigure\PointCount - 1 ] = TPoint_Create( 0, 0 ) Return True Else Return False EndIf End Function Function TFigure_Destroy( pFigure.TFigure ) For i = 0 To pFigure\PointCount - 1 TPoint_Destroy( pFigure\Acc_[i] ) TPoint_Destroy( pFigure\Point_[i] ) TPoint_Destroy( pFigure\Constr_[i] ) Next Delete pFigure End Function Graphics 800, 600, 0, 2 SetBuffer BackBuffer() Figure.TFigure = TFigure_Create() TFigure_AddPoint( Figure, 400-100, 300-100 ) TFigure_AddPoint( Figure, 400+100, 300-100 ) TFigure_AddPoint( Figure, 400+100, 300+100 ) TFigure_AddPoint( Figure, 400-100, 300+100 ) While Not KeyDown( 1 ) Cls If KeyHit( 57 ) Then TestMode = 1 - TestMode DB_CurrentPoint = (DB_CurrentPoint + MouseZSpeed() + 4 * 4) Mod 4 Text 1,1,DB_CurrentPoint UpdateFigures ShowFigures Flip Wend TFigure_Destroy( Figure ) End Function UpdateFigures() Local lFigure.TFigure Local lStress#, lAngle#, lX1#, lY1#, lX2#, lY2# For lFigure = Each TFigure For i = 0 To lFigure\PointCount - 1 lFigure\Acc_[i]\Y = lFigure\Acc_[i]\Y + Sgn( 10 - lFigure\Acc_[i]\Y ) lFigure\Point_[i]\X = lFigure\Point_[i]\X + lFigure\Acc_[i]\X lFigure\Point_[i]\Y = lFigure\Point_[i]\Y + lFigure\Acc_[i]\Y If lFigure\Point_[i]\X < 0 Then lFigure\Point_[i]\X = 0 lFigure\Acc_[i]\X = -lFigure\Acc_[i]\X * 0.75 If lFigure\Point_[i]\X > GraphicsWidth() Then lFigure\Point_[i]\X = GraphicsWidth() lFigure\Acc_[i]\X = -lFigure\Acc_[i]\X * 0.75 If lFigure\Point_[i]\Y < 0 Then lFigure\Point_[i]\Y = 0 lFigure\Acc_[i]\Y = -lFigure\Acc_[i]\Y * 0.75 If lFigure\Point_[i]\Y > GraphicsHeight() Then lFigure\Point_[i]\Y = GraphicsHeight() lFigure\Acc_[i]\Y = -lFigure\Acc_[i]\Y * 0.75 If MouseDown( 1 ) Then lFigure\Point_[DB_CurrentPoint]\X = MouseX() lFigure\Point_[DB_CurrentPoint]\Y = MouseY() EndIf For j = 0 To lFigure\PointCount - 1 If i <> j Then lX1 = lFigure\Point_[i]\X lY1 = lFigure\Point_[i]\Y lX2 = lFigure\Point_[j]\X lY2 = lFigure\Point_[j]\Y lStress = Distance( lX1, lY1, lX2, lY2 ) - Distance( lFigure\Constr_[i]\X, lFigure\Constr_[i]\Y, lFigure\Constr_[j]\X, lFigure\Constr_[j]\Y ) lAngle = Angle( lX1, lY1, lX2, lY2 ) lFigure\Point_[i]\X = lFigure\Point_[i]\X + Cos( lAngle ) * lStress / 2 lFigure\Point_[i]\Y = lFigure\Point_[i]\Y + Sin( lAngle ) * lStress / 2 lFigure\Point_[j]\X = lFigure\Point_[j]\X - Cos( lAngle ) * lStress / 2 lFigure\Point_[j]\Y = lFigure\Point_[j]\Y - Sin( lAngle ) * lStress / 2 If TestMode Then lX1 = lFigure\Point_[i]\X lY1 = lFigure\Point_[i]\Y lX2 = lFigure\Point_[j]\X lY2 = lFigure\Point_[j]\Y DB_StressCol# = Abs( lStress / 300 ) Color DB_StressCol * 255, ( 1 - DB_StressCol ) * 255, 20 Line lX1, lY1, lX1 + Cos( lAngle ) * lStress, lY1 + Sin( lAngle ) * lStress Oval lX1 + Cos( lAngle ) * lStress - 3, lY1 + Sin( lAngle ) * lStress - 3, 6, 6, 0 Color 255, 0, 0 Oval lX1 + Cos( lAngle ) * lStress / 2 - 3, lY1 + Sin( lAngle ) * lStress / 2 - 3, 6, 6, 0 Color 225, 125, 0 Line lX1, lY1, lX1 + Cos( lAngle ) * 25, lY1 + Sin( lAngle ) * 25 Color 255, 0, 0 Text lX1 + 3, lY1 + 3, i Color 0, 125, 255 Text lX1 + Cos( lAngle ) * 25, lY1 + Sin( lAngle ) * 25, j EndIf EndIf Next Next Next End Function Function ShowFigures() Local lFigure.TFigure Color 255, 255, 255 For lFigure = Each TFigure For i = 0 To lFigure\PointCount - 1 If TestMode Then Oval lFigure\Point_[i]\X - 4, lFigure\Point_[i]\Y - 4, 8, 8, 0 Else ;Oval lFigure\Point_[i]\X - 4, lFigure\Point_[i]\Y - 4, 8, 8, 0 Line lFigure\Point_[i]\X, lFigure\Point_[i]\Y, lFigure\Point_[( i + 1 ) Mod 4]\X, lFigure\Point_[( i + 1 ) Mod 4]\Y Text lFigure\Point_[i]\X + 5, lFigure\Point_[i]\Y, i EndIf Next Next End Function Function Distance#( pX1#, pY1#, pX2#, pY2# ) Return Sqr( ( pX2 - pX1 ) ^ 2 + ( pY2 - pY1 ) ^ 2 ) End Function Function Angle#( pX1#, pY1#, pX2#, pY2# ) Return ( 450 - ATan2( pX2 - pX1, pY2 - pY1 ) ) Mod 360 End Function |
||
Dies ist ein Text, der an jeden Beitrag von dir angehängt werden kann. Es besteht eine Limit von 500 Buchstaben.
Zuletzt bearbeitet von CodeMaster am Mo Apr 01, Parse error: syntax error, unexpected ';' in htdocs\viewtopic.php on line 102 |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group