1
Fork 0

Compare commits

...

38 Commits
V1.6 ... master

Author SHA1 Message Date
Jake Howard bb2bc41b68 Fixed unit number (facepalm) 2015-09-14 23:00:09 +01:00
Jake Howard 8020853ef7 Moved files over to github 2015-09-14 22:57:43 +01:00
Jake Howard cb5ece304a removed thumbs files 2015-09-14 22:15:05 +01:00
Jake Howard 5640158e82 Initial commit 2015-09-14 22:12:57 +01:00
Jake Howard d91f82a889 fixed neverending loop 2015-06-04 12:34:22 +01:00
Jake Howard 7cf6638cb9 forgot to disable main sound 2015-06-04 12:19:33 +01:00
Jake Howard 5b14f36770 modified OP keyboard shortcuts for OP. 2015-06-04 12:19:22 +01:00
Jake Howard a9d7d9c6f7 fixed forgotten pass 2015-06-04 11:20:26 +01:00
Jake Howard 230c2db7ec readded OP sound 2015-05-21 13:21:46 +01:00
Jake Howard 8f56f52980 changed extension 2015-05-21 13:21:37 +01:00
Jake Howard 0bbd172764 updated display 2015-05-21 13:21:28 +01:00
Jake Howard 3542fe1f74 compressed audio 2015-05-21 13:21:18 +01:00
Jake Howard 1d216164c8 Added window title 2015-05-21 13:09:43 +01:00
Jake Howard 1b34829e62 changed font size 2015-05-21 13:08:46 +01:00
Jake Howard 73a913c43c added branding 2015-05-21 12:58:31 +01:00
Jake Howard b4a8b7db3f updated version 2015-05-19 12:20:09 +01:00
Jake Howard e7687ded09 updated bug when resetting player image. It sent you to origin and you lost instantly 2015-05-19 12:19:47 +01:00
Jake Howard b30a7c4ff0 because windows 2015-05-19 12:19:16 +01:00
Jake Howard f278d9b103 updated levels 2015-05-19 12:19:06 +01:00
Jake Howard 840e1d0b78 updated texture code and lives 2015-05-19 12:17:27 +01:00
Jake Howard 33df9d2ecf added code for calling target image manually 2015-05-19 12:16:56 +01:00
Jake Howard cce185db01 added lives 2015-05-19 12:15:19 +01:00
Jake Howard 852071900e added powerups to game 2015-05-19 12:13:44 +01:00
Jake Howard b166569da3 Added versions to game 2015-05-19 10:09:48 +01:00
TheOrangeOne f9d90cd6ad README.md edited online with Bitbucket 2015-05-14 13:55:48 +00:00
TheOrangeOne ffe7e0568b README.md edited online with Bitbucket 2015-05-14 13:54:47 +00:00
Jake Howard b6566b20ec added option to reset image 2015-05-14 13:21:54 +01:00
Jake Howard 6ce5e0a463 You can now turn OP mode off 2015-05-14 13:21:10 +01:00
Jake Howard 746a9b3389 changed basic instructions and requirements 2015-05-14 13:20:59 +01:00
Jake Howard a6c9e8100b rebranding the game 2015-05-14 13:20:33 +01:00
Jake Howard 42d74daaf8 Flipped sound logic 2015-05-13 09:31:32 +01:00
Jake Howard 51f8d3e4eb stop OP music when you press the button again 2015-05-13 09:31:08 +01:00
Jake Howard 7ae0ca4d3f Lives go red at 1 not 0!! 2015-05-13 09:30:46 +01:00
Jake Howard c91a7e8359 changed sounds tickbox label 2015-05-13 09:30:30 +01:00
Jake Howard b08cf848fa updated default texture pack 2015-05-13 09:30:07 +01:00
Jake Howard f0b36b23d5 added extra import 2015-05-13 09:03:04 +01:00
TheOrangeOne 038fb7a72f README.md edited online with Bitbucket 2015-05-12 22:01:56 +00:00
TheOrangeOne 9c3cc001e8 README.md edited online with Bitbucket 2015-05-12 21:59:11 +00:00
25 changed files with 225 additions and 69 deletions

56
.gitignore vendored
View File

@ -1 +1,57 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/

26
GUI.py
View File

@ -7,16 +7,20 @@ from assets import Textures
PADDING_TITLE = 15
PADDING_BUTTON = 9
VERSION = {"ID":"2.2", "DATE": "19/05/15"}
class Main_Window:
def __init__(self, master):
self.master = master
self.master.title("SPACE INVADERS")
self.master.title("ATTACK ON BLOCKS")
self.title = Label(self.master)
self.title.config(text="SPACE INVADERS!",font=("Courier New", 37))
self.title.pack(side="top", padx=PADDING_BUTTON, pady=PADDING_TITLE/2)
self.title.config(text="ATTACK ON BLOCKS!",font=("Courier New", 37))
self.title.pack(side="top", padx=PADDING_TITLE, pady=PADDING_TITLE/2)
self.version_info = Label(self.master)
self.version_info.config(text="Version {ID} tagged {DATE}".format(**VERSION), font=("Courier New", 13))
self.version_info.pack(side="top", padx=0, pady=PADDING_BUTTON/2)
self.start_button = Button(self.master, style="Menu.TButton")
self.start_button.config(text="Play Game")
@ -38,6 +42,11 @@ class Main_Window:
self.exit_button.pack(ipadx=PADDING_BUTTON/3, ipady=PADDING_BUTTON, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
self.exit_button.bind('<Button-1>', self.close)
self.about_info = Label(self.master)
self.about_info.config(text="Game Created by TheOrangeOne!", font=("Courier New", 9))
self.about_info.bind("<Button-1>", self.show_site)
self.about_info.pack(side="top", padx=0, pady=PADDING_BUTTON/2)
Style().configure("Menu.TButton", font=("Lucida", 21))
Style().configure("About.TButton", font=("Lucida", 17))
Style().configure("Quit.TButton", font=("Lucida", 13))
@ -56,12 +65,15 @@ class Main_Window:
def show_info(self, event):
logging.info("Loading About Page...")
system("start https://bitbucket.org/theorangeone/space-invaders/wiki/Home")
system("start https://bitbucket.org/theorangeone/attack-on-blocks/wiki/Home")
def close(self, event):
logging.critical("Closing Main Window.")
self.master.destroy()
def show_site(self, event):
logging.info("Loading Website")
system("start http://theorangeone.net")
class Options_Window:
def __init__(self):
@ -74,7 +86,7 @@ class Options_Window:
def display(self, master):
self.master = master
self.master.title("SPACE INVADERS - Options")
self.master.title("ATTACK ON BLOCKS - Options")
self.title = Label(self.master)
self.title.config(text="OPTIONS",font=("Courier New", 37))
@ -107,7 +119,7 @@ class Options_Window:
self.using_sounds = IntVar()
self.using_sounds.set(self.options["Sounds"])
self.sounds_check = Checkbutton(self.master, text="Enable Sound Effects", command=self.update_sounds, variable=self.using_sounds)
self.sounds_check = Checkbutton(self.master, text="Use Sound Effects", command=self.update_sounds, variable=self.using_sounds)
self.sounds_check.pack(ipadx=PADDING_BUTTON/3, padx=PADDING_BUTTON)
Style().configure("Minor.TButton", font=("Lucida", 10))

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015 Jake Howard
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,3 +1,3 @@
print("Starting Space Invaders...\nLoading Main Window...")
print("Starting Attack on Blocks...\nLoading Main Window...")
import GUI
GUI.display()

View File

@ -1,24 +1,26 @@
# Space Invaders #
This take on space invaders was written for my IT BTEC course, Unit 21 Games Development at college. This version, written in python, includes more advanced features such as resource packs.
### Requirements ###
* Python
* Pygame
* TKinter
The game is only playable on windows, due to the GUI library only being available on windows. However a cross platform, lightweight version may be made in the future.
### Playing the game ###
* Clone the repository
* Install the required libraries (See Above)
* Run 'Play The Game.py'
### Core Contributors ###
* Jake Howard
* Furhan Bhatti (Well not really)
# Note #
At the moment, the game WILL NOT play at all, as it is still in development, all the time this message is here, the program will not run!
# Attack on Blocks #
This take on space invaders was written for my IT BTEC course, Unit 22 Games Development at college. This version, written in python, includes more advanced features such as resource packs.
### More Information ###
For more information, check out the [Wiki](//bitbucket.org/TheOrangeOne/attack-on-blocks/wiki) page.
### Requirements ###
* Python 3
* Pygame
* TKinter
The game is only playable on windows, due to the GUI library only being available on windows. However a cross platform, lightweight version may be made in the future.
### Playing the game ###
* Clone the repository, or visit the downloads page
* Install the required libraries (See Above)
* Run 'Play The Game.py'
### Core Contributors ###
* Jake Howard
* Furhan Bhatti (Well not really)

BIN
Thumbs.db

Binary file not shown.

View File

@ -9,7 +9,8 @@ class Textures():
"BULLET":"bullet",
"TARGETS":[],
"SHOOTER":"shooter",
"TARGET_BULLET":"bullet_target"
"TARGET_BULLET":"bullet_target",
"POWERUP": "powerup"
}
self.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\"
self.pack = "default"
@ -31,10 +32,14 @@ class Textures():
filename = self.path + self.pack + "\\{0}.png".format(self.images[objectName.upper()])
return pygame.image.load(filename)
def get_target_texture(self):
index = randint(0,len(self.images["TARGETS"])-1) if len(self.images["TARGETS"]) >=1 else 0
filename = self.path + self.pack + "\\{}.png".format(self.images["TARGETS"][randint(0,len(self.images["TARGETS"])-1)])
return pygame.image.load(filename)
def get_target_texture(self, ID=False):
if not ID:
index = randint(0,len(self.images["TARGETS"])-1) if len(self.images["TARGETS"]) >=1 else 0
filename = self.path + self.pack + "\\{}.png".format(self.images["TARGETS"][index])
return [pygame.image.load(filename), index]
else:
filename = self.path + self.pack + "\\target{}.png".format(int(ID))
return [pygame.image.load(filename), ID]
def list_packs(self):
return [x[0].replace(self.path, "") for x in os.walk(self.path)]
@ -48,8 +53,11 @@ Levels = [
Level_Template(4, 15, 3, 1),
Level_Template(3, 7, 2, 2),
Level_Template(5, 15, 2, 1),
Level_Template(1, 20, 100, 0), #All the enemies!
Level_Template(2, 20, 100, 2), #All the enemies!
Level_Template(3, 15, 2, 1),
Level_Template(3, 7, 2, 4),
Level_Template(4, 15, 4, 3),
Level_Template(5, 35, 4, 6),
]
@ -64,12 +72,12 @@ def generate_random_level():
Sounds = {}
def init_sounds():
music_files = ["main.wav", "OP.wav", "shot.wav"]
music_files = ["main.ogg", "OP.ogg", "shot.ogg"]
for file in music_files:
path = os.path.dirname(os.path.realpath(__file__)) + "\\resources\\sounds\\" + file
if file == "main.wav":
if file == "main.ogg":
mixer = pygame.mixer.music
mixer.load(path)
else: mixer = pygame.mixer.Sound(path)
mixer.set_volume(1.0)
Sounds[file.replace(".wav", "")] = mixer
Sounds[file.replace(".ogg", "")] = mixer

View File

@ -2,10 +2,10 @@ import pygame
class Bullet(pygame.sprite.Sprite):
def __init__(self, parent, textures):
def __init__(self, parent, textures, bigger):
super().__init__()
self.width = 6
self.height = 14
self.width = 6 * (1+int(bigger))
self.height = 14 * (1+int(bigger))
self.image = pygame.transform.scale(textures.get_texture("BULLET"), (self.width, self.height))
self.rect = self.image.get_rect()
self.rect.x = parent.rect.x + parent.width/2 - self.width/2

69
game.py
View File

@ -7,7 +7,7 @@ from player import Shooter
from assets import *
from target import Target, generate_targets
POWERUPS = ["SPEED", "DOUBLE", "LIVES", "SCORE", "BIGGER"]
PLAYING_GAME = False
WINDOW_SIZE = (680, 790)
HUD_COLOUR = (255,168,72)
@ -23,13 +23,13 @@ def update_level(window, level, colour=HUD_COLOUR):
def update_lives(window, lives, colour=HUD_COLOUR):
font = pygame.font.SysFont(None, 30, bold=False)
window.blit(font.render("Lives Remaining: {}".format(int(lives)), True, colour if lives != 0 else (255,50,0)), (3.8*WINDOW_SIZE[0]/10, WINDOW_SIZE[1] - 30))
window.blit(font.render("Lives Remaining: {}".format(int(lives)), True, colour if lives != 1 else (255,50,0)), (3.8*WINDOW_SIZE[0]/10, WINDOW_SIZE[1] - 30))
def initialise(menu, options):
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
window = pygame.display.set_mode(WINDOW_SIZE)
pygame.display.set_caption("Attack on Blocks")
exit_code = play(window, options) # Run main game loop
for key, value in Sounds.items():
value.fadeout(500)
@ -57,11 +57,11 @@ def play(window, options):
FPS = player.options["Difficulty"]
timeouts = {
"Target Movement":[FPS*0.75,FPS*0.75],
"Powerup":[FPS*100, FPS*100]
"Target Movement":[FPS*0.65,FPS*0.65],
"Powerup":[FPS*15, FPS*15]
}
init_sounds()
Sounds["main"].play(loops=-1) #Start background music
if options["Sounds"]: Sounds["main"].play(loops=-1) #Start background music
logging.info("Game Started.")
PLAYING_GAME = True
@ -76,16 +76,15 @@ def play(window, options):
return "QUIT"
if event.type == pygame.KEYDOWN and event.key in [pygame.K_SPACE, pygame.K_w, pygame.K_UP] and not fired:
if not player.options["Sounds"]: Sounds["shot"].play()
temp = Bullet(player, player.options["Textures"])
if player.options["Sounds"]: Sounds["shot"].play()
temp = Bullet(player, player.options["Textures"], player.powerup == "BIGGER")
bullet_group.add(temp)
if player.powerup == "DOUBLE":
temp = Bullet(player, player.options["Textures"], player.powerup == "BIGGER")
temp.rect.y += 20
bullet_group.add(temp)
fired = True
if event.type == pygame.KEYDOWN and event.key == pygame.K_KP_PLUS:
if not player.options["Sounds"] or not player.OP:
Sounds["main"].stop()
Sounds["OP"].play(loops=-1)
player.OP = True
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
@ -97,12 +96,28 @@ def play(window, options):
else: player.move(-player.speed)
if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6] and player.OP:
temp = Bullet(player, player.options["Textures"])
temp = Bullet(player, player.options["Textures"], False)
bullet_group.add(temp)
if keys[pygame.K_r] and [pygame.K_9] and [pygame.K_k] and player.OP:
eggs.r9k(window)
if keys[pygame.K_KP4] and keys[pygame.K_KP2] and keys[pygame.K_KP0] and keys[pygame.K_o] and keys[pygame.K_p] and not player.OP:
if player.options["Sounds"]:
Sounds["main"].stop()
Sounds["OP"].play(loops=-1)
player.OP = True
player.change_colour((255,96,0))
logging.warn("OP mode engaged.")
if keys[pygame.K_KP_MINUS] and player.OP:
if player.options["Sounds"]:
Sounds["OP"].stop()
Sounds["main"].play(loops=-1)
player.OP = False
player.reset_image()
logging.warn("OP mode disabled.")
for sprite in bullet_group:
sprite.update()
if sprite.rect.y < 0 or (sprite.rect.y > player.rect.y and sprite.type == "TARGET"):
@ -112,9 +127,14 @@ def play(window, options):
hit_list = pygame.sprite.spritecollide(bullet, target_group, False)
for target in hit_list:
if bullet.type != "TARGET":
target_group.remove(target)
target.lives -= 1
if target.lives <= 0:
target_group.remove(target)
player.score += 1
bullet_group.remove(bullet)
player.score += 1
if target.lives <= 0 and target.type == "POWERUP":
player.powerup = POWERUPS[randint(0,len(POWERUPS)-1)]
logging.info("Powerup set to {}".format(player.powerup))
hit_list = pygame.sprite.spritecollide(bullet, player_group, False)
for player in hit_list:
@ -143,10 +163,20 @@ def play(window, options):
timeouts["Target Movement"][0] = timeouts["Target Movement"][1]
if timeouts["Powerup"][0] <= 0:
timeouts["Powerup"][0] = timeouts["Powerup"][1]
if player.powerup == "SCORE":
player.score += 10
player.powerup = ""
elif player.powerup == "LIVES":
player.lives += 1
player.powerup = ""
for target in target_group:
if target.type == "SHOOTER":
if randint(0,600) > 1: continue
temp = Bullet(target, player.options["Textures"])
temp = Bullet(target, player.options["Textures"], False)
temp.type="TARGET"
temp.image = pygame.transform.scale(player.options["Textures"].get_texture("TARGET_BULLET"), (temp.width, temp.height))
x,y = temp.rect.x, temp.rect.y
@ -165,9 +195,6 @@ def play(window, options):
sleep(0.75)
Sounds["main"].set_volume(1.0)
if player.OP:
player.change_colour((255,96,0)) #override colour change if changed before
update_score(window, player.score)
update_level(window, player.level)
update_lives(window, player.lives)

View File

@ -7,7 +7,8 @@ class Shooter(pygame.sprite.Sprite):
self.width = width
self.height = height
self.colour = colour
self.image = pygame.transform.scale(texture.get_texture("PLAYER"), (self.width, self.height))
self.texture = texture
self.image = pygame.transform.scale(self.texture.get_texture("PLAYER"), (self.width, self.height))
self.rect = self.image.get_rect()
self.speed = 3
self.window_rect = window.get_rect()
@ -33,4 +34,10 @@ class Shooter(pygame.sprite.Sprite):
x,y = self.rect.x, self.rect.y
self.image.fill(colour)
self.rect = self.image.get_rect()
self.set_position(x,y)
self.set_position(x,y)
def reset_image(self):
x,y = self.rect.x, self.rect.y
self.image = pygame.transform.scale(self.texture.get_texture("PLAYER"), (self.width, self.height))
self.rect = self.image.get_rect()
self.set_position(x,y)

BIN
resources/sounds/OP.ogg Normal file

Binary file not shown.

Binary file not shown.

BIN
resources/sounds/shot.ogg Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@ -1,5 +1,6 @@
import pygame, logging
from random import randint
from game import generate_random_level
class Target(pygame.sprite.Sprite):
@ -7,11 +8,14 @@ class Target(pygame.sprite.Sprite):
super().__init__()
self.width = width
self.height = height
self.image = pygame.transform.scale(textures.get_target_texture(), (self.width, self.height))
self.textures = textures
self.default_texture = textures.get_target_texture()
self.image = pygame.transform.scale(self.default_texture[0], (self.width, self.height))
self.rect = self.image.get_rect()
self.speed = 5
self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2)) # centres co-ordinates
self.type = "NORMAL"
self.lives = 1
def move(self):
self.rect.x += self.speed
@ -26,7 +30,6 @@ class Target(pygame.sprite.Sprite):
else:
self.rect.x, self.rect.y = x, y
def generate_targets(player, window_size, Levels):
sprite_list = []
group = pygame.sprite.Group()
@ -46,16 +49,35 @@ def generate_targets(player, window_size, Levels):
firebacks = len(sprite_list)
else: firebacks = level.firebacks
for i in range(firebacks):
loop = 0
changed = False
while not changed:
if loop == firebacks: changed = True
index = randint(0, len(sprite_list)-1) if (len(sprite_list) - 1 != 0) else 0
if sprite_list[index].type != "SHOOTER":
sprite_list[index].type = "SHOOTER"
sprite_list[index].lives = 2
sprite_list[index].image = pygame.transform.scale(player.options["Textures"].get_texture("SHOOTER"), (sprite_list[index].width, sprite_list[index].height))
x,y = sprite_list[index].rect.x, sprite_list[index].rect.y
sprite_list[index].rect = sprite_list[index].image.get_rect()
sprite_list[index].set_position(x,y, center=False) #Already Centered!
changed = True
loop += 1
if len(sprite_list) < level.powerups:
powerups = len(sprite_list)
else: powerups = level.powerups
for i in range(powerups):
changed = False
while not changed:
index = randint(0, len(sprite_list)-1) if (len(sprite_list) - 1 != 0) else 0
if sprite_list[index].type != "POWERUP" and sprite_list[index].type != "SHOOTER" :
sprite_list[index].type = "POWERUP"
sprite_list[index].image = pygame.transform.scale(player.options["Textures"].get_texture("POWERUP"), (sprite_list[index].width, sprite_list[index].height))
x,y = sprite_list[index].rect.x, sprite_list[index].rect.y
sprite_list[index].rect = sprite_list[index].image.get_rect()
sprite_list[index].set_position(x,y, center=False) #Already Centered!
changed = True
for sprite in sprite_list: #Because sprite groups dont support indexing!
group.add(sprite)