Skip to content

Commit

Permalink
refactor modules, Restartdb(), update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andygett committed Apr 23, 2022
1 parent c4ae9b4 commit 508271f
Show file tree
Hide file tree
Showing 12 changed files with 1,269 additions and 1,000 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__/breakout.cpython-39.pyc
__pycache__/powerups.cpython-39.pyc
__pycache__/gameui.cpython-39.pyc
__pycache__/breakoutils.cpython-39.pyc
__pycache__/breakodb.cpython-39.pyc
__pycache__/breakodb.cpython-39.pyc
__pycache__/breakodb.cpython-39.pyc
6 changes: 3 additions & 3 deletions BreakOMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pygame_menuExists = True
except ImportError:
pygame_menuExists = False
print("Install pygame_menu to view menus, change users, etc.")
print("Install pygame_menu to view menus, change users, etc.\n")

import breakout, breakodb

Expand Down Expand Up @@ -84,7 +84,7 @@ def go(self):
if idUser==0: # check for new user
idUser=self.db.insertUser(self.newUser.get_value())
self.db.setConfigValue("lastIdUser", idUser)
breakout.play(idUser)
breakout.Game.play(idUser)
self.showMenu()

def showMenu(self):
Expand All @@ -93,4 +93,4 @@ def showMenu(self):
if pygame_menuExists:
BreakOMenu()
else:
breakout.play()
breakout.Game.play()
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# BreakoutXP-pygame
A fun project to ramp up on Python and sqlite.

A fun project to ramp up on Python and sqlite.

BreakoutXP is based on the classic breakout game in which the user moves a paddle to bounce balls up to a wall to hit and destroy the bricks. BreakoutXP tracks eXperience Points for the current user's game level, game, session and career, persisting these values to the database. When a ball hits something, you get more XP. Acquiring powerups increments XP. Clear most (90%) of the blocks to advance to the next level which grants XP. Each level renders with different colors using a fade-in pattern picked at random.

![Demo with powerups, level transition](https://user-images.githubusercontent.com/46758459/164893711-6a1ff629-bbb6-4349-b61a-645b96700c9f.gif)

### Powerups

1. Wider paddle *(really paddle width change. It can get smaller!)*
2. Multiball 3-5 balls
3. Extra life
4. SloMo
5. Fire ball - the ball destroys the brick, but does not bounce
6. Invinciballs - all balls bounce back up even if the paddle misses
7. Big ball
8. Highball - Balls only interact with bricks on their way down.

Beware powerups with a red number.

### Keyboard commands during play
1. Left & right arrows move paddle
2. Enter shows stats
3. Esc quits to menu or command prompt depending on start method
4. U and D jump up or down a level - fun for viewing different transitions

## Requirements
* python3 which includes sqlite3
* pygame:
* Windows install: `py -m pip install -U pygame --user`
* Mac install: `python3 -m pip install -U pygame --user`

## Optional

pygame-pymenu

## To run from command prompt
1. Without menu, just play the game: `breakout.py`
2. Use menu which allows creating and changing users: `breakomenu.py`
*This "just plays the game" if pygame-menu is not available.*
Binary file modified __pycache__/breakodb.cpython-39.pyc
Binary file not shown.
Binary file modified breakO.db
Binary file not shown.
12 changes: 7 additions & 5 deletions breakOutERD.vuerd.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"canvas": {
"version": "2.2.1",
"version": "2.2.11",
"width": 2000,
"height": 2000,
"scrollTop": -100,
"scrollTop": -38,
"scrollLeft": 0,
"zoomLevel": 1,
"zoomLevel": 0.9,
"show": {
"tableComment": true,
"columnComment": true,
Expand All @@ -19,14 +19,15 @@
},
"database": "SQLite",
"databaseName": "breakOut",
"canvasType": "ERD",
"canvasType": "@vuerd/builtin-sql-ddl",
"language": "GraphQL",
"tableCase": "pascalCase",
"columnCase": "camelCase",
"highlightTheme": "VS2015",
"bracketType": "none",
"setting": {
"relationshipDataTypeSync": true,
"relationshipOptimization": false,
"columnOrder": [
"columnName",
"columnDataType",
Expand All @@ -36,7 +37,8 @@
"columnDefault",
"columnComment"
]
}
},
"pluginSerializationMap": {}
},
"table": {
"tables": [
Expand Down
73 changes: 72 additions & 1 deletion breakodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,75 @@ def setConfigValue(self, setting, value):
cur = self.conn.cursor()
sql="UPDATE Config SET SettingValue = (?) WHERE Setting=(?)"
cur.execute(sql, (value, setting))
self.conn.commit()
self.conn.commit()

# Remove all users and game info from database, shrink db.
# BE CAREFUL WITH THIS. Consider making a copy of BreakO.db
# if it is not too large already.
# Note that NEITHER EventTypes table nor Config table is deleted or rebuilt
def restartDb (self):
cur = self.conn.cursor()
cur.execute("DROP TABLE Events;")
cur.execute("DROP TABLE Levels;")
cur.execute("DROP TABLE Games;")
cur.execute("""DROP TABLE Sessions;""")
cur.execute("""DROP TABLE Users;""")

cur.execute("""
CREATE TABLE Users
(
idUser INTEGER NOT NULL ,
Name TEXT NULL,
Visible BOOLEAN NULL DEFAULT 1 ,
PRIMARY KEY (idUser)
);""")
cur.execute("""CREATE TABLE Sessions
(
idSession INTEGER NOT NULL ,
idUser INTEGER NOT NULL ,
sessionStart TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
sessionEnd TIMESTAMP NULL ,
PRIMARY KEY (idSession) ,
FOREIGN KEY (idUser) REFERENCES Users (idUser)
);""")
cur.execute("""
CREATE TABLE Games
(
idGame INTEGER NOT NULL ,
idSession INTEGER NOT NULL ,
gameStart TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
gameEnd TIMESTAMP NULL ,
levelReached INTEGER ,
endTrigger INTEGER ,
PRIMARY KEY (idGame) ,
FOREIGN KEY (endTrigger) REFERENCES EventTypes (idEventType) ,
FOREIGN KEY (idSession) REFERENCES Sessions (idSession)
);""")
cur.execute("""
CREATE TABLE Levels
(
idLevel INTEGER NOT NULL ,
idGame INTEGER NOT NULL ,
levelStart TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
levelEnd TIMESTAMP NULL ,
levelNumber INTEGER NOT NULL ,
maxBallsInPlay INTEGER NULL ,
pauseDuration INTEGER NULL ,
PRIMARY KEY (idLevel) ,
FOREIGN KEY (idGame) REFERENCES Games (idGame)
);""")
cur.execute("""
CREATE TABLE Events
(
idEvent INTEGER NOT NULL ,
idEventType INTEGER NOT NULL ,
idLevel INTEGER NOT NULL ,
time TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY (idEvent) ,
FOREIGN KEY (idEventType) REFERENCES EventTypes (idEventType) ,
FOREIGN KEY (idLevel) REFERENCES Levels (idLevel)
);""")
cur.execute("""INSERT INTO Users (Name) VALUES ('Guest');""")
cur.execute("""UPDATE Config SET SettingValue = ('1') WHERE Setting='lastIdUser'""")
self.conn.commit()
cur.execute("VACUUM")
Loading

0 comments on commit 508271f

Please sign in to comment.