-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
97 lines (78 loc) · 1.93 KB
/
script.js
File metadata and controls
97 lines (78 loc) · 1.93 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
function SaveData(points, upgrade) {
window.localStorage.setItem("points", points);
window.localStorage.setItem("upgrade", upgrade);
}
function GetData() {
return [window.localStorage.getItem("points"), +window.localStorage.getItem("upgrade")]
}
function ClearData(){
window.localStorage.clear();
}
let Score = 0;
let MoneyOnClick = 1;
document.querySelector("#button").addEventListener("click", ()=>{
Score = +Score + (+MoneyOnClick * Coef());
SaveData(Score, MoneyOnClick)
UpdateScore()
console.log(Score, MoneyOnClick)
})
function UpdateScore(){
document.querySelector("#score").innerHTML = Score;
document.querySelector("#level").innerHTML = MoneyOnClick;
}
document.querySelector("#ButtonUpgrader").addEventListener("click",()=>{
if (Score >= MoneyOnClick){
Score -= MoneyOnClick;
MoneyOnClick = +MoneyOnClick + 1;
}
SaveData(Score, MoneyOnClick)
UpdateScore()
})
Score = GetData()[0]
MoneyOnClick = GetData()[1]
if (Score == null || Score == NaN || Score == undefined){
Score = 0
}
UpdateScore()
let canvas = document.createElement("canvas");
let ctx = canvas.getContext("2d");
canvas.width = 500;
canvas.height = 50;
document.body.appendChild(canvas)
let State = 250;
document.addEventListener("keydown", (key)=>{
if(key.code == "Space"){
State += 100
}
});
function Clamp(vvalue, vmin, vmax){
if(vvalue < vmin){
return vmin;
}
else if(vvalue > vmax){
return vmax;
}
return vvalue;
}
function Render(){
ctx.fillStyle = "red";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = "yellow";
ctx.fillRect(100, 0, canvas.width-200, canvas.height);
ctx.fillStyle = "green";
ctx.fillRect(200, 0, canvas.width-400, canvas.height);
State -=5;
ctx.fillStyle = "white";
ctx.fillRect(State - 5, 20, 10, 10);
State = Clamp(State, 0, 500)
}
function Coef(){
if(State < 100 || State >= 400){
return -1;
}
else if(State < 200 || State >= 300){
return 0;
}
return 1;
}
setInterval(Render, 1000/60)