diff --git a/Participants.md b/Participants.md new file mode 100644 index 0000000..706c4f4 --- /dev/null +++ b/Participants.md @@ -0,0 +1,9 @@ +## These are the particpipants +Pranshu +Priyam +DK +<<<<<<< HEAD +Kanishk Garg(b20109) +======= +Kanishk Garg(B20109) +>>>>>>> 3c26255 (Added Kanishk garg) diff --git a/README.md b/README.md index 1314e44..bb9f1c3 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,11 @@ The [DehlaPakad](https://dehlapakad.com) team wants to create a new game. But th ## Get started To get started, go to the [issues](https://github.com/KamandPrompt/git_hero_2021/issues) tab. Start with the challenge 1 to challenge 6. The scores for them are alongside and they go in order, so until you complete the challenge1, you cannot move to challenge2. You need to complete previous challenges first. +## Submission +You need to document all the steps you follow along the way in a file named `report.md` +Once you are done with the as many challenges as you were able to solve, you need to make a final Pull Request containing that file. +The marks you get for each question will depend on the quality of your commits, time taken to make the commits, and how well you are able to explain the steps taken. + ## Some Tips Google, git status and git log are your best friends in this challenge. diff --git a/assets/bolt_gold.png b/assets/bolt_gold.png new file mode 100644 index 0000000..c22e0a2 Binary files /dev/null and b/assets/bolt_gold.png differ diff --git a/assets/laserRed16.png b/assets/laserRed16.png new file mode 100644 index 0000000..b12fcd5 Binary files /dev/null and b/assets/laserRed16.png differ diff --git a/assets/main.png b/assets/main.png new file mode 100644 index 0000000..34b79d2 Binary files /dev/null and b/assets/main.png differ diff --git a/assets/meteorBrown_big1.png b/assets/meteorBrown_big1.png new file mode 100644 index 0000000..31e06a4 Binary files /dev/null and b/assets/meteorBrown_big1.png differ diff --git a/assets/meteorBrown_big2.png b/assets/meteorBrown_big2.png new file mode 100644 index 0000000..90413d7 Binary files /dev/null and b/assets/meteorBrown_big2.png differ diff --git a/assets/meteorBrown_med1.png b/assets/meteorBrown_med1.png new file mode 100644 index 0000000..14fa6f5 Binary files /dev/null and b/assets/meteorBrown_med1.png differ diff --git a/assets/meteorBrown_med3.png b/assets/meteorBrown_med3.png new file mode 100644 index 0000000..5ec2d1e Binary files /dev/null and b/assets/meteorBrown_med3.png differ diff --git a/assets/meteorBrown_small1.png b/assets/meteorBrown_small1.png new file mode 100644 index 0000000..60cf04a Binary files /dev/null and b/assets/meteorBrown_small1.png differ diff --git a/assets/meteorBrown_small2.png b/assets/meteorBrown_small2.png new file mode 100644 index 0000000..48cbc23 Binary files /dev/null and b/assets/meteorBrown_small2.png differ diff --git a/assets/meteorBrown_tiny1.png b/assets/meteorBrown_tiny1.png new file mode 100644 index 0000000..69ef3a3 Binary files /dev/null and b/assets/meteorBrown_tiny1.png differ diff --git a/assets/missile.png b/assets/missile.png new file mode 100644 index 0000000..5733789 Binary files /dev/null and b/assets/missile.png differ diff --git a/assets/playerShip1_orange.png b/assets/playerShip1_orange.png new file mode 100644 index 0000000..3902283 Binary files /dev/null and b/assets/playerShip1_orange.png differ diff --git a/assets/regularExplosion00.png b/assets/regularExplosion00.png new file mode 100644 index 0000000..13c68ba Binary files /dev/null and b/assets/regularExplosion00.png differ diff --git a/assets/regularExplosion01.png b/assets/regularExplosion01.png new file mode 100644 index 0000000..c93cbb9 Binary files /dev/null and b/assets/regularExplosion01.png differ diff --git a/assets/regularExplosion02.png b/assets/regularExplosion02.png new file mode 100644 index 0000000..e233256 Binary files /dev/null and b/assets/regularExplosion02.png differ diff --git a/assets/regularExplosion03.png b/assets/regularExplosion03.png new file mode 100644 index 0000000..8573393 Binary files /dev/null and b/assets/regularExplosion03.png differ diff --git a/assets/regularExplosion04.png b/assets/regularExplosion04.png new file mode 100644 index 0000000..3660462 Binary files /dev/null and b/assets/regularExplosion04.png differ diff --git a/assets/regularExplosion05.png b/assets/regularExplosion05.png new file mode 100644 index 0000000..bc90cb2 Binary files /dev/null and b/assets/regularExplosion05.png differ diff --git a/assets/regularExplosion06.png b/assets/regularExplosion06.png new file mode 100644 index 0000000..95b844b Binary files /dev/null and b/assets/regularExplosion06.png differ diff --git a/assets/regularExplosion07.png b/assets/regularExplosion07.png new file mode 100644 index 0000000..ba9c95a Binary files /dev/null and b/assets/regularExplosion07.png differ diff --git a/assets/regularExplosion08.png b/assets/regularExplosion08.png new file mode 100644 index 0000000..323559f Binary files /dev/null and b/assets/regularExplosion08.png differ diff --git a/assets/shield_gold.png b/assets/shield_gold.png new file mode 100644 index 0000000..08598e8 Binary files /dev/null and b/assets/shield_gold.png differ diff --git a/assets/sonicExplosion00.png b/assets/sonicExplosion00.png new file mode 100644 index 0000000..7042a33 Binary files /dev/null and b/assets/sonicExplosion00.png differ diff --git a/assets/sonicExplosion01.png b/assets/sonicExplosion01.png new file mode 100644 index 0000000..a3a353a Binary files /dev/null and b/assets/sonicExplosion01.png differ diff --git a/assets/sonicExplosion02.png b/assets/sonicExplosion02.png new file mode 100644 index 0000000..b272b52 Binary files /dev/null and b/assets/sonicExplosion02.png differ diff --git a/assets/sonicExplosion03.png b/assets/sonicExplosion03.png new file mode 100644 index 0000000..6158e4b Binary files /dev/null and b/assets/sonicExplosion03.png differ diff --git a/assets/sonicExplosion04.png b/assets/sonicExplosion04.png new file mode 100644 index 0000000..3660462 Binary files /dev/null and b/assets/sonicExplosion04.png differ diff --git a/assets/sonicExplosion05.png b/assets/sonicExplosion05.png new file mode 100644 index 0000000..bc90cb2 Binary files /dev/null and b/assets/sonicExplosion05.png differ diff --git a/assets/sonicExplosion06.png b/assets/sonicExplosion06.png new file mode 100644 index 0000000..95b844b Binary files /dev/null and b/assets/sonicExplosion06.png differ diff --git a/assets/sonicExplosion07.png b/assets/sonicExplosion07.png new file mode 100644 index 0000000..ba9c95a Binary files /dev/null and b/assets/sonicExplosion07.png differ diff --git a/assets/sonicExplosion08.png b/assets/sonicExplosion08.png new file mode 100644 index 0000000..323559f Binary files /dev/null and b/assets/sonicExplosion08.png differ diff --git a/assets/starfield.png b/assets/starfield.png new file mode 100644 index 0000000..99a4043 Binary files /dev/null and b/assets/starfield.png differ diff --git a/sounds/expl6.wav b/sounds/expl6.wav new file mode 100644 index 0000000..e78d7f2 Binary files /dev/null and b/sounds/expl6.wav differ diff --git a/sounds/getready.ogg b/sounds/getready.ogg new file mode 100644 index 0000000..4c9d191 Binary files /dev/null and b/sounds/getready.ogg differ diff --git a/sounds/menu.ogg b/sounds/menu.ogg new file mode 100644 index 0000000..a3ae32e Binary files /dev/null and b/sounds/menu.ogg differ diff --git a/sounds/pew.wav b/sounds/pew.wav new file mode 100644 index 0000000..3fb335f Binary files /dev/null and b/sounds/pew.wav differ diff --git a/sounds/rocket.ogg b/sounds/rocket.ogg new file mode 100644 index 0000000..bb596da Binary files /dev/null and b/sounds/rocket.ogg differ diff --git a/sounds/rumble1.ogg b/sounds/rumble1.ogg new file mode 100644 index 0000000..78acaeb Binary files /dev/null and b/sounds/rumble1.ogg differ diff --git a/sounds/tgfcoder-FrozenJam-SeamlessLoop.ogg b/sounds/tgfcoder-FrozenJam-SeamlessLoop.ogg new file mode 100644 index 0000000..a33edf6 Binary files /dev/null and b/sounds/tgfcoder-FrozenJam-SeamlessLoop.ogg differ diff --git a/spaceShooter.py b/spaceShooter.py index 38dc91d..d4791b2 100644 --- a/spaceShooter.py +++ b/spaceShooter.py @@ -10,22 +10,22 @@ # @Last Modified time: 2016-10-16 # MIT License. You can find a copy of the License @ http://prodicus.mit-license.org -## Game music Attribution -##Frozen Jam by tgfcoder licensed under CC-BY-3 +# Game music Attribution +# Frozen Jam by tgfcoder licensed under CC-BY-3 -## Additional assets by: Branden M. Ardelean (Github: @bardlean86) +# Additional assets by: Branden M. Ardelean (Github: @bardlean86) from __future__ import division import pygame import random from os import path -## assets folder +# assets folder img_dir = path.join(path.dirname(__file__), 'assets') sound_folder = path.join(path.dirname(__file__), 'sounds') ############################### -## to be placed in "constant.py" later +# to be placed in "constant.py" later WIDTH = 480 HEIGHT = 600 FPS = 60 @@ -33,7 +33,7 @@ BAR_LENGTH = 100 BAR_HEIGHT = 10 -# Define Colors +# Define Colors WHITE = (255, 255, 255) BLACK = (0, 0, 0) RED = (255, 0, 0) @@ -43,17 +43,18 @@ ############################### ############################### -## to placed in "__init__.py" later -## initialize pygame and create window +# to placed in "__init__.py" later +# initialize pygame and create window pygame.init() -pygame.mixer.init() ## For sound +pygame.mixer.init() # For sound screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Space Shooter") -clock = pygame.time.Clock() ## For syncing the FPS +clock = pygame.time.Clock() # For syncing the FPS ############################### font_name = pygame.font.match_font('arial') + def main_menu(): global screen @@ -63,7 +64,7 @@ def main_menu(): title = pygame.image.load(path.join(img_dir, "main.png")).convert() title = pygame.transform.scale(title, (WIDTH, HEIGHT), screen) - screen.blit(title, (0,0)) + screen.blit(title, (0, 0)) pygame.display.update() while True: @@ -75,25 +76,26 @@ def main_menu(): pygame.quit() quit() elif ev.type == pygame.QUIT: - pygame.quit() - quit() + pygame.quit() + quit() else: draw_text(screen, "Press [ENTER] To Begin", 30, WIDTH/2, HEIGHT/2) draw_text(screen, "or [Q] To Quit", 30, WIDTH/2, (HEIGHT/2)+40) pygame.display.update() - #pygame.mixer.music.stop() - ready = pygame.mixer.Sound(path.join(sound_folder,'getready.ogg')) + # pygame.mixer.music.stop() + ready = pygame.mixer.Sound(path.join(sound_folder, 'getready.ogg')) ready.play() screen.fill(BLACK) draw_text(screen, "GET READY!", 40, WIDTH/2, HEIGHT/2) pygame.display.update() - + def draw_text(surf, text, size, x, y): - ## selecting a cross platform font to display the score + # selecting a cross platform font to display the score font = pygame.font.Font(font_name, size) - text_surface = font.render(text, True, WHITE) ## True denotes the font to be anti-aliased + # True denotes the font to be anti-aliased + text_surface = font.render(text, True, WHITE) text_rect = text_surface.get_rect() text_rect.midtop = (x, y) surf.blit(text_surface, text_rect) @@ -102,8 +104,8 @@ def draw_text(surf, text, size, x, y): def draw_shield_bar(surf, x, y, pct): # if pct < 0: # pct = 0 - pct = max(pct, 0) - ## moving them to top + pct = max(pct, 0) + # moving them to top # BAR_LENGTH = 100 # BAR_HEIGHT = 10 fill = (pct / 100) * BAR_LENGTH @@ -115,18 +117,18 @@ def draw_shield_bar(surf, x, y, pct): def draw_lives(surf, x, y, lives, img): for i in range(lives): - img_rect= img.get_rect() + img_rect = img.get_rect() img_rect.x = x + 30 * i img_rect.y = y surf.blit(img, img_rect) - def newmob(): mob_element = Mob() all_sprites.add(mob_element) mobs.add(mob_element) + class Explosion(pygame.sprite.Sprite): def __init__(self, center, size): pygame.sprite.Sprite.__init__(self) @@ -134,7 +136,7 @@ def __init__(self, center, size): self.image = explosion_anim[self.size][0] self.rect = self.image.get_rect() self.rect.center = center - self.frame = 0 + self.frame = 0 self.last_update = pygame.time.get_ticks() self.frame_rate = 75 @@ -155,14 +157,14 @@ def update(self): class Player(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) - ## scale the player img down + # scale the player img down self.image = pygame.transform.scale(player_img, (50, 38)) self.image.set_colorkey(BLACK) self.rect = self.image.get_rect() self.radius = 20 self.rect.centerx = WIDTH / 2 self.rect.bottom = HEIGHT - 10 - self.speedx = 0 + self.speedx = 0 self.shield = 100 self.shoot_delay = 250 self.last_shot = pygame.time.get_ticks() @@ -173,33 +175,33 @@ def __init__(self): self.power_timer = pygame.time.get_ticks() def update(self): - ## time out for powerups - if self.power >=2 and pygame.time.get_ticks() - self.power_time > POWERUP_TIME: + # time out for powerups + if self.power >= 2 and pygame.time.get_ticks() - self.power_time > POWERUP_TIME: self.power -= 1 self.power_time = pygame.time.get_ticks() - ## unhide + # unhide if self.hidden and pygame.time.get_ticks() - self.hide_timer > 1000: self.hidden = False self.rect.centerx = WIDTH / 2 self.rect.bottom = HEIGHT - 30 - self.speedx = 0 ## makes the player static in the screen by default. - # then we have to check whether there is an event hanlding being done for the arrow keys being - ## pressed + self.speedx = 0 # makes the player static in the screen by default. + # then we have to check whether there is an event hanlding being done for the arrow keys being + # pressed - ## will give back a list of the keys which happen to be pressed down at that moment - keystate = pygame.key.get_pressed() + # will give back a list of the keys which happen to be pressed down at that moment + keystate = pygame.key.get_pressed() if keystate[pygame.K_LEFT]: self.speedx = -5 elif keystate[pygame.K_RIGHT]: self.speedx = 5 - #Fire weapons by holding spacebar + # Fire weapons by holding spacebar if keystate[pygame.K_SPACE]: self.shoot() - ## check for the borders at the left and right + # check for the borders at the left and right if self.rect.right > WIDTH: self.rect.right = WIDTH if self.rect.left < 0: @@ -208,7 +210,7 @@ def update(self): self.rect.x += self.speedx def shoot(self): - ## to tell the bullet where to spawn + # to tell the bullet where to spawn now = pygame.time.get_ticks() if now - self.last_shot > self.shoot_delay: self.last_shot = now @@ -230,7 +232,8 @@ def shoot(self): if self.power >= 3: bullet1 = Bullet(self.rect.left, self.rect.centery) bullet2 = Bullet(self.rect.right, self.rect.centery) - missile1 = Missile(self.rect.centerx, self.rect.top) # Missile shoots from center of ship + # Missile shoots from center of ship + missile1 = Missile(self.rect.centerx, self.rect.top) all_sprites.add(bullet1) all_sprites.add(bullet2) all_sprites.add(missile1) @@ -258,24 +261,26 @@ def __init__(self): self.image_orig.set_colorkey(BLACK) self.image = self.image_orig.copy() self.rect = self.image.get_rect() - self.radius = int(self.rect.width *.90 / 2) + self.radius = int(self.rect.width * .90 / 2) self.rect.x = random.randrange(0, WIDTH - self.rect.width) self.rect.y = random.randrange(-150, -100) - self.speedy = random.randrange(5, 20) ## for randomizing the speed of the Mob + # for randomizing the speed of the Mob + self.speedy = random.randrange(5, 20) - ## randomize the movements a little more + # randomize the movements a little more self.speedx = random.randrange(-3, 3) - ## adding rotation to the mob element + # adding rotation to the mob element self.rotation = 0 self.rotation_speed = random.randrange(-8, 8) - self.last_update = pygame.time.get_ticks() ## time when the rotation has to happen - + # time when the rotation has to happen + self.last_update = pygame.time.get_ticks() + def rotate(self): time_now = pygame.time.get_ticks() - if time_now - self.last_update > 50: # in milliseconds + if time_now - self.last_update > 50: # in milliseconds self.last_update = time_now - self.rotation = (self.rotation + self.rotation_speed) % 360 + self.rotation = (self.rotation + self.rotation_speed) % 360 new_image = pygame.transform.rotate(self.image_orig, self.rotation) old_center = self.rect.center self.image = new_image @@ -286,14 +291,17 @@ def update(self): self.rotate() self.rect.x += self.speedx self.rect.y += self.speedy - ## now what if the mob element goes out of the screen + # now what if the mob element goes out of the screen if (self.rect.top > HEIGHT + 10) or (self.rect.left < -25) or (self.rect.right > WIDTH + 20): self.rect.x = random.randrange(0, WIDTH - self.rect.width) self.rect.y = random.randrange(-100, -40) - self.speedy = random.randrange(1, 8) ## for randomizing the speed of the Mob + # for randomizing the speed of the Mob + self.speedy = random.randrange(1, 8) + +# defines the sprite for Powerups + -## defines the sprite for Powerups class Pow(pygame.sprite.Sprite): def __init__(self, center): pygame.sprite.Sprite.__init__(self) @@ -301,43 +309,44 @@ def __init__(self, center): self.image = powerup_images[self.type] self.image.set_colorkey(BLACK) self.rect = self.image.get_rect() - ## place the bullet according to the current position of the player + # place the bullet according to the current position of the player self.rect.center = center self.speedy = 2 def update(self): """should spawn right in front of the player""" self.rect.y += self.speedy - ## kill the sprite after it moves over the top border + # kill the sprite after it moves over the top border if self.rect.top > HEIGHT: self.kill() - -## defines the sprite for bullets +# defines the sprite for bullets 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() - ## place the bullet according to the current position of the player - self.rect.bottom = y + # place the bullet according to the current position of the player + self.rect.bottom = y self.rect.centerx = x self.speedy = -10 def update(self): """should spawn right in front of the player""" self.rect.y += self.speedy - ## kill the sprite after it moves over the top border + # kill the sprite after it moves over the top border if self.rect.bottom < 0: self.kill() - ## now we need a way to shoot - ## lets bind it to "spacebar". - ## adding an event for it in Game loop + # now we need a way to shoot + # lets bind it to "spacebar". + # adding an event for it in Game loop + +# FIRE ZE MISSILES + -## FIRE ZE MISSILES class Missile(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) @@ -356,23 +365,25 @@ def update(self): ################################################### -## Load all game images +# Load all game images background = pygame.image.load(path.join(img_dir, 'starfield.png')).convert() background_rect = background.get_rect() -## ^^ draw this rect first +# ^^ draw this rect first -player_img = pygame.image.load(path.join(img_dir, 'playerShip1_orange.png')).convert() +player_img = pygame.image.load( + path.join(img_dir, 'playerShip1_orange.png')).convert() player_mini_img = pygame.transform.scale(player_img, (25, 19)) player_mini_img.set_colorkey(BLACK) bullet_img = pygame.image.load(path.join(img_dir, 'laserRed16.png')).convert() -missile_img = pygame.image.load(path.join(img_dir, 'missile.png')).convert_alpha() +missile_img = pygame.image.load( + path.join(img_dir, 'missile.png')).convert_alpha() # meteor_img = pygame.image.load(path.join(img_dir, 'meteorBrown_med1.png')).convert() meteor_images = [] meteor_list = [ 'meteorBrown_big1.png', - 'meteorBrown_big2.png', - 'meteorBrown_med1.png', + 'meteorBrown_big2.png', + 'meteorBrown_med1.png', 'meteorBrown_med3.png', 'meteorBrown_small1.png', 'meteorBrown_small2.png', @@ -380,9 +391,10 @@ def update(self): ] for image in meteor_list: - meteor_images.append(pygame.image.load(path.join(img_dir, image)).convert()) + meteor_images.append(pygame.image.load( + path.join(img_dir, image)).convert()) -## meteor explosion +# meteor explosion explosion_anim = {} explosion_anim['lg'] = [] explosion_anim['sm'] = [] @@ -391,48 +403,50 @@ def update(self): filename = 'regularExplosion0{}.png'.format(i) img = pygame.image.load(path.join(img_dir, filename)).convert() img.set_colorkey(BLACK) - ## resize the explosion + # resize the explosion img_lg = pygame.transform.scale(img, (75, 75)) explosion_anim['lg'].append(img_lg) img_sm = pygame.transform.scale(img, (32, 32)) explosion_anim['sm'].append(img_sm) - ## player explosion + # player explosion filename = 'sonicExplosion0{}.png'.format(i) img = pygame.image.load(path.join(img_dir, filename)).convert() img.set_colorkey(BLACK) explosion_anim['player'].append(img) -## load power ups +# load power ups powerup_images = {} -powerup_images['shield'] = pygame.image.load(path.join(img_dir, 'shield_gold.png')).convert() -powerup_images['gun'] = pygame.image.load(path.join(img_dir, 'bolt_gold.png')).convert() +powerup_images['shield'] = pygame.image.load( + path.join(img_dir, 'shield_gold.png')).convert() +powerup_images['gun'] = pygame.image.load( + path.join(img_dir, 'bolt_gold.png')).convert() ################################################### ################################################### -### Load all game sounds +# Load all game sounds shooting_sound = pygame.mixer.Sound(path.join(sound_folder, 'pew.wav')) missile_sound = pygame.mixer.Sound(path.join(sound_folder, 'rocket.ogg')) expl_sounds = [] for sound in ['expl3.wav', 'expl6.wav']: expl_sounds.append(pygame.mixer.Sound(path.join(sound_folder, sound))) -## main background music +# main background music #pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')) -pygame.mixer.music.set_volume(0.2) ## simmered the sound down a little +pygame.mixer.music.set_volume(0.2) # simmered the sound down a little player_die_sound = pygame.mixer.Sound(path.join(sound_folder, 'rumble1.ogg')) ################################################### -## TODO: make the game music loop over again and again. play(loops=-1) is not working -# Error : +# TODO: make the game music loop over again and again. play(loops=-1) is not working +# Error : # TypeError: play() takes no keyword arguments -#pygame.mixer.music.play() +# pygame.mixer.music.play() ############################# -## Game loop +# Game loop running = True menu_display = True while running: @@ -440,42 +454,45 @@ def update(self): main_menu() pygame.time.wait(3000) - #Stop menu music + # Stop menu music pygame.mixer.music.stop() - #Play the gameplay music - pygame.mixer.music.load(path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')) - pygame.mixer.music.play(-1) ## makes the gameplay sound in an endless loop - + # Play the gameplay music + pygame.mixer.music.load( + path.join(sound_folder, 'tgfcoder-FrozenJam-SeamlessLoop.ogg')) + # makes the gameplay sound in an endless loop + pygame.mixer.music.play(-1) + menu_display = False - - ## group all the sprites together for ease of update + + # group all the sprites together for ease of update all_sprites = pygame.sprite.Group() player = Player() all_sprites.add(player) - ## spawn a group of mob + # spawn a group of mob mobs = pygame.sprite.Group() - for i in range(8): ## 8 mobs + for i in range(8): # 8 mobs # mob_element = Mob() # all_sprites.add(mob_element) # mobs.add(mob_element) newmob() - ## group for bullets + # group for bullets bullets = pygame.sprite.Group() powerups = pygame.sprite.Group() - #### Score board variable + # Score board variable score = 0 - - #1 Process input/events - clock.tick(FPS) ## will make the loop run at the same speed all the time - for event in pygame.event.get(): # gets all the events which have occured till now and keeps tab of them. - ## listening for the the X button at the top + + # 1 Process input/events + clock.tick(FPS) # will make the loop run at the same speed all the time + # gets all the events which have occured till now and keeps tab of them. + for event in pygame.event.get(): + # listening for the the X button at the top if event.type == pygame.QUIT: running = False - ## Press ESC to exit game + # Press ESC to exit game if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False @@ -484,17 +501,16 @@ def update(self): # if event.key == pygame.K_SPACE: # player.shoot() ## we have to define the shoot() function - #2 Update + # 2 Update all_sprites.update() - - ## check if a bullet hit a mob - ## now we have a group of bullets and a group of mob + # check if a bullet hit a mob + # now we have a group of bullets and a group of mob hits = pygame.sprite.groupcollide(mobs, bullets, True, True) - ## now as we delete the mob element when we hit one with a bullet, we need to respawn them again - ## as there will be no mob_elements left out + # now as we delete the mob element when we hit one with a bullet, we need to respawn them again + # as there will be no mob_elements left out for hit in hits: - score += 50 - hit.radius ## give different scores for hitting big and small metoers + score += 50 - hit.radius # give different scores for hitting big and small metoers random.choice(expl_sounds).play() # m = Mob() # all_sprites.add(m) @@ -505,19 +521,21 @@ def update(self): pow = Pow(hit.rect.center) all_sprites.add(pow) powerups.add(pow) - newmob() ## spawn a new mob + newmob() # spawn a new mob - ## ^^ the above loop will create the amount of mob objects which were killed spawn again + # ^^ the above loop will create the amount of mob objects which were killed spawn again ######################### - ## check if the player collides with the mob - hits = pygame.sprite.spritecollide(player, mobs, True, pygame.sprite.collide_circle) ## gives back a list, True makes the mob element disappear + # check if the player collides with the mob + # gives back a list, True makes the mob element disappear + hits = pygame.sprite.spritecollide( + player, mobs, True, pygame.sprite.collide_circle) for hit in hits: player.shield -= hit.radius * 2 expl = Explosion(hit.rect.center, 'sm') all_sprites.add(expl) newmob() - if player.shield <= 0: + if player.shield <= 0: player_die_sound.play() death_explosion = Explosion(player.rect.center, 'player') all_sprites.add(death_explosion) @@ -526,7 +544,7 @@ def update(self): player.lives -= 1 player.shield = 100 - ## if the player hit a power up + # if the player hit a power up hits = pygame.sprite.spritecollide(player, powerups, True) for hit in hits: if hit.type == 'shield': @@ -536,7 +554,7 @@ def update(self): if hit.type == 'gun': player.powerup() - ## if player died and the explosion has finished, end game + # if player died and the explosion has finished, end game if player.lives == 0 and not death_explosion.alive(): # print("Hack the game!") @@ -547,20 +565,20 @@ def update(self): menu_display = True pygame.display.update() - - #3 Draw/render + # 3 Draw/render screen.fill(BLACK) - ## draw the stargaze.png image + # draw the stargaze.png image screen.blit(background, background_rect) all_sprites.draw(screen) - draw_text(screen, str(score), 18, WIDTH / 2, 10) ## 10px down from the screen + # 10px down from the screen + draw_text(screen, str(score), 18, WIDTH / 2, 10) draw_shield_bar(screen, 5, 5, player.shield) # Draw lives draw_lives(screen, WIDTH - 100, 5, player.lives, player_mini_img) - ## Done after drawing everything to the screen - pygame.display.flip() + # Done after drawing everything to the screen + pygame.display.flip() pygame.quit() diff --git a/wow.txt b/wow.txt new file mode 100644 index 0000000..34bad31 --- /dev/null +++ b/wow.txt @@ -0,0 +1,4 @@ +Really You are smart. Your skills to google are good. +Just on the way to complete all + +Do try taking parts in Quizzes in online :P