+ All Categories
Home > Documents > Spong Bluetooth game Developed by: Erik Matzols Fredrik Lindberg.

Spong Bluetooth game Developed by: Erik Matzols Fredrik Lindberg.

Date post: 31-Dec-2015
Category:
Upload: jody-small
View: 219 times
Download: 2 times
Share this document with a friend
Popular Tags:
18
Spong Bluetooth game Developed by: Erik Matzols Fredrik Lindberg
Transcript

Spong Bluetooth game

Developed by:

Erik Matzols

Fredrik Lindberg

Spong game

• Uses the J-82 API for bluetooth communication• Uses J4ME library to eliminate some

annoyances with the J2ME UI.• Each player controls a paddle and need to

prevent the ball from falling from the playing field• The winner is the one who has managed to

score most points. The point limit is decided by the one who host the game

Supported Devices

• Need MIDP-2.0 and CLDC-1.1

• Screen resolution of 240x320.

• Game will run fine on other resolutions that support the other criterias but size of graphics content will affect gameplay.

J4ME

• Able to set a theme for the entire application.

• Have some basic ”form” capability and able to have custom backgrounds.

• Only uses a small fraction of the library for automatic button placement and automatic scrolling of text on the instruction page.

• Check it out on http://code.google.com/p/j4me/

Spong game: Main menu

The main menu has four selections.

• New game - will bring you to a new page for selection of hosting or joining a game.

• Options – Set your nickname,servername and the points limit when you act as server.

• Instruction – show a text with instruction how to play the game.

• Quit – Obvious.

Spong game: Instructions

• Scrollbar to the left if text is larger than the screen height.

• Back button to return to main menu

Spong game: Options

• Data is stored in a permanent record store

• Nickname is sent when establishing connection

Spong game: Host/Join

Spong Game: Selecting server

• Multiple servers to select from if multiple hosts exist

Spong Game: Game session

• Client commands are sent to server and processed

• Server sends new state to client that the client renders

The Code

• The game consists of 17 classes

• Spong, SpongModel, Menu, BluetoothClient, BluetoothServer, GameSession,Paddle, Ball .....

Spong,SpongModel

• Spong - A public class extends MIDlet. Spong creates an instance of the class SpongModel when the method startApp() is called.

• SpongModel - A public class that contains the BluetoothClient,BluetoothServer Menu and GameSession instances. Its responsibility is to contain and communicate with the various objects such as the Menu, Bluetoothserver , BluetoothClient and the GameSession.

Menu

• Menu – A public class that extends Dialog which is a J4ME class that implements some simple ”form” functionality. The Menu consists of several classes that implements the submenus.

• The buttons are a custom item that can change its color if it is selected. A variable in each menu keeps track of the current selected button.

BluetoothServer,BluetoothClient

• BluetoothServer – A public class that implements Runnable. It will wait in a blocking thread until a connection has been accepted or the user presses the cancel button which will call the stop() method for the BluetoothServer thread.

• BluetoothClient – A public class that implements DiscoveryListener and Runnable. Implements the DiscoveryListener interface to be able to query other Bluetoothdevices and return a list of connectable devices to the user. The user can at any time press the canel button and terminate the search.

• Both BluetoothClient and BluetoothServer communicates with the SpongModel via callbacks.

GameSession

GameSession• Implements Runnable and Canvas.• Created after a connection has been made. • Creates paddle and ball and draws all game graphics.• Determines who act as server based on a variable sent

to constructor.• Reads keypresses into a keyState.• Server has authority and simulates the ball and does

collision detection.• Client send its input to the server which in turn send a

new state for the paddles and balls to the client so it can render the new state.

Paddle , Ball

• Paddle – Represents the paddle the user controls. Is a serializable object that can be sent over the bluetooth connection

• Ball – Represents the ball. Is a serializable object that can be sent over the bluetooth connection.

The homepage

• Adapts to different screen sizes.

• OTA support for the game Spong.

• Uses WURFL to check if device is capable of running the game.

• A Flash Lite demo of the game

• Check it out http://www.nada.kth.se/~matzols/

The End


Recommended