-
[F8] Simple Flash 8 code help - pop up screen when somebody wins flash game
Hi,
I have a flash game version of breakout - here
The same thing happens (final score screen - play again?) when someone wins and loses. How do I make it so that when all the bricks are knocked down...a screen pops up saying "You Win!" and have a link to a web page?
I know how busy you are so if you could just point me in the right direction for how to solve this issue, that would be great. All responses are welcomed.
Thank you for your time. I really appreciate it!
Sincerely,
Staniel
-
I assume you didn´t wrote the game code? because otherwise you´d certainly know where the part of the code is that detects whenever a brick was hit wich X´th it was out of the ones that were there from the start.
Because you´d basicly check of course if all bricks are destroyed and if so display whater you want.
A easy way would be to use a counter and count each time a brick got hit like:
and after that check if it reached the total amount:
PHP Code:
if (hit >= totalAmount){
//popup message code....
}
-
Exactly as render saids !! or two diferets ways after you save the points and all that stuff.
That pop up, can be make it in other frames after the game... that is simple, loading the point variables.
Or can be done with a movie clip, showing "true" when the game finish.
Also you can see the last button than apeer and try yo make all this in that place.
-
Thanks renderhjc and flashxi for your responses
Hi renderhjc and flashxi,
Thank you for your help. I wanted to give it my best shot at implementing what you said, but have not been able to figure it out.
The basic code template was not written by me. I added several modifications and graphics to the game. It is my first attempt in flash game realm. Would I learn more by building a game from scratch?
Anyway on to the problem:
I was not sure where to add the code and where the modifications need to go as far as numbers are concerned. Here is the code:
PHP Code:
ball._x = 200;
ball._y = 200;
paddle._x = 200;
deltaX = Math.round(Math.random()*10)-5;
deltaY = 10;
ballsLeft = 2;
theScore = 0;
tileNum = 12;
targetList = [];
maketargetList(tileNum);
resetTiles();
function maketargetList(numOfTiles){
for(i=0;i<numOfTiles;i++){
targetList[i] = String("tile"+(i+1));
}
}
function moveBall(){
ball._x += deltaX;
ball._y += deltaY;
//check if ball hits the paddle
if(ball.hitTest(_root.paddle) && this.deltaY>0){
paddleHit();
}
//check left side
if((ball._x - 12.5) < 0){
this.flipX();
}
//check right side
if((ball._x + 12.5) > 400){
this.flipX();
}
//check the roof
if((ball._y - 12.5) < 0){
this.flipY();
}
//check to see if player missed ball
if(ball._y > 500){
ballsLeft--;
if(ballsLeft<0){
ballsLeft=0;
gotoAndStop(5);
}
else{
ball._x = 200;
ball._y = 200;
deltaX = Math.round(Math.random()*10)-5;
deltaY = 10;
}
}
//check if ball hits a tile
var theTileNum = targetList.length;
for(i=0;i<theTileNum;i++){
var thisTile = targetList[i];
if(ball.hitTest(_root[thisTile])){
theScore +=10;
_root[thisTile]._x += -1000;
targetList.splice(i,1); //remove tile from array
flipY();
if(targetList.length == 0){
gotoAndStop(5);
*******renderhjc code******if (hit 12>= 12totalAmount){
on(release) {
getURL("javascript:alert('Hi Mom!!');");
}
} *******end renderhjc code***************
}
}
}
}
function flipY() {
deltaY *= -1;
}
function flipX() {
this.deltaX *= -1;
}
function paddleHit() {
deltaX = (ball._x - paddle._x)/4;
flipY();
}
function resetTiles() {
for (i=0; i<tileNum; i++) {
var thisTile = targetList[i];
_root[thisTile]._x = _root[thisTile].startX;
}
}
Thanks again for you help!
Staniel
-
you dont seem to have basic knowledge of Actionscript
the only change or addition you need is here:
PHP Code:
if(targetList.length == 0){
gotoAndStop(5);
getURL("javascript:alert('Advertising crap popup window!!!');");
}
because that if(){ condition checks already if the bricks are all gone. just somewhat before they are removed from the array
PHP Code:
targetList.splice(i,1); //remove tile from array
wich means that the array gets shorter and shorter each time the ball hits a another brick until this condition says true:
PHP Code:
if(targetList.length == 0){
wich is of course the case if no bricks are left anymore. Within that condition do your code to popup whatever. But remember hardly no Browser today lets flash movies open popups by default in most cases even in the IE they are blocked by default (for good reasons)- but well that´s another problem.
the complete code in case you didn´t understood all what I said:
PHP Code:
ball._x = 200;
ball._y = 200;
paddle._x = 200;
deltaX = Math.round(Math.random()*10)-5;
deltaY = 10;
ballsLeft = 2;
theScore = 0;
tileNum = 12;
targetList = [];
maketargetList(tileNum);
resetTiles();
function maketargetList(numOfTiles){
for(i=0;i<numOfTiles;i++){
targetList[i] = String("tile"+(i+1));
}
}
function moveBall(){
ball._x += deltaX;
ball._y += deltaY;
//check if ball hits the paddle
if(ball.hitTest(_root.paddle) && this.deltaY>0){
paddleHit();
}
//check left side
if((ball._x - 12.5) < 0){
this.flipX();
}
//check right side
if((ball._x + 12.5) > 400){
this.flipX();
}
//check the roof
if((ball._y - 12.5) < 0){
this.flipY();
}
//check to see if player missed ball
if(ball._y > 500){
ballsLeft--;
if(ballsLeft<0){
ballsLeft=0;
gotoAndStop(5);
}
else{
ball._x = 200;
ball._y = 200;
deltaX = Math.round(Math.random()*10)-5;
deltaY = 10;
}
}
//check if ball hits a tile
var theTileNum = targetList.length;
for(i=0;i<theTileNum;i++){
var thisTile = targetList[i];
if(ball.hitTest(_root[thisTile])){
theScore +=10;
_root[thisTile]._x += -1000;
targetList.splice(i,1); //remove tile from array
flipY();
if(targetList.length == 0){
gotoAndStop(5);
getURL("javascript:alert('Advertising crap popup window!!!');");
}
}
}
}
function flipY() {
deltaY *= -1;
}
function flipX() {
this.deltaX *= -1;
}
function paddleHit() {
deltaX = (ball._x - paddle._x)/4;
flipY();
}
function resetTiles() {
for (i=0; i<tileNum; i++) {
var thisTile = targetList[i];
_root[thisTile]._x = _root[thisTile].startX;
}
}
-
Thanks renderhjs
Thank you for laying out the way you did. I am very early on into learning actionscript. I apologize for not knowing more.
I tried your code which worked, but still had trouble on the end. I have decided to put this project on hold for the time being until I can take a course on actionscript.
I am sure your code is correct. I am just to new at this point.
I looked over your portfolio. It is amazing. You do really great work. I am sure you will be very successful in whatever you do.
Thanks again for the help! I very much appreciate it.
Sincerely,
Staniel
ps
when you said:
getURL("javascript:alert('Advertising crap popup window!!!');");
i was just looking for a way to implement a form...and figured that it would be easier to send them to a html form (which I know how to build) rather then figure out xml or php or whatever is used in flash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|