Python - duda: movimiento paleta derecha con el mouse(turtle, juego pong)

 
Vista:
sin imagen de perfil
Val: 6
Ha disminuido su posición en 20 puestos en Python (en relación al último mes)
Gráfica de Python

duda: movimiento paleta derecha con el mouse(turtle, juego pong)

Publicado por israel (3 intervenciones) el 13/06/2022 02:25:30
hola , tengo una duda. como puedo mover la paleta con el mouse en vez de con los botones
y que se reinicie a los 15 puntos. e buscado y pensado pero siempre es error.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import turtle as t
import os
#import winsound #sonido windows
 
 
 
#ventana del juego
p=t.Screen()
p.title("Pong Game")
p.bgcolor("black")
p.setup(width=800,height=600)
 
 
 
 
#Pale izquierdo
pady=t.Turtle()
pady.speed(0)
pady.shape("square")
pady.color("orange")
pady.shapesize(stretch_wid=6,stretch_len=2)
pady.penup()
pady.goto(-350,0)
 
 
 
#Pale derecho
padx=t.Turtle()
padx.speed(0)
padx.shape("square")
padx.color("orange")
padx.shapesize(stretch_wid=6,stretch_len=2)
padx.penup()
padx.goto(350,0)
 
 
#pelota
pelota=t.Turtle()
pelota.speed(100)
pelota.shape("circle")
pelota.color("red")
pelota.penup()
pelota.goto(5,5)
pelotaxdire= 8
pelotaydire= -8
 
#puntaje
pu=t.Turtle()
pu.speed(0)
pu.color("white")
pu.penup()
pu.hideturtle()
pu.goto(0,260)
 
#Contador:
Jugador1 = 0
Jugador2 = 0
sketch = t.Turtle()
sketch.speed(0)
sketch.color("red")
sketch.penup()
sketch.hideturtle()
sketch.goto(0, 260)
sketch.write("Jugador1 : 0    Jugador2: 0",align="center", font=("Courier", 24, "normal"))
 
 
 
#MovVerticalPale:
def paddleaup():
    y = pady.ycor()
    y += 20
    pady.sety(y)
 
def paddleadown():
    y = pady.ycor()
    y -= 20
    pady.sety(y)
 
def paddlebup():
    y = padx.ycor()
    y += 20
    padx.sety(y)
 
def paddlebdown():
    y = padx.ycor()
    y -= 20
    padx.sety(y)
 
#def TeclasMovPaletas():
t.listen()
t.onkeypress(paddleaup, "e")
t.onkeypress(paddleadown, "x")
t.onkeypress(paddlebup, "e")
t.onkeypress(paddlebdown, "x")
 
 
while True:
    t.update()
 
    pelota.setx(pelota.xcor()+ pelotaxdire)
    pelota.sety(pelota.ycor()+ pelotaydire)
 
    if pelota.ycor() > 280:
        pelota.sety(280)
        pelotaydire *= -1
        #winsound.PlaySound("bounce.wav",winsound.SND_ASYNC)
        os.system("aplay bounce.wav&")
 
    if pelota.ycor() < -280:
        pelota.sety(-280)
        pelotaydire *= -1
        #winsound.PlaySound("bounce.wav",winsound.SND_ASYNC)
        #os.system("aplay bounce.wav&")
 
    if pelota.xcor() > 500:
        pelota.goto(0, 0)
        pelotaydire *= -1
        Jugador1 += 1
        sketch.clear()
        sketch.write("Jugador1 :{}    Jugador2 : {}".format(
                      Jugador1, Jugador2), align="center",
                      font=("Courier", 24, "normal"))
 
    if pelota.xcor() < -500:
        pelota.goto(0, 0)
        pelotaydire *= -1
        Jugador2 += 1
        sketch.clear()
        sketch.write("Jugador1 : {}    Jugador2: {}".format(
                                 Jugador1, Jugador2), align="center",
                                 font=("Courier", 24, "normal"))
 
    #def BordeDePaleta():
    if (pelota.xcor() > 310):
        if (pelota.xcor() < 370):
            if (pelota.ycor() < padx.ycor()+60):
                if (pelota.ycor() > padx.ycor()-60):
                    pelota.setx(310)
                    pelotaxdire*=-1
 
    if (pelota.xcor()<-310):
        if (pelota.xcor()>-370):
            if (pelota.ycor()<pady.ycor()+60):
                if (pelota.ycor()>pady.ycor()-60):
                    pelota.setx(-310)
                    pelotaxdire*=-1
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil

duda: movimiento paleta derecha con el mouse(turtle, juego pong)

Publicado por Rolando José (44 intervenciones) el 18/06/2022 01:05:56
Te felicito me gusto mucho tu juego solame te le cambie para que tambien funcionara con w y z la raqueta izquierda y yo creo que no es necesario el uso del mouse. Yo voy z ver si lo paso a tkinter xq el manejo de eventos en tkinter es mas facil y ahi si podria usar el mouse para mover la raqueta que este bajo el mouse.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar