Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 12-04-2006, 07:20 AM   #1
apolloman
Registered User
 
Join Date: Oct 2006
Posts: 131
Default [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.
apolloman is offline   Reply With Quote
Old 12-04-2006, 07:21 AM   #2
apolloman
Registered User
 
Join Date: Oct 2006
Posts: 131
Default ...

oh yeah, and of course when I release this it will all be documented.
apolloman is offline   Reply With Quote
Old 12-04-2006, 07:24 AM   #3
apolloman
Registered User
 
Join Date: Oct 2006
Posts: 131
Default ...

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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 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, 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.
apolloman is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sharedObject custom class problems with persistence earman ActionScript 3.0 1 05-15-2008 07:40 PM
Flash Remoting with Perl dopefries Flash Remoting 3 02-17-2007 01:42 PM
Extendings class... simonboris ActionScript 2.0 0 02-25-2006 04:53 PM
[AS1] "Roads" and connections in a tile based game Chen Baiwan Gaming and Game Development 1 10-13-2005 04:21 PM
Database simulated with arrays on a cd-rom lecasn5 Components 61 09-07-2004 11:40 AM


All times are GMT. The time now is 12:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.