def slide(self): try: self.fpy += self.fpdy #check for collision ( left|right, top ) collided = False for key in self.game.wallsControls.keys(): wall = self.game.wallsControls[key] if wall is None: continue issilver = wall.type == 5 isgold = wall.type == 10 wall = wall.rect if wall.collidelist([(self.fireRect.left, self.fpy), (self.fireRect.right, self.fpy) ]) is not None: self.fpy = wall.bottom self.setPos() self.game.setCollideWall(key) if not isgold and not issilver: self.containers.new_bonus(wall) collided = True #if not want double hits break #break if collided: self.fire.setVisible(0) self.stop() if len(self.containers.enemies) > 1: for enemy in self.containers.enemies: collided = False try: if enemy.enemyRect.collidelist([ (self.fireRect.left, self.fpy), (self.fireRect.right, self.fpy) ]) is not None: if not enemy.dead: enemy.image = "boom.gif" enemy.enemyControl.setImage( os.path.join(MEDIAS_PATH, enemy.image)) utilities.SFX("bang.wav") enemy.dead = True collided = True break except: pass #print_exc() if collided: self.fire.setVisible(0) self.stop() except: print_exc() self.setPos()
def start(self): self._stop = False self.fireRect = self.fire.getRect() vausRect = self.game.getCurrentVausRect() self.fireRect.left = self.fireRect.left + 2 self.fireRect.right = self.fireRect.right - 2 self.fpx = vausRect.x self.fpy = self.fireRect.y self.fpdy = -self.speed utilities.SFX("laser.wav") self.setPos() self.update = self.slide
def slide(self): # bounce from vaus bounce_from_vaus = False self.ballRect = self.ballControl.getRect() if int(self.fpy + self.ballRect.h) >= self.defaultVausTop > int( self.fpy): vausRect = self.game.getCurrentVausRect() #if vausRect.colliderect( self.ballRect ) and self.fpdy < 0: # print "frappe par le bas! ou ball pris dans le vaus :))", self.fpdy # #sleep( 1 ) if self.fpdy > 0 and vausRect.colliderect( self.ballRect) is not None: utilities.SFX("ping3.wav") #if self.game.vausHasCatch and not self.newStart: # self.ballControl.setVisible( 0 ) # self.window.setProperty( "level.ballRunning", "" ) # sleep( .5 ) # self.game.ballRunning = False # self._stop = True self.newStart = False ballpos = self.ballRect.right - vausRect.left - 1 ballmax = self.ballRect.width + vausRect.width - 2 factor = float(ballpos) / ballmax self.new_angle(factor) if self.speed == 3: self.speed = BALL_SPEED_START self.game.ballSpeed = self.speed bounce_from_vaus = True # usual movement self.fpx = self.fpx + self.fpdx self.fpy = self.fpy + self.fpdy self.setint() if bounce_from_vaus: #sert a rien de continuer, car pas de wall proche self.setfp() self.setPos() return #''' sur EDEN cela semble ok # ball vs ball, optional try: if len(self.containers.balls) > 1: actual_rect = Rect(self.ballRect.x, self.ballRect.y, self.ballRect.w, self.ballRect.h) for ball in self.containers.balls: if hasattr(ball, 'ballRect') and self.Id != ball.Id: if ball.dead: continue vs = Rect(ball.ballRect.x, ball.ballRect.y, ball.ballRect.w, ball.ballRect.h) point = actual_rect.colliderect(vs) if point is not None: if point == 0: #"center": self.fpx = vs.x - (vs.w / 2) if point == 1: #"midtop": self.fpy = vs.y - vs.h if point == 2: #"midleft": self.fpx = vs.x - vs.w if point == 3: #"midbottom": self.fpy = vs.y + vs.h if point == 4: #"midright": self.fpx = vs.x + vs.w if point == 5: #"topleft": self.fpx, self.fpy = vs.topleft if point == 6: #"topright": self.fpx, self.fpy = vs.topright if point == 7: #"bottomleft": self.fpx, self.fpy = vs.bottomleft if point == 8: #"bottomright": self.fpx, self.fpy = vs.bottomright self.fpdx, self.fpdy = -self.fpdx, -self.fpdy except: print_exc() #''' # bounce from borders gameplay if self.ballRect.left <= self.gamePlay.left: # |O utilities.SFX("ping1.wav") self.ballRect.x = self.gamePlay.left + 1 self.setfp() self.fpdx = -self.fpdx return self.setPos() elif self.ballRect.right >= self.gamePlay.right: # O| utilities.SFX("ping1.wav") self.ballRect.x = self.gamePlay.right - 1 - self.ballRect.w self.setfp() self.fpdx = -self.fpdx return self.setPos() elif self.ballRect.top <= self.gamePlay.top: # _ # O utilities.SFX("ping1.wav") self.ballRect.y = self.gamePlay.top + 1 self.setfp() self.fpdy = -self.fpdy return self.setPos() elif self.ballRect.top >= self.gamePlay.bottom: # O # ¯ ballsOnScreen = 0 for ball in self.containers.balls: if not ball.dead and self.Id != ball.Id: ballsOnScreen += 1 if not ballsOnScreen: utilities.SFX("dead.wav") self.window.setProperty("vaus.statut", "BOOM") sleep(1) self.window.setProperty("vaus.statut", "NORMAL") self.game.ballRunning = False self.window.setProperty("level.ballRunning", "") else: utilities.SFX("bang.wav") self.stop() self.dead = True return #pass #elif self.ballRect.bottom >= self.gamePlay.bottom: # for testing not dead ball # O # ¯ #utilities.SFX( "dead.wav" ) #self.ballRect.y = self.gamePlay.bottom - 1 - self.ballRect.h #self.setfp() #self.fpdy = -self.fpdy #return self.setPos() #pass # bounce from walls try: # wallsCollided detect pas tous le temps tout les walls :( merde #tb = Rect( self.ballRect.x, self.ballRect.y, self.ballRect.w, self.ballRect.h ) #wallsDict = dict( [ (k,v.rect) for k,v in self.game.wallsControls.items() ] ) #wallsCollided = tb.collidedictall( wallsDict ) #if wallsCollided: # print "wallsCollided", wallsCollided # destroy walls gold_new_angle = False for key in self.game.wallsControls.keys(): wall = self.game.wallsControls[key] if wall is None: continue issilver = wall.type == 5 isgold = wall.type == 10 wall = wall.rect tb = Rect(self.ballRect.x, self.ballRect.y, self.ballRect.w, self.ballRect.h) # []-wall, O-ball left = right = up = down = 0 #[ tb.midleft, tb.midtop, tb.midbottom, tb.midright ] #[ tb.topleft, tb.topright, tb.bottomleft, tb.bottomright ] if isgold and wall.collidelist([ tb.midleft, tb.midtop, tb.midbottom, tb.midright ]) is not None: goldWall = self.game.wallsControls[key] # []O if self.ballRect.left <= wall.right < self.ballRect.right: if goldWall.vs_gold[2]: # ball entre deux gold if self.fpdy > 0: # ball direction vers le bas self.ballRect.y = wall.top - 1 - self.ballRect.h # on la place au dessus else: #sinon ball vers le haut self.ballRect.y = wall.bottom + 1 # on la place au dessous if not gold_new_angle: # on change une seule fois l'angle gold_new_angle = True self.fpdy = -self.fpdy else: # pas de vs gold, on fait comme un block normal right = 1 self.ballRect.x = wall.right + 1 if not gold_new_angle: gold_new_angle = True self.fpdx = -self.fpdx self.setfp() # O[] elif self.ballRect.left < wall.left <= self.ballRect.right: if goldWall.vs_gold[0]: if self.fpdy > 0: self.ballRect.y = wall.top - 1 - self.ballRect.h else: self.ballRect.y = wall.bottom + 1 if not gold_new_angle: gold_new_angle = True self.fpdy = -self.fpdy else: left = -1 self.ballRect.x = wall.left - 1 - self.ballRect.w if not gold_new_angle: gold_new_angle = True self.fpdx = -self.fpdx self.setfp() # O # [¯] elif self.ballRect.top < wall.top >= self.ballRect.bottom: if goldWall.vs_gold[1]: if self.fpdx > 0: self.ballRect.x = wall.left - 1 - self.ballRect.w else: self.ballRect.x = wall.right + 1 if not gold_new_angle: gold_new_angle = True self.fpdx = -self.fpdx else: up = -1 self.ballRect.y = wall.top - 1 - self.ballRect.h if not gold_new_angle: gold_new_angle = True self.fpdy = -self.fpdy self.setfp() # [_] # O elif self.ballRect.bottom > wall.bottom <= self.ballRect.top: if goldWall.vs_gold[3]: if self.fpdx > 0: self.ballRect.x = wall.left - 1 - self.ballRect.w else: self.ballRect.x = wall.right + 1 if not gold_new_angle: gold_new_angle = True self.fpdx = -self.fpdx else: down = 1 self.ballRect.y = wall.bottom + 1 if not gold_new_angle: gold_new_angle = True self.fpdy = -self.fpdy self.setfp() utilities.SFX("ping3.wav") elif wall.collidelist( [tb.midleft, tb.midtop, tb.midbottom, tb.midright]) is not None: #print key, wall # O[] if self.ballRect.left < wall.left <= self.ballRect.right: self.ballRect.x = wall.left - 1 - self.ballRect.w self.setint() left = -1 # O # [¯] if self.ballRect.top < wall.top >= self.ballRect.bottom: self.ballRect.y = wall.top - 1 - self.ballRect.h self.setint() up = -1 # []O if self.ballRect.left <= wall.right < self.ballRect.right: self.ballRect.x = wall.right + 1 self.setint() right = 1 # [_] # O if self.ballRect.bottom > wall.bottom <= self.ballRect.top: self.ballRect.y = wall.bottom + 1 self.setint() down = 1 self.game.setCollideWall(key, 1) if not isgold and not issilver: self.containers.new_bonus(wall) # Si la balle est invitée à aller dans deux directions, alors on change pas de direction. dx, dy = (left + right), (up + down) if dx is not 0: #if isgold: self.fpdx = -self.fpdx #else: self.fpdx = dx * abs(self.fpdx) if dy is not 0: #if isgold: self.fpdy = -self.fpdy #else: self.fpdy = dy * abs(self.fpdy) except: print_exc() self.setPos()