Flappy Plane
About this app
A flappy bird style game where you fly a plane.
Flappy Plane
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Flappy Plane</title>
<meta name="description" content="A flappy bird style game where you fly a plane.">
<meta name="keywords" content="flappy bird, plane, game, web app">
<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-168115632457687";
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">
// App Javascript Goes Here
let canvas, ctx, plane, pipes, gravity, thrust, gameLoop, score, gameOver;
function startGame() {
canvas = document.getElementById("gameCanvas");
ctx = canvas.getContext("2d");
plane = new Plane();
pipes = [];
gravity = 0.15;
thrust = -3.5;
score = 0;
gameOver = false;
spawnPipes();
gameLoop = setInterval(updateGame, 20);
ctx.font = "20px Arial";
ctx.fillText("joeyv0.2", 10, 20);
}
function Plane() {
this.x = 50;
this.y = canvas.height / 2;
this.width = 20;
this.height = 20;
this.velocity = 0;
this.draw = function() {
ctx.fillStyle = "purple";
ctx.fillRect(this.x, this.y, this.width, this.height);
}
}
function Pipe() {
this.width = 40;
this.height = Math.floor(Math.random() * (canvas.height / 2));
this.x = canvas.width;
this.y = Math.random() > 0.5 ? 0 : canvas.height - this.height;
this.draw = function() {
ctx.fillStyle = "white";
ctx.fillRect(this.x, this.y, this.width, this.height);
}
}
function spawnPipes() {
pipes.push(new Pipe());
setTimeout(spawnPipes, 2000);
}
function updateGame() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
plane.velocity += gravity;
plane.y += plane.velocity;
for (let i = pipes.length - 1; i >= 0; i--) {
pipes[i].x -= 2;
pipes[i].draw();
if (plane.x < pipes[i].x + pipes[i].width &&
plane.x + plane.width > pipes[i].x &&
plane.y < pipes[i].y + pipes[i].height &&
plane.y + plane.height > pipes[i].y) {
gameOver = true;
endGame();
}
if (pipes[i].x < plane.x && !pipes[i].passed) {
pipes[i].passed = true;
score++;
}
if (pipes[i].x + pipes[i].width < 0) {
pipes.splice(i, 1);
}
}
if (plane.y > canvas.height || plane.y < 0) {
gameOver = true;
endGame();
}
plane.draw();
ctx.font = "20px Arial";
ctx.fillText("Score: " + score, 10, 50);
ctx.fillText("joeyv0.2", 10, 20);
}
function endGame() {
clearInterval(gameLoop);
ctx.font = "30px Arial";
ctx.fillStyle = "red";
ctx.fillText("Game Over!", canvas.width / 2 - 80, canvas.height / 2);
ctx.fillText("Your score: " + score, canvas.width / 2 - 80, canvas.height / 2 + 40);
}
function fly() {
if (!gameOver) {
plane.velocity = thrust;
}
}
document.addEventListener("DOMContentLoaded", startGame);
document.addEventListener("keydown", fly);
document.addEventListener("click", fly);
document.addEventListener("touchstart", fly);
</script>
<style>
/* App CSS Goes Here */
body {
background-color: #87CEEB;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#gameCanvas {
border: 2px solid black;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<!-- App HTML Goes Here -->
<canvas id="gameCanvas" width="400" height="600"></canvas>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!