Scrolling Space Shooter Game
Development
The implementation of a java based scrolling space shooter was a project during my apprenticeship. I then developed the game with the final concept during my free time somewhere around Christmas 2005.
Detailed Description
This scrolling space shooter game started as an ordinary clone of all the top/down or side scrolling shooters everyone knows. Since it is, for programmers, hard to get decent art for games I had an idea in late 2005 on how to change the clone into something more special.
Previously the game was a Swing application using local assets stored in gif and xml files. The core idea was to push all the assets to an online server and to change the Swing application into an Applet. Then it is possible to publis the level editor as an Applet as well. Now everyone can create and publish campaigns to the game. The idea was that users may interact with the game and create better campaigns using their own art and style. Ultimately every user would be able to create his/her top/down scrolling shooter game.
The current state of the project allows the creation of new levels and campaigns using predefined arts, units and unit-behaviours. There are some important features missing, especially a dedicated content publishing system.
Technical Details
- Programming Language: Java, PHP3
- Development Environment: Eclipse, Zend Studio
- Project Size (Java code): 221 files, 14055 code lines, 4057 comment lines, 1777 blank lines, 552 KiB code
- Project Size (PHP code): 33 files, 2766 code lines, 208 comment lines, 384 blank lines, 91.6 KiB code
- Project Duration: Working prototype, but not yet finished
- Technology used: Swing, Applets, MySQL
Feature List
- Game assets are stored on a central server
- A webserver delivers content
- PHP scripts are used to dynamically create campaign and level assets
- Data are stored inside a MySQL database
- The game runs inside an Applet and allows to play any published campaigns
- An Editor has been implemented, running inside an Applet as well
- Rendering using pure java.awt.Graphics
- Some others
Challenges
The first challenge of this project was to run the game on Java using only the basic Graphics API available. The project originated at a time where Java optimization started and machines were slower. So it was much more sensitive regarding performance problems than it is now. Some challenges have been:
- It is possible to use animated gifs with the Java API, but Java seems to be unable to animate them smoothly in performance critical environments. So I had to implement my own sprites class.
- Java reacts quickly if there are too many objects allocated. I solved this implementing some kind of allocation counter which was triggered by each object inside the constructor. I quickly discovered that I allocated lots of Vector2D instances in places where I would have been able to use the old vector instead of allocating a new one. This boosted performance significantly.
The second challenge was to implement the service infrastructure. For security reasons Java Applets are only allowed to contact the server they have been downloaded from. So I added php scripts through which the game and the level editor can communicate with the server and download the latest campaigns and levels.
Credits
The DirectX 7.0 SDK contained a space shooter like the space shooter I developed, but written in Visual Basic. To test the editor and the game I used the assets provided there.
Screenshots
Videos
Code Sample
I will provide two code samples.
The first sample shows the main game loop implemented in Java.
/*! \todo Input so implementieren, dass P abgefangen werden kann, OHNE dass
auch alle anderen Tasten bearbeitet werden...
\bug Pause funktioniert nicht
*/
public void run() {
if (!gameOver) {
doGame();
}
else {
displayGameOver();
}
}
private void doGame() {
//System.out.println("----------------------------------------------");
currentFrameTime = System.currentTimeMillis();
delta = currentFrameTime - lastFrameTime;
delta /= 1000;
//System.out.println(currentFrameTime+"/"+lastFrameTime+"/"+delta);
lastFrameTime = currentFrameTime;
if (delta != 0) {
sceneGraph.getStats().setFPS((float)(1.0 / delta));
}
//System.out.println("Reset");
sceneGraph.reset(/*(float)delta*/);
//System.out.println("UseInput");
sceneGraph.useInput((float)delta);
try {
pauseGuard.lock();
if (!pause) {
pauseGuard.unlock();
sceneGraph.moveObjects((float)float);
sceneGraph.collideObjects();
sceneGraph.insertObjects((float)float);
sceneGraph.removeObjects((float)float);
sceneGraph.drawObjects((float)float);
}
// give cpu to other threads as well
Thread.yield();
}
catch (InterruptedException e) {
e.printStackTrace();
}
finally {
pauseGuard.unlock();
}
checkPlayerDead();
checkLevelDone();
}
The second shows the php script written to load a list of levels from the database. Note that at the time of implementation PHP was still at version 3 and procedural.
<?php
include "../global/error.php";
include "../global/encoding.php";
include "../db/mysqlcon.php";
include "../tables/campaign.php";
include "../tables/user.php";
include "../tables/entity.php";
include "../tables/layer.php";
include "../tables/level.php";
include "../global/authorization.php";
$errorcode = 0;
$errordescription = "";
function check_parameters() {
check_input_parameter('campaign');
check_input_parameter('Login_Email');
}
function create_response($data) {
echo "<response>\n";
echo " <code>0</code>\n";
echo " <errordescription/>\n";
echo " <arguments>\n";
echo " <argument>\n";
echo " <data>" . encode_for_response($data) . "</data>\n";
echo " </argument>\n";
echo " </arguments>\n";
echo "</response>\n";
}
function create_data() {
$data = "";
$campaignid = $_POST['campaign'];
$data = $data . "<campaign_list>\n";
$data = $data . Level_Xml_GetAllLevelsFromCampaign($campaignid);
$data = $data . "</campaign_list>\n";
create_response($data);
}
check_authorization();
check_parameters();
create_data();
?>
Additional Material / Downloads
Not available.
Related Links
Not available.