def draw(__): if not __.destroy: __.z += __.speed if 0 <= __.z <= K.longueur_map + 4 * __.longueur: glPushMatrix() glTranslatef(__.x, __.y, __.z) glScalef(__.largeur, __.largeur, __.longueur) glColor4ub(__.r, __.v, __.b, __.a) glCallList(__.liste_tir) glPopMatrix() temp = __.x, __.y, __.z __.gen.set_coords(temp, temp) for obj in K.obj: if K.bloc and obj.x + obj.rx2 >= __.x - __.largeur and obj.x - obj.rx2 <= __.x + __.largeur and\ obj.y + obj.ry2 >= __.y - __.largeur and obj.y - obj.ry2 <= __.y + __.largeur and\ obj.z + obj.rz2 >= __.z and obj.z - obj.rz2 <= __.z + __.longueur or\ not K.bloc and obj.z + obj.rz2 >= __.z and obj.z - obj.rz2 <= __.z + __.longueur and\ DISTANCE(__.x, __.y, obj.x, obj.y) <= obj.r2 + __.largeur: __.gen.reinit_particules() __.destroy = True if K.mode_jeu == 2: obj.vie -= 1 break else: K.tir.remove(__) else: if __.gen.particules: for i in __.gen.particules: i.z -= K.joueur.v/10. __.gen.draw() else: K.tir.remove(__)
def __init__(__, boss, coords=(), speeds_min=(0, 0, 0), speeds_max=(0, 0, 0), rxmin=K.largeur_mapH2 / 5, rxmax=K.largeur_mapH2 / 3, rymin=K.largeur_mapV2 / 5, rymax=K.largeur_mapV2 / 3, rzmin=0, rzmax=0, auto_destruction=False, vie=1): K.obj.append(__) __.boss = boss __.vie_max = vie __.vie = vie if rxmin > rxmax: rxmin, rxmax = rxmax, rxmin elif rxmax == rxmin: rxmax += 1 if rymin > rymax: rymin, rymax = rymax, rymin elif rymax == rymin: rymax += 1 __.rx_max = int(rxmax) __.rx_min = int(rxmin) __.ry_max = int(rymax) __.ry_min = int(rymin) if rzmax: __.rz_max = int(rzmax) else: __.rz_max = int(DISTANCE(0, 0, __.rx_max, __.ry_max)) if rzmin: __.rz_min = int(rzmin) else: __.rz_min = int(DISTANCE(0, 0, __.rx_min, __.ry_min)) if __.rz_min > __.rz_max: __.rz_min, __.rz_max = __.rz_max, __.rz_min elif __.rz_max == __.rz_min: __.rz_max += 1 __.xs_min, __.ys_min, __.zs_min = speeds_min __.xs_max, __.ys_max, __.zs_max = speeds_max if __.xs_min > __.xs_max: __.xs_min, __.xs_max = __.xs_max, __.xs_min if __.ys_min > __.ys_max: __.ys_min, __.ys_max = __.ys_max, __.ys_min if __.zs_min > __.zs_max: __.zs_min, __.zs_max = __.zs_max, __.zs_min __.coords = coords __.len_coords = len(coords) __.auto_destruction = auto_destruction __.new_coords()
def draw(__): if not __.destroy: if K.mode_cylindre: __.angle = (__.angle + __.xs) % 360 temp = __.r + __.ys if 2 + __.rayon <= temp < K.largeur_mapH2 - __.rayon: __.r = temp elif temp < 2 + __.rayon: __.r = 2 + __.rayon __.ys = -__.ys else: __.r = K.largeur_mapH2 - __.rayon __.ys = -__.ys cos, sin = CoSinus(__.angle) __.x = cos * __.r __.y = sin * __.r else: tempc = __.x + __.xs templ = K.largeur_mapH2 - __.rayon if -templ <= tempc <= templ: __.x = tempc else: __.xs = -__.xs if -templ > tempc: __.x = -templ else: __.x = templ tempc = __.y + __.ys templ = K.largeur_mapV2 - __.rayon if -templ <= tempc <= templ: __.y = tempc else: __.ys = -__.ys if -templ > tempc: __.y = -templ else: __.y = templ __.z += __.zs - K.joueur.v if __.z < -__.rayon: __.z = -__.rayon elif __.z > K.longueur_map * 2: __.z = K.longueur_map * 2 __.zs += K.joueur.vadd * (1 + 9 * __.accelere) if randrange(100) == 50: __.accelere = not __.accelere temp = __.x, __.y, __.z __.gen.set_coords(temp, temp) glPushMatrix() glTranslatef(__.x, __.y, __.z) glScalef(__.rayon, __.rayon, __.rayon) glCallList(__.boss.liste_sphere) glPopMatrix() for tir in K.tir: if __.z + __.rayon >= tir.z and __.z - __.rayon <= tir.z + tir.longueur and\ DISTANCE(__.x, __.y, tir.x, tir.y) <= __.rayon + tir.longueur: __.gen.reinit_particules() tir.destroy = __.destroy = True break else: if __.gen.particules: for i in __.gen.particules: i.z -= K.joueur.v / 10. __.gen.draw()
def collision_joueur(__, jx, jy): if K.bloc and __.x - __.rx2 < jx < __.x + __.rx2 and __.y - __.ry2 < jy < __.y + __.ry2 or\ not K.bloc and DISTANCE(__.x, __.y, jx, jy) < __.r2: K.joueur.score -= ((180 - K.joueur.v) / 720) * K.joueur.score if K.joueur.v > 30: K.joueur.v -= 30 else: K.joueur.v = 0 __.accelere = False __.collision = True K.joueur.vie -= 1 __.play = True if K.joueur.vie: __.son_collision.play() else: K.joueur.son_panne.play() K.joueur.channel_avance.stop() pygame.mixer.music.fadeout(5000)
def new_coords(__): __.vie = __.vie_max __.collision = False __.rx = randint(__.rx_min, __.rx_max) __.rx2 = __.rx / 2. __.ry = randint(__.ry_min, __.ry_max) __.ry2 = __.ry / 2. __.rz = randint(__.rz_min, __.rz_max) __.rz2 = __.rz / 2. __.r2 = DISTANCE(0, 0, __.rx, __.ry) / 2. __.xs = randint(__.xs_min, __.xs_max) / 100. __.ys = randint(__.ys_min, __.ys_max) / 100. __.zs = randint(__.zs_min, __.zs_max) / 100. if not __.len_coords or __.len_coords == 1: if K.mode_cylindre: angle = random() * 360 temp_min, temp_max = 2 + int(__.ry2), K.largeur_mapH2 - int( __.ry2) if temp_min > temp_max: temp_min, temp_max = temp_max, temp_min r_cylindre = randint(temp_min, temp_max) cos, sin = CoSinus(angle) __.x = cos * r_cylindre __.y = -sin * r_cylindre else: temp = int(K.largeur_mapH2 - __.rx2) __.x = randint(-temp, temp) temp = int(K.largeur_mapV2 - __.ry2) __.y = randint(-temp, temp) if __.len_coords == 1: __.z = __.coords[0] else: __.z = randint(K.longueur_map + int(__.rz2), K.longueur_map * 2 - int(__.rz2)) elif __.len_coords == 3: __.x, __.y, __.z = __.coords elif __.len_coords == 2: __.x, __.y = __.coords __.z = randint(K.longueur_map + int(__.rz2), K.longueur_map * 2 - int(__.rz2)) __.play = False
def draw(__): jx, jy = K.joueur.x, K.joueur.y __.z -= K.joueur.v10 - __.zs if __.z > K.longueur_map * 3: __.new_coords() if not K.no_grav: if K.mode_cylindre: r_cylindre = DISTANCE(0, 0, __.x, __.y) if r_cylindre + K.grav < K.largeur_mapH2 - 0.1: r_cylindre += K.grav elif r_cylindre >= K.largeur_mapH2: r_cylindre = K.largeur_mapH2 cos, sin = CoSinus(DIRECTION(0, 0, __.x, __.y) + __.xs) __.x = cos * r_cylindre __.y = -sin * r_cylindre else: if K.grav_dir == 0: temp = __.ry2 * K.bloc - K.largeur_mapV2 + 0.1 if __.y - K.grav > temp: __.y -= K.grav else: __.y = temp elif K.grav_dir == 1: temp = -__.rx2 * K.bloc + K.largeur_mapH2 - 0.1 if __.x + K.grav < temp: __.x += K.grav else: __.x = temp elif K.grav_dir == 2: temp = -__.ry2 * K.bloc + K.largeur_mapV2 - 0.1 if __.y + K.grav < temp: __.y += K.grav else: __.y = temp elif K.grav_dir == 3: temp = __.rx2 * K.bloc - K.largeur_mapH2 + 0.1 if __.x - K.grav > temp: __.x -= K.grav else: __.x = temp if K.mode_cylindre: if K.no_grav: temp = DISTANCE(0, 0, __.x, __.y) + __.ys if 2 + __.r2 / 2 <= temp <= K.largeur_mapH2 - 0.1: r_cylindre = temp elif temp >= K.largeur_mapH2 - 0.1: r_cylindre = K.largeur_mapH2 - 0.1 __.ys = -__.ys elif temp < 2 + __.r2 / 2: r_cylindre = 2 + __.r2 / 2 __.ys = -__.ys cos, sin = CoSinus(DIRECTION(0, 0, __.x, __.y) + __.xs) __.x = cos * r_cylindre __.y = -sin * r_cylindre else: if K.no_grav or 1 != K.grav_dir != 3: temp = -__.rx2 * K.bloc + K.largeur_mapH2 - 0.1 if -temp <= __.x + __.xs <= temp: __.x += __.xs elif -temp > __.x + __.xs: __.x = -temp __.xs = -__.xs elif temp < __.x + __.xs: __.x = temp __.xs = -__.xs if K.no_grav or 0 != K.grav_dir != 2: temp = -__.ry2 * K.bloc + K.largeur_mapV2 - 0.1 if -temp <= __.y + __.ys <= temp: __.y += __.ys elif -temp > __.y + __.ys: __.y = -temp __.ys = -__.ys elif temp < __.y + __.ys: __.y = temp __.ys = -__.ys glPushMatrix() if K.bloc: glTranslatef(__.x - __.rx2, __.y - __.ry2, __.z - __.rz2) glScaled(__.rx, __.ry, __.rz) glCallList(__.boss.map.liste_cube) else: glTranslatef(__.x, __.y, __.z) glScalef(__.r2, __.r2, __.r2) glCallList(__.boss.map.liste_cylindre) glPopMatrix() if K.joueur.v: if not __.collision and __.z - __.rz2 <= 0 < __.z + __.rz2: __.collision_joueur(jx, jy) if not __.play: dist = DISTANCE(jx, jy, __.x, __.y) if dist < 10 + __.r2 or K.joueur.v >= 120: __.sons[2].play() elif dist < 20 + __.r2 or K.joueur.v >= 60: __.sons[1].play() elif dist < 30 + __.r2: __.sons[0].play() __.play = True elif __.z + __.rz2 < 0: if K.mode_jeu == 2: K.joueur.vie -= 1 if __.auto_destruction: K.obj.remove(__) else: __.new_coords() if K.mode_jeu == 2 and __.vie <= 0: K.joueur.score += __.vie_max * ( K.joueur.v + K.joueur.accelere) * 10 / (1 + 9 * bool(not K.joueur.accelere)) if __.auto_destruction: K.obj.remove(__) else: __.new_coords()
def draw(__): if pygame.mouse.get_focused(): pygame.mouse.set_pos(K.w2, K.h2) vL = __.vL * (1 + bool(not K.no_grav)) __.v10 = __.v / 10 __.dist_mapH = K.largeur_mapH2 - 4 __.dist_mapV = K.largeur_mapV2 - 4 __.dist_map = DISTANCE(0, 0, __.dist_mapH, __.dist_mapV) if K.mode_cylindre: #calcul de l'angle de rotation de la camera if not K.no_grav: temp = 90 * K.grav_dir else: temp = 0 if __.angle_grav != temp: distance_plus = (temp + 360 - __.angle_grav) % 360 distance_moins = (__.angle_grav + 360 - temp) % 360 if distance_plus < distance_moins: if (__.angle_grav - temp) % 360 > 1: __.angle_grav += 1 else: __.angle_grav = temp else: if (__.angle_grav - temp) % 360 > 1: __.angle_grav -= 1 else: __.angle_grav = temp #calcul des coordonnees cos, sin = CoSinus(DIRECTION(0, 0, __.x2, __.y2)) if not K.no_grav and not (1 != K.grav_dir != 3): cos, sin = sin, cos tempx = -cos * vL if abs(tempx) < 5e-2 or abs(tempx) == 2: tempx = __.x2 = 0 __.angle = (__.angle + tempx) % 360 if not K.no_grav and not (1 != K.grav_dir != 3): __.mousey -= int(tempx * 10) else: __.mousex += int(tempx * 10) if K.no_grav: tempy = sin * vL if abs(tempy) == 2: tempy = __.y2 = 0 tempy = __.r + tempy if 2 <= tempy < __.dist_mapH: __.r = tempy elif tempy >= __.dist_mapH: __.r = __.dist_mapH elif 2 > tempy: __.r = 2 else: if __.r + K.grav < __.dist_mapH - 0.1: __.r += K.grav elif __.r >= __.dist_mapH: __.r = __.dist_mapH - 0.1 if not K.no_grav and not (1 != K.grav_dir != 3): __.x2 = 0 else: __.y2 = 0 Cos, Sin = CoSinus(__.angle + __.angle_grav) __.x = Cos * __.r __.y = -Sin * __.r else: cos, sin = CoSinus(DIRECTION(__.x, __.y, __.x2, __.y2)) if DISTANCE(__.x, __.y, __.x2, __.y2) > vL: tempx = __.x + cos * vL tempy = __.y - sin * vL else: tempx = __.x2 tempy = __.y2 if K.no_grav or 1 != K.grav_dir != 3: if -__.dist_mapH <= tempx <= __.dist_mapH: __.x = tempx elif -__.dist_mapH > tempx: __.x = -__.dist_mapH elif __.dist_mapH < tempx: __.x = __.dist_mapH if K.no_grav or 0 != K.grav_dir != 2: if -__.dist_mapV <= tempy <= __.dist_mapV: __.y = tempy elif -__.dist_mapV > tempy: __.y = -__.dist_mapV elif __.dist_mapV < tempy: __.y = __.dist_mapV if not K.no_grav: if K.grav_dir == 0: __.y2 = __.y if __.y - K.grav > -__.dist_mapV: __.y -= K.grav else: __.y = -__.dist_mapV elif K.grav_dir == 1: __.x2 = __.x if __.x + K.grav < __.dist_mapH: __.x += K.grav else: __.x = __.dist_mapH elif K.grav_dir == 2: __.y2 = __.y if __.y + K.grav < __.dist_mapV: __.y += K.grav else: __.y = __.dist_mapV elif K.grav_dir == 3: __.x2 = __.x if __.x - K.grav > -__.dist_mapH: __.x -= K.grav else: __.x = -__.dist_mapH if __.vie > 0: if __.vie > __.vie_max: __.vie = __.vie_max if not K.end: if __.v < 180: __.v += __.vadd if __.accelere: __.v += __.vadd * 10 + __.time_accel_pressed __.time_accel_pressed += 0.00002 if not __.channel_avance.get_busy(): __.channel_avance.play(__.son_avance) else: __.v = 180 if K.mode_jeu != 2: if K.mode_cylindre: if K.no_grav: __.score += (__.dist_mapH - 2 - DISTANCE( 0, 0, __.x, __.y)) * __.calc_bonus_score() else: __.score += 10 * __.calc_bonus_score() else: if K.no_grav: __.score += (__.dist_map - DISTANCE( 0, 0, __.x, __.y)) * __.calc_bonus_score() else: __.score += (__.dist_mapH - DISTANCE( 0, 0, __.x, 0)) * __.calc_bonus_score() elif __.v > 0: __.v -= 1 if __.v < 0: __.v = 0 else: __.v = 0 if __.vmax < __.v: __.vmax = __.v __.distance += __.v if 1000 * __.distm <= __.distance: __.vm = __.vm * __.distm + __.v __.distm += 1 __.vm = __.vm / __.distm glDeleteTextures(__.tex_vit) if __.vie > 0: __.tex_vit = surface_to_texture( __.font.render(str(int(__.v / K.temps_boucle * 3600)), True, pygame.Color(255, 0, 0))) else: __.tex_vit = surface_to_texture( __.font.render(str(int(__.vmax / K.temps_boucle * 3600)), True, pygame.Color(255, 0, 0))) glDeleteTextures(__.tex_dis) __.tex_dis = surface_to_texture( __.font.render(str(int(__.distance / 1000)), True, pygame.Color(255, 0, 0))) glDeleteTextures(__.tex_sco) __.tex_sco = surface_to_texture( __.font.render(str(int(__.score)), True, pygame.Color(255, 0, 0))) glDeleteTextures(__.tex_deg) __.tex_deg = surface_to_texture( __.font.render( "[" + "=" * __.vie + " " * (__.vie_max - __.vie) + "] ", True, pygame.Color(255, 0, 0))) #dessine l'interface 2D activ_2D(K.w, K.h) glColor4ub(255, 0, 0, 200) glPointSize(3) glPushMatrix() if K.mode_cylindre: glTranslatef(K.w2 - __.x2, K.h2 + __.y2, 0) else: glTranslatef(K.w2 - __.x2 + __.x, K.h2 + __.y2 - __.y, 0) glCallList(__.liste_point) glPopMatrix() glColor4ub(255, 0, 0, 128) glLineWidth(1) glCallList(__.liste_cokpit) if not K.no_grav and K.grav_dir == 0: alpha = 255 glLineWidth(3) else: alpha = 128 glLineWidth(1) glColor4ub(255, 0, 0, alpha) glCallList(__.liste_line_bas) if not K.no_grav and K.grav_dir == 1: alpha = 255 glLineWidth(5) else: alpha = 128 glLineWidth(1) glColor4ub(255, 0, 0, alpha) glCallList(__.liste_line_droite) if not K.no_grav and K.grav_dir == 2: alpha = 255 glLineWidth(5) else: alpha = 128 glLineWidth(1) glColor4ub(255, 0, 0, alpha) glCallList(__.liste_line_haut) if not K.no_grav and K.grav_dir == 3: alpha = 255 glLineWidth(5) else: alpha = 128 glLineWidth(1) glColor4ub(255, 0, 0, alpha) glCallList(__.liste_line_gauche) glCallList(__.test_aff[0]) if __.draw_line_cursor: glLineWidth(1) glColor4ub(255, 0, 0, 255) glBegin(GL_LINES) if K.mode_cylindre: glVertex2f(K.w2, K.h2) glVertex2f(K.w2 - __.x2, K.h2 + __.y2) else: glVertex2f(K.w2, K.h2) glVertex2f(K.w2 - __.x2 + __.x, K.h2 + __.y2 - __.y) glEnd() desactiv_2D() if K.mode_cylindre: __.x2 = __.mousex / K.w2 * __.dist_mapH __.y2 = __.mousey / K.h2 * __.dist_mapV + __.r else: __.x2 = __.mousex / K.w2 * __.dist_mapH __.y2 = __.mousey / K.h2 * __.dist_mapV #positionne la camera if K.mode_cylindre: glRotatef(90 - __.angle, 0, 0, 1) gluLookAt(__.x, __.y, 0, __.x, __.y, 10, 0, 1, 0)