diff --git a/packages/client/index.html b/packages/client/index.html
index 34ac846..d7b32d0 100644
--- a/packages/client/index.html
+++ b/packages/client/index.html
@@ -3,7 +3,7 @@
-
+
diff --git a/packages/client/public/serviceWorker.js b/packages/client/public/serviceWorker.js
index 7a7c762..00f3c3d 100644
--- a/packages/client/public/serviceWorker.js
+++ b/packages/client/public/serviceWorker.js
@@ -1,13 +1,12 @@
const CACHE_NAME = 'cache-data-v1'
-const urlsToCache = [
- '/'
-]
+const urlsToCache = ['/']
-const networkFirst = async (request) => {
+const networkFirst = async request => {
const cache = await caches.open(CACHE_NAME)
try {
const response = await fetch(request)
- const cachePutCondition = response && response.status === 200 && response.type === 'basic'
+ const cachePutCondition =
+ response && response.status === 200 && response.type === 'basic'
if (cachePutCondition) {
await cache.put(request, response.clone())
}
@@ -25,21 +24,21 @@ const networkFirst = async (request) => {
}
}
-self.addEventListener('install', (event) => {
+self.addEventListener('install', event => {
event.waitUntil(
caches
.open(CACHE_NAME)
- .then((cache) => {
+ .then(cache => {
return cache.addAll(urlsToCache)
})
.then(() => self.skipWaiting())
- .catch((err) => {
+ .catch(err => {
console.error('Cache installation failed:', err)
})
)
})
-self.addEventListener('fetch', (event) => {
+self.addEventListener('fetch', event => {
const { request } = event
const { url, method } = request
diff --git a/packages/client/src/assets/images/sprites/Bullet.png b/packages/client/src/assets/images/sprites/Bullet.png
new file mode 100644
index 0000000..d2a21d5
Binary files /dev/null and b/packages/client/src/assets/images/sprites/Bullet.png differ
diff --git a/packages/client/src/assets/images/sprites/bang.png b/packages/client/src/assets/images/sprites/bang.png
new file mode 100644
index 0000000..b220ec0
Binary files /dev/null and b/packages/client/src/assets/images/sprites/bang.png differ
diff --git a/packages/client/src/assets/images/sprites/enemy.png b/packages/client/src/assets/images/sprites/enemy.png
new file mode 100644
index 0000000..44c3154
Binary files /dev/null and b/packages/client/src/assets/images/sprites/enemy.png differ
diff --git a/packages/client/src/assets/images/sprites/enemy.svg b/packages/client/src/assets/images/sprites/enemy.svg
deleted file mode 100644
index 51a4469..0000000
--- a/packages/client/src/assets/images/sprites/enemy.svg
+++ /dev/null
@@ -1,14 +0,0 @@
-
diff --git a/packages/client/src/assets/images/sprites/shot.png b/packages/client/src/assets/images/sprites/shot.png
new file mode 100644
index 0000000..991d07e
Binary files /dev/null and b/packages/client/src/assets/images/sprites/shot.png differ
diff --git a/packages/client/src/assets/images/sprites/steel.png b/packages/client/src/assets/images/sprites/steel.png
new file mode 100644
index 0000000..ad85f90
Binary files /dev/null and b/packages/client/src/assets/images/sprites/steel.png differ
diff --git a/packages/client/src/assets/images/sprites/tank.png b/packages/client/src/assets/images/sprites/tank.png
new file mode 100644
index 0000000..56e0a69
Binary files /dev/null and b/packages/client/src/assets/images/sprites/tank.png differ
diff --git a/packages/client/src/assets/images/sprites/tank.svg b/packages/client/src/assets/images/sprites/tank.svg
deleted file mode 100644
index 1c8083e..0000000
--- a/packages/client/src/assets/images/sprites/tank.svg
+++ /dev/null
@@ -1,14 +0,0 @@
-
diff --git a/packages/client/src/assets/images/sprites/tree.png b/packages/client/src/assets/images/sprites/tree.png
new file mode 100644
index 0000000..51bd31a
Binary files /dev/null and b/packages/client/src/assets/images/sprites/tree.png differ
diff --git a/packages/client/src/assets/images/sprites/wall.png b/packages/client/src/assets/images/sprites/wall.png
new file mode 100644
index 0000000..c84a5c9
Binary files /dev/null and b/packages/client/src/assets/images/sprites/wall.png differ
diff --git a/packages/client/src/assets/images/sprites/wall.svg b/packages/client/src/assets/images/sprites/wall.svg
deleted file mode 100644
index 380f0dd..0000000
--- a/packages/client/src/assets/images/sprites/wall.svg
+++ /dev/null
@@ -1,9 +0,0 @@
-
diff --git a/packages/client/src/components/Game/Game.tsx b/packages/client/src/components/Game/Game.tsx
index dfb0664..abedf67 100644
--- a/packages/client/src/components/Game/Game.tsx
+++ b/packages/client/src/components/Game/Game.tsx
@@ -1,15 +1,17 @@
import React, { useCallback, useEffect, useRef, useState } from 'react'
import './Game.scss'
-import { initializeEnemies } from '@/components/Game/enemy'
+import {
+ initializeCampanyEnemies,
+ initializeRandomEnemies,
+} from '@/components/Game/enemy'
import { PLAYER_DEFAULT_PARAMS } from '@/components/Game/player'
import { gameLoop } from '@/components/Game/gameLoop'
+import { handleKeyDown, handleKeyUp } from '@/components/Game/controls'
+import { AbstractEntity, Effect, Obstacle } from '@/components/Game/gameTypes'
import {
- handleKeyDown,
- handleKeyUp,
- updatePlayerMovement,
-} from '@/components/Game/controls'
-import { ControlsProps, Obstacle } from '@/components/Game/gameTypes'
-import { initializeObstacle } from '@/components/Game/obstacle'
+ initializeCompanyMapObstacle,
+ initializeRandomObstacle,
+} from '@/components/Game/obstacle'
import { Modal } from '../common/Modal/Modal'
const livesUse = 3
@@ -17,8 +19,10 @@ const livesUse = 3
export const Game: React.FC = () => {
const canvasRef = useRef(null)
const playerRef = useRef(PLAYER_DEFAULT_PARAMS)
- const enemiesRef = useRef(initializeEnemies())
- const obstaclesRef = useRef(initializeObstacle())
+ const enemiesRef = useRef(initializeRandomEnemies(5))
+ const bulletsRef = useRef([])
+ const obstaclesRef = useRef(initializeRandomObstacle(20))
+ const effectsRef = useRef([])
const livesRef = useRef(livesUse)
const [gameStarted, setGameStarted] = useState(false)
const [isPaused, setIsPaused] = useState(false)
@@ -40,19 +44,14 @@ export const Game: React.FC = () => {
if (!isPausedRef.current && !isGameOver && canvasRef.current) {
const context = canvasRef.current.getContext('2d')
if (context) {
- const moveProps: ControlsProps = {
- playerRef,
- obstacles: obstaclesRef.current,
- canvasWidth: canvasRef.current.width,
- canvasHeight: canvasRef.current.height,
- }
- updatePlayerMovement(moveProps)
-
gameLoop(
context,
+ canvasRef,
playerRef,
enemiesRef,
- obstaclesRef.current,
+ bulletsRef,
+ obstaclesRef,
+ effectsRef,
livesRef,
handleGameOver
)
@@ -86,9 +85,21 @@ export const Game: React.FC = () => {
setIsPaused(false)
isPausedRef.current = false
setIsGameOver(false)
- livesRef.current = 3
+ livesRef.current = livesUse
+ playerRef.current = { ...PLAYER_DEFAULT_PARAMS }
+ enemiesRef.current = initializeRandomEnemies(5)
+ obstaclesRef.current = initializeRandomObstacle(20)
+ }
+
+ const startCompany = () => {
+ setGameStarted(true)
+ setIsPaused(false)
+ isPausedRef.current = false
+ setIsGameOver(false)
+ livesRef.current = livesUse
playerRef.current = { ...PLAYER_DEFAULT_PARAMS }
- enemiesRef.current = initializeEnemies()
+ enemiesRef.current = initializeCampanyEnemies()
+ obstaclesRef.current = initializeCompanyMapObstacle()
}
return (
@@ -97,7 +108,10 @@ export const Game: React.FC = () => {
{!gameStarted ? (
-
+ <>
+
+
+ >
) : (