Skip to content
Open
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
37 changes: 34 additions & 3 deletions Spacey.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
import numpy as np


class Background_scroll(pygame.sprite.Sprite):
def __init__(self, background_image):
pygame.sprite.Sprite.__init__(self)
self.image = background_image
self.n_pixel_roll = 2 # Number of rows to roll from bottom to top
self.update_speed = 2 # Roll ever n frames

gameDisplay.blit(self.image, (0,0))

def update(self):
if frame_count % self.update_speed == 0:
# Convert surface to numpy array
imgarr = pygame.surfarray.array3d(self.image)
# Roll the image array
imgarr = np.roll(imgarr, self.n_pixel_roll, axis=1)
# Convert numpy array back to pygame surface
self.image = pygame.pixelcopy.make_surface(imgarr)

gameDisplay.blit(self.image, (0,0))


class Explosion(pygame.sprite.Sprite):
def __init__(self, frames, xcoord, ycoord, scale=1.5, update_n=1):
pygame.sprite.Sprite.__init__(self) # call Sprite initializer
Expand All @@ -16,6 +37,7 @@ def __init__(self, frames, xcoord, ycoord, scale=1.5, update_n=1):
self.update_n = update_n
self.update_counter = self.update_n


def update(self):
self.update_counter -= 1
if self.frame >= len(self.frames) - 1:
Expand Down Expand Up @@ -417,7 +439,7 @@ def main_menu():
quit()

# Update main menu
gameDisplay.blit(background, (0, 0))
gameDisplay.blit(background_img, (0, 0))
startbutton = gameDisplay.blit(start_button, (button_x_center, display_height * 0.4))
creditbutton = gameDisplay.blit(credit_button, (button_x_center, display_height * 0.5))
quitbutton = gameDisplay.blit(quit_button, (button_x_center, display_height * 0.6))
Expand All @@ -443,6 +465,11 @@ def credit_loop():

def game_loop():

# Instantiate background
global background_img, frame_count
frame_count = 0
background = Background_scroll(background_img)

# Instantiate Ship & Meteor and create a group for lasersprites
global ship, ship_group, meteors, lasers, score_count, enemies, fps, timer, enemy_lasers, score_count
global boss_bomb, explosions, explosions_boss
Expand Down Expand Up @@ -568,7 +595,7 @@ def game_loop():
continue

# Update display and sprites
gameDisplay.blit(background, (0, 0))
background.update()
ship.update()

if len(meteors) < 1 and enemies_meteors_spawning:
Expand Down Expand Up @@ -702,6 +729,10 @@ def game_loop():
# Set FPS
clock.tick(fps)

#frame counter
frame_count += 1



# Here we initialize pygame, set variables and start the actual game
pygame.init()
Expand Down Expand Up @@ -780,7 +811,7 @@ def game_loop():
missile = spritesheetspace2.subsurface(pygame.Rect(1093, 711, 19, 40))
boss_image = spritesheetspace2.subsurface(pygame.Rect(276, 0, 172, 151))
controlscheme = pygame.image.load('Textures/controlscheme.png')
background = pygame.image.load('Textures/space_background.png').convert()
background_img = pygame.image.load('Textures/space_background.png').convert()
credit_background = pygame.image.load('Textures/credits.png').convert()

# Load files used in the game
Expand Down