summaryrefslogtreecommitdiff
path: root/src/engine/screen.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/screen.js')
-rw-r--r--src/engine/screen.js51
1 files changed, 48 insertions, 3 deletions
diff --git a/src/engine/screen.js b/src/engine/screen.js
index e9e5ef4..b1da92d 100644
--- a/src/engine/screen.js
+++ b/src/engine/screen.js
@@ -76,11 +76,12 @@ export class Screen {
///////////////////// COMMANDS //////////////////////
append(element) { this.spawn.appendChild(element) }
- draw(span, position, size, /* rotation = 0 */) {
+ draw(span, position, size, rotation) {
span.style.width = `${size.x * this.scale}px`
span.style.height = `${size.y * this.scale}px`
- span.style.top = `${(position.y - size.y / 2) * this.scale}px`
- span.style.left = `${(position.x - size.x / 2) * this.scale}px`
+ span.style.top = `${(position.y - size.y / 2 + this.additionalPosition.y) * this.scale}px`
+ span.style.left = `${(position.x - size.x / 2 + this.additionalPosition.x) * this.scale}px`
+ span.style.rotate = `${rotation}deg`
}
setBackground(img) { this.background.src = img }
@@ -95,4 +96,48 @@ export class Screen {
position.y - size.y / 2 > this.viewport.y
)
}
+
+ shaking = false
+ additionalPosition = new Vector(0, 0)
+ shake() {
+ this.shaking = true
+ this.shakingTimeLeft = 6
+ }
+
+ update() {
+ if (this.shaking) {
+ switch (this.shakingTimeLeft) {
+ case 6:
+ this.additionalPosition.x = 9
+ this.additionalPosition.y = -3
+ break
+
+ case 5:
+ this.additionalPosition.x = -8
+ this.additionalPosition.y = 2
+ break
+
+ case 4:
+ this.additionalPosition.x = 5
+ this.additionalPosition.y = 1
+ break
+
+ case 3:
+ this.additionalPosition.x = -4
+ this.additionalPosition.y = -2
+ break
+
+ case 2:
+ this.additionalPosition.x = 3
+ this.additionalPosition.y = -1
+ break
+
+ case 1:
+ this.additionalPosition.x = 0
+ this.shaking = false
+ break
+ }
+ this.shakingTimeLeft --
+ }
+ }
}