-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
117 lines (89 loc) · 6.11 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"""
Attribution:
1. Player rotation was adapted from this video tutorial by Web Dev Junkie: https: // www.youtube.com/watch?v = _WJSH7NxtRc. Made adjustments to it so that the player's gun pointed to the mouse.
2. Code to move a canvas element from its current position to a target position was borrowed from a html5gamedevs forum post reply written by a user called "Exca".
Available from: https: // www.html5gamedevs.com/topic/36416-bullet-go-on-mouse-position/
This was used for getting bullets to move towards where the player and enemies are aiming and for the enemy "chase" behaviour.
The code for actually creating enemies and bullets and managing them was all written by me.
I also wrote code to ensure the bullets originated from the barrell of the player's gun. The extent of these modifications are discussed in comments below.
3. Borrowed code from an article written by Pranchal Katiyar to find out if a user was running the game on a Window's machine. Available from: https: // www.geeksforgeeks.org/detect-the-operating-system-of-user-using-javascript/
4. Media query code for seeing if a user's screen was below a given width was borrowed from W3Schools. Available from: https: // www.w3schools.com/howto/howto_js_media_queries.asp
Both 3 and 4 were adapted to be used in conjuction with each other to detect if the user was on a machine that might experience a mouse position bug.
If the user was running Windows and the screen was also below a certain width then the javascript offsets their recorded mouse position to account for the bug.
5. Player and enemy art was made by Riley Gombart and is licensed under Creative Commons Attribution 3.0.
Art available from: https: // opengameart.org/content/animated-top-down-survivor-player
License available from: https: // creativecommons.org/licenses/by/3.0/
6. The enemy art was made greyscale using the Grayscale Image Online tool. Available from: https: // pinetools.com/grayscale-image
7. Background music is "Ascent to the Station" by TeknoAXE and is a royalty free piece of music. Available from: http: // teknoaxe.com/Home.php
8. All sound effects were generated by me using the online tool jsfxr. Availbale from: https: // sfxr.me/
9. Font used is Ubuntu by Dalton Maag. Available from: https: // fonts.google.com/specimen/Ubuntu
10. All other HTML, CSS, Javascript, Python and art was written/made by me. I made the tileset in an online tool called Piskel. Available from: https: // www.piskelapp.com/
"""
"""
Things to note:
1. The game is very difficult to play with a track pad so I'd recommend using a mouse.
2. Having the tab zoomed in or out messes up the mouse positioning. Please ensure that your zoom settings are set to their default(i.e. 100 % or 1.0) to avoid issues.
3. There are issues with running the game in Chrome on laptop's running Windows, the details of which are in comments below.
I implemented a fix but the game runs much better on laptop's running Linux and on Windows Desktops.
I'd recommend playing it on such a machine for the optimum experience.
4. The controls are W to go up, S to go down, A to go left, and D to go right. (Or alternatively UP, DOWN LEFT, RIGHT arrow keys)
"""
import math
from functools import wraps
from werkzeug.security import generate_password_hash, check_password_hash
from database import get_db, close_db
from flask import Flask, render_template, session, g, redirect, url_for, request
app = Flask(__name__)
app.config["SECRET_KEY"] = "demistifyeasypetenimblesauce"
@app.teardown_appcontext
def close_db_at_end_of_request(e=None):
"""
Closes the connection to the database at the end of a user request
"""
close_db(e)
@app.route("/", methods=["GET", "POST"])
def index():
return render_template("index.html")
@app.route("/game", methods=["GET", "POST"])
def game():
return render_template("game.html")
@app.route("/high_scores", methods=["GET", "POST"])
def high_scores():
"""Fetches the top 10 recorded scores in each difficulty category from the database"""
db = get_db()
scoresLecturer = db.execute(
"""SELECT * FROM scoresLecturer ORDER BY round DESC LIMIT 10""").fetchall()
scoresStudent = db.execute(
"""SELECT * FROM scoresStudent ORDER BY round DESC LIMIT 10""").fetchall()
return render_template("high_scores.html", scoresLecturer=scoresLecturer, scoresStudent=scoresStudent)
@app.route("/store_round", methods=["POST"])
def store_round():
"""
Stores the user's score. If the user does not have a recorded score in the given category then
a new on is recorded with a round of 1. If the user's score is greater than the score currently
recorded for them in that given category then that will become their new high score.
"""
db = get_db()
playerRound = int(request.form["round"])
gamerTag = request.form["gamerTag"]
print(gamerTag)
difficulty = request.form["difficulty"]
if gamerTag != "":
if difficulty == "L E C T U R E R":
if db.execute("""SELECT gamer_tag FROM scoresLecturer WHERE gamer_tag = ?""", (gamerTag,)).fetchone() is None:
db.execute(
"""INSERT INTO scoresLecturer(gamer_tag, round) VALUES(?, ?)""", (gamerTag, 1))
db.commit()
if playerRound > db.execute("SELECT round FROM scoresLecturer WHERE gamer_tag = ?", (gamerTag,)).fetchone()["round"]:
db.execute(
"""UPDATE scoresLecturer SET round = ? WHERE gamer_tag = ?""", (playerRound, gamerTag,))
db.commit()
else:
if db.execute("""SELECT gamer_tag FROM scoresStudent WHERE gamer_tag = ?""", (gamerTag,)).fetchone() is None:
db.execute(
"""INSERT INTO scoresStudent(gamer_tag, round) VALUES(?, ?)""", (gamerTag, 1))
db.commit()
if playerRound > db.execute("SELECT round FROM scoresStudent WHERE gamer_tag = ?", (gamerTag,)).fetchone()["round"]:
db.execute(
"""UPDATE scoresStudent SET round = ? WHERE gamer_tag = ?""", (playerRound, gamerTag))
db.commit()