Sci-Fi Fantasy Tetris

Play Tetris with sci-fi fantasy gem blocks.

Info

Created On: April 10, 2023
Created By: @CalculatorTools

AI

Model: gpt-3.5-turbo-0301
Time: 104 seconds
Prompt Tokens: 740
Completion Tokens: 2532
Total Token Cost: 3272

Get This App On Your Website

1. Copy the code above with the iframe and link.
2. Paste the code into your website.
3. Resize the iframe to fit your website.

Javascript, HTML, CSS Code

                    
<html>
<head>
<script type="text/javascript"> window.addEventListener('error', function(event) { var message = JSON.parse(JSON.stringify(event.message)); var source = event.filename; var lineno = event.lineno; var colno = event.colno; var error = event.error; window.parent.postMessage({ type: 'iframeError', details: { message: message, source: source, lineno: lineno, colno: colno, error: error ? error.stack : '' } }, '*'); }); window.addEventListener('unhandledrejection', function(event) { window.parent.postMessage({ type: 'iframePromiseRejection', details: { reason: event.reason } }, '*'); }); </script>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Sci-Fi Fantasy Tetris</title>
<meta name="description" content="Play Tetris with sci-fi fantasy gem blocks.">
<meta name="keywords" content="tetris, sci-fi, fantasy, gems">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<!-- Built-In Functions for Apps -->
<script type="text/javascript">
var localStoragePrefix = "ct-168115628517182";
var lastSave = 0;
// save to localstorage
function saveLocal(data) {
if (Date.now() - lastSave < 1000) {
return;
}
// save to cookie
let cookie = localStoragePrefix + "=" + JSON.stringify(data) + "; path=" + window.location.pathname + "'; SameSite=Strict";
cookie += "; expires=" + new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 1000).toUTCString();
document.cookie = cookie;
lastSave = Date.now();
}

// load from localstorage
function loadLocal() {
var cookiePrefix = localStoragePrefix + "=";
var cookieStart = document.cookie.indexOf(cookiePrefix);
if (cookieStart > -1) {
let cookieEnd = document.cookie.indexOf(";", cookieStart);
if (cookieEnd == -1) {
cookieEnd = document.cookie.length;
}
var cookieData = document.cookie.substring(cookieStart + cookiePrefix.length, cookieEnd);
return JSON.parse(cookieData);
}
}
</script>

<script type="text/javascript">
// Game Variables
var score = 0;
var level = 1;
var boardWidth = 10;
var boardHeight = 20;
var blockWidth = 30;
var blockHeight = 30;
var blockTypes = [
{
id: 1,
color: "#FFB6C1",
shape: [
[1, 1],
[1, 1]
]
},
{
id: 2,
color: "#00FFFF",
shape: [
[0, 2, 0],
[2, 2, 2]
]
},
{
id: 3,
color: "#FFD700",
shape: [
[3, 3, 0],
[0, 3, 3]
]
},
{
id: 4,
color: "#FF1493",
shape: [
[0, 4, 4],
[4, 4, 0]
]
},
{
id: 5,
color: "#00FF7F",
shape: [
[5, 5, 5],
[0, 5, 0]
]
},
{
id: 6,
color: "#800080",
shape: [
[6, 6, 6],
[6, 0, 0]
]
},
{
id: 7,
color: "#FFA500",
shape: [
[7, 7, 7, 7]
]
}
];
var currentBlock;
var currentBlockType;
var currentBlockRotation = 0;
var currentBlockX = 0;
var currentBlockY = 0;
var board = [];

// Create the game board
function createBoard() {
for (var y = 0; y < boardHeight; y++) {
board[y] = [];
for (var x = 0; x < boardWidth; x++) {
board[y][x] = 0;
}
}
}

// Create a new block
function newBlock() {
var randomType = Math.floor(Math.random() * blockTypes.length);
currentBlockType = blockTypes[randomType];
currentBlock = currentBlockType.shape;
currentBlockRotation = 0;
currentBlockX = Math.floor(Math.random() * (boardWidth - currentBlock[0].length + 1));
currentBlockY = 0;
if (checkCollision()) {
gameOver();
}
}

// Draw the game board
function drawBoard() {
var html = "";
for (var y = 0; y < boardHeight; y++) {
for (var x = 0; x < boardWidth; x++) {
var color = "";
if (board[y][x]) {
color = currentBlockType.color;
}
html += '<div class="block" style="background-color:' + color + ';"></div>';
}
}
$("#board").html(html);
}

// Draw the current block
function drawBlock() {
var html = "";
for (var y = 0; y < currentBlock.length; y++) {
for (var x = 0; x < currentBlock[y].length; x++) {
if (currentBlock[y][x]) {
var blockX = currentBlockX + x;
var blockY = currentBlockY + y;
var color = currentBlockType.color;
html += '<div class="block" style="background-color:' + color + ';"></div>';
}
}
}
$("#block").html(html);
}

// Check for collision
function checkCollision() {
for (var y = 0; y < currentBlock.length; y++) {
for (var x = 0; x < currentBlock[y].length; x++) {
if (currentBlock[y][x]) {
var blockX = currentBlockX + x;
var blockY = currentBlockY + y;
if (blockY >= boardHeight || blockX < 0 || blockX >= boardWidth || board[blockY][blockX]) {
return true;
}
}
}
}
return false;
}

// Merge the current block with the game board
function mergeBlock() {
for (var y = 0; y < currentBlock.length; y++) {
for (var x = 0; x < currentBlock[y].length; x++) {
if (currentBlock[y][x]) {
var blockX = currentBlockX + x;
var blockY = currentBlockY + y;
board[blockY][blockX] = currentBlock[y][x];
}
}
}
}

// Clear full rows and increase score
function clearRows() {
var rowsCleared = 0;
for (var y = boardHeight - 1; y >= 0; y--) {
var rowFull = true;
for (var x = 0; x < boardWidth; x++) {
if (!board[y][x]) {
rowFull = false;
break;
}
}
if (rowFull) {
rowsCleared++;
for (var i = y; i > 0; i--) {
for (var x = 0; x < boardWidth; x++) {
board[i][x] = board[i-1][x];
}
}
y++;
}
}
if (rowsCleared == 1) {
score += 100 * level;
} else if (rowsCleared == 2) {
score += 200 * level;
} else if (rowsCleared == 3) {
score += 300 * level;
} else if (rowsCleared == 4) {
score += 400 * level;
}
}

// Game over function
function gameOver() {
alert("Game Over!");
location.reload();
}

// Move the current block down
function moveDown() {
currentBlockY++;
if (checkCollision()) {
currentBlockY--;
mergeBlock();
clearRows();
newBlock();
}
}

// Move the current block left
function moveLeft() {
currentBlockX--;
if (checkCollision()) {
currentBlockX++;
}
}

// Move the current block right
function moveRight() {
currentBlockX++;
if (checkCollision()) {
currentBlockX--;
}
}

// Rotate the current block
function rotateBlock() {
var newBlock = [];
for (var y = 0; y < currentBlock[0].length; y++) {
newBlock[y] = [];
for (var x = 0; x < currentBlock.length; x++) {
newBlock[y][x] = currentBlock[currentBlock.length - 1 - x][y];
}
}
currentBlock = newBlock;
if (checkCollision()) {
currentBlock = currentBlockType.shape;
}
}

// Handle keyboard input
$(document).keydown(function(e) {
switch (e.which) {
case 37: // Left arrow
moveLeft();
break;
case 38: // Up arrow
rotateBlock();
break;
case 39: // Right arrow
moveRight();
break;
case 40: // Down arrow
moveDown();
break;
}
});

// Game loop
function gameLoop() {
moveDown();
drawBoard();
drawBlock();
setTimeout(gameLoop, 500 - level * 50);
}

// Start the game
function startGame() {
createBoard();
newBlock();
gameLoop();
}

$(document).ready(function() {
startGame();
});
</script>

<style>
/* App CSS Goes Here */
body {
background-color: #000000;
color: #FFFFFF;
}

#main-container {
margin-top: 20px;
}

#board {
width: 300px;
height: 600px;
background-color: #222222;
float: left;
}

.block {
width: 30px;
height: 30px;
margin: 0;
padding: 0;
float: left;
border: 1px solid #000000;
}

#block {
width: 90px;
height: 90px;
float: left;
margin-left: 20px;
margin-right: 20px;
}

.score {
margin-top: 10px;
}
</style>

<link rel="canonical" href="https://calculator.tools/prompt/94/">
<meta charset="utf-8">
</head>
<body>
<div id="main-container" class="container">
<div id="board"></div>
<div id="block"></div>
<div class="score">Score: <span id="score">0</span></div>
<div class="score">Level: <span id="level">1</span></div>
</div>
<script type="text/javascript"> var localStoragePrefix = "ct-{{ cachebreaker }}"; var lastSave = 0; function saveLocal(data) { if (Date.now() - lastSave < 1000) { return; } let cookie = localStoragePrefix + "=" + JSON.stringify(data) + "; path=" + window.location.pathname + "'; SameSite=Strict"; cookie += "; expires=" + new Date(Date.now() + 1000 * 60 * 60 * 24 * 365 * 1000).toUTCString(); document.cookie = cookie; lastSave = Date.now(); } function loadLocal() { var cookiePrefix = localStoragePrefix + "="; var cookieStart = document.cookie.indexOf(cookiePrefix); if (cookieStart > -1) { let cookieEnd = document.cookie.indexOf(";", cookieStart); if (cookieEnd == -1) { cookieEnd = document.cookie.length; } var cookieData = document.cookie.substring(cookieStart + cookiePrefix.length, cookieEnd); return JSON.parse(cookieData); } } </script>

<script type="text/javascript"> window.addEventListener('load', function() { var observer = new MutationObserver(function() { window.parent.postMessage({height: document.documentElement.scrollHeight || document.body.scrollHeight},"*"); }); observer.observe(document.body, {attributes: true, childList: true, subtree: true}); window.parent.postMessage({height: document.documentElement.scrollHeight || document.body.scrollHeight},"*"); }); </script>
</body>
</html>

FAQ

What is Calculator Tools?

Calculator Tools allows you to instantly create and generate any simple one page web app for free and immediately have it online to use and share. This means anything! Mini apps, calculators, trackers, tools, games, puzzles, screensavers... anything you can think of that the AI can handle.

The AI uses Javacript, HTML, and CSS programming to code your app up in moments. This currently uses GPT-4 the latest and most powerful version of the OpenAI GPT language model.

What Do You Mean Make An App?

Have you ever just wanted a simple app but didn't want to learn programming or pay someone to make it for you? Calculator Tools is the solution! Just type in your prompt and the AI will generate a simple app for you in seconds. You can then customize it to your liking and share it with your friends.

AI has become so powerful it is that simple these days.

Does This Use ChatGPT?

It uses GPT-4 which is the most powerful model for ChatGPT.

Calculator Tools does not remember things from prompt to prompt, each image is a unique image that does not reference any of the images or prompts previously supplied.