Funciona con un par de variables, por supuesto que solo es la base del movimiento de un objeto.
Obs: La idea principal para el movimiento del objeto es de "Edwin Macz" un compañero de trabajo.
Este es el código:
PUBLIC oForm1 oForm1 = NEWOBJECT("Form1") oForm1.SHOW(1) RETURN DEFINE CLASS Form1 AS FORM HEIGHT = 307 WIDTH = 447 DOCREATE = .T. AUTOCENTER = .T. CAPTION = "Ping-Pong" BACKCOLOR = RGB(0,128,255) NAME = "Form1" ADD OBJECT bola AS SHAPE WITH ; TOP = 0, ; LEFT = 0, ; HEIGHT = 23, ; WIDTH = 26, ; CURVATURE = 75, ; BACKCOLOR = RGB(255,255,0), ; NAME = "bola" ADD OBJECT timer1 AS TIMER WITH ; TOP = 0, ; LEFT = 420, ; HEIGHT = 23, ; WIDTH = 23, ; NAME = "Timer1" ADD OBJECT barra AS COMMANDBUTTON WITH ; TOP = 200, ; LEFT = 171, ; HEIGHT = 13, ; WIDTH = 108, ; CAPTION = "", ; BACKCOLOR = RGB(0,0,160), ; NAME = "barra" ADD OBJECT lblb2 AS COMMANDBUTTON WITH ; TOP = 200, ; LEFT = 171, ; HEIGHT = 13, ; WIDTH = 4, ; CAPTION = "", ; BACKCOLOR = RGB(128,0,0), ; NAME = "LblB2" PROCEDURE INIT THISFORM.timer1.INTERVAL = 5 PUBLIC x AS INTEGER, Y AS INTEGER, vCont AS INTEGER STORE 1 TO x, Y vCont = 0 ENDPROC PROCEDURE MOUSEMOVE LPARAMETERS nButton, nShift, nXCoord, nYCoord THISFORM.barra.LEFT = nXCoord THISFORM.lblb2.LEFT = nXCoord ENDPROC PROCEDURE timer1.TIMER THISFORM.bola.LEFT = THISFORM.bola.LEFT + x THISFORM.bola.TOP = THISFORM.bola.TOP + Y vcol1 = INT(RAND()*256) vcol2 = INT(RAND()*256) vcol3 = INT(RAND()*256) IF THISFORM.bola.LEFT + THISFORM.bola.WIDTH => THISFORM.WIDTH x = -1 ELSE IF THISFORM.bola.LEFT = 0 x = 1 ENDIF ENDIF IF THISFORM.bola.TOP + THISFORM.bola.HEIGHT => THISFORM.HEIGHT Y = -1 ELSE IF THISFORM.bola.TOP = 0 Y = 1 ENDIF ENDIF IF THISFORM.bola.TOP + THISFORM.bola.HEIGHT = THISFORM.barra.TOP ; AND THISFORM.bola.LEFT + THISFORM.bola.WIDTH >= THISFORM.barra.LEFT ; AND THISFORM.bola.LEFT <= THISFORM.barra.LEFT + THISFORM.barra.WIDTH THISFORM.bola.BACKCOLOR = RGB(vcol1,vcol2,vcol3) Y = -1 IF THISFORM.lblB2.WIDTH < THISFORM.barra.WIDTH THISFORM.lblB2.WIDTH = THISFORM.lblB2.WIDTH + 10 ELSE MESSAGEBOX("Finalizado") THISFORM.RELEASE ENDIF ENDIF IF THISFORM.bola.TOP = THISFORM.barra.TOP + THISFORM.barra.HEIGHT ; AND THISFORM.bola.LEFT + THISFORM.bola.WIDTH >= THISFORM.barra.LEFT ; AND THISFORM.bola.LEFT <= THISFORM.barra.LEFT + THISFORM.barra.WIDTH THISFORM.bola.BACKCOLOR=RGB(vcol1,vcol2,vcol3) Y = 1 IF THISFORM.lblB2.WIDTH >10 THISFORM.lblB2.WIDTH = THISFORM.lblB2.WIDTH - 10 ENDIF ENDIF ENDPROC ENDDEFINE
Otto Pérez
Disculpa ..soy principiante y pues tengo mis dudas basicamente en el segnificado de ciertas comandos y/o variables ..como por ejemplo en la codificacion de la bola que es= "Vcol1"? no se si serias tan amable de explicarme cual es la funcion de eso.. y que es "x" y "Y" porque no la declaraste o al menos no lo vi.
ResponderBorrarMuchas gracias (si me funciono solo quisiera saber un poco sobre cada cosa que utilizaste especialmente en la codificacion de la bola)