Compare commits
141 commits
Author | SHA1 | Date | |
---|---|---|---|
bb2bc41b68 | |||
8020853ef7 | |||
cb5ece304a | |||
|
5640158e82 | ||
d91f82a889 | |||
7cf6638cb9 | |||
5b14f36770 | |||
a9d7d9c6f7 | |||
230c2db7ec | |||
8f56f52980 | |||
0bbd172764 | |||
3542fe1f74 | |||
1d216164c8 | |||
1b34829e62 | |||
73a913c43c | |||
b4a8b7db3f | |||
e7687ded09 | |||
b30a7c4ff0 | |||
f278d9b103 | |||
840e1d0b78 | |||
33df9d2ecf | |||
cce185db01 | |||
852071900e | |||
b166569da3 | |||
|
f9d90cd6ad | ||
|
ffe7e0568b | ||
b6566b20ec | |||
6ce5e0a463 | |||
746a9b3389 | |||
a6c9e8100b | |||
42d74daaf8 | |||
51f8d3e4eb | |||
7ae0ca4d3f | |||
c91a7e8359 | |||
b08cf848fa | |||
f0b36b23d5 | |||
|
038fb7a72f | ||
|
9c3cc001e8 | ||
b773930dd2 | |||
3ba98e89a6 | |||
43883a0ee2 | |||
cb82deed7b | |||
0d4580c854 | |||
cea485736e | |||
1784865b1a | |||
99ab88af18 | |||
c0f78046ef | |||
7475a69d2a | |||
11ff4cd502 | |||
0bc944c284 | |||
07ecced10b | |||
1b44b11144 | |||
f8e2e5df71 | |||
a56dd547b9 | |||
613a4b36c7 | |||
701f722f10 | |||
55f3bdae15 | |||
9fb556cc7a | |||
e50d081004 | |||
5f4d456388 | |||
e34d53fdd4 | |||
3f25eb13b4 | |||
f7de3262d9 | |||
d005fd5a52 | |||
a0c1a77ef6 | |||
9196224a32 | |||
ab74f0bcad | |||
e16ee98f04 | |||
cb4293370a | |||
|
c627f7f13b | ||
00f6fd2e5e | |||
150efceafc | |||
8d3a77a9c3 | |||
e21781e586 | |||
03de948eb4 | |||
e34503d2bc | |||
a499534f11 | |||
fdd6994ce0 | |||
9f7918ab0e | |||
5ff6de4b58 | |||
ed548bdcf5 | |||
0d4080e8ae | |||
2769e423db | |||
7ce3cbe077 | |||
307b99fe19 | |||
4460a0bb12 | |||
a780da7dbe | |||
68f5d76512 | |||
08e21b471a | |||
d61d4ca0ec | |||
ae52af7426 | |||
30d08f0036 | |||
3cc1b12f38 | |||
577d0be1c1 | |||
a4a3541fcb | |||
64eb14bed8 | |||
76b229f40b | |||
7f497f2b61 | |||
709b17b7d8 | |||
bfe6ad55ed | |||
749cdf77a2 | |||
afcd0a29a7 | |||
038aacb383 | |||
61215ec634 | |||
1d922b846c | |||
e68f820765 | |||
b24e9e9c69 | |||
f08a12d577 | |||
b4d835fe70 | |||
654498fcbb | |||
fd143380b3 | |||
cb28b4ab4e | |||
47464b7428 | |||
ef48e91b82 | |||
d2d0ff4e29 | |||
e14cac3a65 | |||
ad1de703f6 | |||
1f8574d85e | |||
d1a5e2c0e5 | |||
b43a2b32b3 | |||
e9d20130c4 | |||
da9b7318f6 | |||
3c4eff2130 | |||
8a5756051d | |||
f74812bc3b | |||
9e34de19b4 | |||
e819e2e46d | |||
36d6e309ff | |||
265f886b23 | |||
3789bfd66a | |||
6715733162 | |||
a352c41651 | |||
dda6e8dd9d | |||
9955f7aa5b | |||
b31fad219e | |||
7821265f6f | |||
1dd1205cb4 | |||
788a58f014 | |||
a20a1d361d | |||
171a18b946 | |||
2e700da34a |
56
.gitignore
vendored
|
@ -1 +1,57 @@
|
||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__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/
|
||||||
|
|
126
GUI.py
|
@ -1,46 +1,147 @@
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
from tkinter.ttk import *
|
from tkinter.ttk import *
|
||||||
import logging
|
import logging
|
||||||
|
from os import system
|
||||||
import game
|
import game
|
||||||
|
from assets import Textures
|
||||||
|
|
||||||
PADDING_TITLE = 15
|
PADDING_TITLE = 15
|
||||||
PADDING_BUTTON = 9
|
PADDING_BUTTON = 9
|
||||||
|
VERSION = {"ID":"2.2", "DATE": "19/05/15"}
|
||||||
PROGRAM_OPEN = True
|
|
||||||
|
|
||||||
class Main_Window:
|
class Main_Window:
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
self.master = master
|
self.master = master
|
||||||
self.master.title("SPACE INVADERS")
|
self.master.title("ATTACK ON BLOCKS")
|
||||||
|
|
||||||
self.title = Label(self.master)
|
self.title = Label(self.master)
|
||||||
self.title.config(text="SPACE INVADERS!",font=("Courier New", 37))
|
self.title.config(text="ATTACK ON BLOCKS!",font=("Courier New", 37))
|
||||||
self.title.pack(side="top", padx=PADDING_BUTTON, pady=PADDING_TITLE/2)
|
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 = Button(self.master, style="Menu.TButton")
|
||||||
self.start_button.config(text="Play Game")
|
self.start_button.config(text="Play Game")
|
||||||
self.start_button.pack(fill=BOTH, ipadx=PADDING_BUTTON/2, ipady=PADDING_BUTTON/2, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
|
self.start_button.pack(fill=BOTH, ipadx=PADDING_BUTTON/2, ipady=PADDING_BUTTON/2, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
|
||||||
self.start_button.bind('<Button-1>', self.play_game)
|
self.start_button.bind('<Button-1>', self.play_game)
|
||||||
|
|
||||||
|
self.options_button = Button(self.master, style="Menu.TButton")
|
||||||
|
self.options_button.config(text="Show Options")
|
||||||
|
self.options_button.pack(fill=BOTH, ipadx=PADDING_BUTTON/2, ipady=PADDING_BUTTON/2, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
|
||||||
|
self.options_button.bind('<Button-1>', self.show_options)
|
||||||
|
|
||||||
|
self.help_button = Button(self.master, style="About.TButton")
|
||||||
|
self.help_button.config(text="About / Help")
|
||||||
|
self.help_button.pack(fill=BOTH, ipadx=PADDING_BUTTON/4, ipady=PADDING_BUTTON/4, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
|
||||||
|
self.help_button.bind('<Button-1>', self.show_info)
|
||||||
|
|
||||||
self.exit_button = Button(self.master, style="Quit.TButton")
|
self.exit_button = Button(self.master, style="Quit.TButton")
|
||||||
self.exit_button.config(text="Quit Game")
|
self.exit_button.config(text="Quit Game")
|
||||||
self.exit_button.pack(ipadx=PADDING_BUTTON/3, ipady=PADDING_BUTTON, padx=PADDING_BUTTON, pady=PADDING_BUTTON)
|
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.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", 25 ))
|
Style().configure("Menu.TButton", font=("Lucida", 21))
|
||||||
Style().configure("Quit.TButton", font=("Lucida", 15))
|
Style().configure("About.TButton", font=("Lucida", 17))
|
||||||
|
Style().configure("Quit.TButton", font=("Lucida", 13))
|
||||||
|
|
||||||
logging.info("GUI Generated.")
|
self.options_window = Options_Window()
|
||||||
|
logging.debug("GUI Generated.")
|
||||||
|
|
||||||
def play_game(self, event):
|
def play_game(self, event):
|
||||||
logging.info("Game Started.")
|
|
||||||
self.master.withdraw()
|
self.master.withdraw()
|
||||||
game.initialise(self.master, None)
|
exit_code = game.initialise(self.master, self.options_window.options)
|
||||||
|
if exit_code != "QUIT": self.title["text"] = exit_messages[exit_code]
|
||||||
|
|
||||||
|
def show_options(self, event):
|
||||||
|
self.new_window = Toplevel(self.master)
|
||||||
|
self.options_window.display(self.new_window)
|
||||||
|
|
||||||
|
def show_info(self, event):
|
||||||
|
logging.info("Loading About Page...")
|
||||||
|
system("start https://bitbucket.org/theorangeone/attack-on-blocks/wiki/Home")
|
||||||
|
|
||||||
def close(self, event):
|
def close(self, event):
|
||||||
logging.critical("Closing Main Window.")
|
logging.critical("Closing Main Window.")
|
||||||
self.master.destroy()
|
self.master.destroy()
|
||||||
|
|
||||||
|
def show_site(self, event):
|
||||||
|
logging.info("Loading Website")
|
||||||
|
system("start http://theorangeone.net")
|
||||||
|
|
||||||
|
class Options_Window:
|
||||||
|
def __init__(self):
|
||||||
|
self.textures_object = Textures()
|
||||||
|
self.options = {
|
||||||
|
"Difficulty": 120,
|
||||||
|
"Textures": self.textures_object,
|
||||||
|
"Sounds": True
|
||||||
|
}
|
||||||
|
|
||||||
|
def display(self, master):
|
||||||
|
self.master = master
|
||||||
|
self.master.title("ATTACK ON BLOCKS - Options")
|
||||||
|
|
||||||
|
self.title = Label(self.master)
|
||||||
|
self.title.config(text="OPTIONS",font=("Courier New", 37))
|
||||||
|
self.title.pack(side="top", padx=PADDING_TITLE, pady=PADDING_TITLE/2)
|
||||||
|
|
||||||
|
self.difficulty_title = Label(self.master)
|
||||||
|
self.difficulty_title.config(text="Current Difficulty: {}".format(self.options["Difficulty"]), font=("Courier New", 13))
|
||||||
|
self.difficulty_title.pack(ipadx=PADDING_BUTTON/3, padx=PADDING_BUTTON)
|
||||||
|
self.difficulty_scale = Scale(self.master, from_=5, to=500, orient="horizontal", command=self.update_difficulty, length=350)
|
||||||
|
self.difficulty_scale.pack(ipadx=PADDING_BUTTON/3, padx=PADDING_BUTTON/3)
|
||||||
|
self.difficulty_scale["value"] = self.options["Difficulty"]
|
||||||
|
self.difficulty_reset_button = Button(self.master, style="Minor.TButton")
|
||||||
|
self.difficulty_reset_button.config(text="Reset Difficulty")
|
||||||
|
self.difficulty_reset_button.pack(ipadx=PADDING_BUTTON/3, padx=PADDING_BUTTON/3)
|
||||||
|
self.difficulty_reset_button.bind('<Button-1>', self.reset_difficulty)
|
||||||
|
|
||||||
|
Frame(self.master,height=23).pack()
|
||||||
|
|
||||||
|
self.texture_title = Label(self.master)
|
||||||
|
self.texture_title.config(text="Select Texture Pack", font=("Courier New", 13))
|
||||||
|
self.texture_title.pack(ipadx=PADDING_BUTTON/3, padx=PADDING_BUTTON)
|
||||||
|
self.texture_select = Listbox(master)
|
||||||
|
self.texture_select.delete(0, END)
|
||||||
|
for directory in self.options["Textures"].list_packs():
|
||||||
|
if directory == "": continue
|
||||||
|
self.texture_select.insert(END, directory)
|
||||||
|
self.texture_select.pack(ipadx=PADDING_BUTTON/3, padx=PADDING_BUTTON/3)
|
||||||
|
|
||||||
|
Frame(self.master,height=23).pack()
|
||||||
|
|
||||||
|
self.using_sounds = IntVar()
|
||||||
|
self.using_sounds.set(self.options["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))
|
||||||
|
self.master.protocol('WM_DELETE_WINDOW', self.close)
|
||||||
|
logging.info("Options menu created.")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.options["Textures"].pack = self.texture_select.get(ACTIVE) if self.texture_select.get(ACTIVE) != "" else "default" # Because it has no changed event
|
||||||
|
logging.info("Selected Texture Pack: {}".format(self.options["Textures"].pack))
|
||||||
|
self.master.destroy()
|
||||||
|
|
||||||
|
def update_sounds(self):
|
||||||
|
self.options["Sounds"] = self.using_sounds.get()
|
||||||
|
|
||||||
|
def update_difficulty(self, event):
|
||||||
|
self.options["Difficulty"] = int(self.difficulty_scale.get())
|
||||||
|
self.difficulty_title["text"] = "Current Difficulty: {}".format(self.options["Difficulty"])
|
||||||
|
|
||||||
|
def reset_difficulty(self, event):
|
||||||
|
self.options["Difficulty"] = 120
|
||||||
|
self.difficulty_title["text"] = "Current Difficulty: {}".format(self.options["Difficulty"])
|
||||||
|
self.difficulty_scale["value"] = 120
|
||||||
|
|
||||||
|
|
||||||
def display():
|
def display():
|
||||||
|
@ -50,6 +151,11 @@ def display():
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
exit_messages = {
|
||||||
|
"LIVES":"You ran out of lives!",
|
||||||
|
"PLAYER COLLISION":"The enemies got to you!"
|
||||||
|
}
|
||||||
|
|
||||||
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
|
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
|
22
LICENSE
Normal 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.
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
print("Game Loading...")
|
print("Starting Attack on Blocks...\nLoading Main Window...")
|
||||||
import GUI
|
import GUI
|
||||||
GUI.display()
|
GUI.display()
|
||||||
|
|
50
README.md
|
@ -1,24 +1,26 @@
|
||||||
# Space Invaders #
|
# Attack on Blocks #
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
### Requirements ###
|
### More Information ###
|
||||||
|
|
||||||
* Python
|
For more information, check out the [Wiki](//bitbucket.org/TheOrangeOne/attack-on-blocks/wiki) page.
|
||||||
* Pygame
|
|
||||||
* TKinter
|
### Requirements ###
|
||||||
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.
|
|
||||||
|
* Python 3
|
||||||
### Playing the game ###
|
* Pygame
|
||||||
|
* TKinter
|
||||||
* Clone the repository
|
|
||||||
* Install the required libraries (See Above)
|
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.
|
||||||
* Run 'Play The Game.py'
|
|
||||||
|
### Playing the game ###
|
||||||
### Core Contributors ###
|
|
||||||
|
* Clone the repository, or visit the downloads page
|
||||||
* Jake Howard
|
* Install the required libraries (See Above)
|
||||||
* Furhan Bhatti
|
* Run 'Play The Game.py'
|
||||||
|
|
||||||
# Note #
|
### Core Contributors ###
|
||||||
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!
|
|
||||||
|
* Jake Howard
|
||||||
|
* Furhan Bhatti (Well not really)
|
||||||
|
|
BIN
Thumbs.db
83
assets.py
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
import os, pygame, glob, logging
|
||||||
|
from collections import namedtuple
|
||||||
|
from random import randint
|
||||||
|
|
||||||
|
class Textures():
|
||||||
|
def __init__(self):
|
||||||
|
self.images = {
|
||||||
|
"PLAYER":"player",
|
||||||
|
"BULLET":"bullet",
|
||||||
|
"TARGETS":[],
|
||||||
|
"SHOOTER":"shooter",
|
||||||
|
"TARGET_BULLET":"bullet_target",
|
||||||
|
"POWERUP": "powerup"
|
||||||
|
}
|
||||||
|
self.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\"
|
||||||
|
self.pack = "default"
|
||||||
|
|
||||||
|
def load_texture_pack(self, pack_name):
|
||||||
|
if os.path.exists(self.path + pack_name):
|
||||||
|
self.images["TARGETS"] = []
|
||||||
|
|
||||||
|
targets = glob.glob(self.path+pack_name+"\\target*.png")
|
||||||
|
logging.debug("Found {0} target files.".format(len(targets)))
|
||||||
|
for file in targets:
|
||||||
|
filename = file.split("\\")[-1].replace(".png", "")
|
||||||
|
self.images["TARGETS"].append(filename)
|
||||||
|
|
||||||
|
self.pack = pack_name
|
||||||
|
else: logging.warn("Cannot find texture pack '{}'".format(ppack_name))
|
||||||
|
|
||||||
|
def get_texture(self, objectName):
|
||||||
|
filename = self.path + self.pack + "\\{0}.png".format(self.images[objectName.upper()])
|
||||||
|
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)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Level_Template = namedtuple('Level_Template', ("rows", "padding", "firebacks", "powerups"))
|
||||||
|
Levels = [
|
||||||
|
Level_Template(2, 20, 0, 0),
|
||||||
|
Level_Template(3, 15, 1, 0),
|
||||||
|
Level_Template(4, 15, 3, 1),
|
||||||
|
Level_Template(3, 7, 2, 2),
|
||||||
|
Level_Template(5, 15, 2, 1),
|
||||||
|
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),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_level():
|
||||||
|
logging.info("Generating a random level!")
|
||||||
|
rows = randint(1, 12)
|
||||||
|
padding = randint(5, 30)
|
||||||
|
firebacks = randint(0, 15)
|
||||||
|
powerups = randint(0, 15)
|
||||||
|
return Level_Template(rows, padding, firebacks, powerups)
|
||||||
|
|
||||||
|
|
||||||
|
Sounds = {}
|
||||||
|
def init_sounds():
|
||||||
|
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.ogg":
|
||||||
|
mixer = pygame.mixer.music
|
||||||
|
mixer.load(path)
|
||||||
|
else: mixer = pygame.mixer.Sound(path)
|
||||||
|
mixer.set_volume(1.0)
|
||||||
|
Sounds[file.replace(".ogg", "")] = mixer
|
20
bullet.py
|
@ -2,22 +2,20 @@ import pygame
|
||||||
|
|
||||||
|
|
||||||
class Bullet(pygame.sprite.Sprite):
|
class Bullet(pygame.sprite.Sprite):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent, textures, bigger):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.width = 4
|
self.width = 6 * (1+int(bigger))
|
||||||
self.height = 10
|
self.height = 14 * (1+int(bigger))
|
||||||
self.image = pygame.Surface((self.width, self.height))
|
self.image = pygame.transform.scale(textures.get_texture("BULLET"), (self.width, self.height))
|
||||||
self.image.fill((255,255,255))
|
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.rect.x = parent.rect.x + parent.width/2
|
self.rect.x = parent.rect.x + parent.width/2 - self.width/2
|
||||||
self.rect.y = parent.rect.y
|
self.rect.y = parent.rect.y + parent.height/2
|
||||||
self.speed = 5
|
self.speed = 5
|
||||||
|
self.type = "PLAYER"
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
def set_position(self,x,y):
|
def set_position(self,x,y):
|
||||||
self.rect.x, self.rect.y = x,y
|
self.rect.x, self.rect.y = x,y
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.rect.y -= self.speed #direction may need editing?
|
self.rect.y -= self.speed #direction may need editing?
|
||||||
|
|
||||||
def at_top(self):
|
|
||||||
return (self.rect.y == 0)
|
|
13
eggs.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import pygame, logging, urllib.request, io
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
def r9k(window):
|
||||||
|
logging.warn("Look, you found a pepe!")
|
||||||
|
raw_image = urllib.request.urlopen("http://img.ifcdn.com/images/620f230fad2806fe5305fac45dd673b8fc005b98c1e3b8584abc9c439b050950_1.jpg").read()
|
||||||
|
image_file = io.BytesIO(raw_image)
|
||||||
|
image = pygame.transform.scale(pygame.image.load(image_file), window.get_size())
|
||||||
|
window.blit(image, (0,0))
|
||||||
|
font = pygame.font.SysFont(None, 30, bold=False)
|
||||||
|
window.blit(font.render("A rare pepe has been found. Alert R9k", True, (0,0,0)), (window.get_width()/2-175, window.get_height()/2))
|
||||||
|
pygame.display.update()
|
||||||
|
sleep(9)
|
313
game.py
|
@ -1,103 +1,210 @@
|
||||||
import pygame, logging
|
import pygame, logging
|
||||||
|
from time import time, sleep
|
||||||
import bullet, player, textures
|
from random import randint
|
||||||
from bullet import Bullet
|
import eggs
|
||||||
from player import Shooter
|
from bullet import Bullet
|
||||||
from textures import Textures
|
from player import Shooter
|
||||||
from target import Target
|
from assets import *
|
||||||
|
from target import Target, generate_targets
|
||||||
|
|
||||||
PLAYING_GAME = False
|
POWERUPS = ["SPEED", "DOUBLE", "LIVES", "SCORE", "BIGGER"]
|
||||||
WINDOW_SIZE = (640,480)
|
PLAYING_GAME = False
|
||||||
FPS = 120
|
WINDOW_SIZE = (680, 790)
|
||||||
|
HUD_COLOUR = (255,168,72)
|
||||||
def rounding(x, base): return int(base * round(float(x)/base))
|
|
||||||
|
|
||||||
|
def update_score(window, score, colour=HUD_COLOUR):
|
||||||
def initialise(menu, options):
|
font = pygame.font.SysFont(None, 30, bold=False)
|
||||||
pygame.mixer.pre_init(44100, -16, 2, 2048)
|
window.blit(font.render("Score: {}".format(int(score)), True, colour), (25, WINDOW_SIZE[1] - 30))
|
||||||
pygame.init()
|
|
||||||
window = pygame.display.set_mode(WINDOW_SIZE)
|
def update_level(window, level, colour=HUD_COLOUR):
|
||||||
|
font = pygame.font.SysFont(None, 30, bold=False)
|
||||||
exit_code = play(window) # Run main game loop
|
window.blit(font.render("Level: {}".format(int(level)+1), True, colour), (8.5*WINDOW_SIZE[0]/10, WINDOW_SIZE[1] - 30))
|
||||||
if exit_code =
|
|
||||||
pygame.quit()
|
def update_lives(window, lives, colour=HUD_COLOUR):
|
||||||
# Reshow the main menu
|
font = pygame.font.SysFont(None, 30, bold=False)
|
||||||
|
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 generate_targets():
|
def initialise(menu, options):
|
||||||
group = pygame.sprite.Group()
|
pygame.mixer.pre_init(44100, -16, 2, 2048)
|
||||||
target_object = Target()
|
pygame.init()
|
||||||
for i in range(10,150,50):
|
window = pygame.display.set_mode(WINDOW_SIZE)
|
||||||
for j in range(10, 150, 50):
|
pygame.display.set_caption("Attack on Blocks")
|
||||||
temp = Target()
|
exit_code = play(window, options) # Run main game loop
|
||||||
logging.debug("Target generated with position ({},{})".format(j,i))
|
for key, value in Sounds.items():
|
||||||
temp.set_position(j,i)
|
value.fadeout(500)
|
||||||
group.add(temp)
|
|
||||||
del temp
|
logging.debug("Game Exited with code {}".format(exit_code))
|
||||||
return group
|
if exit_code != "QUIT": sleep(1)
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
def play(window):
|
menu.deiconify()
|
||||||
window_rect = window.get_rect()
|
return exit_code
|
||||||
|
|
||||||
player = Shooter(window=window)
|
def play(window, options):
|
||||||
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.93)
|
window_rect = window.get_rect()
|
||||||
player_group = pygame.sprite.Group()
|
options["Textures"].load_texture_pack(options["Textures"].pack)
|
||||||
player_group.add(player)
|
player = Shooter(window=window, texture=options["Textures"])
|
||||||
player_group.draw(window)
|
player.set_position(WINDOW_SIZE[0]/2, WINDOW_SIZE[1]*0.90)
|
||||||
|
player.options = options
|
||||||
target_group = generate_targets()
|
player_group = pygame.sprite.Group()
|
||||||
bullet_group = pygame.sprite.Group()
|
player_group.add(player)
|
||||||
|
|
||||||
clock = pygame.time.Clock()
|
target_group = generate_targets(player, WINDOW_SIZE, Levels)
|
||||||
PLAYING_GAME = True
|
bullet_group = pygame.sprite.Group()
|
||||||
|
|
||||||
while PLAYING_GAME:
|
clock = pygame.time.Clock()
|
||||||
window.fill((0,0,0))
|
FPS = player.options["Difficulty"]
|
||||||
player_group.update()
|
|
||||||
|
timeouts = {
|
||||||
for event in pygame.event.get():
|
"Target Movement":[FPS*0.65,FPS*0.65],
|
||||||
if event.type == pygame.QUIT:
|
"Powerup":[FPS*15, FPS*15]
|
||||||
logging.critical("Exiting Game...")
|
}
|
||||||
PLAYING_GAME = False
|
init_sounds()
|
||||||
return "QUIT"
|
if options["Sounds"]: Sounds["main"].play(loops=-1) #Start background music
|
||||||
|
|
||||||
if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
logging.info("Game Started.")
|
||||||
temp = Bullet(player)
|
PLAYING_GAME = True
|
||||||
bullet_group.add(temp)
|
while PLAYING_GAME:
|
||||||
|
window.fill((0,0,0))
|
||||||
keys = pygame.key.get_pressed()
|
|
||||||
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
|
fired = False
|
||||||
player.move(player.speed)
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
|
logging.critical("Exiting Game...")
|
||||||
player.move(-player.speed)
|
PLAYING_GAME = False
|
||||||
|
return "QUIT"
|
||||||
if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6]:
|
|
||||||
temp = Bullet(player)
|
if event.type == pygame.KEYDOWN and event.key in [pygame.K_SPACE, pygame.K_w, pygame.K_UP] and not fired:
|
||||||
bullet_group.add(temp)
|
if player.options["Sounds"]: Sounds["shot"].play()
|
||||||
|
temp = Bullet(player, player.options["Textures"], player.powerup == "BIGGER")
|
||||||
for sprite in bullet_group:
|
bullet_group.add(temp)
|
||||||
if not sprite.at_top():
|
if player.powerup == "DOUBLE":
|
||||||
sprite.update()
|
temp = Bullet(player, player.options["Textures"], player.powerup == "BIGGER")
|
||||||
if sprite.rect.y < 0:
|
temp.rect.y += 20
|
||||||
bullet_group.remove(sprite)
|
bullet_group.add(temp)
|
||||||
|
fired = True
|
||||||
for bullet in bullet_group:
|
|
||||||
hit_list = pygame.sprite.spritecollide(bullet, target_group, True)
|
|
||||||
for target in hit_list:
|
keys = pygame.key.get_pressed()
|
||||||
target_group.remove(target)
|
if keys[pygame.K_RIGHT] or keys[pygame.K_d]:
|
||||||
bullet_group.remove(bullet)
|
if player.powerup == "SPEED": player.move(player.speed * 1.5)
|
||||||
logging.info("Hit Target!")
|
else: player.move(player.speed)
|
||||||
|
|
||||||
player_group.update()
|
if keys[pygame.K_LEFT] or keys[pygame.K_a]:
|
||||||
bullet_group.draw(window)
|
if player.powerup == "SPEED": player.move(-player.speed*1.5)
|
||||||
target_group.draw(window)
|
else: player.move(-player.speed)
|
||||||
player_group.draw(window)
|
|
||||||
pygame.display.update()
|
if keys[pygame.K_KP4] and keys[pygame.K_KP5] and keys[pygame.K_KP6] and player.OP:
|
||||||
clock.tick(FPS)
|
temp = Bullet(player, player.options["Textures"], False)
|
||||||
|
bullet_group.add(temp)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if keys[pygame.K_r] and [pygame.K_9] and [pygame.K_k] and player.OP:
|
||||||
initialise(None, None)
|
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"):
|
||||||
|
bullet_group.remove(sprite)
|
||||||
|
|
||||||
|
for bullet in bullet_group:
|
||||||
|
hit_list = pygame.sprite.spritecollide(bullet, target_group, False)
|
||||||
|
for target in hit_list:
|
||||||
|
if bullet.type != "TARGET":
|
||||||
|
target.lives -= 1
|
||||||
|
if target.lives <= 0:
|
||||||
|
target_group.remove(target)
|
||||||
|
player.score += 1
|
||||||
|
bullet_group.remove(bullet)
|
||||||
|
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:
|
||||||
|
if bullet.type == "TARGET":
|
||||||
|
bullet_group.remove(bullet)
|
||||||
|
logging.info("You were hit by a target's bullet!")
|
||||||
|
if not player.OP: player.lives -= 1
|
||||||
|
if player.lives <= 0:
|
||||||
|
return "LIVES"
|
||||||
|
|
||||||
|
if timeouts["Target Movement"][0] <=0:
|
||||||
|
drop_targets = False
|
||||||
|
for target in target_group:
|
||||||
|
target.move()
|
||||||
|
if target.rect.x <= 30 or target.rect.x >=WINDOW_SIZE[0] - target.width/2 - 30:
|
||||||
|
drop_targets = True
|
||||||
|
|
||||||
|
if target.rect.y >= player.rect.y + target.height/2:
|
||||||
|
PLAYING_GAME = False
|
||||||
|
return "PLAYER COLLISION"
|
||||||
|
|
||||||
|
if drop_targets:
|
||||||
|
logging.debug("The targets are moving down a level!")
|
||||||
|
for target in target_group:
|
||||||
|
target.drop()
|
||||||
|
|
||||||
|
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"], 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
|
||||||
|
temp.rect = temp.image.get_rect()
|
||||||
|
temp.set_position(x,y)
|
||||||
|
temp.speed = -1 #So it shoots down!
|
||||||
|
bullet_group.add(temp)
|
||||||
|
|
||||||
|
if len(target_group) == 0: #If all current players are gone.
|
||||||
|
player.level += 1
|
||||||
|
Sounds["main"].set_volume(0.5)
|
||||||
|
target_group = generate_targets(player, WINDOW_SIZE, Levels)
|
||||||
|
target_group.draw(window)
|
||||||
|
bullet_group.empty()
|
||||||
|
pygame.display.update()
|
||||||
|
sleep(0.75)
|
||||||
|
Sounds["main"].set_volume(1.0)
|
||||||
|
|
||||||
|
update_score(window, player.score)
|
||||||
|
update_level(window, player.level)
|
||||||
|
update_lives(window, player.lives)
|
||||||
|
|
||||||
|
target_group.draw(window)
|
||||||
|
bullet_group.draw(window)
|
||||||
|
player_group.draw(window)
|
||||||
|
|
||||||
|
for key, value in timeouts.items():
|
||||||
|
value[0] -= 1
|
||||||
|
|
||||||
|
pygame.display.update()
|
||||||
|
clock.tick(FPS)
|
39
player.py
|
@ -2,19 +2,42 @@ import pygame
|
||||||
|
|
||||||
|
|
||||||
class Shooter(pygame.sprite.Sprite):
|
class Shooter(pygame.sprite.Sprite):
|
||||||
def __init__(self, window, color=(30,0,150), width=50, height=25):
|
def __init__(self, window, texture, colour=(255,255,255), width=55, height=25):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.image = pygame.Surface((width, height))
|
self.colour = colour
|
||||||
self.image.fill(color)
|
self.texture = texture
|
||||||
|
self.image = pygame.transform.scale(self.texture.get_texture("PLAYER"), (self.width, self.height))
|
||||||
self.rect = self.image.get_rect()
|
self.rect = self.image.get_rect()
|
||||||
self.speed = 4
|
self.speed = 3
|
||||||
self.window_rect = window.get_rect()
|
self.window_rect = window.get_rect()
|
||||||
|
|
||||||
|
self.score = 0
|
||||||
|
self.OP = False
|
||||||
|
self.level = 0
|
||||||
|
self.lives = 3
|
||||||
|
self.powerup = ""
|
||||||
|
|
||||||
def set_position(self,x,y):
|
def set_position(self,x,y):
|
||||||
self.rect.x, self.rect.y = x,y
|
self.rect.x, self.rect.y = x, y
|
||||||
|
|
||||||
def move(self, value):
|
def move(self, value):
|
||||||
self.rect.x += value
|
self.rect.x += value
|
||||||
self.rect.clamp_ip(self.window_rect)
|
self.rect.clamp_ip(self.window_rect)
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
self.image.fill(self.colour)
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
|
||||||
|
def change_colour(self, colour):
|
||||||
|
x,y = self.rect.x, self.rect.y
|
||||||
|
self.image.fill(colour)
|
||||||
|
self.rect = self.image.get_rect()
|
||||||
|
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
BIN
resources/sounds/main.ogg
Normal file
BIN
resources/sounds/shot.ogg
Normal file
BIN
resources/texture_packs/default/bullet.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
resources/texture_packs/default/bullet_target.png
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
resources/texture_packs/default/player.png
Normal file
After Width: | Height: | Size: 63 KiB |
BIN
resources/texture_packs/default/powerup.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
resources/texture_packs/default/shooter.png
Normal file
After Width: | Height: | Size: 59 KiB |
BIN
resources/texture_packs/default/target0.png
Normal file
After Width: | Height: | Size: 48 KiB |
BIN
resources/texture_packs/default/target1.png
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
resources/texture_packs/default/target2.png
Normal file
After Width: | Height: | Size: 48 KiB |
90
target.py
|
@ -1,21 +1,85 @@
|
||||||
import pygame
|
import pygame, logging
|
||||||
|
from random import randint
|
||||||
|
from game import generate_random_level
|
||||||
|
|
||||||
|
|
||||||
class Target(pygame.sprite.Sprite):
|
class Target(pygame.sprite.Sprite):
|
||||||
def __init__(self, color=(30,0,150), width=16, height=16):
|
def __init__(self, x, y, textures, color=(30,0,150), width=23, height=23):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.image = pygame.Surface((self.width, self.height))
|
self.textures = textures
|
||||||
self.image.fill(color)
|
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.rect = self.image.get_rect()
|
||||||
self.speed = 4
|
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 set_position(self,x,y):
|
def move(self):
|
||||||
self.rect.x, self.rect.y = (x+(self.width/2)),(x+(self.width/2)) # centres co-ordinates
|
self.rect.x += self.speed
|
||||||
|
|
||||||
def move(self, x,y):
|
def drop(self):
|
||||||
if ((self.rect.y + self.width) > window_rect.y) or((self.rect.y - self.width < 0)):
|
self.rect.y += 13
|
||||||
movement = self.speed
|
self.speed *= -1
|
||||||
|
|
||||||
|
def set_position(self, x, y, center=False):
|
||||||
|
if center:
|
||||||
|
self.rect.x, self.rect.y = (x+(self.width/2)),(y+(self.width/2))
|
||||||
else:
|
else:
|
||||||
movement = -self.speed
|
self.rect.x, self.rect.y = x, y
|
||||||
self.rect.y += movement
|
|
||||||
|
def generate_targets(player, window_size, Levels):
|
||||||
|
sprite_list = []
|
||||||
|
group = pygame.sprite.Group()
|
||||||
|
if player.level > len(Levels)-1:
|
||||||
|
level = generate_random_level()
|
||||||
|
else: level = Levels[player.level]
|
||||||
|
logging.debug("Generating Level: " + str(level))
|
||||||
|
|
||||||
|
for i in range(level.rows):
|
||||||
|
i *= level.padding + 8
|
||||||
|
for j in range(75, window_size[0] - 75, level.padding + 10):
|
||||||
|
temp = Target(x=j,y=i, textures=player.options["Textures"])
|
||||||
|
sprite_list.append(temp)
|
||||||
|
del temp
|
||||||
|
|
||||||
|
if len(sprite_list) < level.firebacks:
|
||||||
|
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)
|
||||||
|
return group
|
||||||
|
|
28
textures.py
|
@ -1,28 +0,0 @@
|
||||||
import os, pygame, glob, logging
|
|
||||||
|
|
||||||
|
|
||||||
class Textures():
|
|
||||||
def __init__(self):
|
|
||||||
self.images = {
|
|
||||||
"PLAYER":"player.png",
|
|
||||||
"BULLET":"bullet.png",
|
|
||||||
"TARGETS":[]
|
|
||||||
}
|
|
||||||
self.path=os.path.dirname(os.path.realpath(__file__)) + "\\resources\\texture_packs\\"
|
|
||||||
self.pack = "default"
|
|
||||||
|
|
||||||
def loadTexturePack(self, packName):
|
|
||||||
if os.path.exists(self.path + packName):
|
|
||||||
self.images["TARGETS"] = []
|
|
||||||
|
|
||||||
targets = glob.glob(self.path+packName+"\\target*.png")
|
|
||||||
logging.debug("Found {0} target files.".format(len(targets)))
|
|
||||||
for file in targets:
|
|
||||||
fileName = file.split("\\")[-1]
|
|
||||||
self.images["TARGETS"].append(filename)
|
|
||||||
|
|
||||||
self.pack = packName
|
|
||||||
|
|
||||||
def getTexture(self, objectName):
|
|
||||||
filename = self.path + self.pack + "\\{0}.png".format(self.images[objectName.upper()])
|
|
||||||
return pygame.image.load(filename)
|
|