Commit c7016226 authored by jwacyk's avatar jwacyk
Browse files

ajout de la classe menu

parent c74c13af
......@@ -6,6 +6,8 @@ import time
import constants
from cursor import Cursor
from player import Player
from menu import Menu
pygame.display.init()
......@@ -15,75 +17,10 @@ screen = pygame.display.set_mode(constants.SCREENSIZE)
pygame.time.set_timer(pygame.USEREVENT,constants.REFRESHTIME)
screen.fill(constants.WHITE)
pygame.display.update()
black_rect = pygame.Rect(10, 10, 30, 30)
yellow_rect = pygame.Rect(50, 10, 30, 30)
orange_rect = pygame.Rect(90, 10, 30, 30)
red_rect = pygame.Rect(130, 10, 30, 30)
pink_rect = pygame.Rect(10, 50, 30, 30)
purple_rect = pygame.Rect(50, 50 , 30, 30)
blue_rect = pygame.Rect(90, 50, 30, 30)
pretty_blue_rect = pygame.Rect(130, 50, 30, 30)
light_blue_rect = pygame.Rect(10, 90, 30, 30)
green_rect = pygame.Rect(50, 90, 30, 30)
dark_green_rect = pygame.Rect(90, 90, 30, 30)
brown_rect = pygame.Rect(130, 90, 30, 30)
gray_rect = pygame.Rect(10, 130, 30, 30)
dark_gray_rect = pygame.Rect(50, 130, 30, 30)
menu_color_rect = pygame.Rect(0, 0, 160, 160)
show_menu_color = True
side_menu = Menu()
background = pygame.Surface(screen.get_size())
background.fill(constants.WHITE)
def collision(position) :
if menu_color_rect.collidepoint(position) :
if green_rect.collidepoint(position) :
player.set_color(constants.GREEN)
return True
elif black_rect.collidepoint(position):
player.set_color(constants.BLACK)
return True
elif yellow_rect.collidepoint(position):
player.set_color(constants.YELLOW)
return True
elif orange_rect.collidepoint(position):
player.set_color(constants.ORANGE)
return True
elif red_rect.collidepoint(position):
player.set_color(constants.RED)
return True
elif pink_rect.collidepoint(position):
player.set_color(constants.PINK)
return True
elif purple_rect.collidepoint(position):
player.set_color(constants.PURPLE)
return True
elif blue_rect.collidepoint(position):
player.set_color(constants.BLUE)
return True
elif pretty_blue_rect.collidepoint(position):
player.set_color(constants.PRETTY_BLUE)
return True
elif light_blue_rect.collidepoint(position):
player.set_color(constants.LIGHT_BLUE)
return True
elif dark_green_rect.collidepoint(position):
player.set_color(constants.DARK_GREEN)
return True
elif brown_rect.collidepoint(position):
player.set_color(constants.BROWN)
return True
elif gray_rect.collidepoint(position):
player.set_color(constants.GRAY)
return True
elif dark_gray_rect.collidepoint(position):
player.set_color(constants.DARK_GRAY)
return True
else :
return True
else :
return False
while 1 :
for player in players :
......@@ -109,13 +46,13 @@ while 1 :
player.set_color_changed(False)
if cwiid.BTN_LEFT in player.get_boutons() and not(player.get_color_panel()) :
player.set_color_panel(True)
show_menu_color = not(show_menu_color)
side_menu.change_state_show_menu()
if not(cwiid.BTN_1 in player.get_boutons()):
player.set_color_panel(False)
if player.get_position() !=None :
if cwiid.BTN_A in player.get_boutons() :
if show_menu_color :
if not(collision(player.get_position())) :
if not(side_menu.collision(player)) :
pygame.draw.circle(background, player.get_color(), player.get_position(), player.get_size())
else :
pygame.draw.circle(background, player.get_color(), player.get_position(), player.get_size())
......@@ -125,20 +62,7 @@ while 1 :
for player in players:
if player.get_position() !=None :
screen.blit(player.get_cursor(), player.get_cursor().get_position_center(player.get_position()))
if show_menu_color :
pygame.draw.rect(screen, constants.GREEN, green_rect)
pygame.draw.rect(screen, constants.BLACK, black_rect)
pygame.draw.rect(screen, constants.YELLOW, yellow_rect)
pygame.draw.rect(screen, constants.ORANGE, orange_rect)
pygame.draw.rect(screen, constants.RED, red_rect)
pygame.draw.rect(screen, constants.PINK, pink_rect)
pygame.draw.rect(screen, constants.PURPLE, purple_rect)
pygame.draw.rect(screen, constants.BLUE, blue_rect)
pygame.draw.rect(screen, constants.PRETTY_BLUE, pretty_blue_rect)
pygame.draw.rect(screen, constants.LIGHT_BLUE, light_blue_rect)
pygame.draw.rect(screen, constants.DARK_GREEN, dark_green_rect)
pygame.draw.rect(screen, constants.BROWN, brown_rect)
pygame.draw.rect(screen, constants.GRAY, gray_rect)
pygame.draw.rect(screen, constants.DARK_GRAY, dark_gray_rect)
if side_menu.get_show_menu() :
side_menu.show_menu(screen)
pygame.display.update()
import pygame
import constants
import player
class Menu(object):
def __init__(self):
self.black_rect = pygame.Rect(10, 10, 30, 30)
self.yellow_rect = pygame.Rect(50, 10, 30, 30)
self.orange_rect = pygame.Rect(90, 10, 30, 30)
self.red_rect = pygame.Rect(130, 10, 30, 30)
self.pink_rect = pygame.Rect(10, 50, 30, 30)
self.purple_rect = pygame.Rect(50, 50 , 30, 30)
self.blue_rect = pygame.Rect(90, 50, 30, 30)
self.pretty_blue_rect = pygame.Rect(130, 50, 30, 30)
self.light_blue_rect = pygame.Rect(10, 90, 30, 30)
self.green_rect = pygame.Rect(50, 90, 30, 30)
self.dark_green_rect = pygame.Rect(90, 90, 30, 30)
self.brown_rect = pygame.Rect(130, 90, 30, 30)
self.gray_rect = pygame.Rect(10, 130, 30, 30)
self.dark_gray_rect = pygame.Rect(50, 130, 30, 30)
self.menu_color = pygame.Rect(0, 0, 160, 160)
self.show_menu = True
def collision(self, player) :
position = player.get_position()
if self.menu_color.collidepoint(position) :
if self.green_rect.collidepoint(position) :
player.set_color(constants.GREEN)
return True
elif self.black_rect.collidepoint(position):
player.set_color(constants.BLACK)
return True
elif self.yellow_rect.collidepoint(position):
player.set_color(constants.YELLOW)
return True
elif self.orange_rect.collidepoint(position):
player.set_color(constants.ORANGE)
return True
elif self.red_rect.collidepoint(position):
player.set_color(constants.RED)
return True
elif self.pink_rect.collidepoint(position):
player.set_color(constants.PINK)
return True
elif self.purple_rect.collidepoint(position):
player.set_color(constants.PURPLE)
return True
elif self.blue_rect.collidepoint(position):
player.set_color(constants.BLUE)
return True
elif self.pretty_blue_rect.collidepoint(position):
player.set_color(constants.PRETTY_BLUE)
return True
elif self.light_blue_rect.collidepoint(position):
player.set_color(constants.LIGHT_BLUE)
return True
elif self.dark_green_rect.collidepoint(position):
player.set_color(constants.DARK_GREEN)
return True
elif self.brown_rect.collidepoint(position):
player.set_color(constants.BROWN)
return True
elif self.gray_rect.collidepoint(position):
player.set_color(constants.GRAY)
return True
elif self.dark_gray_rect.collidepoint(position):
player.set_color(constants.DARK_GRAY)
return True
else :
return True
else :
return False
def show_menu(self, screen) :
pygame.draw.rect(screen, constants.GREEN, green_rect)
pygame.draw.rect(screen, constants.BLACK, black_rect)
pygame.draw.rect(screen, constants.YELLOW, yellow_rect)
pygame.draw.rect(screen, constants.ORANGE, orange_rect)
pygame.draw.rect(screen, constants.RED, red_rect)
pygame.draw.rect(screen, constants.PINK, pink_rect)
pygame.draw.rect(screen, constants.PURPLE, purple_rect)
pygame.draw.rect(screen, constants.BLUE, blue_rect)
pygame.draw.rect(screen, constants.PRETTY_BLUE, pretty_blue_rect)
pygame.draw.rect(screen, constants.LIGHT_BLUE, light_blue_rect)
pygame.draw.rect(screen, constants.DARK_GREEN, dark_green_rect)
pygame.draw.rect(screen, constants.BROWN, brown_rect)
pygame.draw.rect(screen, constants.GRAY, gray_rect)
pygame.draw.rect(screen, constants.DARK_GRAY, dark_gray_rect)
def set_show_menu(self, state) :
self.show_menu = state
def change_state_show_menu(self) :
self.show_menu = not(self.show_menu)
def get_show_menu(self, state) :
return self.show_menu
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment