def update(self, dt, view): if self.dest not in view.units: view.units.remove(self) view.uisprites.append(Sprite("Explode", self.pos)) return diff = self.dest.pos - self.pos diff_polar = (sqrt(dot(diff, diff)), arctan2(diff[1], diff[0])) self.angle = diff_polar[1] self.pos = self.pos + v( (cos(self.angle), sin(self.angle))) * self.speed * dt if diff_polar[0] < self.dest.size / 2: self.dest.health -= self.damage view.units.remove(self) view.uisprites.append(Sprite("Explode", self.pos))
def update(self, dt, view): Object.update(self, dt, view) if type(self.dest) != type(v(())) and self.dest != None: if self.dest not in view.units or self.dest is self: self.dest = None dest = self.dest if type(dest) != type(v(())) and dest != None: dest = self.dest.pos if dest != None: self.recharge += dt self.moving = True if self.recharge > self.recharge_time: projectile = self.projectile() projectile.pos = place_unit(self.pos, projectile.bound, view.units) projectile.dest = v(self.dest) projectile.player = self.player view.units.append(projectile) self.recharge = 0.0 else: self.recharge = 0.0 self.moving = False if self.health <= 0.0: view.units.remove(self) view.uisprites.append(Sprite("MechExplode", self.pos)) self.finished += .003 if self.finished > 1: self.finished = 1
def update(self, dt, view): if int(random(1)[0] * 50) == 23: pos = self.smoke[int(random() * 3)] view.uisprites.append(Sprite("GeyserSmoke", self.pos + pos, 1. / 2))
def update(self, dt, view): Object.update(self, dt, view) self.moving = False if type(self.dest) == type(v(())) and self.level == 0: self.dest = view.pathfind.get_path( [int(x) for x in self.pos / 32], 0, [int(x) for x in self.dest / 32]) try: self.dest.pop(0) except: pass print self.dest if type(self.dest) != type([]) and type(self.dest) != type(v( ())) and self.dest != None: #dest is unit if self.dest not in view.units or self.dest is self: self.dest = None if type(self.dest) == type([]): dest = v(self.dest[0]) * 32 + (16, 16) elif type(self.dest) != type(v(())) and self.dest != None: dest = self.dest.pos elif self.dest == None: dest = self.pos else: dest = self.dest diff = v(dest) - self.pos diff_polar = (sqrt(dot(diff, diff)), arctan2(diff[1], diff[0])) #diff_polar = (diff_polar[0],int(diff_polar[1]/2/math.pi*32+.5)*1.0/32.0*2*math.pi) angle_error = fix_rad_angle(self.angle - diff_polar[1]) ang_vel = angle_error if abs(ang_vel) > self.ang_speed * dt: ang_vel = dt * self.ang_speed * sign(ang_vel) speed = diff_polar[0] if type(self.dest) == type([]): speed = self.speed * dt if speed > self.speed * dt: speed = self.speed * dt if speed > self.curspeed * dt: self.curspeed += self.accel * dt if self.curspeed > self.speed: self.curspeed = self.speed if speed > self.curspeed * dt: speed = self.curspeed * dt min_error = 1 if type(self.dest) != type([]) and type(self.dest) != type(v( ())) and self.dest != None: min_error = self.range * .9 print "bad attack" if diff_polar[0] > min_error: self.angle -= ang_vel self.moving = True oldpos = v(self.pos) if abs(angle_error) < 0.01 and diff_polar[0] > min_error: self.moving = True newpos = self.pos + v( (cos(diff_polar[1]), sin(diff_polar[1]))) * speed bad = False if self.tangible: myrect = pygame.rect.Rect(self.pos - v(self.bound) / 2, self.bound) for unit in view.units: if unit is not self and unit.tangible and unit.level == self.level: unitrect = pygame.rect.Rect( unit.pos - v(unit.bound) / 2, unit.bound) if myrect.colliderect(unitrect): bad = True break if not bad: self.pos = newpos if (diff_polar[0] < min_error or speed > diff_polar[0]) and type( self.dest) == type([]): self.dest.pop(0) if not self.dest: self.dest = None self.moving = True self.curspeed = self.curspeed * .9 + speed / dt * .1 #print self,speed self.recharge += dt try: self.projectile except AttributeError: pass else: if type(self.dest) != type(v()) and self.dest != None and type( self.dest) != type([]): if self.recharge > self.recharge_time and diff_polar[ 0] <= self.range: projectile = self.projectile() projectile.pos = self.pos.copy() projectile.dest = self.dest projectile.player = self.player view.units.append(projectile) self.recharge = 0.0 if self.health <= 0.0: view.units.remove(self) view.uisprites.append(Sprite("MechExplode", self.pos))
def test_spirit_init(): s = Sprite([0, 0], [1, 1], 'image.png', 100, 100) assert s.speed == [1, 1] assert s.position == [0, 0] assert s.image_path == 'image.png'
def test_update(): s = Sprite([0, 0], [1, 1], 'image.png', 100, 100) s.update() assert s.x == 1 assert s.y == 1
def test_get_size(): s = Sprite([0, 0], [1, 1], 'image.png', 100, 100) assert s.get_size() == [100, 100]
def test_get_x(): s = Sprite([0, 0], [1, 1], 'image.png', 100, 100) assert s.x == 0 assert s.y == 0