def updatePhysics(self, game): # self.f += game.gravity * self.gravityFactor * self.m middleOfScreen = V3(game.screenw / 2.0, game.screenh / 2.0) pullStrength = con.BLACK_HOLE_GRAVITY_STRENGTH * self.gravityFactor ** 2 f = (middleOfScreen - self.pos) * pullStrength if hasattr(self.owner, "favoriteFruit") and self.owner.id == 1: pass # print "vectoMiddle:", game.vectorToMiddle(self.pos).len() if game.vectorToMiddle(self.pos).len() < con.EVENT_HORIZON_RADIUS: self.f += f else: self.f += f * 0.25 # self.v += f * 1e-4 * (self.gravityFactor)**2 if hasattr(self.owner, "type"): po = self.owner.po # print "", po.v self.v += V3() self.a = self.f / self.m self.f = V3() self.v += self.a * game.dt self.pos += self.v * game.dt if self.owner and self.owner.id == 0 and False: print "f :", self.f print "v :", self.v print "a :", self.a print "pos:", self.pos
def update(self, game, key): if self.po: self.po.updatePhysics(game) pos = self.po.pos if ( pos.x < -con.BULLET_REMOVE_BORDER or pos.x > game.screenw + con.BULLET_REMOVE_BORDER or pos.y < -con.BULLET_REMOVE_BORDER or pos.y > game.screenh + con.BULLET_REMOVE_BORDER or self.ttl is not None and self.ttl <= 0 ): self.markedForRemoval = True return if game.vectorToMiddle(pos).len() < game.blackHoleSize: game.blackHoleSize += con.BLACK_HOLE_INCREASE_BY_BULLET self.markedForRemoval = True return # Collision detection with players for player in game.players: if self.owner != player.id and player.po and (self.po.pos - player.po.pos).len() < con.COLLISION_DIST: # print "player %s was hit!" % player.id if player.id == 1: # HANDICAP FOR P2 # player.po.hp -= self.damage / 2.0 player.po.hp -= self.damage else: player.po.hp -= self.damage # p=mv => m1 v1 = m2 v2 => v1 = m2 v2 / v1 vDiff = (self.po.m * self.BULLET_SPEED) / player.po.m player.po.v += self.po.v.normalize() * vDiff player.po.gravityFactor += self.damage / 100.0 # check for player dying if player.po.hp <= 11.0: # random value since we're not # drawing from the top player.po.hp = player.po.maxHp print "player with id=%s died!" % player.id self.markedForRemoval = True return if self.ttl is not None: self.ttl -= 1
def update(self, game, key): if self.po: self.po.updatePhysics(game) if game.vectorToMiddle(self.po.pos + V3(self.hw, self.hh)).len() \ < game.blackHoleSize: self.respawn(game) self.livesLeft -= 1 game.blackHoleSize += con.BLACK_HOLE_INCREASE_BY_PLAYER """ #move player to other side if outside pos = self.po.pos if pos.x + self.w < 0: pos.x = game.screenw elif pos.x >= game.screenw: pos.x = 0 - self.w if pos.y + self.h < 0: pos.y = game.screenh elif pos.y >= game.screenh: pos.y = 0 - self.h """ #bouncy walls pos = self.po.pos if pos.x < 0 and self.po.v.x < 0: self.po.v.x *= con.BOUNCE_FACTOR_ON_WALLS elif pos.x + self.w >= game.screenw and self.po.v.x > 0: self.po.v.x *= con.BOUNCE_FACTOR_ON_WALLS if pos.y < 0 and self.po.v.y < 0: self.po.v.y *= con.BOUNCE_FACTOR_ON_WALLS elif pos.y + self.h >= game.screenh and self.po.v.y > 0: self.po.v.y *= con.BOUNCE_FACTOR_ON_WALLS """ pos = self.po.pos if pos.x < 0 and self.po.v.x < 0: self.po.v.x *= -0.9 elif pos.x + self.w >= game.screenw and self.po.v.x > 0: self.po.v.x *= -0.9 elif pos.y < con.TOP_GLUE_START and self.po.v.y < 5: if pos.y < 0: self.po.v.y += 2.1 self.po.pos.y += 0.5 self.po.v.y *= 0.6 + 0.2*max(0,pos.y)/float(con.TOP_GLUE_START) elif pos.y + self.h >= game.screenh - con.BOTTOM_HEIGHT \ and self.po.v.y > 0: #print "abs(self.po.v.y): ", abs(self.po.v.y) if abs(self.po.v.y) < con.STOP_BOUNCE_LIMIT: self.po.v.y = 0 pos.y = game.screenh - con.BOTTOM_HEIGHT - self.h else: self.po.v.x *= 0.9 self.po.v.y *= con.BOUNCE_FACTOR_ON_FLOOR if pos.y + self.h >= game.screenh - con.BOTTOM_HEIGHT: pos.y = game.screenh - con.BOTTOM_HEIGHT - self.h self.po.v.x *= 0.7 """ self.po.v *= con.PLAYER_DRAG self.updateControls(game, key)