def update(self, mouse): """updates the objects""" self.dir = (mouse - self.location).normalize() * .5 self.acceleration = self.dir self.velocity += self.acceleration limit(self.velocity, 13) self.location += self.velocity self.angle = math.atan2(self.velocity.y, self.velocity.x)
def update(self, mouseX, mouseY): """ updates the objects """ self.mouse = Vector(mouseX, mouseY) self.dir = (self.mouse - self.location).normalize() * 0.5 self.acceleration = self.dir self.velocity += self.acceleration # self.velocity.limit(13) limit(self.velocity, 13) self.location += self.velocity
def update(self, delta): if random.random() < .1 and self.state != STATE_DEAD: self.canseeplayer = len(physics.collisions(self.game.space, self.body.position, self.game.player.body.position, COLLISION_GROUND)) == 0 if self.state != STATE_DEAD and self.health <= 0: self.game.player.enemies_killed += 1 self.state = STATE_DEAD if self.state == STATE_WANDERING: self.body.velocity += pymunk.Vec2d(random.random()*10-5, random.random()*10-5) if self.canseeplayer: self.state = STATE_PREPARING if self.state == STATE_PREPARING: self.facing = self.body.position.x<self.game.player.body.position.x playerdist = (self.body.position-self.game.player.body.position).length if playerdist < self.range*2: self.attack_timer += delta if self.attack_timer > self.attack_time: self.attack_timer = 0 self.state = STATE_ATTACKING flip = -1 if playerdist < self.range else 1 self.body.velocity += flip*(self.body.position-self.game.player.body.position).normalized()*-self.speed/10 if not self.canseeplayer: self.state = STATE_WANDERING if self.state == STATE_ATTACKING: self.facing = self.body.position.x<self.game.player.body.position.x self.body.velocity += (self.body.position-self.game.player.body.position).normalized()*-self.speed/2 if not self.canseeplayer: self.state = STATE_WANDERING if self.state != STATE_DEAD: self.body.velocity = physics.limit(self.body.velocity, self.speed)
def playerUpdateVelocity(self, body, gravity, damping, dt): self.groundNormal = pymunk.Vec2d() self.grounded = False self.grounds = 0 self.get_ground_normal() if self.grounds > 0: self.groundNormal /= self.grounds self.grounded = self.groundNormal.y > 0.0 #self.grounded = self.grounds > 0 if(self.groundNormal.y < 0.0): self.remainingBoost = 0.0 #Do a normal-ish update boost = (self.keyboard.y > 0 and self.remainingBoost > 0.0) g = pymunk.Vec2d(0, 0) if boost or self.grounded else pymunk.Vec2d(0, -600 if self.keyboard.y < 0 else -self.gravity) pymunk.Body.update_velocity(body, g, damping, dt) #Update the surface velocity and friction plane = self.groundNormal.rotated(-90) surface_v = plane*self.speed*self.keyboard.x - plane*plane.dot(self.body.velocity) self.body.velocity += surface_v self.playerShape.friction = 0 #Apply air control if not grounded if not self.grounded: self.body.velocity.x = self.flerpconst(self.body.velocity.x, self.airspeed*self.keyboard.x, self.airspeed*10*dt) self.body.velocity = physics.limit(self.body.velocity, self.maxspeed)