Python - Ayuda para desarrollar un juego en python con pygame

 
Vista:

Ayuda para desarrollar un juego en python con pygame

Publicado por Sergio yance (1 intervención) el 26/10/2015 22:23:48
Hola, necesito ayuda con un juego que debo realizar, se trata de don key kong classic del 89. No tengo muy claro como hacer el mapa del juego y a su vez un generador aleatereo de los mapas, y algunos comandos con los sprites com el saltar y definir bien las clases de los barriles, ayuda por favor. Gracias
Esto es lo que llevo en el momento.
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#----------------------------------------------------------------------
import pygame
 
 
pygame.init()
alto=800
ancho=600
 
window = pygame.display.set_mode((alto,ancho))
 
pygame.display.set_caption("Don King Kong by Sergio Yance")
 
black = (255,255,255)
rojo=(233,73,73)
 
 
moveX,moveY=0,0
 
clock = pygame.time.Clock()
 
class Pared(pygame.sprite.Sprite):
    width = 0
    height = 0
    """ Pared con la que el protagonista puede encontrarse. """
    def __init__(self, x, y, largo, alto):
        """ Constructor para la pared con la que el protagonista puede encontrarse """
        #  Llama al constructor padre
        pygame.sprite.Sprite.__init__(self)
 
        width = largo
        height = alto
        # Construye una pared con las dimensiones especificadas por los parámetros
        self.image = pygame.Surface([largo, alto])
        self.image.fill(pygame.color.Color(50, 50, 50))
        self.image.fill(rojo)
 
 
        # Establece como origen la esquina superior izquierda.
        self.rect = self.image.get_rect()
        self.rect.y = y
        self.rect.x = x
 
 
 
 
class Sprite:
 
    paredes = None
    def __init__(self,x,y):
 
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface([50, 50])
        self.image.fill(pygame.color.Color(255, 255, 255))
        self.x=5
        self.y=530
        self.width=30
        self.height=30
        self.i0 = pygame.image.load("m1.png")
        self.i1 = pygame.image.load("m2.png")
        self.timeTarget=10
        self.timeNum=0
        self.currentImage=0
        self.rect = self.image.get_rect()
        self.rect.y = y
        self.rect.x = x
        cambio_x=0
        cambio_y=0
    def jump(self):
        self.rect.y=+2
        lista_impactos_bloques = pygame.sprite.spritecollide(player, player.paredes, False)
        self.rect.y -=2
        if len(ista_impactos_bloques) > 0:
            self.cambio_y=-10
    def calc_grav(self):
        if self.cambio_y==0:
            self.cambio_y=1
        else:
            self.cambio_y+=.35
        if self.rect.y >= alto -self.rect.height and self.cambio_y >= 0:
            self.cambio_y=0
            self.rect.y= alto-self.rect.height
 
 
    def update(self):
 
 
        self.timeNum+=1
 
        if (self.timeNum==self.timeTarget):
 
            if (self.currentImage==0):
 
                self.currentImage=1
 
            else:
 
                self.currentImage=0
 
            self.timeNum=0
 
        self.render()
 
    def render(self):
 
        if (self.currentImage==0):
 
            window.blit(self.i0, (self.x,self.y))
 
        else:
 
            window.blit(self.i1, (self.x,self.y))
 
 
player=Sprite(100,150)
gameLoop=True
 
pared_list = pygame.sprite.Group()
 
#agregar paredes
w = 800
pared = Pared(0,560,w,800)
pared.width = w
 
 
w = 300
pared1 = Pared(0,50,w,15)
pared1.width = w
 
pared_list.add(pared)
pared_list.add(pared1)
 
player.paredes = pared_list
 
while gameLoop:
 
    for event in pygame.event.get():
 
        if (event.type==pygame.QUIT):
 
            gameLoop=False
 
        if (event.type==pygame.KEYDOWN):
 
            if (event.key==pygame.K_LEFT):
 
                moveX = -3
 
            if (event.key==pygame.K_RIGHT):
 
                moveX = 3
 
            if (event.key==pygame.K_UP):
 
                moveY = -3
 
            if (event.key==pygame.K_DOWN):
 
                moveY = 3
 
        if (event.type==pygame.KEYUP):
 
            if (event.key==pygame.K_LEFT):
 
                moveX=0
 
            if (event.key==pygame.K_RIGHT):
 
                moveX=0
 
            if (event.key==pygame.K_UP):
 
                Sprite.jump
 
            if (event.key==pygame.K_DOWN):
 
                moveY=0
 
    lista_impactos_bloques = pygame.sprite.spritecollide(player, player.paredes, False)
 
    for bloque in lista_impactos_bloques:
        if moveX > 0:
            if player.x + moveX > (bloque.rect.x + bloque.width) - player.width:
                moveX = 0
        else:
            if player.x + moveX < (bloque.rect.x):
                moveX = 0
        if moveY > 0:
            if player.y + moveY>(bloque.rect.y+bloque.width)-player.width:
                moveY= 0
            else:
                if player.y +moveY<(bloque.rect.y):
                    moveY= 0
 
 
    window.fill((0,0,0))
 
    player.x+=moveX
 
    player.y+=moveY
 
    player.rect.x = player.x
    player.rect.y = player.y
 
 
    player.update()
 
 
    pared1.width = window.blit(pared.image, (pared.rect.x, pared.rect.y))
    window.blit(pared1.image, (pared1.rect.x, pared1.rect.y))
 
 
 
 
    clock.tick(50)
 
    pygame.display.flip()
 
 
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