# Game over when score=

**URL:** https://forum.kirupa.com/t/game-over-when-score/129086
**Category:** Uncategorized
**Created:** [November 19, 2004, 10:42am UTC](https://forum.kirupa.com/t/game-over-when-score/129086 "2004-11-19T10:42:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jerryj](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jerryj](https://forum.kirupa.com/u/jerryj)
#### Post date: [November 19, 2004, 10:42am UTC](https://forum.kirupa.com/t/game-over-when-score/129086/1 "2004-11-19T10:42:22Z")

</div>

Hi,  
I took this code from an open source pong game, but it lacks a ‘game over’ scene when player(spieler) or opponent (gegener) reaches a certain amount of points. And that is exactly what I would like to add. I would think I could add something like:

> function spielerwins ()  
> {  
> if(spieler\_score \>= 15)  
> gotoAndPlay(2);  
> }

where frame 2 on the main timeline is a movieclip saying something like: game over, you won.

This is the code from the open source, placed on frame 1 of the main timeline:

> stop();  
> var spieler\_score = 0;  
> var gegner\_score = 0;

loseSnd = new Sound();  
loseSnd.attachSound(“lose”);

bounceSnd = new Sound();  
bounceSnd.attachSound(“bounce”);

// Schwierigkeitsgrad (je grösser der Wert desto Leichter)  
skill = 4;

// Spieler (Init)  
spielerInitObj = new Object();  
spielerInitObj.\_x = 385;  
spielerInitObj.\_y = 150;  
spielerInitObj.onEnterFrame = steuer\_spieler;

// Computergegner (Init)  
gegnerInitObj = new Object();  
gegnerInitObj.\_x = 15;  
gegnerInitObj.\_y = 150;  
gegnerInitObj.onEnterFrame = steuer\_gegner;

// Spielball (Init)  
ballInitObj = new Object();  
ballInitObj.\_x = 200;  
ballInitObj.\_y = 150;  
ballInitObj.vx = 5;  
ballInitObj.vy = 0;  
ballInitObj.onEnterFrame = steuer\_ball;

// Spieler, Gegner und Ball auf die Bühne setzen  
\_root.attachMovie(“rect”,“spieler”,0,spielerInitObj);  
\_root.attachMovie(“edwin2”,“gegner”,1,gegnerInitObj);  
\_root.attachMovie(“ball”,“ball\_mc”,2,ballInitObj);

// Spielersteuerung  
function steuer\_spieler() {  
if(\_root.\_ymouse \> this.\_height/2 && \_root.\_ymouse \< 300 - this.\_height/2) this.\_y = \_root.\_ymouse;  
}

// Computergegnersteuerung  
function steuer\_gegner() {  
this.dy = this.\_y - ball\_mc.\_y;  
this.\_y -= this.dy / skill;  
}

// Ballsteuerung  
function steuer\_ball() {  
// Mittelpunkt des Spielballs  
if(this.\_y \> 300 - this.\_height / 2) this.vy \*= -1;  
if(this.\_y \< 0 + this.\_height / 2) this.vy \*= -1;

// Spieler (verliert den Ball)  
if(this.\_x \> 400) {  
loseSnd.start();  
gegner\_score += 1;  
this.\_x = 200;  
this.\_y = 150;  
this.vx = -5;  
this.vy = 0;  
}

// Computergegner (verliert den Ball)  
if(this.\_x \< 0) {  
loseSnd.start();  
spieler\_score += 1;  
this.\_x = 200;  
this.\_y = 150;  
this.vx = 5;  
this.vy = 0;  
}

// Spieler (Hoch/Runter)  
spieler\_up\_y = spieler.\_y - spieler.\_height / 2;  
spieler\_bottom\_y = spieler.\_y + spieler.\_height / 2;

// Computergegner (Hoch/Runter)  
gegner\_up\_y = gegner.\_y - gegner.\_height / 2;  
gegner\_bottom\_y = gegner.\_y + gegner.\_height / 2;

// Spieler (Bewegungraum festlegen)  
// Ball-Bewegungsrichtung umkehren  
if(this.\_x \> (385 - spieler.\_width / 2) && this.\_y \> spieler\_up\_y && this.\_y \< spieler\_bottom\_y) {  
bounceSnd.start();  
this.vx \*= -1;  
this.vy = (this.\_y - spieler.\_y) \* .8;  
}

// Computergegner (Bewegungsraum festlegen)  
// Ball-Bewegungsrichtung umkehren  
if(this.\_x \< (15 + gegner.\_width / 2) && this.\_y \> gegner\_up\_y && this.\_y \< gegner\_bottom\_y) {  
bounceSnd.start();  
this.vx \*= -1;  
this.vy = (this.\_y - gegner.\_y) \* .8;  
}

// Ballbewegung (Umsetzen)  
this.\_x += this.vx;  
this.\_y += this.vy;

// Ballgeschwindigkeit um den Faktor 1.0001 erhöhen  
this.vx \*= 1.0010;  
this.vy \*= 1.0001;  
}

Could someone tell me how I should do this?I am sorry it is in german, but that’s the source!

Thank you very much again,  
Jerryj.
