def update(self, dT): RelativeSprite.update(self, dT) #change image if self.alive: self.attackTimeout -= dT if random.random() > 0.7: self.i = random.choice(range(len(cat.images['idle']))) self.image = cat.images['idle'][self.i] else: self.image = cat.images['dead'] #change direction if self.alive and self.target: pos = self.target.rect.center targetDir = math.degrees(math.atan2(pos[1] - self.rect.centery, pos[0] - self.rect.centerx)) self.image = rot_center(self.image, -targetDir) #animate if self.alive and self.target: vel = Vec2d(self.target.truePos) - Vec2d(self.truePos) if vel.length < self.aware and vel.length > 0: self.aggro = True vel.length = self.speed self.truePos += vel else: if hasattr(self, 'deathTime') and self.deathTime < pygame.time.get_ticks() - 1000: self.kill()
def __init__(self, x, y): RelativeSprite.__init__(self) #self.tilewidth = tilewidth self.health = ethunterone.maxHealth self.aware = Config['PIXELS_PER_TILE']*8 #self.id = id self.speed = 3 self.musica = Music() self.clientUpdate = False if not ethunterone.images: ss = Spritesheet('tiles-bottom.png') ethunterone.images['idle'] = [] ethunterone.images['idle'].append(ss.image_at(Rect(5*45, 6*45, 45, 45))) ethunterone.images['idle'].append(ss.image_at(Rect(6*45, 6*45, 45, 45))) ethunterone.images['idle'].append(ss.image_at(Rect(0*45, 5*45, 45, 45))) ethunterone.images['dead'] = ss.image_at(Rect(1*45, 5*45, 45, 45)) self.i = random.choice(range(len(ethunterone.images['idle']))) self.image = ethunterone.images['idle'][self.i] self.rect = self.image.get_rect() self.truePos = [x, y] self.range = 50 self.target = None self.attackTimeout = cat.attackTimeout
def update(self, dT): #print self.rect.topleft RelativeSprite.update(self, dT) if self.shootTimeout > 0: self.shootTimeout -= dT if self.slashTimeout > 0: self.slashTimeout -= dT if self.shootTimeout <= 0 and self.slashTimeout <= 0: self.image = self.rot_center(Ally.images['idle'], -90+self.theta)
def __init__(self): RelativeSprite.__init__(self) if not Helicopter.frames: ssHeli = Spritesheet('tiles-bottom.png') #Helicopter.frames = [ssHeli.image_at(Rect(0, 4*45, 45, 45))] Helicopter.frames = [ssHeli.image_at(Rect(((10 + 3*i)*45, 0), (45*3, 45*3))) for i in xrange(6)] self.speed = 3 self.chFrameTimeout = Helicopter.change_frame self.i = 0 self.image = Helicopter.frames[self.i] self.target = None self.rect = self.image.get_rect()
def update(self, dT): RelativeSprite.update(self, dT) if self.target: vel = Vec2d(self.target.truePos) - Vec2d(self.truePos) if vel.length: vel.length = self.speed self.truePos += vel pos = self.target.rect.center targetDir = math.degrees(math.atan2(pos[1] - self.rect.centery, pos[0] - self.rect.centerx)) self.image = Helicopter.frames[self.i] self.image = rot_center(self.image, -targetDir) self.chFrameTimeout -= dT if self.chFrameTimeout <= 0: self.chFrameTimeout += Helicopter.change_frame self.i += 1 self.i %= len(Helicopter.frames)
def __init__(self): RelativeSprite.__init__(self) if not Ally.images: ssFoo = Spritesheet('tiles-bottom.png') Ally.images['idle'] = ssFoo.image_at(Rect(0*45, 4*45, 45, 45)) Ally.images['shooting'] = ssFoo.image_at(Rect(0*45, 6*45, 45, 45)) Ally.images['knife'] = ssFoo.image_at(Rect(7*45, 6*45, 45, 45)) Ally.images['dead'] = ssFoo.image_at(Rect(1*45, 6*45, 45, 45)) self.image = Ally.images['idle'] self.rect = self.image.get_rect() self.speed = Ally.speed self.theta = 0.0 self.health = Ally.maxHealth self.alive = True self.shootTimeout = -1 self.slashTimeout = -1
def __init__(self, x, y): RelativeSprite.__init__(self) #self.tilewidth = tilewidth self.health = cat.maxHealth self.aware = Config['PIXELS_PER_TILE']*4 #self.id = id self.speed = 9 self.musica = Music() if not cat.images: ss = Spritesheet('tiles-bottom.png') cat.images['idle'] = [] cat.images['idle'].append(ss.image_at(Rect(12*45, 3*45, 90, 90))) cat.images['idle'].append(ss.image_at(Rect(14*45, 3*45, 90, 90))) cat.images['dead'] = ss.image_at(Rect(10*45, 3*45, 90, 90)) self.i = 0 self.image = cat.images['idle'][self.i] self.rect = self.image.get_rect() self.truePos = [x, y] self.range = 50 self.target = None self.attackTimeout = cat.attackTimeout self.aggro = False
def generateTiles(block): global enemies_n gpBack = pygame.sprite.RenderUpdates() gpFore = pygame.sprite.RenderUpdates() gpEnem = pygame.sprite.RenderUpdates() prevGenerated = True if block not in seeds: prevGenerated = False seeds[block] = random.randrange(0,10000000) bg, fg, en, it = mapgen.gen_block(seeds[block]) for b in bg: x, y = mapgen.tiles[bg[b]][0] wid = hei = Config['PIXELS_PER_TILE'] rec = Rect((x*wid, y*hei), (wid, hei)) img = ssBottom.image_at(rec) spr = RelativeSprite(camera=hero, offset=(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)) spr.image = img spr.rect = img.get_rect() spr.truePos = [block[0]*Config['PIXELS_PER_BLOCK'] + b[0]*45, block[1]*Config['PIXELS_PER_BLOCK'] + b[1]*45] active.add(spr) gpBack.add(spr) for f in fg: x, y = mapgen.tiles[fg[f]][0] wid = hei = Config['PIXELS_PER_TILE'] rec = Rect((x*wid, y*hei), (wid, hei)) if fg[f] in [1, 10]: rec = Rect((x*wid-1, y*hei-0), (wid, hei)) #0, 0 gives transparent image wtf img = ssTop.image_at(rec) spr = RelativeSprite(camera=hero, offset=(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)) spr.image = img spr.rect = img.get_rect() spr.truePos = [block[0]*Config['PIXELS_PER_BLOCK']+f[0]*45, block[1]*Config['PIXELS_PER_BLOCK']+f[1]*45] active.add(spr) gpFore.add(spr) if not prevGenerated and multiplayer.hosting: for e in en: x, y = mapgen.tiles[en[e]][0] wid = hei = Config['PIXELS_PER_TILE'] rec = Rect((x*wid, y*hei), (wid, hei)) img = ssTop.image_at(rec) truePos = [block[0]*Config['PIXELS_PER_BLOCK']+e[0]*45, block[1]*Config['PIXELS_PER_BLOCK']+e[1]*45] enemyClasses = {1: ethunterone, 2: cat} spr = enemyClasses[en[e]](*truePos) spr.setCamera(hero) spr.setOffset((SCREEN_WIDTH/2, SCREEN_HEIGHT/2)) spr.update(0) enemies.add(spr) actors.add(spr) active.add(spr) spr.target = hero gpEnem.add(spr) if not isinstance(spr, cat): hb = HealthBar(target=spr) actors.add(hb) active.add(hb) enemies_list_lock.acquire() enemies_list[enemies_n] = spr spr.n = enemies_n enemies_n += 1 enemies_list_lock.release() for i in it: print i, it[i] (x, y) = (3, 3) wid = hei = Config['PIXELS_PER_TILE'] rec = Rect((x*wid, y*hei), (wid, hei)) print rec img = ssBottom.image_at(rec) truePos = [block[0]*Config['PIXELS_PER_BLOCK']+i[0]*45, block[1]*Config['PIXELS_PER_BLOCK']+i[1]*45] spr = Gem() spr.truePos = truePos spr.setCamera(hero) spr.setOffset((SCREEN_WIDTH/2, SCREEN_HEIGHT/2)) spr.update(0) items.add(spr) active.add(spr) actors.add(spr) gpEnem.add(spr) return gpBack, gpFore, gpEnem
def __init__(self): RelativeSprite.__init__(self)