-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplatformer.html
40 lines (40 loc) · 1.62 KB
/
platformer.html
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>DDD</title>
</head>
<body>
<script src="main.js"></script>
<script>
var world = new World(document.body, 'white', 500, 500, 0, 0, {x: 0, y: 1});
world.start();
world.el.style.border = '3px solid black';
world.el.style.borderRadius = '3px';
world.set(new world.Rectangle('player', 200, 200, 50, 50,'yellow',1.001),
new world.Rectangle('ground', 0, 450, 1000, 50, 'black', 1000),
new world.Rectangle('d', 400, 200, 400, 400, 'black', 1000),
new world.Circle('dd', 600, 200, 50, 'blue', 1000),
new world.Text('ddd', 50, 50, 'd', 15, 'Arial', 'black'));
world.get('d').gravity = false;
var player = world.get('player');
var ground = world.get('ground');
//player.gravity = false;
ground.gravity = false;
var keys = world.keys;
world.update = function() {
world.get('ddd').text = (world.mouse.x+world.cam.x) + ',' + (world.mouse.y+world.cam.y);
world.get('ddd').x = 50 + world.cam.x;
world.get('ddd').y = 50 + world.cam.y;
if (keys.w) world.addForce({y: -4}, player);
if (keys.a) world.addForce({x: -2}, player);
if (keys.d) world.addForce({x: 2}, player);
if (player.x > 450 + world.cam.x) {world.cam.x+=4;player.x = world.cam.x + 450;};
if (player.x < world.cam.x) {world.cam.x-=4;player.x = world.cam.x;}
if (player.x < 0) {player.x = 0;world.cam.x=0;}
if (player.x > 950) {player.x = 950;world.cam.x=500;}
if (player.y < 0) player.y = 0;
}
</script>
</body>
</html>