-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflatspace.js
41 lines (35 loc) · 1.24 KB
/
flatspace.js
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
// Set up a collection to contain player information. On the server,
// it is backed by a MongoDB collection named "players."
Players = new Meteor.Collection("players");
// The top-level FlatSpace module.
// Provides the following public methods:
// * login(username)
// * logout()
// * msg(log_message)
var fSpace = function () {
//**** PRIVATE ATTRIBUTES ****//
var ship_colors = ["red", "yellow", "blue"];
var ship_types = ["Pilot", "Gunner", "Defender"];
//**** PRIVATE METHODS ****//
return {
//**** PUBLIC METHODS ****//
createNewPlayer: function (player_name, type, color) {
color = color || ship_colors[Math.floor(Math.random() * ship_colors.length)];
type = type || ship_types[Math.floor(Math.random() * ship_types.length)];
// Create the player if the name doesn't already exist
if (Players.find({name: player_name}).fetch().length < 1) {
Players.insert({
name: player_name,
type: type,
color: color,
pos_x: Math.floor(Math.random()*300),
pos_y: Math.floor(Math.random()*300),
vel_x: 0,
vel_y: 0,
rot: 0,
score: Math.floor(Math.random()*10)*5
});
}
},
};
}();