by Muhammad
Space Shooter v3
from flask import jsonify
import logging
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
from werkzeug.security import generate_password_hash, check_password_hash
from gunicorn.app.base import BaseApplication
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your_secret_key' # Change this to a random secret key
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
db = SQLAlchemy(app)
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True, nullable=False)
password = db.Column(db.String(120), nullable=False)
score = db.Column(db.Integer, default=0)
Created: | Last Updated:
Introduction to the Space Shooter v3 Template
The Space Shooter v3 template is a dynamic and engaging space shooter game where players defend against waves of enemies coming from all directions. This template includes user authentication, a leaderboard, and a game interface built with HTML, CSS, JavaScript, and Flask.
Getting Started
To get started with the Space Shooter v3 template, click Start with this Template.
Test
Press the Test button to deploy the app and launch the Lazy CLI. This will set up the environment and start the application.
Entering Input
The application requires user input for authentication and gameplay. Follow these steps:
- Sign Up:
- Navigate to the sign-up page.
- Enter a username and password to create a new account.
-
Click the Sign Up button.
-
Login:
- Navigate to the login page.
- Enter your username and password.
- Click the Login button.
Using the App
Once logged in, you will be directed to the game interface. Here’s how to use the app:
- Start the Game:
- Click the Start Game button to begin playing.
- Use the arrow keys or WASD keys to move your player.
-
Click and drag the mouse to aim and release to shoot projectiles at enemies.
-
View Leaderboard:
- Click the Leaderboard button to view the top scores.
-
The leaderboard will display the top 10 players and their scores.
-
Logout:
- Click the Logout link in the navigation bar to log out of your account.
Integrating the App
The app includes a leaderboard feature that can be integrated into other services. Here’s how to access the leaderboard data:
- Get Leaderboard Data:
- The leaderboard data can be accessed via the
/get_leaderboard
endpoint. - This endpoint returns a JSON response with the top 10 players and their scores.
Sample Request
http
GET /get_leaderboard HTTP/1.1
Host: your-app-url
Authorization: Bearer <your-auth-token>
Sample Response
json
[
{"username": "player1", "score": 1500},
{"username": "player2", "score": 1200},
{"username": "player3", "score": 1100},
...
]
Conclusion
The Space Shooter v3 template provides a fun and interactive way to build a space shooter game with user authentication and a leaderboard. Follow the steps above to set up, test, and use the app. Enjoy defending against waves of enemies and aim for the top of the leaderboard!