-
Notifications
You must be signed in to change notification settings - Fork 1
/
de.py
142 lines (111 loc) · 4.92 KB
/
de.py
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
# Copyright 2015 Demasse Gregoire Balu tristan
""" This file is part of Blindial.
Blindial is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Blindial is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Blindial. If not, see http://www.gnu.org/licenses/.
"""
# -*-coding: utf8 -*-
import pygame
from random import *
from pygame.locals import *
from fonction_Q import *
from fct_affichage import *
from fct_rect import *
from fct_texte import *
from rect_cases import *
from random import choice
import pygame.gfxdraw
###########################
def animation_de(fenetre_jeu):
image_de = ['Images/De1.png', 'Images/De2.png',
'Images/De3.png', 'Images/De4.png']
for i in range(10):
de_face = randint(1,4)
surface_de = pygame.image.load(image_de[de_face-1]).convert_alpha()
fenetre_jeu.blit(surface_de, (1100, 100))
pygame.display.flip()
pygame.time.wait(200)
def lancer_de():
image_de = ['Images/De1.png', 'Images/De2.png',
'Images/De3.png', 'Images/De4.png']
de_point = randint(1, 4)
surface_de = pygame.image.load(image_de[de_point-1]).convert_alpha()
return de_point, surface_de
def verif_case(pos_player, de, liste_case):
"""renvoie la liste des cases ou le joueur peut aller"""
cases_possibles = []
for n in range(-de, de+1):
for c in liste_case:
#si les pos x et y sont a 'de' cases de distance
if c.x == pos_player[0] + (n*68) and\
(c.y == pos_player[1] + ((abs(n)-de)*68) or c.y == pos_player[1] + ((abs(n)-de)*-68)):
#on ajoute la case aux cases possibles
cases_possibles.append(c)
if de == 4:
#on enleve les cases a 4 de distance qu'on ne peut pas atteindre sans tricher
#c.a.d sans passer par des cases qui n'existent pas
if not(pygame.rect.Rect(pos_player[0] + 68, pos_player[1], 62, 62) in liste_case
or pygame.rect.Rect(pos_player[0] - 68, pos_player[1], 62, 62) in liste_case) :
#si il n'y a pas de cases a droite ou a gauche du joueur
for c in cases_possibles[:]:
if (pygame.rect.Rect(pos_player[0] + 4*68, pos_player[1], 62, 62) == c
or pygame.rect.Rect(pos_player[0] - 4*68, pos_player[1], 62, 62) == c):
#on supprime de la liste les cases a 4 de distance en ligne droite
cases_possibles.remove(c)
#on fait la meme chose pour les coordonnes en y
elif not(pygame.rect.Rect(pos_player[0], pos_player[1] + 68, 62, 62) in liste_case
or pygame.rect.Rect(pos_player[0], pos_player[1] - 68, 62, 62) in liste_case) :
#si il n'y a pas de cases au dessus ou en dessous du joueur
for d in cases_possibles[:]:
if (pygame.rect.Rect(pos_player[0], pos_player[1] - 4*68, 62, 62) == d
or pygame.rect.Rect(pos_player[0], pos_player[1] + 4*68, 62, 62) == d):
#on supprime de la liste les cases a 4 de distance en ligne droite
cases_possibles.remove(d)
return cases_possibles
def contour(cases_possibles, joueur, fenetre_jeu):
j = pygame.surface.Surface((62, 62))
j.fill((0, 0, 0))
j.set_colorkey((0,0,0))
pygame.gfxdraw.rectangle(j, (0,0, 62, 62), (0, 255, 0))
fenetre_jeu.blit(j, joueur)
for c in cases_possibles :
s = pygame.surface.Surface((62, 62))
s.fill((0, 0, 0))
s.set_colorkey((0,0,0))
pygame.gfxdraw.rectangle(s, (0,0, 62, 62), (1, 0, 0))
fenetre_jeu.blit(s, c.topleft)
if __name__ == '__main__':
import pygame
import pygame.gfxdraw
from pygame.locals import *
pygame.init()
fenetre_jeu = pygame.display.set_mode((1280, 720))
fond = pygame.image.load('Images/flygame.jpg')
fenetre_jeu.blit(fond, (0,0))
def test(fenetre_jeu, fond):
a, b, c, d, e, f, r, liste_case = rect_cases()
joueur = choice(liste_case)
print(joueur)
de, surf = lancer_de()
print(de)
cases_possibles = verif_case(joueur, 4, liste_case)
print(cases_possibles)
fenetre_jeu.blit(fond, (0,0))
contour(cases_possibles, joueur, fenetre_jeu)
run = True
while run :
for event in pygame.event.get():
if event.type == QUIT:
run = False
if event.type == KEYDOWN:
if event.key == K_SPACE:
test(fenetre_jeu, fond)
pygame.display.flip()
pygame.quit()