This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
forked from Neamar/Wallnumber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.as
127 lines (105 loc) · 2.99 KB
/
Main.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import mochi.as3.*;
/**
* Wallnumber
* @author Neamar
* @see https://github.com/Neamar/Wallnumber/
*/
public final dynamic class Main extends Sprite
{
[Embed(source = "assets/back.png")] private static var Background:Class;
/**
* Largeur du jeu (px)
*/
public static const GAME_WIDTH:int = 800;
/**
* Hauteur du jeu (px)
*/
public static const GAME_HEIGHT:int = 600;
/**
* Le nombre de voies sur le jeu (grosso modo, un équivalent du nombre de vies)
*/
public static const NB_LANES:int = 5;
/**
* La hauteur du HUD
*/
public static const HUD_HEIGHT:int = 75;
/**
* La hauteur d'une voie
*/
public static const LANE_HEIGHT:int = (GAME_HEIGHT - HUD_HEIGHT) / NB_LANES;
/**
* La vitesse maximale que l'on puisse atteindre, au delà de laquelle on est bridé
*/
public static const SPEED_MAX:int = 50;
/**
* Le facteur de perte de vitesse lorsque l'on perd une voie (< 1 pour ralentir le jeu)
*/
public static const SPEED_DAMP:Number = .75;
/**
* Nombre de frames par secondes
*/
public static const FRAME_RATE:int = 30;
/**
* Multiplicateur pour la fermeture d'une voie
*/
public static const LANE_FACTOR:int = 5;
/**
* La partie "non" utilisable d'une voie.
*/
public static const LANE_OFFSETX:int = 80;
/**
* Les différentes couleurs de voies
*
* La première est la majeure, la seconde couleur la mineure (plus laiteuse, utilisée pour les filtres)
*/
public static var laneColors:Array = [
[0xe42322, 0xf02626],
[0x3b9114, 0x53d553],
[0x70419c, 0xb253b8],
[0x138faa, 0x53a5b7],
[0xe616df, 0xbd6bba]
];
/**
* Le jeu en cours
*/
public static var currentGame:Game = null;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Un joli fond
addChild(new Background());
// Lancer un jeu !
setupNewGame();
//Préparer les highscores
MochiServices.connect("c0066d922623e3a8", this);
}
protected function setupNewGame():void
{
//Nettoyer l'ancienne partie
if (currentGame != null)
{
removeChild(currentGame.view);
currentGame.removeEventListener(Game.GAMEOVER, registerHighscore);
}
currentGame = new Game(this.stage);
currentGame.addEventListener(Game.GAMEOVER, registerHighscore);
addChild(currentGame.view);
}
protected function registerHighscore(e:Event):void
{
var o:Object = { n: [3, 12, 15, 14, 13, 6, 14, 10, 3, 12, 13, 5, 13, 8, 13, 9], f: function (i:Number,s:String):String { if (s.length == 16) return s; return this.f(i+1,s + this.n[i].toString(16));}};
var boardID:String = o.f(0,"");
MochiScores.showLeaderboard({boardID: boardID, score: currentGame.score, onClose:setupNewGame});
}
}
}