-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.js
117 lines (107 loc) · 3.52 KB
/
engine.js
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
console.info("Uses Move v1.0 by CornSeller");
function geid(id) {
return document.getElementById(id);
}
function gec(classN) {
return document.getElementsByClassName(classN);
}
function moveTarget(mt) {
return mTarget = geid(mt);
}
function cls() {
return console.clear();
}
function l(a) {
return console.log(a);
}
function e(a) {
return console.error(a);
}
function i(a) {
return console.info(a);
}
function w(a) {
return console.warn(a);
}
function d(a) {
return console.debug(a);
}
function setSprite(a, b) {
if (b) {mTarget.backgroundColor = 'rgba(0, 0, 0, 0)';}
mTarget.style.backgroundSize = 'cover'; // upewnia sie że całe zdjecie weźmie w kadr backgroundu
mTarget.style.backgroundImage = 'url("' + a + '")';
return;
}
/*var Sprites = {
spriteUp: undefined,
spriteDown: undefined,
spriteLeft: undefined,
spriteRight: undefined
};
function setSprites(a, b, c, d) {
} #TO BE ADDED# */
addEventListener('keydown', function(event){
switch(event.key) {
case 'w':
movement(mTarget, true, false, false, false);
break;
case 'a':
movement(mTarget, false, false, true, false);
break;
case 's':
movement(mTarget, false, true, false, false);
break;
case 'd':
movement(mTarget, false, false, false, true);
break;
}
});
function movement(mTarget, moveUp, moveDown, moveLeft, moveRight) {
if (!mTarget) { return;}
if (moveUp) { move(1);}
else if (moveDown) { move(2);}
else if (moveLeft) { move(3);}
else if (moveRight) { move(4);}
else {console.error('Move v1.0: Something went wrong during movement!');}
function move(parimeter) {
const currentTop = parseInt(mTarget.style.top || 0, 10);
const currentLeft = parseInt(mTarget.style.left || 0, 10);
switch (parimeter) {
case 1:
mTarget.style.top = (currentTop - 15) + 'px';
break;
case 2:
mTarget.style.top = (currentTop + 15) + 'px';
break;
case 3:
mTarget.style.left = (currentLeft - 15) + 'px';
break;
case 4:
mTarget.style.left = (currentLeft + 15) + 'px';
break;
default:
console.error('Move v1.0: Something went wrong during movement!');
break;
}
}
}
function move(parimeter) {
const currentTop = parseInt(moveTarget.style.top || 0, 10);
const currentLeft = parseInt(moveTarget.style.left || 0, 10); // na przyszłość: parseInt zamienia string na integer, wpierw sprawdza czy przypisać jako liczba wartość a jak tej wartości nie ma oddaje zero a nastepnie ", 10" oznacza ustawianie liczb jako Base 10 (system liczbowy dziesiętny czyli zwykły).
//console.log('moveTarget moved!');
switch (parimeter) {
case 1:
moveTarget.style.top = (currentTop - 15) + 'px';
break;
case 2:
moveTarget.style.top = (currentTop + 15) + 'px';
break;
case 3:
moveTarget.style.left = (currentLeft - 15) + 'px';
break;
case 4:
moveTarget.style.left = (currentLeft + 15) + 'px';
break;
}
}
function preventOOB() {}