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
| import pygame
import webbrowser
from pygame.locals import *
from pygame import *
from tkinter import *
from webbrowser import *
from math import atan2,degrees
fenetretk = Tk()
fenetretk.title('Gold Cup Racing Launcher 1.0 ')
fenetretk.geometry('890x540')
l = LabelFrame(fenetretk, text="News", padx=30, pady=30)
l.pack(fill="both", expand="yes")
Label(l, text="Bienvenue sur Gold Cup Racing").pack()
Button(fenetretk, text ='New Profile').pack(side=LEFT, padx=5, pady=5)
bouton_quitter = Button(fenetretk, text=" Play ", command=fenetretk.quit)
Button(fenetretk, text ='Edit Profile').pack(side=RIGHT, padx=5, pady=5)
bouton_quitter.pack()
fenetretk.mainloop()
pygame.init()
#Ouverture de la fenêtre Pygame
fenetre = pygame.display.set_mode((800, 596))
iconfile = "data/images/icon.png" # appico.xbm sous linux
#Icone
icone = pygame.image.load("data/images/icon.png")
pygame.display.set_icon(icone)
#Titre
pygame.display.set_caption("Gold Cup Racing")
#Chargement et collage du personnage
perso = pygame.image.load("data/images/background.png").convert()
position_perso = perso.get_rect()
fenetre.blit(perso, position_perso)
road = pygame.image.load("data/images/road.png").convert_alpha()
#Chargement et collage du fond
fond = pygame.image.load("data/images/car.png").convert_alpha()
fenetre.blit(road, (200,200))
son = pygame.mixer.Sound("data/audio/vroom.wav")
pygame.key.set_repeat(50, 0)
vrect = fond.get_rect(center=(400,400))
#~ dans l'image d'origine, le vaisseau doit être vertical
#~ en direction du haut, c'est l'angle zero.
#BOUCLE INFINIE
continuer = 1
while continuer:
for event in pygame.event.get(): #Attente des événements
if event.type == QUIT:
continuer = 0
if event.type == KEYDOWN:
if event.key == K_ESCAPE: #Si "flèche bas"
#On descend le perso
continuer = 0
if event.key == K_s: #Si "flèche bas"
#On descend le perso
position_perso = position_perso.move(0,10)
son.play()
if event.key == K_w: #Si "flèche bas"
#On descend le perso
position_perso = position_perso.move(0,-10)
son.play()
if event.key == K_q: #Si "flèche bas"
#On descend le perso
position_perso = position_perso.move(-10,0)
son.play()
if event.key == K_d: #Si "flèche bas"
#On descend le perso
position_perso = position_perso.move(10,0)
son.play()
if event.type == KEYUP:
if event.key == K_w:
son.stop()
if event.key == K_s:
son.stop()
if event.key == K_q:
son.stop()
if event.key == K_d:
son.stop()
while True:
ev = event.wait()
if ev.type == QUIT: break
if ev.type == MOUSEMOTION:
#~ on recupere les coordonnees de la souris
#~ pour calculer un angle en fonction du centre du l'image
x,y = ev.pos
angle = degrees(atan2(vrect.centerx-x,vrect.centery-y))
#~ on efface l'ancienne image en recuperant de rect
r = fenetre.fill(0,vrect)
#~ on contruit l'image du vaisseau rotate
#~ sans oublier de recalculer sa position
newimg = pygame.transform.rotate(fond,angle)
vrect = newimg.get_rect(center=(400,400))
#~ on affiche la nouvelle image
#~ et on actualise
vrect = fenetre.blit(newimg,vrect)
pygame.display.update((r,vrect))
#Re-collage
fenetre.blit(perso, position_perso)
fenetre.blit(road, (50,50))
quit() |
Partager