12-04-2006, 07:20 AM
|
#1
|
|
Registered User
Join Date: Oct 2006
Posts: 131
|
[AS2] game tile class yet again!
I haven't posted for a couple days because I've been modifying this a lot.
here's the example:
http://sickbooks.com/testing/game4.html
read the fine print on top so you know what to do.
I have combined the use a a few classes that I wrote...
the classes are:
GameBoard (the tile aspect)
GamePlayControl (smooth keyboard control)
BatchSmooth(tweening everything in one shot)
on another project im working on a socket server. the goal of all this is to make it easy to start building a game. here's all the code on the main timeline from that link i gave you...
Code:
var myKeyValues:Array = new Array();
myKeyValues[0] = ["map_up", 38, true];
myKeyValues[1] = ["map_down", 40, true];
myKeyValues[2] = ["map_left", 37, true];
myKeyValues[3] = ["map_right", 39, true];
myKeyValues[4] = ["player_up", 87, true];
myKeyValues[5] = ["player_down", 83, true];
myKeyValues[6] = ["player_left", 65, true];
myKeyValues[7] = ["player_right", 68, true];
myKeyValues[8] = ["player2_up", 84, true];
myKeyValues[9] = ["player2_down", 71, true];
myKeyValues[10] = ["player2_left", 70, true];
myKeyValues[11] = ["player2_right", 72, true];
var gameBoard:GameBoard = new GameBoard(mapContainer, "myTile", 40);
var gpc:GamePlayControl = new GamePlayControl(myKeyValues, runGameKeys, 35, false);
var batchTween:BatchSmooth = new BatchSmooth(updatePositions);
gameBoard.setScreen(500, 300);
function runGameKeys(val):Void
{
var spd:Number = 15;
var pl_spd:Number = 10;
if (val == "map_up") batchTween.modifyGoToValue('map', '_y', -spd);
else if (val == "map_down") batchTween.modifyGoToValue('map', '_y', spd);
else if (val == "map_left") batchTween.modifyGoToValue('map', '_x', -spd);
else if (val == "map_right") batchTween.modifyGoToValue('map', '_x', spd);
else if (val == "player_up") batchTween.modifyGoToValue('player_mc0', '_y', -pl_spd);
else if (val == "player_down") batchTween.modifyGoToValue('player_mc0', '_y', pl_spd);
else if (val == "player_left") batchTween.modifyGoToValue('player_mc0', '_x', -pl_spd);
else if (val == "player_right") batchTween.modifyGoToValue('player_mc0', '_x', pl_spd);
else if (val == "player2_up") batchTween.modifyGoToValue('player_mc27', '_y', -pl_spd);
else if (val == "player2_down") batchTween.modifyGoToValue('player_mc27', '_y', pl_spd);
else if (val == "player2_left") batchTween.modifyGoToValue('player_mc27', '_x', -pl_spd);
else if (val == "player2_right") batchTween.modifyGoToValue('player_mc27', '_x', pl_spd);
}
var mapXML:XML = new XML();
mapXML.ignoreWhite = true;
mapXML.load("level001.xml");
mapXML.onLoad = parseMapXML;
function parseMapXML(ok):Void
{
if(ok)
{
gameBoard.loadXML(mapXML);
gameBoard.drawMapAtXY(0, 0);
gameBoard.addPlayer("player_mc", 0, 200, 200);
gameBoard.addPlayer("player_mc", 27, 400, 200);
batchTween.addToBatch('player_mc0', ['_x', '_y'], [200, 200], 3);
batchTween.addToBatch('player_mc27', ['_x', '_y'], [400, 200], 3);
batchTween.addToBatch('map', ['_x', '_y'], [0, 0], 6);
boardW = (gameBoard._colCount * gameBoard._gridSize);
boardH = (gameBoard._rowCount * gameBoard._gridSize);
batchTween.defineRange('map', '_x', 0, boardW - gameBoard._screenWidth);
batchTween.defineRange('map', '_y', 0, boardH - gameBoard._screenHeight);
batchTween.defineRange('player_mc0', '_x', 0, boardW);
batchTween.defineRange('player_mc0', '_y', 0, boardH);
batchTween.defineRange('player_mc27', '_x', 0, boardW);
batchTween.defineRange('player_mc27', '_y', 0, boardH);
setInterval(redrawGameBoard, 30);
}
}
var avgTotal:Number = 0;
var avgCount:Number = 0;
var bestTime:Number = 99999999999;
var worstTime:Number = 0;
function redrawGameBoard():Void
{
var sT = getTimer();
batchTween.runBatch();
var eT = getTimer();
var total = eT - sT;
if (total > worstTime) worstTime = total;
if (total < bestTime) bestTime = total;
avgTotal += total;
avgCount++;
var currentAVG = Math.round(avgTotal/avgCount);
tester.text = 'current['+total+'ms] ---> worst['+worstTime+'ms] : best['+bestTime+'ms] ---> avg['+currentAVG+'ms]';
}
function updatePositions(id, attr, val):Void
{
if (id.slice(0, 9) == "player_mc")
{
var idNum:Number = Number (id.slice(9));
gameBoard.updatePlayerProp(idNum, attr, val);
}
else if (id == "map")
{
if (attr == '_x') gameBoard.drawMapAtXY(val, undefined);
else if (attr == '_y') gameBoard.drawMapAtXY(undefined, val);
}
}
hideSides_mc.onPress = function()
{
if (hideSides_mc._alpha == 100) hideSides_mc._alpha = 75;
else hideSides_mc._alpha = 100;
}
some of that is for testing. But for the most part you can get a game running under 100 lines of code with these classes.
I just want you guys to check it out and give me your stats.
Mine are...
current[13ms] ---> worst[24ms] : best[12ms] ---> avg[15ms]
the next class I need to finish is one that I didn't list above, which is a collision detection class. This will include circle math, distance formula, grid checking for solid surfaces etc...
If you guys can think of anything that would make this package more complete just let me know.
|
|
|
12-04-2006, 07:21 AM
|
#2
|
|
Registered User
Join Date: Oct 2006
Posts: 131
|
...
oh yeah, and of course when I release this it will all be documented.
|
|
|
12-04-2006, 07:24 AM
|
#3
|
|
Registered User
Join Date: Oct 2006
Posts: 131
|
...
sorry, one more thing... here's what the levels xml description looks like...
http://sickbooks.com/testing/level001.xml
that format isn't set in stone, but its working for now.
plus there a methods to easily put the map together in other ways.
EDIT:
I'll just paste it here...
Code:
<level title="Destiny">
<map>
<r>3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3</r>
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3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
<r>3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3</r>
</map>
<definitions>
<d id="0" v="undefined" />
<d id="1" v="ground" />
<d id="2" v="yellow block" />
<d id="3" v="green dotted ground" />
</definitions>
</level>
Last edited by apolloman; 12-04-2006 at 07:26 AM.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 09:38 PM.
///
|
|