Embedded Codes For Games
Nov 4th, 2019
Never

The width of the game window will auto-adjust to fit the available space on PC, tablet or smartphone. The games are made in HTML5 and will run in any web browser. No flash player needed. How to embed a game. Simply copy the embed code below and paste it where you want the game to appear on your page. Make sure to copy the complete code. Free games for your website, simply copy and paste the code of each game you want to add to your page. We did all of the work for you. Your source for fun, free games, services, freeware. Example code for shooting game
Not a member of Pastebin yet?Sign Up, it unlocks many cool features!
- <html>
- <title></title>
- html, body {
- margin: 0;
- body {
- display: flex;
- justify-content: center;
- canvas {
- }
- </head>
- <canvas width='400' height='400'></canvas>
- var canvas = document.getElementById('game');
- var grid = 16;
- x: 160,
- // snake velocity. moves one grid length every frame in either the x or y direction
- dy: 0,
- // keep track of all grids the snake body occupies
- // length of the snake. grows when eating an apple
- };
- x: 320,
- };
- // @see https://stackoverflow.com/a/1527820/2124254
- return Math.floor(Math.random() * (max - min)) + min;
- // game loop
- requestAnimationFrame(loop);
- // slow game loop to 15 fps instead of 60 (60/15 = 4)
- return;
- count = 0;
- context.clearRect(0,0,canvas.width,canvas.height);
- snake.x += snake.dx;
- // wrap snake position horizontally on edge of screen
- snake.x = canvas.width - grid;
- else if (snake.x >= canvas.width) {
- }
- // wrap snake position vertically on edge of screen
- snake.y = canvas.height - grid;
- else if (snake.y >= canvas.height) {
- }
- // keep track of where snake has been. front of the array is always the head
- // remove cells as we move away from them
- snake.cells.pop();
- // draw apple
- context.fillRect(apple.x, apple.y, grid-1, grid-1);
- context.fillStyle = 'green';
- // drawing 1 px smaller than the grid creates a grid effect in the snake body so you can see how long it is
- context.fillRect(cell.x, cell.y, grid-1, grid-1);
- if (cell.x apple.x && cell.y apple.y) {
- // canvas is 400x400 which is 25x25 grids
- apple.y = getRandomInt(0, 25) * grid;
- // check collision with all cells after this one (modified bubble sort)
- for (var i = index + 1; i < snake.cells.length; i++) {
- // snake occupies same space as a body part. reset game
- if (cell.x snake.cells[i].x && cell.y snake.cells[i].y) {
- snake.y = 160;
- snake.maxCells = 4;
- snake.dy = 0;
- apple.y = getRandomInt(0, 25) * grid;
- }
- }
- document.addEventListener('keydown', function(e) {
- // prevent snake from backtracking on itself by checking that it's
- // not already moving on the same axis (pressing left while moving
- // left won't do anything, and pressing right while moving left
- // shouldn't let you collide with your own body)
- // left arrow key
- snake.dx = -grid;
- }
- else if (e.which 38 && snake.dy 0) {
- snake.dx = 0;
- // right arrow key
- snake.dx = grid;
- }
- else if (e.which 40 && snake.dy 0) {
- snake.dx = 0;
- });
- requestAnimationFrame(loop);
- </body>

RAW Paste Data