<!--Language english-->
<html lang="en">
<head>
<!--The title-->
<title>F2 Games Limited</title>
<!-- Adding the jQuery-->
<script src="http://code.jquery.com/jquery-git2.js"></script>
</head>
<body>
<!-- Centering the canvas-->
<center>
<!-- Setting the id and properties of canvas-->
<canvas id="gameCanvas" width="1000" height="800" style="border:5px solid green"></canvas>
<!-- Linking Javascript with the HTML-->
<script src="js/Game.js"></script>
</center>
</body>
</html>
//Setting the canvas and context
var canvas = document.getElementById('gameCanvas');
var context = canvas.getContext('2d');
//Uploading car
var car = new Image();
car.src = "http://images.clipartpanda.com/car-top-view-clipart-red-racing-car-top-view-fe3a.png";
//Setting properties of car
var x = 450;
var y = 730;
var speed = 10;
var angle = 990;
var mod = 0;
//Event listeners for keys
window.addEventListener("keydown", keypress_handler, false);
window.addEventListener("keyup", keyup_handler, false);
//Interval for animation
var moveInterval = setInterval(function () {
draw();
}, 30);
//Drawing the car turning and changing speed
function draw() {
context.clearRect(0, 0, canvas.width, canvas.height);
x += (speed * mod) * Math.cos(Math.PI / 180 * angle);
y += (speed * mod) * Math.sin(Math.PI / 180 * angle);
context.save();
context.translate(x, y);
context.rotate(Math.PI / 180 * angle);
context.drawImage(car, -(car.width / 2), -(car.height / 2));
context.restore();
}
//Setting the keys
function keyup_handler(event) {
if (event.keyCode == 38 || event.keyCode == 40) {
mod = 0;
}
}
//Setting all of the keys
function keypress_handler(event) {
console.log(x, y);
if (event.keyCode == 38) {
mod = 1;
}
if (event.keyCode == 40) {
mod = -1;
}
if (event.keyCode == 37) {
angle -= 5;
}
if (event.keyCode == 39) {
angle += 5;
}
}
//=============================================================================other car======================================================================================================================
//Uploading car
var car1 = new Image();
car1.src = "http://www.i2clipart.com/cliparts/f/e/3/a/128135fe3a51f073730a8d561282d05b4f35ab.png";
//Setting properties of car
var x1 = 450;
var y1 = 400;
var speed1 = 10;
var angle1 = 990;
var mod1 = 0;
//Event listeners for keys
window.addEventListener("keydown", keypress_handler1, false);
window.addEventListener("keyup", keyup_handler1, false);
//Interval for animation
var moveInterval = setInterval(function () {
drawCar();
}, 30);
//Drawing the car turning and changing speed
function drawCar() {
context.clearRect(0, 0, canvas.width, canvas.height);
x1 += (speed1 * mod1) * Math.cos(Math.PI / 180 * angle1);
y1 += (speed1 * mod1) * Math.sin(Math.PI / 180 * angle1);
context.save();
context.translate(x, y);
context.rotate(Math.PI / 180 * angle1);
context.drawImage(car1, -(car1.width / 2), -(car1.height / 2));
}
//Setting the keys
function keyup_handler1(event) {
if (event.keyCode == 38 || event.keyCode == 40) {
mod1 = 0;
}
}
//Setting all of the keys
function keypress_handler1(event) {
console.log(x, y);
if (event.keyCode == 87) {
mod1 = 1;
}
if (event.keyCode == 83) {
mod1 = -1;
}
if (event.keyCode == 65) {
angle1 -= 5;
}
if (event.keyCode == 68) {
angle1 += 5;
}
}
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |