0% found this document useful (0 votes)
11 views1 page

Shake

The document defines code for a screen shake effect and bullet firing in a game. It includes a screen_shake variable to control shake amount and random offsets added to rendering. It also defines a Bullet class for bullet sprites with position, speed, and shooting methods. Finally, it includes an update method for a background that scrolls upwards over time and resets at the bottom of the screen.

Uploaded by

Wyhang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Shake

The document defines code for a screen shake effect and bullet firing in a game. It includes a screen_shake variable to control shake amount and random offsets added to rendering. It also defines a Bullet class for bullet sprites with position, speed, and shooting methods. Finally, it includes an update method for a background that scrolls upwards over time and resets at the bottom of the screen.

Uploaded by

Wyhang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

screen_shake = 30

if screen_shake > 0:
screen_shake -= 1
render_offset = [0, 0]
if screen_shake:
render_offset[0] = random.randint(0, 8) - 4
render_offset[1] = random.randint(0, 8) - 4

class Bullet(pygame.sprite.Sprite):
def __init__(self, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = bullet_img
self.image.set_colorkey(BLACK)
self.rect = self.image.get_rect()
self.rect.centerx = x
self.rect.bottom = y
self.speedy = -20

def shoot(self):
if not (self.hidden):
if self.gun == 1:
bullet = Bullet(self.rect.centerx, self.rect.top)
all_sprites.add(bullet)
bullets.add(bullet)
shoot_sound.play()
elif self.gun >= 2:
bullet1 = Bullet(self.rect.left, self.rect.centery)
bullet2 = Bullet(self.rect.right, self.rect.centery)
all_sprites.add(bullet1)
all_sprites.add(bullet2)
bullets.add(bullet1)
bullets.add(bullet2)
shoot_sound.play()

self.rect.x += self.speedx
self.rect.x -= self.speedx

def update(self) :
self.bgY1 -= self.movingUpspeed
self.bgY2 -= self.movingUpspeed
if self.bgY1 >= self.rectBGimg.height:
self.bgY1 = -self.rectBGimg.height
if self.bgY2 >= self.rectBGimg2.height:
self.bgY2 = -self.rectBGimg2.height

You might also like