Mar-06-2020, 03:04 AM
Trying to make a new boss, but I don't know if this method is viable. It's an alien centipede type thing.
I spawn the head and the head spawns the next segment and so on. Each segment to follow to previous... but it runs SLOW.
Is this method even workable? All together it is composed of 6 sprites.
The self.direction are to do with images when they are all set up, and not the movement. The monster just moves in a square, but ultimately I just want to command the head and the rest should/does follow, just the slowdown is unplayable. Is it better to just have a bunch of separate segments with the same movement logic so they only appear to be connected? I'd like to maybe make this creature playable at some point, that's why I picked this method.
Ideas? Thanks.
I spawn the head and the head spawns the next segment and so on. Each segment to follow to previous... but it runs SLOW.
Is this method even workable? All together it is composed of 6 sprites.
The self.direction are to do with images when they are all set up, and not the movement. The monster just moves in a square, but ultimately I just want to command the head and the rest should/does follow, just the slowdown is unplayable. Is it better to just have a bunch of separate segments with the same movement logic so they only appear to be connected? I'd like to maybe make this creature playable at some point, that's why I picked this method.
Ideas? Thanks.
class Boss2(pg.sprite.Sprite):
def __init__(self, game, x, y):
self.groups = game.boss_group
self._layer = 10
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.image = self.game.boss2_head
self.rect = self.image.get_rect()
self.rect.x = x * self.game.block_size
self.rect.y = y * self.game.block_size
self.integretty = 200
self.pos = pg.math.Vector2(self.rect.center)
self.direction = "right"
self.last_update = pg.time.get_ticks()
self.frame_rate = 100
self.frame = 0
self.prev_pos = 0
def update(self, game, dt):
now = pg.time.get_ticks()
if self.frame == 1:
Boss_body_seg(self, self.game, 5)
if now - self.last_update > self.frame_rate:
self.last_update = now
self.frame += 1
if self.frame <= 30:
self.prev_pos = pg.math.Vector2(self.rect.center)
self.pos += (10, 0)
self.rect.center = self.pos
self.direction = "right"
self.image = self.game.boss2_right
if self.frame > 30 and self.frame <= 60:
self.prev_pos = pg.math.Vector2(self.rect.center)
self.pos += (0, 10)
self.rect.center = self.pos
self.direction = "down"
self.image = self.game.boss2_down
if self.frame > 60 and self.frame <= 90:
self.prev_pos = pg.math.Vector2(self.rect.center)
self.pos += (-10, 0)
self.rect.center = self.pos
self.direction = "left"
self.image = self.game.boss2_left
if self.frame > 90 and self.frame <= 120:
self.prev_pos = pg.math.Vector2(self.rect.center)
self.pos += (0, -10)
self.rect.center = self.pos
self.direction = "up"
self.image = self.game.boss2_up
if self.frame == 120:
self.frame = 0
class Boss_body_seg(pg.sprite.Sprite):
def __init__(self, prev_seg, game, num):
self.groups = game.boss_group
self._layer = prev_seg._layer - 1
pg.sprite.Sprite.__init__(self, self.groups)
self.game = game
self.prev_seg = prev_seg
self.image = self.game.boss2_body
self.rect = self.image.get_rect()
self.integretty = 200
self.pos = self.prev_seg.prev_pos
self.num = num - 1
self.direction = self.prev_seg.direction
self.last_update = pg.time.get_ticks()
self.frame_rate = 120
self.frame = 0
def update(self, game, dt):
if self.frame == 10 and self.num > 0:
Boss_body_seg(self, self.game, self.num)
now = pg.time.get_ticks()
if now - self.last_update > self.frame_rate:
self.last_update = now
self.frame += 1
self.prev_pos = self.rect.center
self.direction = self.prev_seg.direction
self.pos = self.prev_seg.prev_pos
self.rect.center = self.pos
self.image = self.game.boss2_downleft
