Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steventify #1

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 02 - The Background/Readme.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 03 - Now we play/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -163,4 +163,4 @@ def on_execute(self):
if __name__ == "__main__" :
theApp = App()
theApp.on_execute()
#
#
Binary file modified 03 - Now we play/sprites/Player_ship (16 x 16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions 04 - Enemies/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -212,4 +212,4 @@ def on_execute(self):
if __name__ == "__main__" :
theApp = App()
theApp.on_execute()
#
#
27 changes: 17 additions & 10 deletions 05 - Its all coming together/app.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -296,4 +303,4 @@ def on_execute(self):

if __name__ == "__main__":
app = App()
app.on_execute()
app.on_execute()
Binary file modified sprites/Alan (16 x 16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sprites/Enemy_projectile (16 x 16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sprites/Player_ship (16 x 16).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sprites/Space_BG (2 frames) (64 x 64).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.