Design consideration of Space Blok XNA
This page describes the designs and implementations chosen for Space Blok.
Importing 3D models
XNA 4.0 on Windows Phone 7.0 allows the importing of Autodesk FBX files, making it easy to get the 3D models into the application.
In Space Blok, the Ball, the Platform, and the GameLevel objects are imported from FBX files.
For example, the loading of the Ball model is done in one line of code:
Model ballModel = Game.Content.Load<Model>(@"Models\sphere");
in which 'Models\sphere' is the path to the sphere.fbx file.
Integration of BEPUphysics
The minimum required amount of information about BEPUphysics is listed here to get you started.
The simulation needs a world to live in, so BEPUphysics represents an abstraction called Space which can be created in code as follows:
space = new Space(); space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);
The gravity for space is set to represent the gravity on earth.
Space requires to be updated on each 'tick' so that BEPUphysics can simulate all of its objects. Call the following method on the update on your application:
space.Update();
In BEPUphysics, all objects in space are called Entities and there are many kinds of them, such as Box, Cylinder, and Sphere. To create a Sphere object for the simulation, this code can be used:
Entity ballEntity = new Sphere(Vector3.Zero, 0.5f, 1.0f); space.Add(ballEntity);
This creates a 0.5 radius sphere to the origo of space with a mass of 1.0f. The ball is added to the space, allowing BEPUphysics to move the ball on each 'tick'.
To check how the simulation of the Sphere entity and updating of the position of the ball's graphical representation is done in Space Blok, see the following code files:
More information about using BEPUphysics can be found at their website:
The documentation for the library can be found here:
http://bepuphysics.codeplex.com/documentation
Multitouch support
Multitouch support is implemented into the HandleInput method of Platform.cs. Here is the simplified version of the method:
public void HandleInput(InputState input) { foreach (TouchLocation touchLocation in input.TouchState) { if (touchLocation.State == TouchLocationState.Pressed) { // This platform is picked, store the touch id, location and timestamp. } else if (touchLocation.State == TouchLocationState.Released) { // Ignore releases which have no matching pressed id if (pressedLocations.Id == touchLocation.Id) { // Calculate the swipe data and launch the ball } } } }
Implementation of screen management
The screen system of Space Blok is implemented by deriving all the screens from the class GameScreen.
GameScreen has access to ScreenManager, which manages the stack of currently existing screens. All screens can add or remove other screens via the ScreenManager.
ScreenManager draws the screen stack upwards from the bottom, allowing the painting of many screens with opacity. All of the screens on the stack are updated by the screen manager, but only the topmost screen will have user input handling.
Release downloads
Attachments
-
game_view.jpg
(98.5 KB) -
added by kratsan 7 months ago.
-
in_game_menu.jpg
(69.0 KB) -
added by kratsan 7 months ago.
-
main_menu.jpg
(90.6 KB) -
added by kratsan 7 months ago.
-
Winning_screen.jpg
(73.3 KB) -
added by kratsan 7 months ago.
-
info_view.jpg
(121.8 KB) -
added by kratsan 7 months ago.

