-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom_transition.html
138 lines (126 loc) · 3.84 KB
/
room_transition.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
"use strict";
var playerDiv;
var player = {x: 5, y: 5, xVel: 0, yVel: 0, width: 48, height: 48}
var roomView = {x: 0, y: 0, width: 320, height: 240}
var nextRoomView = {x: 0, y: 0, width: 320, height: 240}
var dispDiv;
var transitingRoom = false;
function mainLoop() {
if (transitingRoom) {
runRoomTransit();
return;
}
player.x += player.xVel;
player.y += player.yVel;
playerDiv.style.left = player.x + "px";
playerDiv.style.top = player.y + "px";
if (player.x + (0.5 * player.width) > roomView.x + roomView.width) {
nextRoomView.x = roomView.x + roomView.width;
transitingRoom = true;
}
if (player.y + (0.5 * player.height) > roomView.y + roomView.height) {
nextRoomView.y = roomView.y + roomView.height;
transitingRoom = true;
}
}
//window.location = "http://www.youtube.com/watch?v=oHg5SJYRHA0";
function runRoomTransit() {
//console.log(roomView)
//console.log(nextRoomView)
var testTrans = true;
if (Math.abs(roomView.x - nextRoomView.x) > 5) {
roomView.x += 2 * (roomView.x > nextRoomView.x? -1:1)
testTrans = false;
} else {
roomView.x = nextRoomView.x;
}
if (Math.abs(roomView.y - nextRoomView.y) > 2) {
roomView.y += 2 * (roomView.y > nextRoomView.y? -1: 1)
testTrans = false;
} else {
roomView.y = nextRoomView.y;
}
if (testTrans) {
transitingRoom = false;
if (roomView.x == 320) {
loadRick();
}
if (roomView.y >= 240) {
window.location = "http://www.youtube.com/watch?v=sP4NMoJcFd4";
}
}
dispDiv.scrollLeft = roomView.x;
dispDiv.scrollTop = roomView.y;
}
function loadRick() {
window.location = "http://www.youtube.com/watch?v=oHg5SJYRHA0";
}
function keyDownHandler(e) {
switch (e.keyCode) {
case 37:
player.xVel = -4;
break;
case 39:
player.xVel = 4;
break;
case 38:
player.yVel = -4;
break;
case 40:
player.yVel = 4;
break;
}
}
function keyUpHandler(e) {
switch (e.keyCode) {
case 37:
player.xVel = 0;
break;
case 39:
player.xVel = 0;
break;
case 38:
player.yVel = 0;
break;
case 40:
player.yVel = 0;
break;
}
}
function loadHandler() {
playerDiv = document.getElementById("gamechar");
dispDiv = document.getElementById("dispdiv");
setInterval(mainLoop, 50);
dispDiv.scrollLeft = dispDiv.scrollTop = 0;
}
window.onkeydown = keyDownHandler;
window.onkeyup = keyUpHandler;
window.onload = loadHandler;
</script>
<body>
<div id="dispdiv" style="width: 320px; height: 240px; background-color: #000000; overflow: hidden; position: absolute; left: 0px; top: 0px">
<div id="containerdiv" style="width: 640px; height: 480px">
<div id="flowerz" style="position: absolute; left: 13px; top: 37px">
<img src="http://media-mcw.cursecdn.com/b/bc/Cyan_Flower.png" width="48" height="48" alt="flowerz">
</div>
<div id="rick" style="position: absolute; left: 325px; top: 5px">
<img id="rickpic" src="http://upload.wikimedia.org/wikipedia/en/f/f7/RickRoll.png" width="300" height="220" alt="rick">
</div>
<div id="ilovecat" style="position: absolute; left: 5px; top: 245px">
<img id="ilovecatpic" src="http://i4.ytimg.com/vi/sP4NMoJcFd4/hqdefault.jpg" width="300" height="220" alt="cat">
</div>
<div id="gamechar" style="position: absolute; left: 5px; top: 5px; z-index:19132">
<img src="http://static.minecraftforum.net//public/style_emoticons/default/steve_tearful.gif" width="48" height="48" alt="char">
</div>
</div>
</div>
<div style="position: absolute; left: 0px; top: 250px">
<center><input type="button" onmousedown="player.yVel = -4" onmouseup="player.yVel = 0" value="Up"></center><br>
<center><input type="button" onmousedown="player.xVel = -4" onmouseup="player.xVel = 0" value="Left"><input type="button" onmousedown="player.yVel = 4" onmouseup="player.yVel = 0" value="Down"><input type="button" onmousedown="player.xVel = 4" onmouseup="player.xVel = 0" value="Right"></center><br>
</div>
</body>
</html>