Une grosse connerie

21 Aug, 2005

Un pong en Flash ! Trop fort !

Posted by: Laurent Tu In: Une grosse connerie

Vu que ça faisait longtemps que je n’avais pas fait de truc super con en Flash (ça manquait à la catégorie Grosse Connerie), voici un petit Pong que je viens de programmer puisque je me faisais chier. (Christophe paie son nutella si on dépasse le niveau 6) :

Et op, je paie mon code :

splash.onPress = function() { 	youpi(); 	this._visible = false; } function youpi() { 	// les scores 	var score1:Number = 0; 	var score2:Number = 0; 	_root.level = 1; 	_root.niveau.text = "Level 1"; 	_root.score.text = "0 - 0"; 	// on attache les clips 	_root.attachMovie("raquette","raquette1",5); 	_root.attachMovie("raquette","raquette2",6); 	_root.attachMovie("balle","balle",7); 	// on initialise les positions 	_root.raquette1._x = 0; 	_root.raquette1._y = 0; 	_root.raquette2._x = 350 - _root.raquette1._width; 	_root.raquette2._y = 0; 	_root.balle._x = 350/2; 	_root.balle._y = Math.random()*400; 	// on initialise les vitesses 	sens = Math.random(); 	if (sens <= 0.25) { 		_root.balle._vx = Math.random()*3+2; 		_root.balle._vy = Math.random()*3+2; 	} else if (sens >= 0.25 && sens <= 0.50) { 		_root.balle._vx = Math.random()*3+2; 		_root.balle._vy = - (Math.random()*3+2); 	} else if (sens >= 0.75) { 		_root.balle._vx = - (Math.random()*3+2); 		_root.balle._vy = Math.random()*3+2; 	} else { 		_root.balle._vx = - (Math.random()*3+2); 		_root.balle._vy = - (Math.random()*3+2); 	} 	// ce que fait la balle quand elle se ballade 	_root.balle.onEnterFrame = function() { 		this._x += this._vx; 		this._y += this._vy; 		// si elle tape à gauche 		if (this._x < 0) { 			this._vx = Math.abs(this._vx); 			score2++; 			_root.score.text = score1+" - "+score2; 			// on a perdu 			if (score2 == 5) { 				killall(); 				splash._visible = true; 			} 		} 		// si elle tape à droite 		if (this._x > 350 - this._width) { 			this._vx = - Math.abs(this._vx); 			score1++; 			_root.score.text = score1+" - "+score2; 			// on passe au niveau suivant 			if (score1 == 5) { 				_root.level ++; 				_root.niveau.text = "Level "+_root.level; 				score1 = 0; 				score2 = 0; 				_root.score.text = "0 - 0"; 			} 		} 		// si elle tape en haut 		if (this._y < 0) { 			this._vy = Math.abs(this._vy); 		} 		// si elle tape en bas 		if (this._y > 400 - this._height) { 			this._vy = - Math.abs(this._vy); 		} 		// si elle tape sur votre raquette 		if (this._x < 0+_root.raquette1._width 			&& this._y > _root.raquette1._y 			&& this._y < _root.raquette1._y+_root.raquette1._height-this._height) { 			// this._vx = Math.abs(this._vx); trop simple 			if (_root.balle._vy > 0) signe = 1 			else signe = -1; 			_root.balle._vx = Math.random()*3+2; 			_root.balle._vy = signe*(Math.random()*3+2); 		} 		// si elle tape sur la raquette de l'ordinateur 		if (this._x > 350 - this._width-_root.raquette2._width 			&& this._y > _root.raquette2._y 			&& this._y < _root.raquette2._y+_root.raquette2._height-this._height) { 			// this._vx = - Math.abs(this._vx); 			if (_root.balle._vy > 0) signe = 1 			else signe = -1; 			_root.balle._vx = - (Math.random()*3+2); 			_root.balle._vy = signe*(Math.random()*3+2); 		} 		// l'AI !!! (un grand mot peut être) 		ai_raquette(); 	} 	// comment qu'on bouge la raquette 	Key.addListener(raquette1); 	_root.raquette1.onKeyDown = function() { 		if (Key.isDown(Key.DOWN)) { 			this._vy = 5; 			this._sy = 1; 			_root.raquette1.onEnterFrame = function() { 				res = this._y + this._sy*this._vy; 				if (res <= 400 - this._height) { 					this._y = res; 				} 				this._vy --; 				if (this._vy == 0) delete this.onEnterFrame; 			} 		} else if (Key.isDown(Key.UP)) { 			this._vy = 5; 			this._sy = -1; 			_root.raquette1.onEnterFrame = function() { 				res = this._y + this._sy*this._vy; 				if (res >= 0) { 					this._y = res; 				} 				this._vy --; 				if (this._vy == 0) delete this.onEnterFrame; 			} 		} 	} } // comportement de l'ordinateur function ai_raquette() { 	if (_root.balle._y < _root.raquette2._y+_root.raquette2._height/2) _root.raquette2._y -= _root.level; 	else _root.raquette2._y += _root.level; } // on butte tout function killall() { 	_root.balle.removeMovieClip(); 	_root.raquette1.removeMovieClip(); 	_root.raquette2.removeMovieClip(); }

Contrat Creative Commons
Cette création est mise à disposition sous un contrat Creative Commons.

Comments to "Un pong en Flash ! Trop fort !"

1 | endive

August 21st, 2005 at 1:18 am

Avatar

il est trop chiant ton pong. et puis y ‘a un bug quand l’ordinateur sort des bords.

2 | Laurent

August 21st, 2005 at 12:57 pm

Avatar

Oui je sais, mais c’était trop compliqué pour moi.

3 | Max

August 23rd, 2005 at 11:53 pm

Avatar

Je n’ai fais que level 4 mais ma partie a duré 13h14min47s. Chris tu paies ton hélico à la place ?

Comment Form

About

Les opinions exprimées sur ce blog sont personnelles.

Ceci est le blog personnel de Laurent Tu. C'est une grosse connerie. Les billets marqués "Un gros bordel" sont des billets spontannés sans censure du flot de pensée, vous lisez donc à vos risques et périls.

Vous pouvez retrouver l'activité en ligne de Laurent sur FriendFeed:

Subscribe to me on FriendFeed