summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-25 09:32:05 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-25 09:32:05 +0100
commit1fc522bc8c4a96858223e597ced8fea94ba57874 (patch)
treee7dc943a068d8d5ae7db0511348029700c8f767e
parentfe63ca3c64d2dd310268df7391ba6de5e9b7a2f2 (diff)
fixed background
-rw-r--r--src/engine/screen.js8
-rw-r--r--src/entities/hello_kitty.js2
-rw-r--r--src/entities/hello_kitty_background.js12
3 files changed, 14 insertions, 8 deletions
diff --git a/src/engine/screen.js b/src/engine/screen.js
index 173e285..e9e5ef4 100644
--- a/src/engine/screen.js
+++ b/src/engine/screen.js
@@ -89,10 +89,10 @@ export class Screen {
isOffLimits(position, size) {
return (
- position.x + size.x < 0 ||
- position.y + size.y < 0 ||
- position.x - size.x > this.viewport.x ||
- position.y - size.y > this.viewport.y
+ position.x + size.x / 2 < 0 ||
+ position.y + size.y / 2 < 0 ||
+ position.x - size.x / 2 > this.viewport.x ||
+ position.y - size.y / 2 > this.viewport.y
)
}
}
diff --git a/src/entities/hello_kitty.js b/src/entities/hello_kitty.js
index eb7552a..69646fd 100644
--- a/src/entities/hello_kitty.js
+++ b/src/entities/hello_kitty.js
@@ -8,7 +8,7 @@ export class HelloKitty extends Entity {
max_hp = 500
hp = this.max_hp
previous = 0
- moveInterval = 30
+ moveInterval = 26
justGotHit = false
turningRight = false
diff --git a/src/entities/hello_kitty_background.js b/src/entities/hello_kitty_background.js
index 70f0b9d..0ff405b 100644
--- a/src/entities/hello_kitty_background.js
+++ b/src/entities/hello_kitty_background.js
@@ -3,11 +3,14 @@ import { BACKGROUND } from "../assets.js"
import { Entity } from "../entities/entity.js"
import { Engine } from "../engine.js"
+// i am aware this code is a mess
+// but i don't have enough time to clean it up
+
export class HelloKittyBackground extends Entity {
speed = 20
- stage = 0
constructor(position = null) {
+ let first = (position == null)
let size = new Vector(1300, 2080)
let x_margin = 0
if (position == null) position = new Vector(
@@ -15,7 +18,6 @@ export class HelloKittyBackground extends Entity {
- (size.y / 2) + Engine.screen.viewport.y,
)
super({
- //size: new Vector(650, 1040),
size: size,
position: position,
sprite: BACKGROUND.KITTY,
@@ -23,6 +25,7 @@ export class HelloKittyBackground extends Entity {
this.span.style.zIndex = -3
this.max_down = (this.size.y / 2)
this.x_margin = x_margin
+ this.stage = first ? 0 : 1
}
update() {
@@ -39,6 +42,9 @@ export class HelloKittyBackground extends Entity {
this.stage++
return
}
- if (Engine.screen.isOffLimits(this.position, this.size)) this.remove()
+ if (
+ this.position.y > 0 &&
+ Engine.screen.isOffLimits(this.position, this.size)
+ ) this.position.y -= this.size.y * 2
}
}