This document provides an overview of developing a Silverlight game, including designing levels and storyboards, implementing game logic for player movement and collision detection, developing the game using tools like Visual Studio and Expression Blend, and organizing code using the MVC pattern. It also describes techniques for animating game elements like scrolling the game board and frame-by-frame animations, as well as managing sounds. The game is divided into modular XAP files that are downloaded and loaded dynamically.
OpenShift Commons Paris - Choose Your Own Observability Adventure
Silverlight as a Gaming Platform
2. Overview / Introduction to our work in
Silverlight
Developing with the Silverlight 2 Framework
Design of the Concept / Storyboards
Architecture
Game Logic
Scrolling Game Board
Player Movement
Collision Detection
Media - Animation / Sounds
Tools and Techniques
4. Compelling Cross-Platform User Experience
Flexible object-oriented model
Fully managed code to improve encapsulation
and centralization
Declarative presentation language (Xaml)
Role specific tools
Rapid application development
8. Create level treatments and script
Sketch and storyboard main game element
Character, Prop, Backgrounds, Levels…
Illustrate and Animate game elements
Design Game screen
Intro, Level Chooser, Game Won, Game Lost
14. void Page_Loaded(object sender, RoutedEventArgse)
{
LayoutRoot.Children.Add(_preLoader);
Uri addressUri = new Uri(quot;ClientBin/MiniclipIdent.xapquot;,
UriKind.Relative);
System.Net.WebClient wc = new System.Net.WebClient();
wc.BaseAddress = baseUri;
wc.OpenReadCompleted += new
OpenReadCompletedEventHandler(IdentDownloaded);
wc.OpenReadAsync(addressUri);
...
}
15. void IdentDownloaded(object
sender, System.Net.OpenReadCompletedEventArgse)
{. . .
foreach (XElement setting in myAssemblies)
{
uncompressedFile = Application.GetResourceStream(sri,
new Uri(setting.Attribute(quot;Sourcequot;).Value,
UriKind.Relative));
AssemblyPartap = new AssemblyPart();
Assembly a = ap.Load(uncompressedFile.Stream);
}
}
16. Model-View-Controller Pattern
Model
Manages the behavior and state of
an application. Encompasses all of
the business logic. Notifies the
view of changes
View Controller
Renders the models Responding to interactions
Receives input from users within the view and translates
these inputs into actions
and fires events to the
performed by the model
controller.
19. Board Controller
Instantiates our collision detection
Attaches event handlers for keyboard and
board events
Board events control EVERYTHING
They by acting upon the appropriate model.
Player Teleported
Paddles animated
Item picked up
Projectile Deflected
20. public void playerTeleported()
{
Teleport source = gameModel.getPlayer().getOnTeleport();
Teleport destination = source.getLinkedTeleport();
if (destination.getMaintainDirection())
{
//reset the teleport data
gameModel.getPlayer().setOnTeleport(null);
//continue animating the player
MovementDescriptor nextLocation =
getNextDirectedLocationMultiple
(gameModel.getPlayer().getDirection());
gameModel.getPlayer().setNewLocation(nextLocation);
view.animatePlayerJump(nextLocation);
}
else
view.scrollPlayerReturn(); //scroll over to the exit
}
21. Board Composition
A board is a multi-dimensional map of tiles
each placed at a different “z” layer.
Each of our tiles is a “UserControl” that
exhibit specific collision behavior
22. Board Composition
Through our use of
layers, we can maximize our
efficiency of collision
detection by ignoring tiles
that are not at the same z-
index.
Secondly, we can allow tiles
to be stacked to maximize
the reusability of tiles.
23. Board Composition
To achieve tiles at multiple layers, we uses a
single parent canvas with a series of sibling
canvases.
Each tile at the same “z” layer, is inserted
into one of these canvases.
In most situations the player is located in the
middle layer.
24. Levels (Boards)
Our boards are defined in XML, generated
by a open source tool called “TileStudio”
Each board consists of a series of 40x40
tiles positioned in a grid (max 100x100
tiles).
Our game “screen” is scrolling and only
displays about 10 tiles across by 14 tiles
high
26. private void buildBoard(object sender, GameEventArgsgea)
{
BoardDatanextBoard =
_gameConfig.getSpecificBoard(gea.TargetLevel);
//pull the definition of the board out of the assembly
Stream s = this.GetType().Assembly.
GetManifestResourceStream(namespacePrefix +
nextBoard.filename);
string boardXml = new StreamReader(s).ReadToEnd();
gameModel = new GameDefintion(boardXml);
playerScore = new PlayerStats(nextBoard);
view.Board = gameModel;
collider = new Collisions(gameModel);
}
27. Models
Each of our tiles has a corresponding Model
which maintains its logical state.
Position (x,y,z), Rotation, Orientation…
Each model exposes methods to calculate
the appropriate reaction to game events.
29. Scrolling Game Board
When the game begins, our game board
immediately renders each tile for that level,
setting each tiles visibility to collapsed. We
divide our level into a series of screens;
each screen is comprised of 10x14 tiles.
A timer begins (Game tick) which will be
used to control tile visibility.
30. Scrolling Game Board
Based on the position of the player, we
visualize a screen of tiles one tile larger then
our screen dimensions.
31. Player Movement
The player is always centered on the
screen.
To give the perception that the player is
moving, the entire board animates in opposite
direction to the player.
Keyboard mappings
Space bar – Fires a projectile
Ctrl – Activates a tile (player picks up a prop)
Left, Right, Up and Down – Player moves
32. Scrolling Game Board
Once per game tick, we evaluate if a new screen
of tiles need to be visualized based on the
movement of the player.
33. Projectile
When the gun is fired, the scrolling board
follows the projectile to its destination, upon
impact (stick or deflection), the view
animates back to the players original
location
35. Collisions occur when a player is asked to
consume an adjacent tile occupied by an
existing tile at its same z-layer.
Each time the appropriate movement key is
pressed, a method in our board controller is
fired, in turn calling a method within our
collision detection class. This method
checks to see if a tile at the same z-index is
blocking the movement.
36. When a player attempts to move to an
adjacent tile, that tile determine the effect of
the collision.
37. To expedite the process of finding the next
blocking tile, a generic collection is
constructed that will hold a reference to
each tile model within its relationship to the
game board.
Through the use of polymorphism we can
quickly allow each tile to determine its
reaction to a collision.
38. private List<Tile>[][] gameGrid = new
List<Tile>[gameModel.getRows()][];
for (inti=0; i<gameGrid.Length; i++)
{
gameGrid[i] = new
List<Tile>[gameModel.getColumns()];
for (intj=0; j<gameGrid[i].Length; j++)
{
gameGrid[i][j] = new List<Tile>();
}
}
40. Time Based
Silverlight uses a property-based animation
model. A model which is time based.
Silverlight can only modify the value of a
property over an interval of time.
In essence, it you set the initial state, the final
state, and the duration of your animation then
Silverlight will calculates the frame rate.
41. Frame-by-Frame - Stacked Frames
Using this technique a series of frames are
stacked at the same X,Y. Key frames are
created toggling the opacity of the current
and previous frame.
42. Frame-by-Frame - Canvas Clip
Using this technique, each frame is positioned
adjacent to each other within a single canvas. A
canvas clip is defined the width and height of a single
frame. Key frames are created moving the canvas
strip from right to left
44. There are numerous situations where we
use a combination of Frame-By-Frame
animations within a time-based animation.
Player movement
Firing of Projectile
Deflection of Projectile
46. Sounds
All of our sounds are managed in a single
sound factory (singleton).
Extracts sounds from game assembly using
app.manifest and an audio xml config file
This configfile defines our LeadIn / LeadOuts
for sound loops
Controls the muting of sounds
Centralizes access to our generic sound
dictionary