
26-11-2006, 19:00
|
|
|
|
חבר מתאריך: 10.06.06
הודעות: 7
|
|
|
משחק בפלאש עזרה בקוד
עשיתי ככה משחק:
קוד:
stop();
function initGame() {
// the range of falling apple clips
firstApple = 1;
lastApple = 0;
// init the score
score = 0;
// set the number of apples to fall
totalApples = 30;
// init the speed and time delay
timeSinceLastApple = 0;
appleSpeed = 15;
// create the fox so that it is on top of the apples
attachMovie( "running fox", "fox", 999999 );
fox._x = 275;
fox._y = 300;
}
function moveFox() {
// check for arrow keys
if (Key.isDown(Key.RIGHT)) {
dx = 10;
// fox faces right
fox._xscale = -Math.abs(fox._xscale);
} else if (Key.isDown(Key.LEFT)) {
dx = -10;
// fox faces left
fox._xscale = Math.abs(fox._xscale);
} else {
// no movement
dx = 0;
}
// move the fox and limit that movement
fox._x += dx;
if (fox._x < 30) fox._x = 30;
if (fox._x > 520) fox._x = 520;
// make the fox run or stand still
if ((dx != 0) and (fox._currentFrame == 1)) {
fox.gotoAndPlay("run");
} else if ((dx == 0) and (fox._currentFrame != 1)) {
fox.gotoAndPlay("stand");
}
}
function dropNewApple() {
// only drop if it has been long enough
if (timeSinceLastApple > 20) {
// only drop if there are more apples
if (lastApple < totalApples) {
// only drop 10% of the time
if (Math.random() < .1) {
// create next apple and set its locations
lastApple++;
attachMovie( "apple", "apple"+lastApple, lastApple );
_root["apple"+lastApple]._x = Math.random()*490+30;
_root["apple"+lastApple]._y = 0;
// reset time delay for next apple
timeSinceLastApple = 0;
// increase apple speed
if (appleSpeed < 10) appleSpeed += .5;
}
}
}
// even if no apple dropped, get closer to next drop
timeSinceLastApple++;
}
function moveApples() {
// loop through all existing apple clips
for (i=firstApple;i<=lastApple;i++) {
// get apple location
x = _root["apple"+i]._x;
y = _root["apple"+i]._y + appleSpeed;
// see if apple reached ground
if (y > 400) {
removeApple(i);
// see if apple hit basket
} else if ((Math.abs(y-fox._y) < 48) and (Math.abs(x-fox._x) < 30)) {
removeApple(i);
score += 1;
// continue to move apple
} else {
_root["apple"+i]._y = y;
}
}
}
function removeApple(n) {
// take away apple movie clip
_root["apple"+n].removeMovieClip();
// reset range of apples to move
firstApple = n+1;
// see if this was the last apple
if (n == totalApples) {
fox.removeMovieClip();
gotoAndPlay("game over");
}
}
עכשיו אני רוצה שיפול מדי פעם חוץ מה apple גם לדוגמה banana
ושזה יתן 5 נקודות לא אחת, וגם להוסיף שיפול גם לדוגמה bullet שזה יפסיק את המשחק אוטמוטית ויפסיל אותך
וקוד אחרון שאני רוצה להוסיף זה קוד שברגע שאני אוסף 20 (לדוגמה) apples זה יעביר אותי לסצנה שאני בוחר
תודה
|