Click here for free DL of the app version that can save data.
No:42254 58
Prev Next
A game where you play as a cube dashing infinitely..ALL
Developer User18852|Date and time 24/2/11 8:20:30
Build time 13.258 sec|Game capacity 4.207KB|Script


Sure! Below is a sample implementation of the game you described using HTML and JavaScript. The game will run inside a `` element and can be played by tapping or clicking on the screen to make the cube jump. Pictograms are // Cube object var Cube = function() { this.x = 50; this.y = canvas.height / 2; this.speed = 2; }; Cube.prototype.draw = function() { ctx.fillStyle = "blue"; ctx.fillRect(this.x, this.y, 20, 20); }; Cube.prototype.update = function() { this.x += this.speed; // Check collision with spikes if (spikes.checkCollision(this.x, this.y)) { gameOver(); } // Check if cube reached the portal if (portal.checkCollision(this.x, this.y)) { gameWon(); } }; // Spikes object var Spikes = function() { this.position = [ { x: 200, y: canvas.height / 2 }, { x: 300, y: canvas.height / 2 }, { x: 400, y: canvas.height / 2 } ]; }; Spikes.prototype.draw = function() { ctx.fillStyle = "red"; for (var i = 0; i < this.position.length; i++) { ctx.fillRect(this.position[i].x, this.position[i].y, 10, 30); } }; Spikes.prototype.checkCollision = function(cubeX, cubeY) { for (var i = 0; i < this.position.length; i++) { var spikeX = this.position[i].x; var spikeY = this.position[i].y; if (cubeX + 20 >= spikeX && cubeX <= spikeX + 10 && cubeY + 20 >= spikeY && cubeY <= spikeY + 30) { return true; } } return false; }; // Portal object var Portal = function() { this.x = 500; this.y = canvas.height / 2; this.width = 20; this.height = 40; }; Portal.prototype.draw = function() { ctx.fillStyle = "green"; ctx.fillRect(this.x, this.y, this.width, this.height); }; Portal.prototype.checkCollision = function(cubeX, cubeY) { if (cubeX + 20 >= this.x && cubeY + 20 >= this.y && cubeY <= this.y + this.height) { return true; } return false; }; // Game initialization function init() { canvas = document.getElementById("gameCanvas"); ctx = canvas.getContext("2d"); cube = new Cube(); spikes = new Spikes(); portal = new Portal(); isGameOver = false; isGameWon = false; gameLoop = setInterval(update, 10); } // Game update function update() { ctx.clearRect(0, 0, canvas.width, canvas.height); if (!isGameOver && !isGameWon) { cube.update(); } cube.draw(); spikes.draw(); portal.draw(); } // Game over function gameOver() { clearInterval(gameLoop); isGameOver = true; setTimeout(function() { init(); }, 1000); } // Game won function gameWon() { clearInterval(gameLoop); isGameWon = true; setTimeout(function() { init(); }, 1000); } // Handle screen tap/click document.addEventListener("mousedown", function(event) { if (!isGameOver && !isGameWon) { cube.y -= 50; // Jump height } }); // Start the game init();

To play the game, copy the code above and save it as an HTML file with a .html extension. Open the file in a web browser, and you should be able to play the cube dash game on your smartphone or desktop.

Prev Next   Back  0  0 Menu 

[PR]現在の売れ筋Kindle本ランキング

Click here for free DL of the app version that can save data.

(C)2023 HisashiApp