Sunday, May 8, 2011

1st game e-mailed to Adam; here is 'funkyActionScript' coding

Here is the coding for game1, if anyone cares to take a look at it. This game does have 'issues'.

//EMDA 203 "First Game" base code v.1
//v1: now with Mouse Control! //Sound! hitTestObject! StageBoundaryBounces!

package
{
//import flash.display.DisplayObject;
//I couldn't figure out the visibility stuff...
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Mouse;
import flash.events.MouseEvent;
import flash.display.DisplayObjectContainer;
//
//import flash.media.Sound;//

public class FirstGame1v2 extends MovieClip
{
//Declare Global Variables
var player:MovieClip;
var ball:MovieClip;
var ball2:MovieClip;
var projectile:MovieClip;
var projectile2:MovieClip;
var vx:Number;
var vy:Number;
//var ballBounceSound:Sound;//***NEW
//var playerSound:Sound;//***NEW
var score:Number; //The score

public function FirstGame1v2()//CONSTRUCTOR FUNCTION
{
//Instantiate Variables
trace ("top of constructor")
player = new SmallVertRayGun;
ball = new SmallSaucerGuy;
ball2 = new Alien;
projectile = new SmallRay;
projectile2 = new SmallRay;
vx = 15; //setting movement rates; see much farther down
vy = 2; //setting movement rates; see much farther down

//ballBounceSound = new SoundBasso;//***NEW
//playerSound = new SoundGlass;//***NEW

trace ("Welcome to Galactic Xenophobia!");
score = 0; //This starts the game at 0
trace ("the score is " + score);

//Hide the mouse ***NEW
Mouse.hide();

//Set up the stage
addChild(player);
addChild(ball);
addChild(ball2);
addChild(projectile);
addChild(projectile2);


player.x = stage.stageWidth*.5; //positioning raygun
player.y = stage.stageHeight*.93; //positioning raygun
ball.x = stage.stageWidth*.5;
//positioning SaucerGuy, when he makes his(?) entry
ball.y = stage.stageHeight*.05;
//positioning SaucerGuy, when he makes his(?) entry
ball2.x = stage.stageWidth*.5;
//positioning Alien, when he makes his(?) entry
ball2.y = stage.stageHeight*(.001);
//positioning Alien, when he makes his(?) entry



// Event Listeners
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.CLICK, myClick);
//looking for mouseClick, to do something with

}

// Event Handlers

function myClick (event:MouseEvent):void
//this is for firing ray with mouseClick
{

trace ("mouse click detected");
//had problems; testing function

addChild(projectile2); //moving 'ray';
projectile2.x = (player.x - 10);
projectile2.y = stage.stageHeight*.87;
//these last 2 lines superimpose it on original 'ray'


if (projectile2.y == projectile.y)
{

removeChild(projectile);
}

trace
("Do you truly feel comfortable trying to destroy ");
//testing things
trace ("something/someone you have never even tried to talk to?");

if ((projectile2.y < projectile.y) || (projectile2.y == 0)) { //trace ("Hunh?"); //testing things removeChild(projectile); } if (projectile2.y < 0) { addChild(projectile); } } function onEnterFrame(event:Event):void { // PLAYER X CONTROLLED BY MOUSE ***NEW player.x = mouseX; projectile.x = (player.x - 10); projectile.y = stage.stageHeight*.87; //Stage Boundary Collisions if(ball.x > stage.stageWidth || ball.x < 0) { vx = -vx; //ballBounceSound.play();//***NEW } if(ball.y < 0) { vy = -vy; } //check for Saucer/RayGun collisions if(player.hitTestObject(ball)) { removeChild(ball); addChild(ball); ball.x = stage.stageWidth*.5; ball.y = stage.stageHeight*.05; //playerSound.play();//***NEW addScore(-2); //penalty for saucer crashing into your gun emplacement } //check for Projectile/Saucer collisions if(projectile2.hitTestObject(ball)) { removeChild(projectile2); removeChild(ball); addChild(ball); ball.x = stage.stageWidth*.5; ball.y = stage.stageHeight*.05; //playerSound.play();//***NEW addScore(2); } //check for 'friendly fire' collateral damage if(projectile2.hitTestObject(ball2)) { removeChild(projectile2); removeChild(ball2); trace ("What are you doing! That organism was on our side!") //playerSound.play();//***NEW addScore(-8); } //allows SmallSaucerGuy to advance down past SmallRayGun, and move off stage // and then brings in new SmallSaucerGuy if(ball.y > stage.stageHeight*.99)
{

addChild(ball);
ball.x = stage.stageWidth*.5;
ball.y = stage.stageHeight*.05;
//ballBounceSound.play();//***NEW
addScore(-2); // you snooze, you lose

}





//move stuff
ball.x += vx;
ball.y += vy;
ball2.y += 2*vy;

projectile2.y += 4*(-vy); //speed of 'ray' (projectile2)



}// end onEnterFrame function


function addScore(addThis:Number):void
//adds or subtracts certain amount to score
{
score += addThis; //computes the score
trace ("your score is " + score); //displays the score

if (score > 2)
{
vx = 30;
//increases the side-to-side speed of the saucer
}


if (score > 8)
{
trace ("Your score may be 10, but Pride goeth before the fall...");
vx = 45; //increases the side-to-side speed of the saucer
vy = 5;
//increases the speed of the saucer's vertical approach to your position
}

if (score > 10)
{
//this makes the saucerGuy very small
ball.width = ball.width*.15;
ball.height = ball.height*.15;
}

if (score > 12)
{
//now you lose your rayGuy completely
removeChild(player);
}

if (score < 12)
{
addChild(player);
}

if (score < 10)
{
ball.width = ball.width*1;
ball.height = ball.height*1;
}

if (score < -12)
{
trace ("Your defensive efforts have been sorely inadequate.");
trace ("If you have actually survived this possibly hostile ");
trace ("extraterrestrial border incursion, consider yourself");
trace ("posted to kitchen duty until the time and date of your ");
trace ("court-martial has been scheduled.");
}

}


}// end class
} // end package

No comments:

Post a Comment