Interactive Actor Game
Nov 2, 2023
v.0
An interactive 2d game where actors can display graphics, move, and interact with each other. Game Interactive 2D Movement Graphics Actors Interaction

Versions  

Bugs  
None!

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

                
<!DOCTYPE html>
<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>Pixel Adventure Game</title>
<meta name="description" content="A 2D pixel adventure game where a ghost girl collects skulls and avoids zombies.">
<meta name="keywords" content="pixel adventure, game, 2d, ghost girl, skulls, zombies">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.2/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">

<style>
/* App CSS Goes Here */
#gameCanvas {
border: 1px solid #000;
background: url('https://images.unsplash.com/photo-1560807707-3b7f5e9f6fdd') no-repeat center center fixed;
background-size: cover;
}
</style>

<link rel="canonical" href="https://calculator.tools/app/interactive-actor-game-566/">
<meta charset="utf-8">

</head>
<body>
<div id="main-container" class="container">
<canvas id="gameCanvas" width="480" height="320"></canvas>
</div>

<script type="text/javascript">
try {
var actors = []; // Store all actors
var userActor; // The actor controlled by the user
var canvas = document.getElementById("gameCanvas");
var ctx = canvas.getContext("2d");
var score = 0;
var collectiblesCollected = 0;
var isGameOver = false;
var isGameWon = false;

function Actor(x, y, color) { // Actor class
this.x = x;
this.y = y;
this.color = color;
this.dx = 0; // Change in x
this.dy = 0; // Change in y
this.size = 20;
}

Actor.prototype.draw = function() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI*2);
ctx.fillStyle = this.color;
ctx.fill();
ctx.closePath();
};

Actor.prototype.update = function() {
this.x += this.dx;
this.y += this.dy;
};

// Create user actor
userActor = new Actor(canvas.width/2, canvas.height-30, "#F0FFFF");
actors.push(userActor);

// Create collectible item
var collectible = new Actor(Math.random() * (canvas.width - 40) + 20, Math.random() * (canvas.height - 40) + 20, "#FFFFFF");
collectible.size = 10;
actors.push(collectible);

// Create creature actors
for(var i = 0; i < 5; i++) {
var creature = new Actor(Math.random() * (canvas.width - 40) + 20, Math.random() * (canvas.height - 40) + 20, "#00FF00");
creature.size = 15;
actors.push(creature);
}

// Event listener for user control
document.addEventListener("keydown", function(event) {
if(event.key == "Right" || event.key == "ArrowRight") {
userActor.dx = 2;
}
else if(event.key == "Left" || event.key == "ArrowLeft") {
userActor.dx = -2;
}
});

document.addEventListener("keyup", function(event) {
if(event.key == "Right" || event.key == "ArrowRight") {
userActor.dx = 0;
}
else if(event.key == "Left" || event.key == "ArrowLeft") {
userActor.dx = 0;
}
});

canvas.addEventListener("touchstart", function(event) {
var touchX = event.touches[0].clientX;
if(touchX < userActor.x) {
userActor.dx = -2;
}
else if(touchX > userActor.x) {
userActor.dx = 2;
}
});

canvas.addEventListener("touchend", function(event) {
userActor.dx = 0;
});

function shrinkActor() {
if(userActor.size > 10) {
userActor.size -= 5;
}
else {
isGameOver = true;
}
}

function detectCollision() {
for(var i = 1; i < actors.length; i++) {
var dx = userActor.x - actors[i].x;
var dy = userActor.y - actors[i].y;
var distance = Math.sqrt(dx * dx + dy * dy);

if(distance < userActor.size + actors[i].size) {
if(i === 1) {
collectiblesCollected++;
score++;
if(collectiblesCollected === 5) {
isGameWon = true;
}
collectible.x = Math.random() * (canvas.width - 40) + 20;
collectible.y = Math.random() * (canvas.height - 40) + 20;
}
else {
shrinkActor();
}
actors.splice(i, 1);
break;
}
}
}

function drawActors() {
for(var i = 0; i < actors.length; i++) {
actors[i].draw();
}
}

function updateActors() {
for(var i = 0; i < actors.length; i++) {
actors[i].update();
}
}

function drawScore() {
ctx.font = "16px Arial";
ctx.fillStyle = "#000000";
ctx.fillText("Score: " + score, 8, 20);
}

function drawGameOver() {
ctx.font = "40px Arial";
ctx.fillStyle = "#FF0000";
ctx.fillText("Game Over", canvas.width/2 - 120, canvas.height/2);
}

function drawGameWon() {
ctx.font = "40px Arial";
ctx.fillStyle = "#00FF00";
ctx.fillText("You Won!", canvas.width/2 - 100, canvas.height/2);
}

function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
if(!isGameOver && !isGameWon) {
drawActors();
updateActors();
detectCollision();
drawScore();
requestAnimationFrame(draw);
}
else if(isGameOver) {
drawGameOver();
}
else if(isGameWon) {
drawGameWon();
}
}

draw();

} catch (error) {
throw error;
}
</script>
<script type="text/javascript"> var localStoragePrefix = "ct-566"; 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>

NEW APPS

These are apps made by the community!

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.