-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.js
73 lines (63 loc) · 1.73 KB
/
player.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
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
let shipScale = 60;
let shipWidth = shipScale * SCALE;
let shipHeight = shipWidth; // 0.978 ?
let forward;
let backward;
let left;
let right;
let boosters;
let blasters;
let interact;
let blastCooldown = false;
let collisionRange = 0.66;
let pickupRange = 1.5;
let shipImage = new Image();
shipImage.src = "images/ship.png";
let ship = { // write a class instead as there is to be added different ships
image: shipImage,
width: shipWidth,
height: shipHeight,
xPos: -2500,
yPos: -2500,
speed: 0*GAME_SPEED/GAME_FPS,
maxSpeed: 10*GAME_SPEED/GAME_FPS,
acceleration: 0.25*GAME_SPEED/GAME_FPS,
deceleration: 0.1*GAME_SPEED/GAME_FPS,
rotation: 0,
rotationSpeed: 0*GAME_SPEED/GAME_FPS,
maxRotationSpeed: 5*GAME_SPEED/GAME_FPS,
rotationAcceleration: 0.5*GAME_SPEED/GAME_FPS,
energyRestoration: 0.2,
energyConsumption: 0.2,
energyStore: 1000,
energyCapacity: 1000,
boostConsumption: 0.5,
boostTank: 200,
boostCapacity: 200,
health: 1000,
maxHealth: 1000,
shield: 50,
maxShield: 50
}
var motionTrailLength = 10;
var shipPositions = [];
// MOVE
const SCREEN_MIDDLE = {x: SCREEN_WIDTH/2-ship.width/2, y: SCREEN_HEIGHT/2-ship.height/2};
let MAP_LEFT = SCREEN_MIDDLE.x-(MAP_SIZE/2)+ship.width/2
let MAP_TOP = SCREEN_MIDDLE.y-(MAP_SIZE/2)+ship.height/2
const POSITIONS = {
screen: {
left: 0,
right: SCREEN_WIDTH,
top: 0,
bottom: SCREEN_HEIGHT,
middleX: SCREEN_WIDTH/2,
middleY: SCREEN_HEIGHT/2
},
map: {
left: MAP_LEFT,
right: MAP_LEFT + MAP_SIZE,
top: MAP_TOP,
bottom: MAP_TOP + MAP_SIZE
}
};