Accueil > > > JEU DU VIH EN AS 3
JEU DU VIH EN AS 3
Information sur la source
Description
C'est un petit jeu qui est inspiré du vieu jeu de commète. Sauf que j'ai un peu remplacé tout les élements et rajouté une touche pour le bouclier. normalement dans le vrai jeu ya aussi une touche pour un déplacement aléatiore mais j'ai pas trouvé la solution donc voila.
Source
-
- package {
- import flash.display.*;
- import flash.events.*;
- import flash.text.*;
- import flash.utils.getTimer;
- import flash.utils.Timer;
- import flash.geom.Point;
-
- public class SpaceRocks extends MovieClip {
- static const shipRotationSpeed:Number = .1;
- static const rockSpeedStart:Number = .03;
- static const rockSpeedIncrease:Number = .02;
- static const missileSpeed:Number = .2;
- static const thrustPower:Number = .15;
- static const shipRadius:Number = 20;
- static const startingShips:uint = 3;
-
- // game objects
- private var ship:Ship;
- private var rocks:Array;
- private var missiles:Array;
-
- // animation timer
- private var lastTime:uint;
-
- // touches
- private var rightArrow:Boolean = false;
- private var leftArrow:Boolean = false;
- private var upArrow:Boolean = false;
-
-
- private var shipMoveX:Number;
- private var shipMoveY:Number;
-
- // timers
- private var delayTimer:Timer;
- private var shieldTimer:Timer;
-
- // game mode
- private var gameMode:String;
- private var shieldOn:Boolean;
-
- // vaisseua et armes
- private var shipsLeft:uint;
- private var shieldsLeft:uint;
- private var shipIcons:Array;
- private var shieldIcons:Array;
- private var scoreDisplay:TextField;
-
- // score & niveau
- private var gameScore:Number;
- private var gameLevel:uint;
-
- // sprites
- private var gameObjects:Sprite;
- private var scoreObjects:Sprite;
-
-
- // commencer
- public function startSpaceRocks() {
- // set up sprites
- gameObjects = new Sprite();
- addChild(gameObjects);
- scoreObjects = new Sprite();
- addChild(scoreObjects);
-
- // score a zero
- gameLevel = 1;
- shipsLeft = startingShips;
- gameScore = 0;
- createShipIcons();
- createScoreDisplay();
-
- // listenerss
- addEventListener(Event.ENTER_FRAME,moveGameObjects);
- stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
- stage.addEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
-
- // start
- gameMode = "delay";
- shieldOn = false;
- missiles = new Array();
- nextRockWave(null);
- newShip(null);
- }
-
-
- // SCORE OBJECTS
-
- // nombre restant afficheur
- public function createShipIcons() {
- shipIcons = new Array();
- for(var i:uint=0;i<shipsLeft;i++) {
- var newShip:ShipIcon = new ShipIcon();
- newShip.x = 20+i*15;
- newShip.y = 375;
- scoreObjects.addChild(newShip);
- shipIcons.push(newShip);
- }
- }
-
- // nb restant
- public function createShieldIcons() {
- shieldIcons = new Array();
- for(var i:uint=0;i<shieldsLeft;i++) {
- var newShield:ShieldIcon = new ShieldIcon();
- newShield.x = 530-i*15;
- newShield.y = 375;
- scoreObjects.addChild(newShield);
- shieldIcons.push(newShield);
- }
- }
-
- // affichage du score
- public function createScoreDisplay() {
- scoreDisplay = new TextField();
- scoreDisplay.x = 500;
- scoreDisplay.y = 10;
- scoreDisplay.width = 40;
- scoreDisplay.selectable = false;
- var scoreDisplayFormat = new TextFormat();
- scoreDisplayFormat.color = 0xFFFFFF;
- scoreDisplayFormat.font = "Arial";
- scoreDisplayFormat.align = "right";
- scoreDisplay.defaultTextFormat = scoreDisplayFormat;
- scoreObjects.addChild(scoreDisplay);
- updateScore();
- }
-
- // nouveau score a montrer
- public function updateScore() {
- scoreDisplay.text = String(gameScore);
- }
-
- // enlever un icone
- public function removeShipIcon() {
- scoreObjects.removeChild(shipIcons.pop());
- }
-
- // ""
- public function removeShieldIcon() {
- scoreObjects.removeChild(shieldIcons.pop());
- }
-
- // ""
- public function removeAllShipIcons() {
- while (shipIcons.length > 0) {
- removeShipIcon();
- }
- }
-
- // remove the rest of the shield icons
- public function removeAllShieldIcons() {
- while (shieldIcons.length > 0) {
- removeShieldIcon();
- }
- }
-
-
- // Creation du héros et du mouvement
-
- // nouveau vaiiseue
- public function newShip(event:TimerEvent) {
- // if ship exists, remove it
- if (ship != null) {
- gameObjects.removeChild(ship);
- ship = null;
- }
-
- //
- if (shipsLeft < 1) {
- endGame();
- return;
- }
-
- // position
- ship = new Ship();
- ship.gotoAndStop(1);
- ship.x = 275;
- ship.y = 200;
- ship.rotation = -90;
- ship.shield.visible = false;
- gameObjects.addChild(ship);
-
- // propriétés
- shipMoveX = 0.0;
- shipMoveY = 0.0;
- gameMode = "play";
-
- // armes
- shieldsLeft = 3;
- createShieldIcons();
-
- //
- if (shipsLeft != startingShips) {
- startShield(true);
- }
- }
-
- // touches
- public function keyDownFunction(event:KeyboardEvent) {
- if (event.keyCode == 37) {
- leftArrow = true;
- } else if (event.keyCode == 39) {
- rightArrow = true;
- } else if (event.keyCode == 38) {
- upArrow = true;
- // show thruster
- if (gameMode == "play") ship.gotoAndStop(2);
- } else if (event.keyCode == 32) { // space
- newMissile();
- } else if (event.keyCode == 90) { // z
- startShield(false);
- }
- }
-
- //
- public function keyUpFunction(event:KeyboardEvent) {
- if (event.keyCode == 37) {
- leftArrow = false;
- } else if (event.keyCode == 39) {
- rightArrow = false;
- } else if (event.keyCode == 38) {
- upArrow = false;
- // remove thruster
- if (gameMode == "play") ship.gotoAndStop(1);
- }
- }
-
-
- public function moveShip(timeDiff:uint) {
-
- // rotation
- if (leftArrow) {
- ship.rotation -= shipRotationSpeed*timeDiff;
- } else if (rightArrow) {
- ship.rotation += shipRotationSpeed*timeDiff;
- } else if (upArrow) {
- shipMoveX += Math.cos(Math.PI*ship.rotation/180)*thrustPower;
- shipMoveY += Math.sin(Math.PI*ship.rotation/180)*thrustPower;
- }
-
- // move
- ship.x += shipMoveX;
- ship.y += shipMoveY;
-
- // retour au bord
- if ((shipMoveX > 0) && (ship.x > 570)) {
- ship.x -= 590;
- }
- if ((shipMoveX < 0) && (ship.x < -20)) {
- ship.x += 590;
- }
- if ((shipMoveY > 0) && (ship.y > 420)) {
- ship.y -= 440;
- }
- if ((shipMoveY < 0) && (ship.y < -20)) {
- ship.y += 440;
- }
- }
-
- // supp vaisseua
- public function shipHit() {
- gameMode = "delay";
- ship.gotoAndPlay("explode");
- removeAllShieldIcons();
- delayTimer = new Timer(2000,1);
- delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE,newShip);
- delayTimer.start();
- removeShipIcon();
- shipsLeft--;
- }
-
- //
- public function startShield(freeShield:Boolean) {
- if (shieldsLeft < 1) return; // no shields left
- if (shieldOn) return; // shield already on
-
- //
- ship.shield.visible = true;
- shieldTimer = new Timer(3000,1);
- shieldTimer.addEventListener(TimerEvent.TIMER_COMPLETE,endShield);
- shieldTimer.start();
-
- //
- if (!freeShield) {
- removeShieldIcon();
- shieldsLeft--;
- }
- shieldOn = true;
- }
-
- // finir les missiles
- public function endShield(event:TimerEvent) {
- ship.shield.visible = false;
- shieldOn = false;
- }
-
- // VihROCKS
-
- //Nouvel cellule
- public function newRock(x,y:int, rockType:String) {
-
- // classe apropriée
- var newRock:MovieClip;
- var rockRadius:Number;
- if (rockType == "Big") {
- newRock = new Rock_Big();
- rockRadius = 35;
- } else if (rockType == "Medium") {
- newRock = new Rock_Medium();
- rockRadius = 20;
- } else if (rockType == "Small") {
- newRock = new Rock_Small();
- rockRadius = 10;
- }
-
- /*
- var rockClass:Object = getDefinitionByName("Rock_"+rockType);
- var newRock:MovieClip = new rockClass();
- */
-
- //
- newRock.gotoAndStop(Math.ceil(Math.random()*3));
-
- // set start position
- newRock.x = x;
- newRock.y = y;
-
- // mouvement rotation random
- var dx:Number = Math.random()*2.0-1.0;
- var dy:Number = Math.random()*2.0-1.0;
- var dr:Number = Math.random();
-
- //
- gameObjects.addChild(newRock);
- rocks.push({rock:newRock, dx:dx, dy:dy, dr:dr, rockType:rockType, rockRadius: rockRadius});
- }
-
- // crer les cellules
- public function nextRockWave(event:TimerEvent) {
- rocks = new Array();
- newRock(100,100,"Big");
- newRock(100,300,"Big");
- newRock(450,100,"Big");
- newRock(450,300,"Big");
- gameMode = "play";
- }
-
- // anime les cellules
- public function moveRocks(timeDiff:uint) {
- for(var i:int=rocks.length-1;i>=0;i--) {
-
- // bouge les cellules
- var rockSpeed:Number = rockSpeedStart + rockSpeedIncrease*gameLevel;
- rocks[i].rock.x += rocks[i].dx*timeDiff*rockSpeed;
- rocks[i].rock.y += rocks[i].dy*timeDiff*rockSpeed;
-
- // rotate cellules
- rocks[i].rock.rotation += rocks[i].dr*timeDiff*rockSpeed;
-
- //
- if ((rocks[i].dx > 0) && (rocks[i].rock.x > 570)) {
- rocks[i].rock.x -= 590;
- }
- if ((rocks[i].dx < 0) && (rocks[i].rock.x < -20)) {
- rocks[i].rock.x += 590;
- }
- if ((rocks[i].dy > 0) && (rocks[i].rock.y > 420)) {
- rocks[i].rock.y -= 440;
- }
- if ((rocks[i].dy < 0) && (rocks[i].rock.y < -20)) {
- rocks[i].rock.y += 440;
- }
- }
- }
-
- public function rockHit(rockNum:uint) {
-
- if (rocks[rockNum].rockType == "Big") {
- newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Medium");
- newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Medium");
- } else if (rocks[rockNum].rockType == "Medium") {
- newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Small");
- newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Small");
- }
-
- gameObjects.removeChild(rocks[rockNum].rock);
- rocks.splice(rockNum,1);
- }
-
-
- // MISSILES
-
- // crer un missile
- public function newMissile() {
- // create
- var newMissile:Missile = new Missile();
-
- // set direction
- newMissile.dx = Math.cos(Math.PI*ship.rotation/180);
- newMissile.dy = Math.sin(Math.PI*ship.rotation/180);
-
- // placement
- newMissile.x = ship.x + newMissile.dx*shipRadius;
- newMissile.y = ship.y + newMissile.dy*shipRadius;
-
- // ajouter
- gameObjects.addChild(newMissile);
- missiles.push(newMissile);
- }
-
- // animer
- public function moveMissiles(timeDiff:uint) {
- for(var i:int=missiles.length-1;i>=0;i--) {
- // move
- missiles[i].x += missiles[i].dx*missileSpeed*timeDiff;
- missiles[i].y += missiles[i].dy*missileSpeed*timeDiff;
- // hors de l'écran
- if ((missiles[i].x < 0) || (missiles[i].x > 550) || (missiles[i].y < 0) || (missiles[i].y > 400)) {
- gameObjects.removeChild(missiles[i]);
- delete missiles[i];
- missiles.splice(i,1);
- }
- }
- }
-
- // supp misile
- public function missileHit(missileNum:uint) {
- gameObjects.removeChild(missiles[missileNum]);
- missiles.splice(missileNum,1);
- }
-
- // interaction et controle
-
- public function moveGameObjects(event:Event) {
- // timer
- var timePassed:uint = getTimer() - lastTime;
- lastTime += timePassed;
- moveRocks(timePassed);
- if (gameMode != "delay") {
- moveShip(timePassed);
- }
- moveMissiles(timePassed);
- checkCollisions();
- }
-
- // tester la collisiion
- public function checkCollisions() {
- // loop through rocks
- rockloop: for(var j:int=rocks.length-1;j>=0;j--) {
- // loop through missiles
- missileloop: for(var i:int=missiles.length-1;i>=0;i--) {
- // collision detection
- if (Point.distance(new Point(rocks[j].rock.x,rocks[j].rock.y),
- new Point(missiles[i].x,missiles[i].y))
- < rocks[j].rockRadius) {
-
- // remove cellules and missile
- rockHit(j);
- missileHit(i);
-
- // add score
- gameScore += 10;
- updateScore();
-
- // pete la boucle
- continue rockloop;
- }
- }
-
- // ^^
- if (gameMode == "play") {
- if (shieldOn == false) { // only if shield is off
- if (Point.distance(new Point(rocks[j].rock.x,rocks[j].rock.y),
- new Point(ship.x,ship.y))
- < rocks[j].rockRadius+shipRadius) {
-
- // supp missile cellule shipHit();
- rockHit(j);
- }
- }
- }
- }
-
- // if ((rocks.length == 0) && (gameMode == "play")) {
- gameMode = "betweenlevels";
- gameLevel++; // + un niveau
- delayTimer = new Timer(2000,1);
- delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE,nextRockWave);
- delayTimer.start();
- }
- }
-
- public function endGame() {
- // supprime les éléments
- removeChild(gameObjects);
- removeChild(scoreObjects);
- gameObjects = null;
- scoreObjects = null;
- removeEventListener(Event.ENTER_FRAME,moveGameObjects);
- stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
- stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
-
- gotoAndStop("gameover");
- }
-
- }
- }
-
- // c'est long hein ?
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.getTimer;
import flash.utils.Timer;
import flash.geom.Point;
public class SpaceRocks extends MovieClip {
static const shipRotationSpeed:Number = .1;
static const rockSpeedStart:Number = .03;
static const rockSpeedIncrease:Number = .02;
static const missileSpeed:Number = .2;
static const thrustPower:Number = .15;
static const shipRadius:Number = 20;
static const startingShips:uint = 3;
// game objects
private var ship:Ship;
private var rocks:Array;
private var missiles:Array;
// animation timer
private var lastTime:uint;
// touches
private var rightArrow:Boolean = false;
private var leftArrow:Boolean = false;
private var upArrow:Boolean = false;
private var shipMoveX:Number;
private var shipMoveY:Number;
// timers
private var delayTimer:Timer;
private var shieldTimer:Timer;
// game mode
private var gameMode:String;
private var shieldOn:Boolean;
// vaisseua et armes
private var shipsLeft:uint;
private var shieldsLeft:uint;
private var shipIcons:Array;
private var shieldIcons:Array;
private var scoreDisplay:TextField;
// score & niveau
private var gameScore:Number;
private var gameLevel:uint;
// sprites
private var gameObjects:Sprite;
private var scoreObjects:Sprite;
// commencer
public function startSpaceRocks() {
// set up sprites
gameObjects = new Sprite();
addChild(gameObjects);
scoreObjects = new Sprite();
addChild(scoreObjects);
// score a zero
gameLevel = 1;
shipsLeft = startingShips;
gameScore = 0;
createShipIcons();
createScoreDisplay();
// listenerss
addEventListener(Event.ENTER_FRAME,moveGameObjects);
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
// start
gameMode = "delay";
shieldOn = false;
missiles = new Array();
nextRockWave(null);
newShip(null);
}
// SCORE OBJECTS
// nombre restant afficheur
public function createShipIcons() {
shipIcons = new Array();
for(var i:uint=0;i<shipsLeft;i++) {
var newShip:ShipIcon = new ShipIcon();
newShip.x = 20+i*15;
newShip.y = 375;
scoreObjects.addChild(newShip);
shipIcons.push(newShip);
}
}
// nb restant
public function createShieldIcons() {
shieldIcons = new Array();
for(var i:uint=0;i<shieldsLeft;i++) {
var newShield:ShieldIcon = new ShieldIcon();
newShield.x = 530-i*15;
newShield.y = 375;
scoreObjects.addChild(newShield);
shieldIcons.push(newShield);
}
}
// affichage du score
public function createScoreDisplay() {
scoreDisplay = new TextField();
scoreDisplay.x = 500;
scoreDisplay.y = 10;
scoreDisplay.width = 40;
scoreDisplay.selectable = false;
var scoreDisplayFormat = new TextFormat();
scoreDisplayFormat.color = 0xFFFFFF;
scoreDisplayFormat.font = "Arial";
scoreDisplayFormat.align = "right";
scoreDisplay.defaultTextFormat = scoreDisplayFormat;
scoreObjects.addChild(scoreDisplay);
updateScore();
}
// nouveau score a montrer
public function updateScore() {
scoreDisplay.text = String(gameScore);
}
// enlever un icone
public function removeShipIcon() {
scoreObjects.removeChild(shipIcons.pop());
}
// ""
public function removeShieldIcon() {
scoreObjects.removeChild(shieldIcons.pop());
}
// ""
public function removeAllShipIcons() {
while (shipIcons.length > 0) {
removeShipIcon();
}
}
// remove the rest of the shield icons
public function removeAllShieldIcons() {
while (shieldIcons.length > 0) {
removeShieldIcon();
}
}
// Creation du héros et du mouvement
// nouveau vaiiseue
public function newShip(event:TimerEvent) {
// if ship exists, remove it
if (ship != null) {
gameObjects.removeChild(ship);
ship = null;
}
//
if (shipsLeft < 1) {
endGame();
return;
}
// position
ship = new Ship();
ship.gotoAndStop(1);
ship.x = 275;
ship.y = 200;
ship.rotation = -90;
ship.shield.visible = false;
gameObjects.addChild(ship);
// propriétés
shipMoveX = 0.0;
shipMoveY = 0.0;
gameMode = "play";
// armes
shieldsLeft = 3;
createShieldIcons();
//
if (shipsLeft != startingShips) {
startShield(true);
}
}
// touches
public function keyDownFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = true;
} else if (event.keyCode == 39) {
rightArrow = true;
} else if (event.keyCode == 38) {
upArrow = true;
// show thruster
if (gameMode == "play") ship.gotoAndStop(2);
} else if (event.keyCode == 32) { // space
newMissile();
} else if (event.keyCode == 90) { // z
startShield(false);
}
}
//
public function keyUpFunction(event:KeyboardEvent) {
if (event.keyCode == 37) {
leftArrow = false;
} else if (event.keyCode == 39) {
rightArrow = false;
} else if (event.keyCode == 38) {
upArrow = false;
// remove thruster
if (gameMode == "play") ship.gotoAndStop(1);
}
}
public function moveShip(timeDiff:uint) {
// rotation
if (leftArrow) {
ship.rotation -= shipRotationSpeed*timeDiff;
} else if (rightArrow) {
ship.rotation += shipRotationSpeed*timeDiff;
} else if (upArrow) {
shipMoveX += Math.cos(Math.PI*ship.rotation/180)*thrustPower;
shipMoveY += Math.sin(Math.PI*ship.rotation/180)*thrustPower;
}
// move
ship.x += shipMoveX;
ship.y += shipMoveY;
// retour au bord
if ((shipMoveX > 0) && (ship.x > 570)) {
ship.x -= 590;
}
if ((shipMoveX < 0) && (ship.x < -20)) {
ship.x += 590;
}
if ((shipMoveY > 0) && (ship.y > 420)) {
ship.y -= 440;
}
if ((shipMoveY < 0) && (ship.y < -20)) {
ship.y += 440;
}
}
// supp vaisseua
public function shipHit() {
gameMode = "delay";
ship.gotoAndPlay("explode");
removeAllShieldIcons();
delayTimer = new Timer(2000,1);
delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE,newShip);
delayTimer.start();
removeShipIcon();
shipsLeft--;
}
//
public function startShield(freeShield:Boolean) {
if (shieldsLeft < 1) return; // no shields left
if (shieldOn) return; // shield already on
//
ship.shield.visible = true;
shieldTimer = new Timer(3000,1);
shieldTimer.addEventListener(TimerEvent.TIMER_COMPLETE,endShield);
shieldTimer.start();
//
if (!freeShield) {
removeShieldIcon();
shieldsLeft--;
}
shieldOn = true;
}
// finir les missiles
public function endShield(event:TimerEvent) {
ship.shield.visible = false;
shieldOn = false;
}
// VihROCKS
//Nouvel cellule
public function newRock(x,y:int, rockType:String) {
// classe apropriée
var newRock:MovieClip;
var rockRadius:Number;
if (rockType == "Big") {
newRock = new Rock_Big();
rockRadius = 35;
} else if (rockType == "Medium") {
newRock = new Rock_Medium();
rockRadius = 20;
} else if (rockType == "Small") {
newRock = new Rock_Small();
rockRadius = 10;
}
/*
var rockClass:Object = getDefinitionByName("Rock_"+rockType);
var newRock:MovieClip = new rockClass();
*/
//
newRock.gotoAndStop(Math.ceil(Math.random()*3));
// set start position
newRock.x = x;
newRock.y = y;
// mouvement rotation random
var dx:Number = Math.random()*2.0-1.0;
var dy:Number = Math.random()*2.0-1.0;
var dr:Number = Math.random();
//
gameObjects.addChild(newRock);
rocks.push({rock:newRock, dx:dx, dy:dy, dr:dr, rockType:rockType, rockRadius: rockRadius});
}
// crer les cellules
public function nextRockWave(event:TimerEvent) {
rocks = new Array();
newRock(100,100,"Big");
newRock(100,300,"Big");
newRock(450,100,"Big");
newRock(450,300,"Big");
gameMode = "play";
}
// anime les cellules
public function moveRocks(timeDiff:uint) {
for(var i:int=rocks.length-1;i>=0;i--) {
// bouge les cellules
var rockSpeed:Number = rockSpeedStart + rockSpeedIncrease*gameLevel;
rocks[i].rock.x += rocks[i].dx*timeDiff*rockSpeed;
rocks[i].rock.y += rocks[i].dy*timeDiff*rockSpeed;
// rotate cellules
rocks[i].rock.rotation += rocks[i].dr*timeDiff*rockSpeed;
//
if ((rocks[i].dx > 0) && (rocks[i].rock.x > 570)) {
rocks[i].rock.x -= 590;
}
if ((rocks[i].dx < 0) && (rocks[i].rock.x < -20)) {
rocks[i].rock.x += 590;
}
if ((rocks[i].dy > 0) && (rocks[i].rock.y > 420)) {
rocks[i].rock.y -= 440;
}
if ((rocks[i].dy < 0) && (rocks[i].rock.y < -20)) {
rocks[i].rock.y += 440;
}
}
}
public function rockHit(rockNum:uint) {
if (rocks[rockNum].rockType == "Big") {
newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Medium");
newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Medium");
} else if (rocks[rockNum].rockType == "Medium") {
newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Small");
newRock(rocks[rockNum].rock.x,rocks[rockNum].rock.y,"Small");
}
gameObjects.removeChild(rocks[rockNum].rock);
rocks.splice(rockNum,1);
}
// MISSILES
// crer un missile
public function newMissile() {
// create
var newMissile:Missile = new Missile();
// set direction
newMissile.dx = Math.cos(Math.PI*ship.rotation/180);
newMissile.dy = Math.sin(Math.PI*ship.rotation/180);
// placement
newMissile.x = ship.x + newMissile.dx*shipRadius;
newMissile.y = ship.y + newMissile.dy*shipRadius;
// ajouter
gameObjects.addChild(newMissile);
missiles.push(newMissile);
}
// animer
public function moveMissiles(timeDiff:uint) {
for(var i:int=missiles.length-1;i>=0;i--) {
// move
missiles[i].x += missiles[i].dx*missileSpeed*timeDiff;
missiles[i].y += missiles[i].dy*missileSpeed*timeDiff;
// hors de l'écran
if ((missiles[i].x < 0) || (missiles[i].x > 550) || (missiles[i].y < 0) || (missiles[i].y > 400)) {
gameObjects.removeChild(missiles[i]);
delete missiles[i];
missiles.splice(i,1);
}
}
}
// supp misile
public function missileHit(missileNum:uint) {
gameObjects.removeChild(missiles[missileNum]);
missiles.splice(missileNum,1);
}
// interaction et controle
public function moveGameObjects(event:Event) {
// timer
var timePassed:uint = getTimer() - lastTime;
lastTime += timePassed;
moveRocks(timePassed);
if (gameMode != "delay") {
moveShip(timePassed);
}
moveMissiles(timePassed);
checkCollisions();
}
// tester la collisiion
public function checkCollisions() {
// loop through rocks
rockloop: for(var j:int=rocks.length-1;j>=0;j--) {
// loop through missiles
missileloop: for(var i:int=missiles.length-1;i>=0;i--) {
// collision detection
if (Point.distance(new Point(rocks[j].rock.x,rocks[j].rock.y),
new Point(missiles[i].x,missiles[i].y))
< rocks[j].rockRadius) {
// remove cellules and missile
rockHit(j);
missileHit(i);
// add score
gameScore += 10;
updateScore();
// pete la boucle
continue rockloop;
}
}
// ^^
if (gameMode == "play") {
if (shieldOn == false) { // only if shield is off
if (Point.distance(new Point(rocks[j].rock.x,rocks[j].rock.y),
new Point(ship.x,ship.y))
< rocks[j].rockRadius+shipRadius) {
// supp missile cellule shipHit();
rockHit(j);
}
}
}
}
// if ((rocks.length == 0) && (gameMode == "play")) {
gameMode = "betweenlevels";
gameLevel++; // + un niveau
delayTimer = new Timer(2000,1);
delayTimer.addEventListener(TimerEvent.TIMER_COMPLETE,nextRockWave);
delayTimer.start();
}
}
public function endGame() {
// supprime les éléments
removeChild(gameObjects);
removeChild(scoreObjects);
gameObjects = null;
scoreObjects = null;
removeEventListener(Event.ENTER_FRAME,moveGameObjects);
stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownFunction);
stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpFunction);
gotoAndStop("gameover");
}
}
}
// c'est long hein ?
Conclusion
la conclusion c'est que je viens de comprendre la puissance de l'as 3. c'est génial. Voila^
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Flash 9 / AS3 + Socket MySQL question [ par _benjy ]
Salut @ tous...Bon j'imgine que certain d'entre vous sont au courant de la publication de Flash 9 Alpha. Perso je l'ai recup av hier, et autant le dir
Découverte de l'AS3...pas gagné [ par Neferieb ]
Bonjour,Je suis un peu dérouté en ce moment car je découvre l'AS3 et je reste perplexe quant au manque d'info pour réaliser des applications web plus
creation sommaire pour videos AS3 [ par mackaB ]
Bonjour, Je vous écris car je fais un projet Flash (9.0) AS 3 et j ai un petit probleme avec les listes.En effet avec AS3, dans Component inspector, l
list et AS3 [ par mackaB ]
Bonjour ,alors mon problème est que je n´arrive pas á relier les élèments d´une liste vers d autres élèments ( par exemple pour se servir de la liste
AS3 TextField & MouseEvent.MOUSE_UP bug avec FireFox ... [ par _benjy ]
SalutBon j'ai trouvé un bug avec FireFox et la gestion d'evenement dans le player sur un TextField.je vous laisse voir par vous mm : http://www.kolaps
Dessin et AS3 [ par choufleur ]
Bonjour à tous,J'ai un dessin en AS3 et je voudrai savoir s'il existe un moyen de faire en sorte que les contours de ce dessin se dessinent tout seul.
"Traduction" basique de _root en AS3.0 [ par nicoool18 ]
Bonjour à tous !Je pratique depuis longtemps l'AS2.0, et je viens de passer en AS3.0, qui est vraiment beaucoup mieux ! Mais bon j'ai quelques soucis
Bouton AS3 - Effet [ par xoot ]
bonjour a toutes et tous,Bon je me suis enfin lancé dans le AS3, bon ma question va paraître bête pour certain(e)en faite je crée un bouton nommé : mo
vu metre as3 [ par podi ]
bonjour..j ai recup un fla qui tourne en as3 il sagit d'un vu metre canal gauche et droite qui bouge sur un mp3 prechargé...mais serait il possible de
passage difficile à AS3 [ par attrition ]
Bonjour à tous! Je débute tout juste en AS3 et souhaite refaire tout mon site ainsi... J'ai créé celui-ci sur une seule séquence avec des envois gotoA
|
Derniers Blogs
[TECHDAYS2012] OUI J'Y SERAI![TECHDAYS2012] OUI J'Y SERAI! par JeremyJeanson
Bonsoir, Certes, je l'annonce avec un peu de retard, mais je serai effectivement au Techdays demain. Comme l'an dernier, je participerai au programme ATE (Ask The Expert). Si vous avez des questions Workflow, WCF, AppFabric ou plus généralement .net, n'hé...
Cliquez pour lire la suite de l'article par JeremyJeanson TFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICESTFS INTEGRATION TOOLS - SUIVI DES SYNCHRONISATIONS AVEC REPORTING SERVICES par vfabing
Afin de s'assurer du bon fonctionnement des différentes synchronisations effectuées par les TFS Integration Tools, 2 rapports sont présents dès l'installation. Il suffit alors d'effectuer les manipulations suivantes pour pouvoir les visualiser : Loca...
Cliquez pour lire la suite de l'article par vfabing CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|