Sunday, January 9, 2011

Grav's source code.

Like I promised a while ago, here's the source code for grav:
Main.as:
package asfiles{
import flash.display.*;
import flash.events.ProgressEvent
import com.newgrounds.API;
import asfiles.*;
public class Game extends MovieClip {
var startscreen:*
public function Game() {
var preloadbalk:Sprite = new Sprite
preloader()
function preloader() {
gotoAndStop(1)
preloadbalk.graphics.beginFill(0x000000);
preloadbalk.graphics.drawRect(0,0,550,400);
addChild(preloadbalk);
loaderInfo.addEventListener(ProgressEvent.PROGRESS,loading);
}
function loading(event:ProgressEvent):void {
var pcent:Number=event.bytesLoaded/event.bytesTotal*100;
preloadbalk.scaleX=pcent/100;
if (pcent==100) {
loaderInfo.removeEventListener(ProgressEvent.PROGRESS,loading)
removeChild(preloadbalk)
startscreen = new startScreen()
gotoAndStop(2)
addChild(startscreen)
}
}
}
}
}


Gameover.as
package asfiles{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import com.newgrounds.API;
import com.newgrounds.APIEvent;
import com.newgrounds.components.FlashAd
import asfiles.*;
public class Gameover extends Sprite {
var _gameoverscreen:Sprite = new Sprite();
var restarttext:TextField=new TextField ;
var fontFormat:TextFormat = new TextFormat();
var highscoretext:TextField=new TextField ;
var combotext:TextField = new TextField ;
var thescore:Number;
var flashad = new FlashAd
public function Gameover(score, combo) {
thescore=score;
gameoverscreen(score, combo);
}
public function gameoverscreen(score, combo) {
_gameoverscreen.graphics.beginFill(0x000000);
_gameoverscreen.graphics.drawRect(0,0,550,400);
restarttext.x=12;
restarttext.y=25;
restarttext.text="Restart?";
restarttext.selectable=false;
highscoretext.x=12;
highscoretext.y=155;
highscoretext.text="Score: "+score;
combotext.x = 12
combotext.y= 325
combotext.text="Best combo: " + combo
combotext.selectable = false
fontFormat.font="arial";
fontFormat.size="40";
fontFormat.color=0xFFFFFF;
restarttext.setTextFormat(fontFormat);
restarttext.autoSize=TextFieldAutoSize.LEFT;
highscoretext.setTextFormat(fontFormat);
highscoretext.autoSize=TextFieldAutoSize.LEFT;
combotext.setTextFormat(fontFormat)
combotext.autoSize=TextFieldAutoSize.LEFT
addChild(_gameoverscreen);
_gameoverscreen.addChild(restarttext);
_gameoverscreen.addChild(highscoretext);
_gameoverscreen.addChild(combotext)
restarttext.addEventListener(MouseEvent.CLICK,restartclick);
flashad.x = 235
flashad.y = 25
_gameoverscreen.addChild(flashad)
}
public function restartclick(e:Event) {
removeChild(_gameoverscreen);
var startscreen:startScreen=new startScreen();
addChild(startscreen);
}

}
}

and startscreen.as:
package asfiles{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.media.Sound
import flash.media.SoundChannel
import com.newgrounds.API;
import asfiles.*;
public class startScreen extends Sprite {
var startText:TextField=new TextField ;
var helpText:TextField=new TextField ;
var _background:Sprite = new Sprite();
var fontFormat:TextFormat = new TextFormat();
var helpfont:TextFormat = new TextFormat();
var helpon:Boolean=false;
var help:Sprite=new Sprite ;
public var gamescreen:Sprite;
var Player:Sprite;
public function startScreen() {
_background.graphics.beginFill(0x000000);
_background.graphics.drawRect(0,0,550,400);
fontFormat.font="Arial";
fontFormat.size="40";
fontFormat.color=0xFFFFFF;
helpfont.font="arial";
helpfont.size="20";
helpfont.color=0xFFFFFF;
startText.text="Start";
startText.x=50;
startText.y=50;
startText.selectable=false;
helpText.text="Help";
helpText.x=200;
helpText.y=50;
startText.setTextFormat(fontFormat);
helpText.setTextFormat(fontFormat);
helpText.selectable=false;
addChild(_background);
_background.addChild(startText);
_background.addChild(helpText);
startText.addEventListener(MouseEvent.CLICK,startClick);
helpText.addEventListener(MouseEvent.CLICK,helpClick);

}
public function startClick(evt:MouseEvent) {
removeChild(_background);
if (helpon==true) {
removeChild(help);
}
gamescreen = new gameScreen();
addChild(gamescreen);
}
public function helpClick(evt:MouseEvent) {
if (helpon==false) {
helpon=true;
_background.addChild(help);
var blockleft:Sprite = new Sprite();//red
var blockup:Sprite = new Sprite();//yellow
var blockright:Sprite = new Sprite();//blue
var blockdown:Sprite = new Sprite();//green
var tfleft:TextField=new TextField ;
var tfup:TextField=new TextField ;
var tfright:TextField=new TextField ;
var tfdown:TextField=new TextField ;
var tfhelptext:TextField=new TextField ;
addChild(help);
drawblock(blockleft,0xFA4141,50,175);
drawblock(blockup,0xFAF91F,50,275);
drawblock(blockright,0x214DF8,200,175);
drawblock(blockdown,0x23F523,200,275);
settext(tfleft,"Left",100,175);
settext(tfup,"Up",100,275);
settext(tfright,"Right",250,175);
settext(tfdown,"Down",250,275);
tfhelptext.text="Collect targets. Fight gravity. Get High Score. Use wasd or the arrow keys to move and collect the targets";
tfhelptext.x=365;
tfhelptext.y=50;
tfhelptext.width=175;
tfhelptext.height=350;
tfhelptext.selectable=false;
tfhelptext.setTextFormat(helpfont);
tfhelptext.wordWrap=true;
help.addChild(tfhelptext);
} else {
helpon=false;
removeChild(help);
}
}
public function drawblock(block, color, xpos , ypos) {
block.graphics.beginFill(color);
block.graphics.drawRect(xpos,ypos,50,50);
help.addChild(block);
}
public function settext(textfield,text,x,y) {
textfield.text=text;
textfield.x=x;
textfield.y=y;
textfield.selectable=false;
textfield.setTextFormat(fontFormat);
textfield.autoSize=TextFieldAutoSize.LEFT;
help.addChild(textfield);
}
}
}

gamescreen.as will be in the next posts, since it's rather large

No comments:

Post a Comment