PDA

View Full Version : game with classes?


medhopz
05-08-2007, 07:06 AM
hey guys,

I'm starting a new game, and i was just wondering if using classes for games is any good

do any of you use them?
if so, how so?
i was thinking maybe a class for each of there: movement, shooting, life system.

im not really sure what type of game i will have, but one thing is for sure, you will be controlling a tank and there is going to be a big map where you can drive around, maybe buy improvements for tank (not sure yet).

thanks for any answers

med

336
05-08-2007, 10:50 AM
Make it like a game with missons, rankings, classes,...
u get better rank when u complete missions good, like having a good time, and when u have the next rank u can do new missions, u know the concept.

like what should be in it: u can get out of the tank to get past obstacles and fix the route to get the tank over it, or for when ur tank gets destroyed u can fight on (probarly run away) as a soldier and get a new tank from the army base.

more vechiles, u can also buy some other vechiles ( like jeep, motorcycle,...)
wich u can buy ( but not so much upgrades, they are just for getting to other places fast, or in battle have an npc controlling it(?))

just suggestions on how the game could be :)

medhopz
05-08-2007, 12:44 PM
good stuff
i'll try some of them, not sure i'm good enough

Ripple_in_Eternity
05-08-2007, 05:30 PM
You don't need classes for each little thing. Functions can work a lot better. Writing class after class seems so...unnecessary.

Logic
05-08-2007, 05:53 PM
Functions do work better sometimes. The advantage to classes is that it creates very portable code which can be reused in multiple applications. Well, yeah, you could copy-and-paste the same functions in but it's much easier to simply import a class and use it instead. OOP (object-oriented coding) gives you much more control over data management as a coder as well.

arkhan
05-09-2007, 05:17 AM
Personally i dont make any classes when coding in the flash IDE..just bat of functions and variables inside functions..it works the same as a class, but its inside the same file..flash isnt very good to work with many .as files..

medhopz
05-09-2007, 05:20 AM
ok thanks guys
ill start working on the game

Jacob
05-09-2007, 10:00 AM
..flash isnt very good to work with many .as files..

Not true at all.

I use classes in every single game I make and I will never go back to the old way of throwing code around inside the fla. When you use OOP the way its intented it makes development easier actually.

truimagz
05-09-2007, 11:02 AM
I would have to agree with jj here.

I rarely if ever code in flash. I typically create project files, and do everything in .as

I find it hard to believe that flash has a hard time with a lot of .as files, since they force us to use one for every new class.

I have some projects at work were I have 50+ .as files in my project, and I would bet i could times that by 100 and it would still run fine.

I reccomened that you create a project file for each thing you make from now on and do all you can to code in external as files, this will help get you into thinking more OOP like.

Another good idea is to start using xml, this can decrease update times drastically, I xml almost everything now, and dont think I'll ever put varaibel values in flash again.

medhopz
05-09-2007, 11:21 AM
wow two totally different opinions

i dont know how to use xml, i would gladly look at a tut if you have one

i'll try both ways, and decide which works better for me

Matt
05-09-2007, 11:50 AM
I do all my coding in flash. I hate having to use multiple files at once, constantly flipping between them, finding the 1 of many that I want.

truimagz
05-09-2007, 01:59 PM
want to learn xml, its extremely easy.

Here is a great book for all things flash.

with this sample you probably learn to use xml right here.

OK WAY

<?xml version="1.0" ?>
<Books>
<Book ISBN="1590596188">
<Title>Foundation ActionScript for Flash 8</Title>
<Authors>
<Author>
<FirstName>Kristian</FirstName>
<FamilyName>Besley</FamilyName>
</Author>
<Author>
<FirstName>Sham</FirstName>
<FamilyName>Bhangal</FamilyName>
</Author>
<Author>
<FirstName>David</FirstName>
<FamilyName>Powers</FamilyName>
</Author>
</Authors>
<Publisher>friends of ED</Publisher>
</Book>
</Books>


GOOD WAY
<Author FirstName="Kristian" FamilyName="Besley" <-----


.AS PARSER


// create XML object and load the XML data
var theBook:XML = new XML();
theBook.ignoreWhite = true;
theBook.load("book.xml");
theBook.onLoad = parseXMLData;
function parseXMLData(success:Boolean):Void {
// make sure the data is loaded
if (success) {
trace(this);
trace("root node is called " + theRoot.nodeName);
trace("number of child nodes: " + theRoot.childNodes.length);
trace("root node's first child is "+ theRoot.firstChild.nodeName);
} else {
trace("Problem loading book.xml");
trace("The error code is " + this.status);
}
}

truimagz
05-09-2007, 02:08 PM
I hate having to use multiple files at once, constantly flipping between them, finding the 1 of many that I want.


But you'll sift through tons of movie clips to find an onClip, or some enterFrame barried somewhere?

put that project aside for a few months and see if you remmember were all those clips are.

you really should have one main as file and your class files, this way you got everybit of code in one spot, and if your like me you have dual monitors and can keep your as file open and your fla to work your graphics in. then just setup a project file to make it easy to see all your files, similar to your library pain.

Jacob
05-09-2007, 02:13 PM
I hate having to use multiple files at once, constantly flipping between them, finding the 1 of many that I want.

Its really not that hard if you organize into packages. Theres a reason every experienced professional level coder uses OOP, and why they brought class support into Flash in the first place - its better.

The whole point of using classes is to ease coding and reduce the amount of code you have to sort through and look at. If you dont know how to organize and use OOP properly, then ya it would be a dog sorting through files.

Ripple_in_Eternity
05-09-2007, 04:04 PM
Classes are quite good if you're a super organized person, creating an excess of them is no fun though. I find making one .as file for a project becomes cumbersome after five or six hundred lines, though that's how I'm doing right now. If you want to be splitting things up, you might as well go with classes. Just don't go making one class for every function you have, split them into functional categories.

I'm curious though, truimagz. How do you use xml in flash as opposed to vars? I tried using it once for a communication program and the results were rather disappointing.

Logic
05-09-2007, 05:38 PM
If you look at truimagz's example above, you'll see how you can load data from an XML file. These values can then easily be cast into variables in Flash once they are loaded. I said 'cast' on purpose because you will need to assign data types. However, by doing this, it lets you remotely control the values which are assigned to variables in Flash at runtime.

truimagz
05-09-2007, 08:04 PM
its just like doing loadVars from php when retrieveing mySQL info.

only difference is you use nodes as opposed to just one var named something that you loaded your vars into.

You can still do things like authors.attributes.name

the otheer advantage is that if you load them and parse them right adding new stuff is a briese.

like say your building out a message box that contains information.

well if you want to add a new line you simply add newtext = myNewXMLItem and then add into your xml theat item
like say you set it all up so but only listed first name, then later you say wait, now I got everyones last name too, well just add a new name into <authors lastName="truimagz" />
then since you drop everything in with a for loop using nodes you can just add one line like I said above newtext = authors.attributes.lastname

truimagz
05-09-2007, 08:13 PM
another HUGE benefit to classes to re-usable code that makes life easier.

when Im bored I sit and make classes to do hings for me, this way i can always call in that file if I ever need it, creating classes is like making tools.

If you build a great hammer, then next time you need to nail something you dont have to find a rock, or re-create the hammer all over again.

arkhan
05-10-2007, 06:33 AM
what I mean is not that I dont like to work with classes. I said I dont like to use them when Im working on the flash IDE..it have a lame system to work with multiple files. up to 5 is ok, more than that it gets anoying..never said flash couldnt handle it. In other dev programs its easyer to handle multiple files..a simple file explorer would make it much easyer in flash.
also, flash doesnt offer much with templates/snnipets..those are real time savers.