MCPcopy Create free account
hub / github.com/creationix/node-sdl / Player

Function Player

examples/Chaser.js:34–45  ·  view source on GitHub ↗
(joystickIndex)

Source from the content-addressed store, hash-verified

32shuffle(colorNames);
33
34function Player(joystickIndex) {
35 SDL.joystickOpen(joystickIndex);
36 players[joystickIndex] = this;
37 this.name = SDL.joystickName(joystickIndex);
38 var colorName = this.colorName = colorNames[joystickIndex % colorNames.length];
39 var angle = 2 * Math.PI / numPlayers * joystickIndex;
40 this.x = Math.floor(Math.sin(angle) * 50 * (numPlayers - 1)) + screen.w / 2;
41 this.y = Math.floor(Math.cos(angle) * 50 * (numPlayers - 1)) + screen.h / 2;
42 this.jx = 0; this.jy = 0;
43 this.speed = 0.3;
44 console.log("New %s player using %s", colorName[0].toUpperCase() + colorName.substr(1), this.name);
45}
46Player.prototype.tick = function (delta) {
47 this.x += this.jx * delta * this.speed;
48 this.y += this.jy * delta * this.speed;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected