This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
catch-me.html
179 lines (141 loc) · 5.54 KB
/
catch-me.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Catch Me If You Can</title>
<link rel="stylesheet" type="text/css" href="build/build.css">
<style>
#CatchMeContainer {
width: 100%;
height: 100%;
position: relative;
background-color: black;
background-repeat: no-repeat;
background-position: 50% 0%;
background-size: cover;
color: #fff;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#CatchMeBox{
width: 100px;
height: 100px;
position: absolute;
background-image: url("sans.png");
background-size: cover;
display: none;
}
#button{
padding: 30px;
font-size: 30px;
background-color: #fff;
border: none;
}
.button{
padding: 30px;
font-size: 30px;
background-color: #fff;
border: none;
margin: 5px;
cursor: pointer;
}
#button:hover{
background-color: #ccc;
}
#CatchMeBox:hover, #button:hover{
cursor: pointer;
}
#CatchMeStart{
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<article>
<section>
<div id = "CatchMeContainer">
<div id = "CatchMeBox" onclick="catchMeScore();"></div>
<div id = "CatchMeText"></div>
<div id = "CatchMeStart">
<h2 id="CatchMeEnding">Catch Me If You Can</h2>
<button id="button" onclick="startCatchMe();">Here We Go!!!</button>
</div>
</div>
</section>
<section>
<h2>Want To Leave Already? :(</h2>
<button class="button" onclick="location.href='#1';">No</button>
<button class="button" onclick="location.href='./index.html';">Yes</button>
</section>
</article>
<script type="text/javascript">
var catchMeContainer = document.getElementById('CatchMeContainer');
var catchMeTopText = document.getElementById('CatchMeText');
var catchMeMiddleText = document.getElementById('CatchMeStart');
var catchMeBox = document.getElementById('CatchMeBox');
var score, lives, caught;
var catchMeTiming;
//untuk efek launch yang lebih keren
catchMeContainer.style.backgroundImage = "url('sans-background.gif')";
catchMeMiddleText.style.display = "none";
function startScene(){
catchMeContainer.style.backgroundImage = "none";
catchMeMiddleText.style.display = "block";
clearInterval(startTiming);
}
var startTiming = setInterval(startScene, 6000);
//ketika tombol START ditekan. karena masih ada kesalahan. lives dimulai dari 50 + 1
function startCatchMe(){
caught = false; score = 0; lives = 51;
catchMeMiddleText.style.display = "none";
catchMeTiming = setInterval(catchMeProcess, 500);
catchMeTopText.style.display = "block";
}
//proses game yang looping dari variabel catchMeTiming
function catchMeProcess(){
catchMeBox.style.display = "block";
if(caught) catchMeBox.style.backgroundImage = "url('sans.png')";
if(caught == false) --lives;
catchMeTopText.innerHTML = "Lives = " + lives + " Score = " + score;
catchMeMoving();
if (lives == 0){
catchMeTopText.innerHTML = "Lives = " + lives + " Score = " + score;
catchMeGameOver();
clearInterval(catchMeTiming);
}
caught = false;
}
//fungsi untuk memindahkan lokasi secara random
function catchMeMoving(){
var x = Math.floor((Math.random() * 460) + 0);
var y = Math.floor((Math.random() * 280) + 30);
catchMeBox.style.marginLeft = x + "px";
catchMeBox.style.marginTop = y + "px";
}
//bila sans berhasil ditangkap
function catchMeScore(){
caught = true;
score++;
catchMeBox.style.backgroundImage = "url('sans-invert.png')";
}
//fungsi yang dijalankan bila lives sudah habis
function catchMeGameOver(){
catchMeMiddleText.style.display = "block";
catchMeBox.style.display = "none";
catchMeTopText.style.display = "none";
document.getElementById('CatchMeEnding').innerHTML = "You Score is " + score + " Fellow Human";
}
//Catch Me by Chandra W
</script>
<script type="text/javascript" src="build/build.js"></script>
</body>
</html>