diff --git "a/app.py" "b/app.py"
--- "a/app.py"
+++ "b/app.py"
@@ -7,708 +7,734 @@ import random
import time
import math
-# --- SERVER CONFIGURATION ---
+--- SERVER CONFIGURATION ---
+
WIDTH = 375
HEIGHT = 812
-app = Flask(__name__)
+app = Flask(name)
app.config['SECRET_KEY'] = 'jungle_jump_pro_2024'
socketio = SocketIO(app, async_mode='eventlet', cors_allowed_origins='*')
-# --- GAME STATE ---
+--- GAME STATE ---
+
players = {}
platforms = []
collectibles = []
enemies = []
highest_y_generated = HEIGHT
-game_events = [] # For broadcasting special events
+game_events = [] # For broadcasting special events
def generate_platform(y_pos, difficulty=1):
- p_type = 'normal'
- vx = 0
- special = None
-
- rand = random.random()
- if rand < 0.15:
- p_type = 'bouncy'
- elif rand < 0.25:
- p_type = 'ice'
- elif rand < 0.32:
- p_type = 'crumbling'
- elif rand < 0.38:
- p_type = 'cloud'
- elif rand < 0.42:
- p_type = 'golden'
-
- if random.random() < 0.25:
- vx = (2 + difficulty * 0.5) if random.random() > 0.5 else -(2 + difficulty * 0.5)
-
- # Special items on platform
- if random.random() < 0.08:
- special = 'spring'
- elif random.random() < 0.05:
- special = 'jetpack'
- elif random.random() < 0.04:
- special = 'shield'
- elif random.random() < 0.03:
- special = 'magnet'
-
- return {
- 'id': int(time.time() * 1000) + random.randint(0, 9999),
- 'x': random.random() * (WIDTH - 70),
- 'y': y_pos,
- 'w': 70 if p_type != 'cloud' else 90,
- 'h': 18,
- 'type': p_type,
- 'vx': vx,
- 'special': special,
- 'broken': False,
- 'wobble': 0
- }
+p_type = 'normal'
+vx = 0
+special = None
+
+code
+Code
+download
+content_copy
+expand_less
+rand = random.random()
+if rand < 0.15:
+ p_type = 'bouncy'
+elif rand < 0.25:
+ p_type = 'ice'
+elif rand < 0.32:
+ p_type = 'crumbling'
+elif rand < 0.38:
+ p_type = 'cloud'
+elif rand < 0.42:
+ p_type = 'golden'
+
+if random.random() < 0.25:
+ vx = (2 + difficulty * 0.5) if random.random() > 0.5 else -(2 + difficulty * 0.5)
+
+# Special items on platform
+if random.random() < 0.08:
+ special = 'spring'
+elif random.random() < 0.05:
+ special = 'jetpack'
+elif random.random() < 0.04:
+ special = 'shield'
+elif random.random() < 0.03:
+ special = 'magnet'
+
+return {
+ 'id': int(time.time() * 1000) + random.randint(0, 9999),
+ 'x': random.random() * (WIDTH - 70),
+ 'y': y_pos,
+ 'w': 70 if p_type != 'cloud' else 90,
+ 'h': 18,
+ 'type': p_type,
+ 'vx': vx,
+ 'special': special,
+ 'broken': False,
+ 'wobble': 0
+}
def generate_collectible(y_pos):
- c_type = 'coin' if random.random() > 0.15 else 'gem'
- return {
- 'id': int(time.time() * 1000) + random.randint(0, 9999),
- 'x': random.random() * (WIDTH - 30),
- 'y': y_pos - 50,
- 'type': c_type,
- 'collected': False,
- 'value': 10 if c_type == 'coin' else 50
- }
+c_type = 'coin' if random.random() > 0.15 else 'gem'
+return {
+'id': int(time.time() * 1000) + random.randint(0, 9999),
+'x': random.random() * (WIDTH - 30),
+'y': y_pos - 50,
+'type': c_type,
+'collected': False,
+'value': 10 if c_type == 'coin' else 50
+}
def generate_enemy(y_pos):
- e_type = random.choice(['slime', 'bat', 'spike'])
- return {
- 'id': int(time.time() * 1000) + random.randint(0, 9999),
- 'x': random.random() * (WIDTH - 40),
- 'y': y_pos - 80,
- 'type': e_type,
- 'vx': 2 if random.random() > 0.5 else -2,
- 'active': True
- }
+e_type = random.choice(['slime', 'bat', 'spike'])
+return {
+'id': int(time.time() * 1000) + random.randint(0, 9999),
+'x': random.random() * (WIDTH - 40),
+'y': y_pos - 80,
+'type': e_type,
+'vx': 2 if random.random() > 0.5 else -2,
+'active': True
+}
def init_world():
- global platforms, collectibles, enemies, highest_y_generated
- platforms = []
- collectibles = []
- enemies = []
-
- # Base platform
- platforms.append({
- 'id': 0, 'x': WIDTH/2 - 50, 'y': HEIGHT - 150,
- 'w': 100, 'h': 20, 'type': 'start', 'vx': 0,
- 'special': None, 'broken': False, 'wobble': 0
- })
+global platforms, collectibles, enemies, highest_y_generated
+platforms = []
+collectibles = []
+enemies = []
+
+code
+Code
+download
+content_copy
+expand_less
+# Base platform
+platforms.append({
+ 'id': 0, 'x': WIDTH/2 - 50, 'y': HEIGHT - 150,
+ 'w': 100, 'h': 20, 'type': 'start', 'vx': 0,
+ 'special': None, 'broken': False, 'wobble': 0
+})
+
+y = HEIGHT - 280
+for i in range(300):
+ difficulty = min(i / 50, 5)
+ gap = 75 + random.random() * (35 + difficulty * 5)
+ platforms.append(generate_platform(y, difficulty))
- y = HEIGHT - 280
- for i in range(300):
- difficulty = min(i / 50, 5)
- gap = 75 + random.random() * (35 + difficulty * 5)
- platforms.append(generate_platform(y, difficulty))
-
- if random.random() < 0.4:
- collectibles.append(generate_collectible(y))
-
- if random.random() < 0.08 and i > 10:
- enemies.append(generate_enemy(y))
-
- y -= gap
+ if random.random() < 0.4:
+ collectibles.append(generate_collectible(y))
+
+ if random.random() < 0.08 and i > 10:
+ enemies.append(generate_enemy(y))
- highest_y_generated = y
+ y -= gap
+
+highest_y_generated = y
init_world()
-# --- ENHANCED HTML TEMPLATE ---
+--- ENHANCED HTML TEMPLATE ---
+
HTML_TEMPLATE = """
+
+
-
-
- 🌴 Jungle Jump Pro - Multiplayer
-
-
+
+
+🌴 Jungle Jump Pro - Multiplayer
+
+
-
-
-
-
-
JUNGLE JUMP
-
✨ Multiplayer Pro Edition ✨
-
-
-
-
-
-
-
+
+
+code
+Code
+download
+content_copy
+expand_less
+
+
+
JUNGLE JUMP
+
✨ Multiplayer Pro Edition ✨
+
+
-
-
-
-
🏆 Top Jumpers
-
Connecting...
-
-
-
-
-
-
x2 COMBO!
+
+
-
-
+
+
+
+
+
🏆 Top Jumpers
+
Connecting...
-
-
-
-
-
-
-
-
+
+
x2 COMBO!
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
GAME OVER
+
0
+
+
Height: 0m
+
Best Combo: x0
-
-
-
GAME OVER
-
0
-
-
Height: 0m
-
Best Combo: x0
+
+
-
-
-
-
-
+
+
-
-
+
+
+
+
+
"""
-# --- FLASK ROUTES & SOCKET EVENTS ---
+--- FLASK ROUTES & SOCKET EVENTS ---
@app.route('/')
def index():
- return render_template_string(HTML_TEMPLATE)
+return render_template_string(HTML_TEMPLATE)
@socketio.on('join')
def on_join(data):
- players[request.sid] = {
- 'name': data.get('name', 'Guest')[:12],
- 'char': data.get('char', 'dino'),
- 'x': WIDTH/2,
- 'y': HEIGHT - 200,
- 'vx': 0,
- 'score': 0,
- 'faceRight': True,
- 'highestY': HEIGHT
- }
- emit('world_data', {
- 'platforms': platforms,
- 'collectibles': collectibles,
- 'enemies': enemies
- })
+players[request.sid] = {
+'name': data.get('name', 'Guest')[:12],
+'char': data.get('char', 'dino'),
+'x': WIDTH/2,
+'y': HEIGHT - 200,
+'vx': 0,
+'score': 0,
+'faceRight': True,
+'highestY': HEIGHT
+}
+emit('world_data', {
+'platforms': platforms,
+'collectibles': collectibles,
+'enemies': enemies
+})
@socketio.on('update')
def on_update(data):
- if request.sid in players:
- p = players[request.sid]
- p['x'] = data.get('x', p['x'])
- p['y'] = data.get('y', p['y'])
- p['vx'] = data.get('vx', p['vx'])
- p['faceRight'] = data.get('faceRight', p['faceRight'])
- p['score'] = data.get('score', p['score'])
- p['char'] = data.get('char', p.get('char', 'dino'))
-
- # Track highest point for achievements
- if p['y'] < p['highestY'] - 5000:
- p['highestY'] = p['y']
- height = int(abs(p['y']) / 100)
- socketio.emit('player_event', {
- 'type': 'record',
- 'name': p['name'],
- 'height': height
- })
-
- # Generate more world as players climb
- global highest_y_generated
- if p['y'] < highest_y_generated + 1500:
- difficulty = min(abs(highest_y_generated) / 5000, 5)
- for _ in range(15):
- gap = 75 + random.random() * (35 + difficulty * 8)
- new_plat = generate_platform(highest_y_generated - gap, difficulty)
- platforms.append(new_plat)
-
- if random.random() < 0.4:
- collectibles.append(generate_collectible(highest_y_generated - gap))
-
- if random.random() < 0.06 + difficulty * 0.02:
- enemies.append(generate_enemy(highest_y_generated - gap))
-
- highest_y_generated = new_plat['y']
+if request.sid in players:
+p = players[request.sid]
+p['x'] = data.get('x', p['x'])
+p['y'] = data.get('y', p['y'])
+p['vx'] = data.get('vx', p['vx'])
+p['faceRight'] = data.get('faceRight', p['faceRight'])
+p['score'] = data.get('score', p['score'])
+p['char'] = data.get('char', p.get('char', 'dino'))
+
+code
+Code
+download
+content_copy
+expand_less
+# Track highest point for achievements
+ if p['y'] < p['highestY'] - 5000:
+ p['highestY'] = p['y']
+ height = int(abs(p['y']) / 100)
+ socketio.emit('player_event', {
+ 'type': 'record',
+ 'name': p['name'],
+ 'height': height
+ })
+
+ # Generate more world as players climb
+ global highest_y_generated
+ if p['y'] < highest_y_generated + 1500:
+ difficulty = min(abs(highest_y_generated) / 5000, 5)
+ for _ in range(15):
+ gap = 75 + random.random() * (35 + difficulty * 8)
+ new_plat = generate_platform(highest_y_generated - gap, difficulty)
+ platforms.append(new_plat)
+
+ if random.random() < 0.4:
+ collectibles.append(generate_collectible(highest_y_generated - gap))
+
+ if random.random() < 0.06 + difficulty * 0.02:
+ enemies.append(generate_enemy(highest_y_generated - gap))
+
+ highest_y_generated = new_plat['y']
@socketio.on('player_died')
def on_died():
- if request.sid in players:
- players[request.sid]['score'] = 0
- players[request.sid]['highestY'] = HEIGHT
+if request.sid in players:
+players[request.sid]['score'] = 0
+players[request.sid]['highestY'] = HEIGHT
@socketio.on('player_restart')
def on_restart():
- if request.sid in players:
- players[request.sid]['score'] = 0
- players[request.sid]['highestY'] = HEIGHT
- emit('world_data', {
- 'platforms': platforms[-100:],
- 'collectibles': [c for c in collectibles if not c['collected']][-50:],
- 'enemies': [e for e in enemies if e['active']][-20:]
- })
+if request.sid in players:
+players[request.sid]['score'] = 0
+players[request.sid]['highestY'] = HEIGHT
+emit('world_data', {
+'platforms': platforms[-100:],
+'collectibles': [c for c in collectibles if not c['collected']][-50:],
+'enemies': [e for e in enemies if e['active']][-20:]
+})
@socketio.on('disconnect')
def on_disconnect():
- if request.sid in players:
- del players[request.sid]
+if request.sid in players:
+del players[request.sid]
def server_loop():
- while True:
- socketio.sleep(0.04) # 25 ticks per second
-
- # Update moving platforms
- for p in platforms:
- if p['vx'] != 0:
- p['x'] += p['vx']
- if p['x'] < 0 or p['x'] + p['w'] > WIDTH:
- p['vx'] *= -1
-
- # Update enemies
- for e in enemies:
- if e['active']:
- e['x'] += e['vx']
- if e['x'] < 0 or e['x'] + 40 > WIDTH:
- e['vx'] *= -1
-
- # Find the lowest active player for cleanup
- if players:
- lowest_y = min(p['y'] for p in players.values())
-
- # Clean up old entities
- global platforms, collectibles, enemies
- platforms = [p for p in platforms if p['y'] < lowest_y + 1500][-500:]
- collectibles = [c for c in collectibles if c['y'] < lowest_y + 1500 and not c['collected']][-200:]
- enemies = [e for e in enemies if e['y'] < lowest_y + 1500 and e['active']][-50:]
-
- # Broadcast game state
- socketio.emit('game_update', {
- 'players': players,
- 'platforms': [p for p in platforms if p['vx'] != 0][-30:] + platforms[-40:]
- })
+global platforms, collectibles, enemies
+while True:
+socketio.sleep(0.04) # 25 ticks per second
+
+code
+Code
+download
+content_copy
+expand_less
+# Update moving platforms
+ for p in platforms:
+ if p['vx'] != 0:
+ p['x'] += p['vx']
+ if p['x'] < 0 or p['x'] + p['w'] > WIDTH:
+ p['vx'] *= -1
+
+ # Update enemies
+ for e in enemies:
+ if e['active']:
+ e['x'] += e['vx']
+ if e['x'] < 0 or e['x'] + 40 > WIDTH:
+ e['vx'] *= -1
+
+ # Find the lowest active player for cleanup
+ if players:
+ lowest_y = min(p['y'] for p in players.values())
+
+ # Clean up old entities
+ platforms = [p for p in platforms if p['y'] < lowest_y + 1500][-500:]
+ collectibles = [c for c in collectibles if c['y'] < lowest_y + 1500 and not c['collected']][-200:]
+ enemies = [e for e in enemies if e['y'] < lowest_y + 1500 and e['active']][-50:]
+
+ # Broadcast game state
+ socketio.emit('game_update', {
+ 'players': players,
+ 'platforms': [p for p in platforms if p['vx'] != 0][-30:] + platforms[-40:]
+ })
socketio.start_background_task(server_loop)
-if __name__ == '__main__':
- print("🎮 Jungle Jump Pro Server Starting...")
- print("🌐 Open http://localhost:7860 to play!")
- socketio.run(app, host='0.0.0.0', port=7860)
\ No newline at end of file
+if name == 'main':
+print("🎮 Jungle Jump Pro Server Starting...")
+print("🌐 Open http://localhost:7860 to play!")
+socketio.run(app, host='0.0.0.0', port=7860)
\ No newline at end of file