-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
104 lines (86 loc) · 2.51 KB
/
Copy pathapp.js
File metadata and controls
104 lines (86 loc) · 2.51 KB
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
var myApp = angular.module('login',[]);
myApp.controller('MainController', ['$scope', '$http', '$interval', function($scope, $http, $interval) {
var MAX_SPEED = 6000;
var FRICTION = 0.97;
var arenaWidth = 800;
var arenaHeight = 800;
var upArrow = 38;
var downArrow = 40;
var rightArrow = 39;
var leftArrow = 37;
var upKey = 87;
var downKey = 83;
var rightKey = 68;
var leftKey = 65;
var wizard = {};
wizard.x = 1000;
wizard.y = 600;
wizard.vx = 0;
wizard.vy = 0;
wizard.width = 30;
wizard.height = 40;
wizard.health = 100;
$scope.doFrame = function() {
wizard.x += wizard.vx / 1000;
wizard.y += wizard.vy / 1000;
wizard.vx *= FRICTION;
wizard.vy *= FRICTION;
}
$scope.accelerate = function(x, y) {
wizard.vx = Math.max(Math.min(MAX_SPEED, wizard.vx + x), -MAX_SPEED);
wizard.vy = Math.max(Math.min(MAX_SPEED, wizard.vy + y), -MAX_SPEED);
}
// this array stores the model view of each object in the arena
var objects = [];
var arena = $("#arena");
var myWizard = $("#myWizard");
arena.css("width", arenaWidth);
arena.css("height", arenaHeight);
myWizard.css("width", wizard.width);
myWizard.css("height", wizard.height);
var joined = false;
var keys = {};
$scope.keyDown = function($event) {
keys[$event.which] = true;
var x = 0;
var y = 0;
console.log(keys);
for (var key in keys) {
if (key == upArrow || key == upKey) {
y += -6000;
}
if (key == downArrow || key == downKey) {
y += 6000;
}
if (key == leftArrow || key == leftKey) {
x += -6000;
}
if (key == rightArrow || key == rightKey) {
x += 6000;
}
}
$scope.accelerate(x, y);
};
$scope.keyUp = function($event) {
delete keys[$event.which];
};
$scope.clickOnArena = function($event) {
console.log("offsetX: " + $event.offsetX);
console.log("offsetY: " + $event.offsetY);
};
function drawModels(model) {
};
$scope.drawArena = function() {
if (!$scope.joined)
return;
$scope.doFrame()
myWizard.css("top", wizard.y);
myWizard.css("left", wizard.x);
};
$scope.joinGame = function() {
$scope.joined = true;
};
$interval(function() {
$scope.drawArena();
}, 20);
}]);