diff --git a/02 - The Background/Readme.org b/02 - The Background/Readme.org index 34f2426..b465a52 100644 --- a/02 - The Background/Readme.org +++ b/02 - The Background/Readme.org @@ -39,7 +39,6 @@ class Level(): return (self.background_a, (0,0)) def on_loop(self, time_now): - print(time_now - self.timer) if time_now - self.timer > 1500: self.timer = time_now self.background_a, self.background_b = self.background_b, self.background_a diff --git a/03 - Now we play/app.py b/03 - Now we play/app.py index 81da28c..3c6e575 100644 --- a/03 - Now we play/app.py +++ b/03 - Now we play/app.py @@ -1,7 +1,7 @@ import pygame import time -WIDTH, HEIGHT = 480, 640 +WIDTH, HEIGHT = 480, 500 SCALE = 1.5 SCALE_WIDTH, SCALE_HEIGHT = WIDTH * SCALE, HEIGHT * SCALE FPS = 60 @@ -163,4 +163,4 @@ def on_execute(self): if __name__ == "__main__" : theApp = App() theApp.on_execute() -# \ No newline at end of file +# diff --git a/03 - Now we play/sprites/Player_ship (16 x 16).png b/03 - Now we play/sprites/Player_ship (16 x 16).png index 25a888b..2981a2e 100644 Binary files a/03 - Now we play/sprites/Player_ship (16 x 16).png and b/03 - Now we play/sprites/Player_ship (16 x 16).png differ diff --git a/04 - Enemies/app.py b/04 - Enemies/app.py index aac6adf..5e83ff0 100644 --- a/04 - Enemies/app.py +++ b/04 - Enemies/app.py @@ -1,7 +1,7 @@ import pygame import time -WIDTH, HEIGHT = 480, 640 +WIDTH, HEIGHT = 480, 540 SCALE = 1.5 SCALE_WIDTH, SCALE_HEIGHT = WIDTH * SCALE, HEIGHT * SCALE FPS = 60 @@ -212,4 +212,4 @@ def on_execute(self): if __name__ == "__main__" : theApp = App() theApp.on_execute() -# \ No newline at end of file +# diff --git a/05 - Its all coming together/app.py b/05 - Its all coming together/app.py index e53f2e0..37e8dc3 100644 --- a/05 - Its all coming together/app.py +++ b/05 - Its all coming together/app.py @@ -1,9 +1,10 @@ import random import pygame import time +import math -WIDTH, HEIGHT = 480, 640 +WIDTH, HEIGHT = 580, 640 SCALE = 1 SCALE_WIDTH, SCALE_HEIGHT = WIDTH * SCALE, HEIGHT * SCALE FPS = 60 @@ -98,20 +99,21 @@ def load_sprite(self): def update(self, dt, time_now): - if time_now - self.timer >= 300: + if time_now - self.timer >= 300: self.image_index += 1 if self.image_index >= len(self.sprites): self.image_index = 0 #print("SPRITE CAHNGE") - if random.random() < 0.025: + if random.random() < 0.005: bullet_group.add(Alien_Bullet(self.rect.centerx, self.rect.bottom)) self.image = self.sprites[self.image_index] self.timer = time_now + self.rect.x += self.dir * 16 class Bullet(pygame.sprite.Sprite): def __init__(self, x, y): pygame.sprite.Sprite.__init__(self) - self.image = pygame.image.load('sprites/Player_beam (16 x 16).png') + self.image = pygame.image.load('sprites/Player_beam (16 x 16).png').convert_alpha() self.image = pygame.transform.scale(self.image, (32,32)) self.rect = self.image.get_rect() self.rect.center = [x,y] @@ -136,7 +138,7 @@ def __init__(self, x, y): self.speed = 500 def load_sprite(self): - sprite_sheet = pygame.image.load('sprites/Enemy_projectile (16 x 16).png') + sprite_sheet = pygame.image.load('sprites/Enemy_projectile (16 x 16).png').convert_alpha() self.image = sprite_sheet; def update(self, dt, time_now): self.rect.y += self.speed * dt @@ -161,7 +163,7 @@ def __init__(self): self.timer = 0 - def create_aliens(self,rows, cols, alien_group): + def create_aliens(self, rows, cols, alien_group): for row in range(rows): for item in range(cols): alien = Alien(80 + item * 64, 100 + row * 64) @@ -225,7 +227,8 @@ def on_init(self): self.bullet_group = bullet_group self.alien_group = alien_group - self.alien_group = self.level.create_aliens(6,6,self.alien_group) + self.alien_group = self.level.create_aliens(6, 6, self.alien_group) + # Handle events def on_event(self, event): if event.type == pygame.QUIT: @@ -235,7 +238,6 @@ def on_event(self, event): def on_loop(self): global GAME_OVER self.clock.tick(FPS) - print(self.clock.get_fps()) self.now = time.time() self.dt = self.now - self.prev_time self.prev_time = self.now @@ -252,7 +254,12 @@ def on_loop(self): self.bullet_group.update(self.dt, time_now) self.alien_group.update(self.dt, time_now) - + alien_hit_edge = any(a.rect.x > WIDTH - a.rect.width or a.rect.x <= 0 for a in self.alien_group) + if alien_hit_edge: + for alien in self.alien_group: + alien.rect.x -= alien.dir * 16 + alien.dir = -alien.dir + alien.rect.y += 16 if len(alien_group) == 0: GAME_OVER = True @@ -296,4 +303,4 @@ def on_execute(self): if __name__ == "__main__": app = App() - app.on_execute() \ No newline at end of file + app.on_execute() diff --git a/sprites/Alan (16 x 16).png b/sprites/Alan (16 x 16).png index ac18e59..b6d774f 100644 Binary files a/sprites/Alan (16 x 16).png and b/sprites/Alan (16 x 16).png differ diff --git a/sprites/Enemy_projectile (16 x 16).png b/sprites/Enemy_projectile (16 x 16).png index b8faa44..e07c3b8 100644 Binary files a/sprites/Enemy_projectile (16 x 16).png and b/sprites/Enemy_projectile (16 x 16).png differ diff --git a/sprites/Player_ship (16 x 16).png b/sprites/Player_ship (16 x 16).png index 25a888b..2981a2e 100644 Binary files a/sprites/Player_ship (16 x 16).png and b/sprites/Player_ship (16 x 16).png differ diff --git a/sprites/Space_BG (2 frames) (64 x 64).png b/sprites/Space_BG (2 frames) (64 x 64).png index d48787f..1636eb5 100644 Binary files a/sprites/Space_BG (2 frames) (64 x 64).png and b/sprites/Space_BG (2 frames) (64 x 64).png differ