Home Web Front-end JS Tutorial Address bar shooting game code based on jquery_jquery

Address bar shooting game code based on jquery_jquery

May 16, 2016 pm 06:09 PM
Address Bar shooting game

Demo address:http://demo.jb51.net/js/2011/hunt/index.htm

Look down for gameplay
Please see the address Letter O on the bar! You use the O to shoot at the a. Use the left and right arrows on your keyboard to move the letter O. When the O moves over a, press the space bar to shoot! The game will time out for 30 seconds, press the ESC key to restart.
Note: Please use the IE browser that comes with the system to open this link.

Address bar shooting game code based on jquery_jquery

You use O to shoot at a. Use the Left Arrow and Right Arrow on your keyboard to move the letter O. When the O moves over a, press the Spacebar to shoot!
Address bar shooting game code based on jquery_jquery

Copy code The code is as follows:

(function() {
var Animal, Game;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Game = (function() {
function Game() {
this.eventReceived = __bind(this.eventReceived, this);;
this.update = __bind(this.update, this);; this.level = 1;
this.levelSize = 60;
this.playerLocation = this.levelSize / 2;
this.start();
}
Game.prototype.start = function() {
var num;
this.points = 0;
this.startTime = new Date;
this.timeLimit = 30;
this.animals = [];
for (num = 4; num >= 1; num--) {
this.addAnimal();
}
return this.interval = setInterval(this.update, 1000 / 30);
};
Game.prototype.gameOver = function() {
clearInterval(this.interval);
return location.hash = "在" (this.elapsedTime()) "秒中你共射中了" this.points "个a! (按ESC键重新开始)";
};
Game.prototype.elapsedTime = function() {
return Math.floor(((new Date).getTime() - this.startTime.getTime()) / 1000);
};
Game.prototype.addAnimal = function() {
var animal;
animal = new Animal(Math.floor(Math.random() * this.levelSize));
return this.animals.push(animal);
};
Game.prototype.removeAnimal = function(deadAnimal) {
var animal;
return this.animals = (function() {
var _i, _len, _ref, _results;
_ref = this.animals;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i ) {
animal = _ref[_i];
if (animal !== deadAnimal) {
_results.push(animal);
}
}
return _results;
}).call(this);
};
Game.prototype.isAnimalAt = function(position) {
var animal, matches;
matches = (function() {
var _i, _len, _ref, _results;
_ref = this.animals;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i ) {
animal = _ref[_i];
if (Math.floor(animal.position) === position) {
_results.push(animal);
}
}
return _results;
}).call(this);
return matches[0];
};
Game.prototype.update = function() {
var animal, position, timeLeft, url, _i, _len, _ref;
url = [];
_ref = this.animals;
for (_i = 0, _len = _ref.length; _i < _len; _i ) {
animal = _ref[_i];
animal.update(this.levelSize);
}
while (url.length < this.levelSize) {
position = url.length;
if (position === this.playerLocation) {
if (this.isAnimalAt(this.playerLocation)) {
url.push("@");
} else {
url.push("O");
}
} else if (this.isAnimalAt(position)) {
url.push("a");
} else {
url.push("-");
}
}
timeLeft = this.timeLimit - this.elapsedTime();
if (timeLeft <= 0) {
return this.gameOver();
} else {
if (timeLeft < 10) {
timeLeft = "0" timeLeft;
}
location.hash = (" " timeLeft "|") url.join("") ("|" timeLeft);
return document.title = "Points " this.points;
}
};
Game.prototype.eventReceived = function(event) {
var animal;
switch (event.which) {
case 37:
this.playerLocation -= 1;
if (this.playerLocation < 0) {
return this.playerLocation = this.levelSize - 1;
}
break;
case 39:
this.playerLocation = 1;
return this.playerLocation %= this.levelSize;
case 38:
case 32:
animal = this.isAnimalAt(this.playerLocation);
if (animal) {
this.points = 1;
this.removeAnimal(animal);
console.log(this.animals.length);
if (this.animals.length === 0) {
return this.gameOver();
}
}
break;
case 27:
return this.start();
}
};
return Game;
})();
Animal = (function() {
function Animal(position) {
this.position = position;
this.velocityChange = Math.random() * 0.5;
this.velocityIndex = Math.random() * Math.PI;
this.dampener = 0.4;
}
Animal.prototype.update = function(levelSize) {
this.velocityIndex = Math.random() * this.velocityChange;
this.position = Math.sin(this.velocityIndex) * this.dampener;
this.position %= levelSize;
if (this.position < 0) {
return this.position = levelSize;
}
};
return Animal;
})();
$(function() {
var game;
game = new Game();
return $(document).keydown(game.eventReceived);
});
}).call(this);
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Fix Google Translate Not Working in Chrome on Windows 10/11 How to Fix Google Translate Not Working in Chrome on Windows 10/11 Apr 15, 2023 pm 12:04 PM

Chrome has an integrated Google Translate module that helps improve users’ browsing experience. When you are looking for information on the internet, you find something that looks suitable, but everything on this page is in a foreign language, which makes it very painful. However, if you are using the Chrome browser, you can translate this page into any language of your choice. Translate entire web pages in French, Spanish, German, Dutch and other foreign languages ​​into your preferred language with just one click. However, over time, users encountered an issue where the integrated translation feature in Chrome stopped working and they were unable to translate web pages. Many Google Chrome users have reported seeing error messages when they open a foreign language webpage and try to translate it.

10 Ways to Easily Find Safari Tabs on iPhone and iPad 10 Ways to Easily Find Safari Tabs on iPhone and iPad Jun 03, 2023 pm 01:05 PM

Web browsing in 2022 is likely to be extremely hectic, resulting in a mountain of tags ranging from basic to unnecessary and even unwarranted. Therefore, the browser must provide a way to quickly find specific tabs that are relevant to you. Fortunately, Safari allows you to search for tabs based on multiple identifiers (i.e. website, recently closed tab, previous/next tab, etc.). This article will take you step by step through all the above methods of finding Safari tabs. So without further ado, let’s find the tag you’re looking for. New features for tabs in Safari with iOS15 Apple has made improvements to Safari’s UI and functionality with the release of iOS15. This update

How to get the address bar address How to get the address bar address Sep 28, 2023 am 11:00 AM

Methods to obtain the address bar address include JavaScript, HTML, back-end programming languages, etc. Detailed introduction: 1. JavaScript. In front-end development, you can use JavaScript to obtain the address bar address. You can use the "window.location" object to obtain the address bar information. The "window.location.href" attribute can obtain the complete address. Column address; 2. HTML, in HTML you can use the "href" of the "<a>" tag, etc.

How to clear chrome address bar records in win10 How to clear chrome address bar records in win10 Mar 28, 2024 pm 02:52 PM

1. Click [Settings] in the menu, or enter [chrome://settings/] in the chrome address bar and press Enter. 2. Click [Show advanced settings] at the bottom of the page. ], as shown in the figure: 3. Click [Clear Browsing Data] under [Privacy Settings]. ] button, as shown in the figure:

How to display web page prefix in the address bar of Google Chrome How to display web page prefix in the address bar of Google Chrome Aug 23, 2024 am 07:31 AM

How to display web page prefix in the address bar of Google Chrome? The address bar of Google Chrome is one of the most important parts of the entire interface, which allows users to access web pages on the Internet by entering URLs. We can browse and manage web pages through the address bar. For example, you can let it display the URL prefix. Friends who don't know how to set it can take a look at the simple method below. By adjusting these features, we can get a better web browsing experience. Simple method teaching 1. First, we open the browser, enter "chrome://flags/#omnibox-context-menu-show-full-urls" in the address bar, and press the Enter key (as shown in the picture). 2. Then enter the new interface and find the

Dark Zone Breakout Story Background Dark Zone Breakout Story Background Oct 12, 2024 am 06:21 AM

Introduction to the background story of the game Dark Zone Breakout: "Dark Zone Breakout" is a hard-core shooting mobile game released by Tencent. The ultimate goal of the game is to evacuate from the dark zone and return fully loaded with supplies. The loot brought out can be stored in the warehouse and sold for money. Different from traditional competitive shooting games, "Dark Zone Breakout" is a tactical shooting game that focuses on PVP and PVE gameplay. It provides Dark Zone pioneers with a more open, free, and realistic hard-core gaming experience. In the game, the number of people, the number of teams, the positions of enemies, and the goals in each round are different. It is this uncertainty that makes every battle situation unpredictable. Only by continuously collecting information and combining your own goals, and making corresponding equipment and tactical choices, can you find your own way to break out.

Mobile games similar to Dark Zone Breakout Mobile games similar to Dark Zone Breakout Oct 11, 2024 pm 07:07 PM

Survival shooting mobile games have always been one of the favorite game categories among players. What mobile games are similar to Dark Zone Breakout? 1. "Call of Duty Mobile" "Call of Duty Mobile" is a massively multiplayer online first-person shooter mobile game. Players will be on the same map with many players, competing in strategy and design skills, and the player or team that wins in the end will be left behind. The ultimate picture quality, ultra-smooth feel, highly restored classic maps and exciting sound effects bring players unparalleled visual and auditory enjoyment. This is the reason why countless players choose this mobile game. More importantly, this mobile game update adds a new mode and unlocks more weapons and equipment for players to collect and choose. 2. "Dawn of Civilization" How can desperate people survive in this wasteland? this game

Dark Zone Breakout background story Dark Zone Breakout background story Oct 11, 2024 pm 08:28 PM

Dark Zone Breakout game background story introduction "Dark Zone Breakout" is a hard-core shooting mobile game released by Tencent. The ultimate goal of the game is to evacuate from the dark zone and return fully loaded with supplies. The loot brought out can be stored in the warehouse and sold for money. Different from traditional competitive shooting games, "Dark Zone Breakout" is a tactical shooting game that focuses on PVP and PVE gameplay. It provides Dark Zone pioneers with a more open, free, and realistic hard-core gaming experience. In the game, the number of people, the number of teams, the positions of enemies, and the goals in each round are different. It is this uncertainty that makes every battle situation unpredictable. Only by continuously collecting information and combining your own goals, and making corresponding equipment and tactical choices, can you find your own way to break out. exist

See all articles