Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Gra internetowa</title>
- <style>
- html, body {
- margin: 0;
- padding: 0;
- height: 100%;
- overflow: hidden;
- }
- #game-container {
- position: relative;
- width: 100vw;
- height: 100vh;
- border: 1px solid black;
- display: none;
- }
- #catcher {
- position: absolute;
- bottom: 5vh;
- width: 11.6vw;
- height: 3vh;
- background-color: blue;
- border-radius: 0; /* Default: no rounded corners */
- transition: border-radius 0.3s; /* Smooth transition */
- }
- #catcher.rounded {
- border-radius: 215px; /* Rounded corners when toggled */
- }
- .object {
- position: absolute;
- width: 1.7vw;
- height: 1.7vw;
- background-color: red;
- }
- #end-message {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- font-weight: bold;
- font-size: 45px;
- display: none;
- text-align: center;
- }
- .menu-container {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- text-align: center;
- font-size: 19px;
- }
- .menu-title {
- font-weight: bold;
- font-size: 40px;
- }
- .menu-item {
- font-size: 19px;
- cursor: pointer;
- margin-bottom: 10px;
- }
- .clickable-text {
- font-size: 19px;
- cursor: pointer;
- font-weight: 100;
- margin-bottom: 28px;
- color: black;
- }
- .color-palette {
- display: none;
- justify-content: center;
- margin-bottom: 20px;
- }
- .color-swatch {
- width: 40px;
- height: 40px;
- border: 2px solid #000;
- margin: 0 5px;
- cursor: pointer;
- }
- /* New CSS for green text highlight */
- .highlight-green {
- color: #05f545;
- }
- </style>
- </head>
- <body>
- <div id="game-container">
- <div id="catcher"></div>
- </div>
- <div id="end-message">
- Koniec Gry! Twój wynik to: <span id="score"></span><br>
- <div class="clickable-text" onclick="restartGame()">Zagraj ponownie</div>
- <div class="clickable-text" onclick="goToMenu()">Wróć do menu</div>
- </div>
- <div id="main-menu" class="menu-container">
- <div class="menu-title">Menu główne</div>
- <br>
- <div class="menu-item" onclick="startGame()">Zacznij grać</div>
- <br>
- <div class="menu-item" onclick="showSettings()">Ustawienia</div>
- <br>
- <div class="menu-item" onclick="showControls()">Sterowanie</div>
- <br>
- <div class="menu-item" onclick="showHowToPlay()">Jak grać</div>
- </div>
- <div id="settings-menu" class="menu-container" style="display: none;">
- <div class="menu-item" onclick="hideSettings()"><b>Wróć</b></div>
- <div class="menu-item" onclick="togglePaddleShape()">Zmień kształt paletki</div>
- <br>
- <div class="clickable-text" onclick="toggleColorPalette()">Zmień kolor paletki</div>
- <div class="color-palette">
- <div class="color-swatch" style="background-color: red;" onclick="setPaddleColor('red')"></div>
- <div class="color-swatch" style="background-color: orange;" onclick="setPaddleColor('orange')"></div>
- <div class="color-swatch" style="background-color: yellow;" onclick="setPaddleColor('yellow')"></div>
- <div class="color-swatch" style="background-color: green;" onclick="setPaddleColor('green')"></div>
- <div class="color-swatch" style="background-color: blue;" onclick="setPaddleColor('blue')"></div>
- <div class="color-swatch" style="background-color: purple;" onclick="setPaddleColor('purple')"></div>
- </div>
- <div class="menu-item" id="toggle-color-change" onclick="toggleCubeColorChange()">Przestań zmieniać kolory kwadracików</div>
- </div>
- <div id="controls-menu" class="menu-container" style="display: none;">
- <div class="menu-item" onclick="hideControls()"><b>Wróć</b></div>
- <div>Poruszaj myszką w lewo i prawo, aby sterować niebieską paletką.</div>
- </div>
- <div id="how-to-play-menu" class="menu-container" style="display: none;">
- <div class="menu-item" onclick="hideHowToPlay()"><b>Wróć</b></div>
- <div>Zbieraj paletką kolorowe kwadraciki aby zdobywać punkty. Jeżeli ominiesz jednego, to przegrywasz!</div>
- </div>
- <script>
- var gameContainer = document.getElementById("game-container");
- var catcher = document.getElementById("catcher");
- var endMessage = document.getElementById("end-message");
- var scoreDisplay = document.getElementById("score");
- var score = 0;
- var missedCubes = 0;
- var cubes = [];
- var initialInterval = 1500;
- var intervalDecreaseRate = 0.9;
- var minInterval = 500;
- var speedIncreaseRate = 0.1;
- var cubeSpeed = 1.0;
- var collectedCubes = 0;
- var colorChangeInterval = 500;
- var changingCubeColors = true;
- var paddleShape = 'rectangle';
- var paddleColor = 'blue';
- var mainMenu = document.getElementById("main-menu");
- var settingsMenu = document.getElementById("settings-menu");
- var controlsMenu = document.getElementById("controls-menu");
- var howToPlayMenu = document.getElementById("how-to-play-menu");
- var objectCreationInterval;
- function startGame() {
- mainMenu.style.display = "none";
- settingsMenu.style.display = "none";
- controlsMenu.style.display = "none";
- howToPlayMenu.style.display = "none";
- gameContainer.style.display = "block";
- catcher.style.display = "block";
- score = -4;
- scoreDisplay.textContent = score;
- collectedCubes = 0;
- cubeSpeed = 1.0;
- colorChangeInterval = 500;
- catcher.style.backgroundColor = paddleColor;
- if (paddleShape === 'rounded') {
- catcher.classList.add('rounded');
- } else {
- catcher.classList.remove('rounded');
- }
- initializeGame();
- }
- function showSettings() {
- mainMenu.style.display = "none";
- settingsMenu.style.display = "block";
- }
- function hideSettings() {
- settingsMenu.style.display = "none";
- mainMenu.style.display = "block";
- }
- function showControls() {
- mainMenu.style.display = "none";
- controlsMenu.style.display = "block";
- }
- function hideControls() {
- controlsMenu.style.display = "none";
- mainMenu.style.display = "block";
- }
- function showHowToPlay() {
- mainMenu.style.display = "none";
- howToPlayMenu.style.display = "block";
- }
- function hideHowToPlay() {
- howToPlayMenu.style.display = "none";
- mainMenu.style.display = "block";
- }
- function setPaddleColor(color) {
- paddleColor = color;
- catcher.style.backgroundColor = paddleColor;
- hideColorPalette();
- }
- function toggleColorPalette() {
- var colorPalette = document.querySelector(".color-palette");
- colorPalette.style.display = colorPalette.style.display === "flex" ? "none" : "flex";
- }
- function hideColorPalette() {
- var colorPalette = document.querySelector(".color-palette");
- colorPalette.style.display = "none";
- }
- function togglePaddleShape() {
- paddleShape = (paddleShape === 'rectangle') ? 'rounded' : 'rectangle';
- catcher.classList.toggle('rounded', paddleShape === 'rounded');
- highlightText('Zmień kształt paletki');
- }
- function highlightText(menuItemText) {
- var menuItem = Array.from(document.querySelectorAll('.menu-item')).find(item => item.textContent.trim() === menuItemText);
- if (menuItem) {
- menuItem.classList.add('highlight-green');
- setTimeout(function() {
- menuItem.classList.remove('highlight-green');
- }, 200);
- }
- }
- function toggleCubeColorChange() {
- changingCubeColors = !changingCubeColors;
- document.getElementById("toggle-color-change").textContent = changingCubeColors ? "Przestań zmieniać kolory kwadracików" : "Zacznij zmieniać kolory kwadracików";
- cubes.forEach(cube => {
- if (changingCubeColors) {
- startCubeColorChange(cube);
- } else {
- stopCubeColorChange(cube);
- }
- });
- console.log('Toggled cube color change. New state:', changingCubeColors);
- }
- function startCubeColorChange(cube) {
- const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple'];
- let currentColorIndex = 0;
- // Clear any existing interval
- if (cube.colorChangeIntervalId) {
- clearInterval(cube.colorChangeIntervalId);
- }
- cube.colorChangeIntervalId = setInterval(() => {
- currentColorIndex = (currentColorIndex + 1) % colors.length;
- cube.style.backgroundColor = colors[currentColorIndex];
- }, colorChangeInterval);
- console.log('Started color change for cube:', cube, 'Interval ID:', cube.colorChangeIntervalId);
- }
- function stopCubeColorChange(cube) {
- if (cube.colorChangeIntervalId) {
- console.log('Clearing interval for cube:', cube, 'Interval ID:', cube.colorChangeIntervalId);
- clearInterval(cube.colorChangeIntervalId);
- cube.colorChangeIntervalId = undefined; // Clear the interval ID
- cube.style.backgroundColor = 'red'; // Reset color to red
- } else {
- console.log('No interval to clear for cube:', cube);
- }
- }
- function adjustColorChangeSpeed(factor) {
- colorChangeInterval = Math.max(colorChangeInterval * factor, 100);
- cubes.forEach(cube => {
- if (changingCubeColors && cube.colorChangeIntervalId) {
- stopCubeColorChange(cube);
- startCubeColorChange(cube);
- }
- });
- }
- function adjustObjectCreationInterval() {
- if (objectCreationInterval) {
- clearInterval(objectCreationInterval);
- }
- var newInterval = initialInterval;
- if (collectedCubes >= 1) {
- newInterval *= 0.001; // More frequent
- }
- newInterval = Math.max(newInterval * intervalDecreaseRate, minInterval);
- objectCreationInterval = setInterval(createObject, newInterval);
- }
- function createObject() {
- var object = document.createElement("div");
- object.className = "object";
- var containerWidth = gameContainer.offsetWidth;
- var objectWidth = object.offsetWidth;
- var maxObjectX = containerWidth - objectWidth;
- var objectX = Math.floor(Math.random() * maxObjectX);
- object.style.left = objectX + "px";
- object.style.top = "0px";
- object.colorChangeIntervalId = undefined; // Initialize interval ID
- cubes.push(object);
- gameContainer.appendChild(object);
- var objectCaught = false;
- var animationInterval = setInterval(function() {
- var objectY = object.offsetTop;
- var containerHeight = gameContainer.offsetHeight;
- if (!objectCaught && objectY + object.offsetHeight >= catcher.offsetTop &&
- objectY <= catcher.offsetTop + catcher.offsetHeight &&
- isColliding(catcher, object)) {
- objectCaught = true;
- clearInterval(animationInterval);
- gameContainer.removeChild(object);
- cubes.splice(cubes.indexOf(object), 1);
- score++;
- scoreDisplay.textContent = score;
- cubeSpeed += speedIncreaseRate;
- collectedCubes++;
- if (collectedCubes % 5 === 0) {
- adjustColorChangeSpeed(0.75);
- }
- if (collectedCubes % 10 === 0) {
- adjustObjectCreationInterval();
- }
- } else if (objectY >= containerHeight) {
- clearInterval(animationInterval);
- gameContainer.removeChild(object);
- cubes.splice(cubes.indexOf(object), 1);
- missedCubes++;
- if (missedCubes >= 1) {
- endGame();
- }
- } else {
- object.style.top = (objectY + cubeSpeed) + "px";
- }
- }, 10);
- if (changingCubeColors) {
- startCubeColorChange(object);
- }
- }
- function isColliding(catcher, object) {
- var catcherRect = catcher.getBoundingClientRect();
- var objectRect = object.getBoundingClientRect();
- return !(objectRect.right < catcherRect.left ||
- objectRect.left > catcherRect.right ||
- objectRect.bottom < catcherRect.top ||
- objectRect.top > catcherRect.bottom);
- }
- function endGame() {
- clearInterval(objectCreationInterval);
- gameContainer.style.display = "none";
- endMessage.style.display = "block";
- scoreDisplay.textContent = score;
- }
- function restartGame() {
- endMessage.style.display = "none";
- startGame();
- }
- function goToMenu() {
- endMessage.style.display = "none";
- mainMenu.style.display = "block";
- }
- function initializeGame() {
- objectCreationInterval = setInterval(createObject, initialInterval);
- }
- document.addEventListener('mousemove', function(event) {
- var containerRect = gameContainer.getBoundingClientRect();
- var mouseX = event.clientX - containerRect.left;
- var catcherWidth = catcher.offsetWidth;
- var newLeft = Math.max(0, Math.min(mouseX - catcherWidth / 2, gameContainer.offsetWidth - catcherWidth));
- catcher.style.left = newLeft + 'px';
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement