Page 1 sur 1

[R] Pong problème

Posté : sam. 14 nov. 2015 11:46
par sozary
Bonjour à tous!

Je faisais juste un petit test en autoit afin de tester un pong. Bon alors ça marche bien, mais la balle semble saccadé...

voyez par vous même:

Code : Tout sélectionner

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

OnAutoItExitRegister("_Close")
Global $vitesse=10
Global $angle=-45
Global $FPS=25
Global $TimeUntilOtherPic=(1/$FPS)*1000
Global $xB=640/2,$yB=480/2
Global $iW = 640, $iH = 480,$colour

Global $Form1 = GUICreate("Pong", $iW, $iH)

_GDIPlus_Startup()
$hGraphics=_GDIPlus_GraphicsCreateFromHWND($Form1)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hBackbuffer,0xFFFFFFFF)
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")
GUISetState(@SW_SHOW)

initBall($hGraphics)

$temps=TimerInit()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch

    if TimerDiff($temps)>=$TimeUntilOtherPic Then
        $temps=TimerInit()
    if $xB>=$iW or $xB<=0 then
        calc_vert()
    ElseIf $yB>=$iH or $yB<=0 Then
        calc_hor()
    EndIf
        deplace($hGraphics,$angle,$vitesse)
    EndIf

WEnd


func initBall($hGraph)
    _GDIPlus_GraphicsFillEllipse2($hGraph,$iW/2,$iH/2,5)
EndFunc


Func calc_hor()
    $angle=360-$angle
EndFunc

Func calc_vert()
    $angle=180-$angle
EndFunc

Func deplace($graph,$angle,$vitesse)
    $temp=(3.141592654*$angle)/180
    _GDIPlus_GraphicsFillEllipse2($graph,$xB,$yB,5,0xFFFFFFFF)
    $xB+=$vitesse*Cos($temp)
    $yB+=$vitesse*sin($temp)
    _GDIPlus_GraphicsFillEllipse2($graph,$xB,$yB,5)
EndFunc

Func _GDIPlus_GraphicsFillEllipse2($hGrap, $x,$y,$r,$color=0xFF000000)
    $colour=_GDIPlus_BrushCreateSolid($color)
    _GDIPlus_GraphicsFillEllipse($hGrap,$x-($r/2),$y-($r/2),$r,$r,$colour)
EndFunc

Func WM_ERASEBKGND()
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
        Return 1
EndFunc
Func _Close()
    GUIRegisterMsg($WM_ERASEBKGND, "")
    _GDIPlus_BrushDispose($colour)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($Form1)
    Exit
EndFunc

Re: [..] Pong problème

Posté : sam. 14 nov. 2015 16:12
par mikell
Hello le scientifique :wink:
Sur ma vieille machine le résultat est meilleur en baissant à la fois $vitesse et $TimeUntilOtherPic
Le petit effet saccadé restant est probablement dû au hardware

Re: [..] Pong problème

Posté : sam. 14 nov. 2015 17:14
par sozary
C'est donc ça! Oui d'accord, de toute façon c'était juste pour tester hein!
merci!

Re: [R] Pong problème

Posté : lun. 16 nov. 2015 16:43
par mdanielm
Sujet résolu un peu rapidement!
Ci dessous je crée la balle dans un bitmap, que je sauvegarde, même si ce n'est pas utile
et je déplace le bitmap de façon à ne pas reconstruire la balle à chaque pas de calcul.
Il me semble que c'est mieux. Qu'en pensez-vous?
Exercices:
1-Utiliser une matrice de rotation pour faire tourner la balle sur elle-même
2-Pourquoi ne pas utiliser une matrice de translation pour la déplacer?
► Afficher le texte

Re: [R] Pong problème

Posté : jeu. 19 nov. 2015 09:35
par sozary
Ah oui avec un bitmap c est mieux c est vrai :D !
Oui résolus rapidement, c est juste que j ai fait ça vite fait car je suis sur plein de trucs en même temps!

Re: [R] Pong problème

Posté : lun. 30 nov. 2015 22:37
par overflow
j ai recupe un script qui fait une peu pareil
► Afficher le texte