Hacer variables de velocidad dinamicas y mejorar fisicas de las semillas
This commit is contained in:
parent
0a20e26554
commit
498bff2d95
1 changed files with 9 additions and 9 deletions
|
@ -3,9 +3,6 @@ import { Juego } from './main'
|
|||
import { boxCollision } from './utils'
|
||||
|
||||
const ENEMIES_NUM = 20
|
||||
const ENEMY_SPEED = 40
|
||||
const PLAYER_SPEED = 200
|
||||
const SEED_SPEED = 1000
|
||||
const SEED_COOLDOWN = 300
|
||||
const MAP_MIN = 1000
|
||||
const MAP_MAX = 5000
|
||||
|
@ -36,13 +33,15 @@ export function createJugandoState(): State {
|
|||
}
|
||||
|
||||
export function update(juego: Juego<State>, dt: number) {
|
||||
const playerSpeed = juego.canvas.width * 0.15
|
||||
const enemySpeed = juego.canvas.width * 0.05
|
||||
if (juego.keyboard.keys.d || juego.keyboard.keys.ArrowRight) {
|
||||
juego.state.side = "right"
|
||||
juego.state.pos.x += (dt / 1000) * PLAYER_SPEED
|
||||
juego.state.pos.x += (dt / 1000) * playerSpeed
|
||||
}
|
||||
if (juego.keyboard.keys.a || juego.keyboard.keys.ArrowLeft) {
|
||||
juego.state.side = "left"
|
||||
juego.state.pos.x -= (dt / 1000) * PLAYER_SPEED
|
||||
juego.state.pos.x -= (dt / 1000) * playerSpeed
|
||||
}
|
||||
|
||||
if (juego.state.pos.x < MAP_MIN) juego.state.pos.x = MAP_MIN
|
||||
|
@ -50,15 +49,16 @@ export function update(juego: Juego<State>, dt: number) {
|
|||
|
||||
juego.state.seedCooldown -= dt
|
||||
if (juego.keyboard.keys[' '] && juego.state.seedCooldown < 0) {
|
||||
const seedSpeed = juego.canvas.width * 0.7
|
||||
juego.state.seeds.push({
|
||||
x: juego.state.pos.x,
|
||||
velocity: { x: juego.state.side === "left" ? -SEED_SPEED : SEED_SPEED },
|
||||
velocity: { x: juego.state.side === "left" ? -seedSpeed : seedSpeed },
|
||||
})
|
||||
juego.state.seedCooldown = SEED_COOLDOWN
|
||||
}
|
||||
for (const seed of juego.state.seeds) {
|
||||
seed.x += (dt / 1000) * seed.velocity.x
|
||||
seed.velocity.x *= 0.9
|
||||
seed.velocity.x *= 0.97
|
||||
for (const enemy of juego.state.enemies) {
|
||||
if (boxCollision({
|
||||
x: seed.x,
|
||||
|
@ -90,9 +90,9 @@ export function update(juego: Juego<State>, dt: number) {
|
|||
for (const enemy of juego.state.enemies) {
|
||||
const distance = enemy.x - juego.state.pos.x
|
||||
if (distance < 0) {
|
||||
enemy.x += (dt / 1000) * ENEMY_SPEED
|
||||
enemy.x += (dt / 1000) * enemySpeed
|
||||
} else {
|
||||
enemy.x -= (dt / 1000) * ENEMY_SPEED
|
||||
enemy.x -= (dt / 1000) * enemySpeed
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue