Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.gskinner.sprites.CollisionDetection;
- import flash.geom.Rectangle;
- //bgScroller
- //player
- bgWidth = 1161.95;
- button1.onRelease = function(){
- trace("level 1");
- lvl = 1;
- setUp(lvl);
- }
- button2.onRelease = function(){
- trace("level 2");
- lvl = 2;
- setUp(lvl);
- }
- setUp = function (lvl){
- trace("running");
- speed = 5;
- for2GroundSpeed = 8;
- _root.createEmptyMovieClip("projectileLayer", this.getNextHighestDepth());
- projectileCount = 0;
- jump = 0;
- jumping = false;
- touchingGround = true;
- ammo = 10;
- firing = false; // Is player firing?
- fireRate = 10; // Frame delay between shots
- score = 0;
- score_txt.text = score;
- counter = 5; // Game time
- counter_txt.text = counter;
- bulletSpeed = 15;
- currentLevel = "level"+lvl;
- trace(currentLevel);
- _root.attachMovie( lvl, currentLevel, 1);
- player.swapDepths(20200);
- mouse.swapDepths(20002);
- //Firing
- // When mouse is down fire the weapon off of ship
- mouse.onMouseDown = function()
- {
- firing = true;
- //trace(firing);
- //For frame
- repeatTime = 0;
- }//end of mouseDown
- // When mouse up do not fire
- mouse.onMouseUp = function()
- {
- //trace("firing the lazer");
- firing = false;
- }//end of shipMouseU
- //MOUSE
- mouse.onEnterFrame = function() {
- //desx =desire postion of the ship on the X_mouse
- //This where you will mess with to add Y ties
- this._x = _xmouse;
- this._y = _ymouse;
- if(this._x < player._x){
- if(this._xscale < 0){
- this._xscale *= -1;
- }//end of if why
- left = false;
- }
- else{
- if(this._xscale >0){
- this._xscale *= -1;
- }//end of if why
- left = true;
- }
- //FIRING
- // How you fire your gun
- //If firing true, repeat time 0 and you have more than 0 ammo
- if (firing && repeatTime == 0 && ammo >=1)
- {
- ammo--;
- trace(ammo);
- //This is for the function for the bullet
- // Tells the bullet to be a little bt above it
- //you can change the angel of where its at
- //Tells the speed and angle of the bullet
- //trace("FUCK");
- if (left){
- createProjectile("bullet", mouse._x, mouse._y, -bulletSpeed, 0);
- }//end of leftfiring
- else{
- createProjectile("bullet", mouse._x, mouse._y, bulletSpeed, 0);
- }//end of riight firing
- }//end of firing && repeatTime == 0
- //its a Loop this ia for a fire rate
- repeatTime ++;
- // in its heart is a loop
- // When it hits a Fire rate of 10 then of back to 0
- repeatTime %= fireRate;
- }//end of the mouse
- ghostEnemyArray = new Array ();
- ghostEnemyArray.push(_root[currentLevel].ghost1);
- //trace(ghostEnemyArray[0]);
- //Will Change for the else
- _root[currentLevel].onEnterFrame = function(){
- if(Key.isDown(Key.RIGHT) || Key.isDown(68)){
- this._x -=speed;
- foreGround1._x -=for2GroundSpeed;
- }//end up up
- //IS UP or w key
- if(Key.isDown(Key.LEFT) || Key.isDown(65)){
- this._x +=speed;
- foreGround1._x +=for2GroundSpeed;
- }//end up up
- //DEBUGGER here!!!
- if(Key.isDown(Key.ENTER)){
- //trace(this._x);
- trace("x: " +this._x + " y: " + this._y);
- trace(this._width/2+1);
- }//end up up
- //the 'walls'
- if(this._x >= 0){
- this._x = 0;
- }
- if(this._x <= -(this._width/2-130 )){
- //trace(this._width/2);
- this._x = -455;
- }
- }//end of onEnterFrame
- //Jumping
- player.onEnterFrame = function(){
- //JUMPING
- if (Key.isDown(Key.SPACE) && !jumping) {
- // if up is pressed and NOT jumping
- jumping = true;
- // jumping is set true
- }
- if (jumping) {
- // if jumping is true
- //this.gotoAndStop("jump");
- this._y -= jump;
- // Y position is set down jump
- jump -= .5;
- // jump is set down .5
- if (jump<0) {
- // if jump is smaller than 0
- falling = true;
- // falling is true
- }
- if (jump<-15) {
- // if jump is smaller than neg. 5
- jump = -15;
- // jump is set to neg 5
- // capping fall speeds prevents falling through grounds
- }
- }
- if (_root[currentLevel].ground.hitTest(this._x, this._y + this._height/2, true) && falling) {
- // if hitting X an Y postions with the ground and falling
- jump = 12;
- // jump is set to 9
- jumping = false;
- // jumping is false
- falling = false;
- // falling is false
- }
- for(i in ghostEnemyArray){
- //trace(ghostEnemyArray[i]._x);
- //trace(i);
- //trace(_root[currentLevel].ghostEnemyArray[marker]._x);
- var collisionPlayer:Rectangle = CollisionDetection.checkForCollision(player,ghostEnemyArray[i],120);
- //trace(_root[currentLevel].boundary);
- // What!? you hit the grass!
- if(collisionPlayer && jumping) {
- ghostEnemyArray[i].play();
- //trace(ghostEnemyArray.splice(i));
- ghostEnemyArray[i].swapDepths(1979);
- ghostEnemyArray[i].removeMovieClip();
- ghostEnemyArray.splice(i);
- //ghostEnemyArray[i].removeMovieClip();
- //delete ghostEnemyArray[i];
- }
- if( collisionPlayer && !jumping){
- trace("u died");
- _root[currentLevel]._x += ghostEnemyArray[i]._width/2;
- //ghostEnemyArray[i].removeMovieClip();
- //this._x += 10;
- }
- }
- return jumping;
- }//end of paplayer
- ghostSpeed = 10;
- ////////////////////
- //GHOST ENEMU
- _root[currentLevel].ghost1.onEnterFrame = function(){
- //trace("rawr");
- //MOVING THE ENEMY
- //checking if touching any invisible markers
- for(var i:String in ghostEnemyArray){
- //the process is very similar to the main guy's testing with other elements
- //trace(ghostEnemyArray[i]);
- var collisionGhost:Rectangle = CollisionDetection.checkForCollision(_root[currentLevel].boundary,ghostEnemyArray[i],120);
- //trace(_root[currentLevel].boundary);
- // What!? you hit the grass!
- if(collisionGhost) {
- //trace("collision between " + _root[currentLevel].boundary + " and " + ghostEnemyArray[i]);
- ghostSpeed =ghostSpeed *-1;
- this._x += ghostSpeed;
- this._xscale *= -1;
- }
- else{this._x += ghostSpeed;
- }
- }
- }//end of GHOST
- }//end of on init
- //Bullets
- //This creates the objects
- // So it can go with Angle and such
- createProjectile = function(type, x, y, dx, dy)
- {
- //nm (everything) is the proj and the count for it
- var nm = "proj" + projectileCount;
- //the count is the depth lvl of the bullet
- //This is attaching the BULLET to the layer
- projectileLayer.attachMovie(type, nm, projectileCount);
- //trace(nm);
- //This defines where it is at
- projectileLayer[nm]._x = x;
- projectileLayer[nm]._y = y;
- // Speed from previously is the same now
- // These are just saftey checks
- projectileLayer[nm].dx = dx;
- projectileLayer[nm].dy = dy;
- //NM is now tied into the the projectile layer now
- // THis is what defines the layer from above
- projectileLayer[nm].onEnterFrame = function()
- {
- //This adds the dx and dy to its x and y
- //This line is what makes it work
- // This defines the speed limits
- this._x += this.dx;
- this._y += this.dy;
- //if it has a thing less than ZERO then REMOVE IT NOW
- if (this._y < 0){
- this.removeMovieClip();
- }//end of y<0
- // LOOP TIME
- //This is the HIT TEST
- //You can adjust this this is so theres 9 bullets and 9 bullets
- for(i in ghostEnemyArray){
- if( ghostEnemyArray[i].hitTest(this._x, this._y, true)){
- ghostEnemyArray[i].play();
- //trace(ghostEnemyArray[i]);
- ghostEnemyArray[i].swapDepths(1979);
- ghostEnemyArray[i].removeMovieClip();
- //trace(ghostEnemyArray.splice(i));
- ghostEnemyArray.splice(i);
- }
- }
- }//end of projectileLayer[nm]
- //max of 10
- projectileCount ++;
- projectileCount %= 10;
- }//end createProjectile
Add Comment
Please, Sign In to add comment