View Full Version : please point me in the right direction!!!
krimzondestiny
May 14th, 2009, 05:55 PM
Hey all. I am creating a simple flash game where you rotate a planet to make the buildings on the planet avoid incoming meteors. I was told that there is another just like it already, but I don't want to see it because it may restrict my imagination.
I have everything pretty much planned out now in a "game script" of everything that i want to happen. only thing is, i'm not sure where to start. Actually, i implemented rotating the planet and the timer so far, but that is all. I was wondering if anyone wouldn't mind reading through my game script and pointing me in the right direction. I am trying to wrap my head around creating classes to handle different aspects of the game, but not sure what to put in a class and what not to. Any help would be greatly appreciated. Thank you says this unworthy and humble one.
I attached the game so far and the word file
Daganev
May 14th, 2009, 05:59 PM
Start with the following:
Building class
Meteor class
Planet class
Score class (make it a singleton or static class)
Main class
Hope that helps. FYI, I didn't read/download your docs :)
krimzondestiny
May 14th, 2009, 06:08 PM
lol...thanks for the speedy reply...i wish you would take a look at them though cuz it shows my basic structure and my planned approach. you see, like previously stated, i'm not sure for the meteor class for instance, should creating them and animating them and the amount of damage they do to the building all be in one class or should the amount of damage be in the building class? Each building has a health bar so should they be in there own class or the meteor class or the building class?
Daganev
May 14th, 2009, 06:19 PM
If you put your docs up in a google doc link or something I'll look at it. But I can't/don't download attachments.
krimzondestiny
May 14th, 2009, 06:26 PM
If you put your docs up in a google doc link or something I'll look at it. But I can't/don't download attachments.
thank you so much...you just made me excited as hell... the url is:
http://docs.google.com/Doc?id=df6c3dn9_0crdx9x76
and a brief description with images
http://docs.google.com/Doc?id=df6c3dn9_1w742qrgg
Daganev
May 14th, 2009, 07:10 PM
Great docs... I'll post some ideas for you when I'm done with this awesome webinar I'm in :)
krimzondestiny
May 14th, 2009, 07:22 PM
thanks
Daganev
May 15th, 2009, 11:34 AM
Ok, so lets go class by class:
First, your building class.
You want your building class to all be the same. Basically, each building that sits on the globe has all of the same properties.
You'll want to assign a movieclip to each instance of the building class, so that you can change the visual of each building.
You'll want each building class, to have a healthbar movieclip associated with it. And you'll want a function on the building class to set the health level, and a function to subtract health from the current level.
Now, for the meteor class. I think most of your actual game play stuff will be done in the meteor class. You want to basically set the size of the meteor, and then have it do various stuff whenever it hits any movieclip. If it's abuilding, it destroys, if its the outer atmosphere, it changes animation, if its the globe, it does other stuff etc. When the metero hits something, you want to send out an event, saying "I've hit MC x, and I'm going to do Y damage to it"
Then you have each of your buildings listening for that event. If X == themselves then run the take damage function based on Y.
On your Planet class, you basically just want to attach instances of the building class, and put in the rotation functions.
For the score class, you bascially want a Singleton, that just keeps track of the score based on what happens in your main class.
In your main class, (this should be your document class) you want to handle the different states "game start, main game, repair, game over" and also generate the meteors and handle score and level. I doubt you need a seperate class for the repair screen, but depeding on how complicated yo want it to be, you can. Game start, and game over, definitly don't need thier own classes.
krimzondestiny
May 15th, 2009, 01:44 PM
awesome...now it doesn't seem quite so daunting anymore and i got a starting point thanks to you...I've been working on bits and pieces here and there to test how i want things to behave. I've got a snippet of code that will be the bread and butter of the meteors but I need to tweak it a bit. It's basically a mouse follower code that i found and adapted. It works great, the only problem is i don't know how to make it not ease into the position and just keep a constant speed until it reaches.
var gravity:Number = 70;
stage.addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(e:Event):void {
var meteorPosX = meteor.x;
var meteorPosY = meteor.y;
var earthPosX = earth.x;
var earthPosY = earth.y;
var dx = Math.round(earthPosX-meteorPosX);
var dy = Math.round(earthPosY-meteorPosY);
meteor.x += dx / gravity;
meteor.y += dy / gravity;
}
Also, for the Planet class...can't i just put the instances of the buildings and planet as well as the rotation function on a frame in the main time line instead of making a class for it? That part is so simple that it seems like overkill to make a class for it.
krimzondestiny
May 15th, 2009, 05:01 PM
So far, this is what my Planet class looks like. It is supposed to instanciate the planet sprite and place it at the center of the screen. then, add event listeners to it so that it can be rotated. am i doing it right so far?
//--------- newPlanet CLASS
//instantiate the newPlanet movie clip and attach instances of the Buildings class,
//and put in the rotation functions.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class newPlanet extends Sprite
{
public function newPlanet()
{
init();
}
private function init():void
{
newPlanet:Sprite = new newPlanet();
newPlanet.x = 250;
newPlanet.y = 200;
addChild(newPlanet);
newPlanet.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
newPlanet.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
private function onDown(e:MouseEvent):void
{
e.currentTarget.addEventListener(Event.ENTER_FRAME , onLoop);
}
private function onUp(e:MouseEvent):void
{
e.currentTarget.removeEventListener(Event.ENTER_FR AME, onLoop);
}
private function onLoop(e:Event):void
{
var dx = root.mouseX - newPlanet.x;
var dy = root.mouseY - newPlanet.y;
var angle = Math.atan2(dy, dx) * 180 / Math.PI;
newPlanet.rotation = angle;
}
}
}
krimzondestiny
May 15th, 2009, 08:54 PM
i believed i have remedied the planet class and here it is:
//-------newPlanet CLASS
//instantiate the newPlanet movie clip and attach instances of the Buildings class,
//and put in the rotation functions.
package {
import flash.display.Sprite;
import flash.events.Event;
public class Planet extends Sprite {
public function Planet() {
init();
}
private function init():void {
this.x=250;
this.y=200;
this.addEventListener(MouseEvent.MOUSE_DOWN,onDown );
this.addEventListener(MouseEvent.MOUSE_UP,onUp);
}
private function onDown(e:MouseEvent):void {
e.currentTarget.addEventListener(Event.ENTER_FRAME ,onLoop);
}
private function onUp(e:MouseEvent):void {
e.currentTarget.removeEventListener(Event.ENTER_FR AME,onLoop);
}
private function onLoop(e:Event):void {
var dx=root.mouseX - x;
var dy=root.mouseY - y;
var angle=Math.atan2(dy,dx) * 180 / Math.PI;
rotation=angle;
}
}
}
I am unsure of how to approach the meteor class because it is like the planet class but it is different in that there will be multiple instances made...a meteor is created randomly off screen and then moved toward the planet movie clip...once the meteor enters the stage, it is supposed to create another meteor and move that one toward the planet movie clip.
//
//METEOR CLASS
//Set the size of the meteor, and then have it do various stuff whenever it hits any movieclip.
//If it's a building, it destroys, if its the outer atmosphere, it changes animation and increases speed,
//if its the globe, it does other stuff etc. When the meteor hits something, send out an event, saying
//"I've hit MC x, and I'm going to do Y damage to it" Have each of building listening for that event.
//If X == themselves, then run the take damage function based on Y.
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Meteors extends MovieClip {
private var meteor:Meteor;
private var meteorArray:Array;
private var diameter:Number;
private var gravity:Number = 10;
public function Meteors() {
init();
}
private function init():void {
meteorArray = new Array;
createMeteor();
addEventListener(Event.ENTER_FRAME,onLoop);
}
private function createMeteor():void {
this.x=Math.random() * 1000;
this.y=Math.random() * 800;
//addChild(meteor);
//meteorArray.push(meteor);
this.addEventListener(Event.ENTER_FRAME,moveMeteor );
}
private function moveMeteor(e:Event):void {
var meteorPosX=meteor.x;
var meteorPosY=meteor.y;
var earthPosX=earth.x;
var earthPosY=earth.y;
var distanceX=Math.round(earthPosX - meteorPosX);
var distanceY=Math.round(earthPosY - meteorPosY);
meteor.x+= distanceX / gravity;
meteor.y+= distanceY / gravity;
if (this.hitTestObject(atmosphere)){
enteredAtmosphere()
}
if (this.hitTestOjbect()){
hitBuilding();
}
}
private function enteredAtmosphere():{
//haven't figure this out yet
}
private function hitBuilding():{
//haven't figure this out yet
}
private function hitPlanet():{
//haven't figure this out yet
}
}
}
Daganev
May 15th, 2009, 09:02 PM
awesome...now it doesn't seem quite so daunting anymore and i got a starting point thanks to you...I've been working on bits and pieces here and there to test how i want things to behave. I've got a snippet of code that will be the bread and butter of the meteors but I need to tweak it a bit. It's basically a mouse follower code that i found and adapted. It works great, the only problem is i don't know how to make it not ease into the position and just keep a constant speed until it reaches.
var gravity:Number = 70;
stage.addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(e:Event):void {
var meteorPosX = meteor.x;
var meteorPosY = meteor.y;
var earthPosX = earth.x;
var earthPosY = earth.y;
var dx = Math.round(earthPosX-meteorPosX);
var dy = Math.round(earthPosY-meteorPosY);
meteor.x += dx / gravity;
meteor.y += dy / gravity;
}
Also, for the Planet class...can't i just put the instances of the buildings and planet as well as the rotation function on a frame in the main time line instead of making a class for it? That part is so simple that it seems like overkill to make a class for it.
Try setting earthPosX and earthPosY as
var earthPosX = earth.x + earth.width/2;
var earthPosY = earth.y + earth.height/2;
That should aim the meteor into the center of the earth, instead of just it's edge , and the easing distance (caused by the /gravity in the formula) should be less noticeable.
The reason why you want a seperate building class, is so that you can manipulate each building better during the Repair screen.
krimzondestiny
May 15th, 2009, 09:13 PM
Try setting earthPosX and earthPosY as
var earthPosX = earth.x + earth.width/2;
var earthPosY = earth.y + earth.height/2;
That should aim the meteor into the center of the earth, instead of just it's edge , and the easing distance (caused by the /gravity in the formula) should be less noticeable.
The reason why you want a seperate building class, is so that you can manipulate each building better during the Repair screen.
i've learned to accept the easing...i just want to get the game to work first so i can test it and then i'll go in and tweak it...now i'm struggling with the specifics of the classes. the meteor class to be specific
Daganev
May 18th, 2009, 03:33 PM
What exactly are you stuck with?
Have your Main class, assign where the meteor class goes, and how big it is. Just put a public function in the meteor class to set it.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.