Initial Commit
This commit is contained in:
35
app.py
Normal file
35
app.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import json
|
||||
from operator import mod
|
||||
from tokenize import String
|
||||
from flask import Flask, request, jsonify
|
||||
from flask_cors import CORS
|
||||
|
||||
player1 = {"name": "Player 1", "xpos": 1, "ypos": 1}
|
||||
|
||||
app = Flask(__name__)
|
||||
CORS(app)
|
||||
@app.route('/api/send', methods=['POST'])
|
||||
|
||||
def receive_data():
|
||||
data = request.get_json()
|
||||
# Input data is the form [reset(bool), isPressed(json)]
|
||||
|
||||
# Handle Resetting
|
||||
if (data['reset']):
|
||||
player1['xpos'] = 0
|
||||
player1['ypos'] = 0
|
||||
|
||||
# Handle key presses
|
||||
if (data['keyDown']['ArrowUp'] == True):
|
||||
player1['ypos'] -= 1
|
||||
if (data['keyDown']['ArrowDown'] == True):
|
||||
player1['ypos'] += 1
|
||||
if (data['keyDown']['ArrowRight'] == True):
|
||||
player1['xpos'] += 1
|
||||
if (data['keyDown']['ArrowLeft'] == True):
|
||||
player1['xpos'] -= 1
|
||||
|
||||
return jsonify(player1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
Reference in New Issue
Block a user