def __init__(self): # config self.config_provider = ConfigProvider() # disk self.disk = Disk() # display self.display = None if (self.config_provider.edit_enabled or self.config_provider.effects_enabled or self.config_provider.audio_enabled or self.config_provider.screen_enabled): self.display = Display() # replay self.replay = None if (self.config_provider.edit_enabled or self.config_provider.audio_enabled or self.config_provider.screen_enabled): self.replay = Replay() # graphics self.graphics = None if (self.config_provider.effects_enabled or self.config_provider.audio_enabled or self.config_provider.screen_enabled): self.graphics = Graphics() # record self.record = None if self.config_provider.record_enabled: self.record = Record(self.config_provider, self.disk) # edit self.edit = None if self.config_provider.edit_enabled: self.edit = Edit(self.config_provider, self.disk, self.display, self.replay) # effects self.effects = None if self.config_provider.effects_enabled: self.effects = Effects(self.config_provider, self.disk, self.display, self.graphics) # audio self.audio = None if self.config_provider.audio_enabled: self.audio = Audio(self.config_provider, self.disk, self.display, self.replay, self.graphics) # screen self.screen = None if self.config_provider.screen_enabled: self.screen = Screen(self.config_provider, self.disk, self.display, self.replay, self.graphics) # frame number self.frame_number = 0
class PyMovieStudio: # initialise def __init__(self): # config self.config_provider = ConfigProvider() # disk self.disk = Disk() # display self.display = None if (self.config_provider.edit_enabled or self.config_provider.effects_enabled or self.config_provider.audio_enabled or self.config_provider.screen_enabled): self.display = Display() # replay self.replay = None if (self.config_provider.edit_enabled or self.config_provider.audio_enabled or self.config_provider.screen_enabled): self.replay = Replay() # graphics self.graphics = None if (self.config_provider.effects_enabled or self.config_provider.audio_enabled or self.config_provider.screen_enabled): self.graphics = Graphics() # record self.record = None if self.config_provider.record_enabled: self.record = Record(self.config_provider, self.disk) # edit self.edit = None if self.config_provider.edit_enabled: self.edit = Edit(self.config_provider, self.disk, self.display, self.replay) # effects self.effects = None if self.config_provider.effects_enabled: self.effects = Effects(self.config_provider, self.disk, self.display, self.graphics) # audio self.audio = None if self.config_provider.audio_enabled: self.audio = Audio(self.config_provider, self.disk, self.display, self.replay, self.graphics) # screen self.screen = None if self.config_provider.screen_enabled: self.screen = Screen(self.config_provider, self.disk, self.display, self.replay, self.graphics) # frame number self.frame_number = 0 # initialise OpenGL def _init_opengl(self): glClearColor(0.0, 0.0, 0.0, 0.0) glClearDepth(1.0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(33.7, 1.3, 0.1, 100.0) glMatrixMode(GL_MODELVIEW) # process frame def _process_frame(self): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() # record if self.record: if self.record.frame(self.frame_number) == False: return # edit if self.edit: if self.edit.frame(self.frame_number) == False: return # effects if self.effects: if self.effects.frame(self.frame_number) == False: return # audio if self.audio: if self.audio.frame(self.frame_number) == False: return # screen if self.screen: if self.screen.frame(self.frame_number) == False: return # increment frame number self.frame_number += 1 glutSwapBuffers() def main(self): # setup and run OpenGL glutInit() glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(640, 480) glutInitWindowPosition(100, 100) glutCreateWindow('PyMovieStudio') glutDisplayFunc(self._process_frame) glutIdleFunc(self._process_frame) self._init_opengl() glutMainLoop()
def setUp(cls): cls.effect = Effects('Hello.wav')
#encoder = rotary_encoder.RotaryEncoder(A_PIN, B_PIN) encoder1 = rotary_encoder.RotaryEncoder.Worker( ENC1_PIN_A, ENC1_PIN_B, sleep_time=SLEEP_TIME_ROTARY) encoder1.start() encoder2 = rotary_encoder.RotaryEncoder.Worker( ENC2_PIN_A, ENC2_PIN_B, sleep_time=SLEEP_TIME_ROTARY) encoder2.start() push_buttons = PushButtons(PUSH_BUTTON_PINS) # We use this socket to switch patches loader_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) loader_socket.connect(('localhost', 5000)) effects = Effects(loader_socket, AVAILABLE_EFFECTS) wanted_effect = effects.current_effect #sleep(0.1) # essential! Or Pd will sometimes stop with a segmentation fault. #send_sock = init_pd_socket() print "listen to Pd..." # Listen to Pd communication = Communication() server_thread = ListenThread(communication=communication) # listen to messages from Pd server_thread.daemon = True server_thread.start() #initialized = False disp_needs_updating = True segment_needs_updating = True
maison=pygame.image.load('assets/bg3.png').convert_alpha() #chargement classe Player(), etc... player = Player() #chargement jeu game = Game() #chargement sol sol = Sol() #Plateforme plateforme = Plateforme() #chargement enemy enemy = Enemy() #chargement effets effects = Effects() #chargement sonor sonore = Sonore() font=pygame.font.Font(None, 50) #PV Joueur PV = 10 music_1PV = False PV_im = pygame.image.load('assets/PV.png').convert_alpha() StrPV = font.render(" "+str(PV),1,(16,16,22)) #Score Joueur score = 0 #Texte score
class Game: def __init__(self, ip): self.C = Client(ip) self.FullS = False self.Ping = 0 print("Loading") pygame.init() PId, BList, PStartPos, MapName = self.C.Start() self.BG = BG(MapName) self.info = pygame.display.Info() self.Clock = pygame.time.Clock() self.size = [] if self.info.current_w > self.BG.MapSize[0]: self.size.append(self.BG.MapSize[0]) else: self.size.append(self.info.current_w) if self.info.current_h > self.BG.MapSize[1]: self.size.append(self.BG.MapSize[1]) else: self.size.append(self.info.current_h) self.PSpeed = 2 self.State = "Alive" self.PressedKeys = [] self.Screen = pygame.display.set_mode(self.size) self.Start(PId, BList, PStartPos) def Request(self): while self.RUN: LastRequest = time.time() data = self.C.recv(wait=None) self.Ping = 1000 * (time.time() - LastRequest) if data != None: if data["Increment"] != self.Increment + 1: print("Missed packet: {} | {}".format( data["Increment"], self.Increment)) self.Increment = data["Increment"] self.RecvedBullets = data["Bullets"] self.RecvedEnemies = data["Players"] if data["You"]["State"] == "Die": self.State = "Die" if data["Gameover"]: self.Gameover = True self.PHealth = data["You"]["Health"] self.Player.MovePos(data["You"]["Coords"][0], data["You"]["Coords"][1]) if data["Blink"]: self.Effects.AddBlinkParticle(data["Blink"]) print("Game ended !") self.C.s.close() def RequireUpdate(self): while 1: self.C.send({"Action": "GetData"}) time.sleep(0.01) def Start(self, PId, BList, PStartPos): print(os.path.isfile(resource_path("Font.ttf"))) self.Font = pygame.font.Font(resource_path("Font.ttf"), 48) self.HFont = pygame.font.Font(resource_path("Font.ttf"), 20) self.PingFont = pygame.font.Font(resource_path("Font.ttf"), 16) self.LastBlink = time.time() self.Gameover = False self.Increment = 1 self.PHealth = 666 self.RecvedBullets = [] self.RecvedEnemies = [] self.BlinkCooldown = 1.5 self.BG.Begin(self.size) self.Bullets = Bll() self.Enemies = Enn() self.Effects = Effects() self.Player = Player(PStartPos, PId) self.BorderList = [pygame.Rect(B) for B in BList] self.RUN = True self.ServerRecvThread = threading.Thread(target=self.Request) self.ServerRecvThread.start() self.ServerSendReqThread = threading.Thread(target=self.RequireUpdate) self.ServerSendReqThread.start() self.GameLoop() def Fire(self, mousePos): self.C.send({ "Action": "Fire", "x": self.Player.xCoord, "y": self.Player.yCoord, "xDir": mousePos[0] + self.BG.MapRect.x, "yDir": mousePos[1] + self.BG.MapRect.y, "Angle": self.Player.Angle }) def PlayerMove(self): if 97 in self.PressedKeys: self.C.send({ "Action": "Move", "Direction": "Left", "Angle": self.Player.Angle }) if 100 in self.PressedKeys: self.C.send({ "Action": "Move", "Direction": "Right", "Angle": self.Player.Angle }) if 115 in self.PressedKeys: self.C.send({ "Action": "Move", "Direction": "Down", "Angle": self.Player.Angle }) if 119 in self.PressedKeys: self.C.send({ "Action": "Move", "Direction": "Up", "Angle": self.Player.Angle }) def Blink(self): y = round(sin(self.Player.Angle * pi / 180) * 100) x = round(cos(self.Player.Angle * pi / 180) * 100) if self.Player.xCoord + x - self.Player.size[ 0] / 2 >= 0 and self.Player.xCoord + x - self.Player.size[ 0] / 2 <= self.BG.MapSize[0]: if self.Player.yCoord + y - self.Player.size[ 1] / 2 >= 0 and self.Player.yCoord + y - self.Player.size[ 1] / 2 <= self.BG.MapSize[0]: self.Player.move(x, y) if self.CheckBorders(): self.Player.move(-x, -y) else: self.LastBlink = time.time() def drawBullets(self, BulletList): for B in BulletList: self.Screen.blit(B.image, B.rect) def drawEnemies(self, EnemiesList): for E in EnemiesList: self.Screen.blit(E.image, E.rect) def drawEffects(self, EffectsList): for E in EffectsList: self.Screen.blit(E[0], E[1]) def CheckBorders(self): if self.Player.RR.collidelist(self.BorderList) in range( len(self.BorderList)): return True else: return False def GameLoop(self): while self.RUN: for event in pygame.event.get(): if event.type == 5: if event.button == 1: if self.State != "Die": self.Fire(event.pos) if event.button == 3: if self.State != "Die": self.C.send({ "Action": "Blink", "Angle": self.Player.Angle }) elif event.type == 2: if self.Gameover: if event.key == 114: self.RUN = False if event.key == 61: if not self.FullS: self.Screen = pygame.display.set_mode( self.size, pygame.FULLSCREEN) self.FullS = True else: self.Screen = pygame.display.set_mode(self.size) self.FullS = False self.PressedKeys.append(event.key) elif event.type == 3: self.PressedKeys.remove(event.key) elif event.type == 12: self.RUN = False self.C.send({"Action": "Leave"}) self.C.s.close() pygame.quit() sys.exit() if not self.RUN: self.C.send({"Action": "Leave"}) self.C.s.close() pygame.quit() break self.PCoords = self.Player.getXY() if self.State != "Die": self.PlayerMove() self.BG.MapUpdate(self.size, self.Player.image.get_size(), self.PCoords) self.Player.Update(pygame.mouse.get_pos()) self.Bullets.Update(self.RecvedBullets, self.BG.MapRect) self.Enemies.Update(self.RecvedEnemies, self.BG.MapRect) Particles = self.Effects.Update(self.BG.MapRect) BulletList = self.Bullets.GetB() EnemiesList = self.Enemies.GetE() #tm = time.time() self.Screen.blit(self.BG.map, (0, 0)) self.drawEffects(Particles) if self.State != "Die": self.Screen.blit( self.Player.image, self.Player.getCoords(self.BG.MapSize, self.size)) self.drawBullets(BulletList) self.drawEnemies(EnemiesList) HealthText = self.HFont.render("Health : " + str(self.PHealth), 1, (255, 255, 255)) self.Screen.blit(HealthText, (5, self.size[1] - 24)) if self.Gameover: Text = self.Font.render("GAME OVER", 1, (255, 0, 0)) self.Screen.blit(Text, ((self.size[0] / 2) - 190, 5)) PingText = self.PingFont.render("Ping:" + str(round(self.Ping)), 1, (0, 0, 255)) self.Screen.blit(PingText, (self.size[0] - 190, self.size[1] - 40)) pygame.display.update() #print(time.time() - tm) self.Clock.tick(60)
def __init__(self): self.vars = EngineVars() self.effects = Effects(self.vars)