Python - Necesito desaparecer la moneda roja en pygame y no se como hacerlo

 
Vista:

Necesito desaparecer la moneda roja en pygame y no se como hacerlo

Publicado por Serch (1 intervención) el 31/10/2020 01:10:58
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import random
import pygame
 
pygame.init()
 
class Monedaroja(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load("images/monedaroja.png")
        self.rect = self.image.get_rect()
 
 
class Moneda(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load("images/moneda.png")
        self.rect = self.image.get_rect()
 
class Mario(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load("images/sprite/mario.png")
        self.rect = self.image.get_rect()
 
class Goomba(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()
        self.image = pygame.image.load("images/sprite/toadmalo.png")
        self.rect = self.image.get_rect()
# Coordenas
marioPosX = 250
marioPosY = 100
 
goombaPosX = 500
goombaPosY = 150
# Velocidad de coordenadas
x_speed = 0
y_speed = 0
# Radio de colisión
marioAncho = 89
marioAlto = 110
 
goombaAncho = 67
goombaAlto = 80
 
# monedaroja
monedarojaPosX = 0
monedarojaPosY = 0
 
# moneda
monedaPosX = 0
monedaPosY = 0
 
# Sirve para saber si cuando detener el bucle
done = False
# Variable para el Tamaño de la pantalla
size = (990, 619)
# Tamaño de la pantalla
screan = pygame.display.set_mode(size)
# El reloj me sirve para que no se vea buggeado al mover la imagen
clock = pygame.time.Clock()
# Sprites
fondo = pygame.image.load("images/fondo1.jpg")
gameOver = pygame.image.load("images/game_over.png") # agregar imagen
colorText = (0,0,0) # Color global
# declarar la fuente del texto
fuente = pygame.font.SysFont("Cooper", 50, bold=False, italic=False)
# vidas
vidas = 3
muertes = 0
text = ""
puntos = 0 #Ver el puntaje
txtPunntos = "" # texto para ver los puntos que llevo
# lista de sprite convertidos a grupos
moneda_list = pygame.sprite.Group()
monedaroja_list = pygame.sprite.Group()
all_sprite_list = pygame.sprite.Group()
 
## Crear moneda roja
for i in range(1):
    monedaroja = Monedaroja()
 
    monedaroja.rect.x = random.randrange(880)
    monedaroja.rect.y = random.randrange(550)
 
    monedaroja_list.add(monedaroja)
    all_sprite_list.add(monedaroja)
 
## Crear la cantidad de monedas en posiciones random
for i in range(10):
    moneda = Moneda()
 
    moneda.rect.x = random.randrange(880)
    moneda.rect.y = random.randrange(550)
 
    moneda_list.add(moneda)
    all_sprite_list.add(moneda)
## agregando los sprite de jugador y enemigo
mario = Mario()
goomba = Goomba()
all_sprite_list.add(mario)
all_sprite_list.add(goomba)
# poner sonido
sound = pygame.mixer.Sound("sounds/marioCoin.wav")
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        # Eventos del teclado clase 4
        if event.type == pygame.KEYDOWN:  # Si presiona la tecla
            if event.key == pygame.K_LEFT:
                x_speed = -3
            if event.key == pygame.K_RIGHT:
                x_speed = 3
            if event.key == pygame.K_UP:
                y_speed = -3
            if event.key == pygame.K_DOWN:
                y_speed = 3
 
        if event.type == pygame.KEYUP:  # Cuando suelta la tecla
            if event.key == pygame.K_LEFT:
                x_speed = 0
            if event.key == pygame.K_RIGHT:
                x_speed = 0
            if event.key == pygame.K_UP:
                y_speed = 0
            if event.key == pygame.K_DOWN:
                y_speed = 0
    # coordenaas para los sprite
    mario.rect.x = marioPosX
    mario.rect.y = marioPosY
 
    goomba.rect.x = goombaPosX
    goomba.rect.y = goombaPosY
    # Posiciones
    marioPosX += x_speed
    marioPosY += y_speed
 
    # Colisiones
    if marioPosX + marioAncho > goombaPosX and \
        marioPosX < goombaPosX + goombaAncho and \
        marioPosY + marioAlto > goombaPosY and \
        marioPosY < goombaPosY + goombaAlto:
        # Acción que deseo que realice el objeto o jugador
        marioPosX = 10
        marioPosY = 10
        # Restar vidas
        muertes = vidas - 1
        vidas = muertes
    all_sprite_list.update() # Actualiza todos los sprite
    monedaroja_hit_list = pygame.sprite.spritecollide(mario, monedaroja_list, True)
    moneda_hit_list = pygame.sprite.spritecollide(mario, moneda_list, True) # Para saber con cual sprite colisiono
    for moneda in moneda_hit_list:
        puntos += 1
        sound.play()
 
    for monedaroja in monedaroja_hit_list:
        puntos += 5
        sound.play()
 
 
    # Para ver el fondo de mi juego
    screan.blit(fondo,[0,0])
    # logica del gamer over
    if vidas == 0:
    	screan.blit(gameOver, [300, 0])
    else:
    	text = fuente.render("Vidas " + str(vidas), True, colorText)
    	screan.blit(text, [10,10])
 
    if vidas != 0:
        all_sprite_list.draw(screan)
        txtPunntos = fuente.render("Puntaje: "+ str(puntos), True, colorText);
        screan.blit(txtPunntos, [500,10])
 
    pygame.display.flip()
    clock.tick(60)
 
pygame.quit()
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