Skip to content
iAliasPublic
forked from jamesward/P2Pong

About

P2P Game Example with Flex

Resources

Stars

1 star

Watchers

1 watching

Forks

 
 

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

P2Pong - Peer-to-Peer Ping Pong Game for Android

P2Pong is a multiplayer ping pong game for Android devices built with Adobe AIR and ActionScript/Flex. Two players can connect over a local network and play ping pong, with each player seeing their own half of the playing field on their device.

Game Features

  • Multiplayer: Two players can connect and play together over a local network
  • Split View: Each player sees their own half of the game field on their device
  • Side Selection: Players choose whether they play on the left or right side
  • Real-time Synchronization: Ball position and velocity are synchronized between devices using P2P networking
  • Touch Controls: Drag the paddle up and down to hit the ball

How to Play

  1. Install the APK: Install P2Pong.apk on two Android devices
  2. Connect to the same network: Both devices must be on the same local network (WiFi)
  3. Launch the app: Open P2Pong on both devices
  4. Choose sides:
    • One player taps "Play Left"
    • The other player taps "Play Right"
  5. Start playing: Once both players have joined, the game starts automatically
  6. Control your paddle: Drag your finger up or down on the paddle to move it
  7. Hit the ball: Try to hit the ball back to your opponent
  8. New game: If the ball goes off-screen, the left player can tap "start new game" to begin again

Technical Details

Technology Stack

  • Platform: Adobe AIR for Android
  • Language: ActionScript 3 / MXML
  • Framework: Apache Flex (Spark components)
  • Networking: RTMFP (Real Time Media Flow Protocol) for P2P communication
  • Minimum Android Version: Android 2.2+ (API level 8+)

Network Architecture

The game uses RTMFP multicast networking to enable direct peer-to-peer communication between devices:

  • Multicast Group: p2pong
  • IP Multicast Address: 239.254.254.1:30303
  • Protocol: rtmfp:// (Adobe's P2P protocol)

Game Synchronization

  • The left player is responsible for ball physics and sends updates to the right player
  • Each player handles their own paddle collision detection
  • Ball velocity changes are communicated via BALL_BOUNCED events
  • Player join events (LEFT_JOINED, RIGHT_JOINED) are broadcast when sides are chosen

Required Android Permissions

  • INTERNET - Network communication
  • ACCESS_NETWORK_STATE - Check network connectivity
  • ACCESS_WIFI_STATE - Access WiFi information
  • CHANGE_WIFI_MULTICAST_STATE - Required for multicast networking

Building from Source

Prerequisites

  • Adobe AIR SDK (version 2.5+)
  • Apache Flex SDK
  • Flash Builder or command-line AIR tools

Build Steps

  1. Clone this repository
  2. Open the project in Flash Builder or use amxmlc command-line compiler
  3. Compile P2Pong.mxml to generate P2Pong.swf
  4. Package the APK using AIR Developer Tool (ADT):
    adt -package -target apk-debug -storetype pkcs12 -keystore your_cert.p12 P2Pong.apk P2Pong-app.xml P2Pong.swf

Project Structure

P2Pong/
├── src/
│   ├── P2Pong.mxml          # Main application file (working version)
│   ├── P2PongNew.mxml       # Incomplete refactoring attempt
│   ├── P2Pong-app.xml       # AIR application descriptor
│   ├── P2PongEvent.as       # Event class for P2P messages
│   ├── Ball.as              # Ball data class
│   ├── Paddle.as            # Paddle data class
│   ├── Player.as            # Player data class
│   ├── Game.as              # Game state class
│   └── NetBus.as            # Network bus (unused stub)
├── bin-debug/
│   ├── P2Pong.apk           # Pre-built Android application
│   ├── P2Pong.swf           # Compiled SWF
│   └── P2Pong-app.xml       # Compiled app descriptor
└── README.md                # This file

Known Issues and Limitations

  1. RTMFP Deprecation: Adobe has deprecated RTMFP, so this may not work on newer AIR runtime versions
  2. Network Discovery: Devices must be on the same local network with multicast enabled
  3. Firewall: Some networks block multicast traffic which will prevent connection
  4. NAT Traversal: The game only works on local networks, not across the internet

Troubleshooting

Players can't connect

  • Ensure both devices are on the same WiFi network
  • Check that multicast is enabled on your router
  • Try disabling firewall temporarily
  • Verify both devices have granted network permissions to the app

Ball doesn't appear

  • Make sure both players have selected their sides (left/right)
  • The left player starts the game - check that both join indicators are visible

App crashes on launch

  • Verify Android version is 2.2 or higher
  • Check that AIR runtime is installed on the device
  • Try reinstalling the APK

License

This is an old educational project. Feel free to use and modify as needed.

Future Improvements

If modernizing this project, consider:

  • Migrating from RTMFP to WebSockets or WebRTC
  • Updating to Apache Royale (the successor to Apache Flex)
  • Converting to a modern framework (React Native, Flutter, etc.)
  • Adding score tracking and game timer
  • Implementing more game modes

About

P2P Game Example with Flex

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages