javascript making a tag game

Solutions on MaxInterview for javascript making a tag game by the best coders in the world

showing results for - "javascript making a tag game"
Jeremiah
30 Mar 2017
1 <!-- A SIMPLE SNAKE GAME MADE BY HTML AND CSS -->
2
3<!DOCTYPE html>
4<html>
5<head>
6  <title></title>
7  <style>
8  html, body {
9    height: 100%;
10    margin: 0;
11  }
12
13  body {
14    background: black;
15    display: flex;
16    align-items: center;
17    justify-content: center;
18  }
19  canvas {
20    border: 1px solid white;
21  }
22  </style>
23</head>
24<body>
25<canvas width="400" height="400" id="game"></canvas>
26<script>
27var canvas = document.getElementById('game');
28var context = canvas.getContext('2d');
29
30var grid = 16;
31var count = 0;
32  
33var snake = {
34  x: 160,
35  y: 160,
36  
37  // snake velocity. moves one grid length every frame in either the x or y direction
38  dx: grid,
39  dy: 0,
40  
41  // keep track of all grids the snake body occupies
42  cells: [],
43  
44  // length of the snake. grows when eating an apple
45  maxCells: 4
46};
47var apple = {
48  x: 320,
49  y: 320
50};
51
52// get random whole numbers in a specific range
53// @see https://stackoverflow.com/a/1527820/2124254
54function getRandomInt(min, max) {
55  return Math.floor(Math.random() * (max - min)) + min;
56}
57
58// game loop
59function loop() {
60  requestAnimationFrame(loop);
61
62  // slow game loop to 15 fps instead of 60 (60/15 = 4)
63  if (++count < 4) {
64    return;
65  }
66
67  count = 0;
68  context.clearRect(0,0,canvas.width,canvas.height);
69
70  // move snake by it's velocity
71  snake.x += snake.dx;
72  snake.y += snake.dy;
73
74  // wrap snake position horizontally on edge of screen
75  if (snake.x < 0) {
76    snake.x = canvas.width - grid;
77  }
78  else if (snake.x >= canvas.width) {
79    snake.x = 0;
80  }
81  
82  // wrap snake position vertically on edge of screen
83  if (snake.y < 0) {
84    snake.y = canvas.height - grid;
85  }
86  else if (snake.y >= canvas.height) {
87    snake.y = 0;
88  }
89
90  // keep track of where snake has been. front of the array is always the head
91  snake.cells.unshift({x: snake.x, y: snake.y});
92
93  // remove cells as we move away from them
94  if (snake.cells.length > snake.maxCells) {
95    snake.cells.pop();
96  }
97
98  // draw apple
99  context.fillStyle = 'red';
100  context.fillRect(apple.x, apple.y, grid-1, grid-1);
101
102  // draw snake one cell at a time
103  context.fillStyle = 'green';
104  snake.cells.forEach(function(cell, index) {
105    
106    // drawing 1 px smaller than the grid creates a grid effect in the snake body so you can see how long it is
107    context.fillRect(cell.x, cell.y, grid-1, grid-1);  
108
109    // snake ate apple
110    if (cell.x === apple.x && cell.y === apple.y) {
111      snake.maxCells++;
112
113      // canvas is 400x400 which is 25x25 grids 
114      apple.x = getRandomInt(0, 25) * grid;
115      apple.y = getRandomInt(0, 25) * grid;
116    }
117
118    // check collision with all cells after this one (modified bubble sort)
119    for (var i = index + 1; i < snake.cells.length; i++) {
120      
121      // snake occupies same space as a body part. reset game
122      if (cell.x === snake.cells[i].x && cell.y === snake.cells[i].y) {
123        snake.x = 160;
124        snake.y = 160;
125        snake.cells = [];
126        snake.maxCells = 4;
127        snake.dx = grid;
128        snake.dy = 0;
129
130        apple.x = getRandomInt(0, 25) * grid;
131        apple.y = getRandomInt(0, 25) * grid;
132      }
133    }
134  });
135}
136
137// listen to keyboard events to move the snake
138document.addEventListener('keydown', function(e) {
139  // prevent snake from backtracking on itself by checking that it's 
140  // not already moving on the same axis (pressing left while moving
141  // left won't do anything, and pressing right while moving left
142  // shouldn't let you collide with your own body)
143  
144  // left arrow key
145  if (e.which === 37 && snake.dx === 0) {
146    snake.dx = -grid;
147    snake.dy = 0;
148  }
149  // up arrow key
150  else if (e.which === 38 && snake.dy === 0) {
151    snake.dy = -grid;
152    snake.dx = 0;
153  }
154  // right arrow key
155  else if (e.which === 39 && snake.dx === 0) {
156    snake.dx = grid;
157    snake.dy = 0;
158  }
159  // down arrow key
160  else if (e.which === 40 && snake.dy === 0) {
161    snake.dy = grid;
162    snake.dx = 0;
163  }
164});
165
166// start the game
167requestAnimationFrame(loop);
168</script>
169</body>
170</html>
Calvin
11 Feb 2016
1//Javascript game template
2//Move player with arrow keys
3
4var canvas = document.createElement("canvas");
5canvas.width = 500;
6canvas.height = 500;
7document.body.appendChild(canvas);
8var ctx = canvas.getContext("2d");
9
10var player = {x: canvas.width / 2, y: canvas.height / 2, speed: 10};
11var keys = [];
12
13function update() {
14  ctx.clearRect(0, 0, canvas.width, canvas.height);
15  
16  ctx.beginPath();
17  ctx.fillStyle = "red";
18  ctx.fillRect(player.x, player.y, 50, 50);
19  
20  if (keys[37])
21    player.x -= player.speed;
22  if (keys[38])
23    player.y -= player.speed;
24  if (keys[39])
25    player.x += player.speed;
26  if (keys[40])
27    player.y += player.speed;
28  
29  requestAnimationFrame(update);
30}
31update();
32
33document.onkeydown = function(e) {
34  keys[e.keyCode] = true;
35}
36document.onkeyup = function(e) {
37  keys[e.keyCode] = false;
38}
Silvia
02 May 2020
1(function)game=tag
2(function)=character=109
3(function)=vehicles=200
queries leading to this page
game htmlgames in html5how to make a browser game with javascriptgame on javascriptcode a game in javascriptmaking javascript gamesjavascript make gamemake game in jshow to make game with jsdifferent ways to go about making a javascript gamecode a javascript gamehow to make games in jsstart game page html cssgames made on canvas tag in htmlmake game in javascripthow to make a simple game with code html5making js gamesmake html based gamebuilding game in javascriptcreating a javascript game in the browsermake games with csshow to put a game in htmljava script gameadd game phpgame html jscoding a game in javascripthow to make a html gsme 5dlearn how to make games with javascripthow to make a video game in html anhow to make js games with bootstraphow to create a html gamejs game designmake a javscript gamewc3 school game htmlgame using html and javsscriptwrite a game in javascriptjs game examplesgames in javascripthow to do javascript gamebasic js gamehow to create a simple game using jsmake js game for browserhow to build a game in javascripthow to make a game javascriptjavascript gamehtml gaameshow to make a game with html and jsmaking game javascripthow to make an interactive game htmlhtml codes for gameshtml make your own gamegame javascript tutorialcan i use javascript for making game 3fbuilding games with javascripthtml5 or javascript for gameshow to make games on javascriptjavascript making a gamegame tutorial in javascriptjs game codehowb to make a game in jslearn how to make games with html css and javascripthow to make a game with javascripthtml and css gamescan you make games with javascriptjs simple game examplehtml code for gaming websitegame makig using jshtml code for gameshow to make a simple game in javascriptjavascript code a gamehow to create a game in javascript with graphicsmake javascript gameshow to creat a game in html onlyhow to make a simple game in htmljavascript how to make a gamemake javascript 2c html and css gamevideo game javascriptcreating a game using javascripthow to create html gamescreating a game in javascripthow to code a game with jscoding a game in htmlsimple game using java scriptmake game in htmljavacript gameshow to make a game using html5html games w3html and js gamesjavascript code for a gamejavascript html css game examplehow to make a game with jsmake a game in html html games projectgames with html codeschreate a game with jscan we create a game using htmlhow to create game using javascriptwhat we need to make a game with javascripthow to make a game from javascriptgame made in htmlhow to make a asimple js gamejavascript game htmlhow to make game using htmlhow to make a simple html gamegave development with htmlcreate javascript gamejavascript game creationgame development w3schoolsbasic game javascriptsimple javascript games for beginnersjavascript videogame projectshow to make game in htmlmake games using javascriptjavascript games tutorialcan i make a game with htmlhow to make a html gamemake javascript game tutorialwhat is the best way to make a game in javascriptto make html gamehow to create game with javascriptjavascript game 3fhow do i create a game using htmlcode javascript gamemaking game with javascriptmaking a game wid html only htmlw3schools canvas gamemaking a game with javascriptmaking the easiest game in javascriptcan i make a game with javascriptmake a game with htmlhow to create an html game how to creat a game in htmlhow to create a game in javasc ript build a game using javascripthtml gamehow to make game app on javascriptgame with htmlhow to make a simple game with htmlhtml game windowgame using htmlmake javascript gameusing js to make a gamejs html and css gamehow to make a game using jsmaking game in html 27how to make javascript gameinteractive game javascriptsimple games using html and css with source codeimportanttags to create a game in htmlmaking a game in javascriptmaking a game using javascript for beginnershtml games w3schoolsbuild game javascriptmaking a game in jsgaming htmlhow to make a game only using jshow to make a js gamecreate game with htmla simple game to create with javascripthow to make a game on htmlhtml 5 game projectjava scripts command gamemaking a game using javascriptjs 2c php game htmlcreate a game htmlmake html gamehow make game javascripthow to make game using javascriptcreate html gamecoding with javascript gamegames for javascriptjavascript tutorial game javascript html5 gamehtml games code to addeasy html gamesimple game with javascriptjavascript game development with demow3school canvas gameflappy bird js w3schoolsjavascript simple gamewhat are the games using htmlmaking games in javascripthow to make games in javascriptjavascript game tutorialshow to add html gamessimple diy javascript gamemaking a javascript gamehow to put a javascript game into my html websitecreating a game in jscreate interactive game in javascripthow to make a 2d game unityhtml5 game tutorialhow to make js browser gamehow to create a game using javascripthow to create a html 5 gamejavascript game developmentwriting a game in javascripthow you kan to create game from html and cssjavascript games codehow to make a javascript gfamehow to make html gamesbuild games with javascriptmaking a game using jsgames javascript codemaking games with javascripthow to make game with htmlsimple game javascriptmake game with javascriptcreate game with jsgame in html source codecan you make game using htmlhow to make a javascript game with codehtml basic gamegame on htmlgames with jshtml game developmentcreate a game with javascripthtml5 canvas gamehow to make a game in javascriptsimplest game in htmlcreate a gamews in javascripthtml game basicsgame navigation html5how to create a javascript game in websitehtml css game detailcan you make game in javascriptjava for html code game onlinehow to create games using javascriptmake g html gamehow to code a game in javascript easy html game to createhow to make a game in javascript for beginners with only codeseasy to make javascript gamsmake a simple game using javascriptmaking a html game tutorial 1html and css gamehow to make game on javascripthow to make agame in javascriptmini html js gamehow to make a basic game in javascript game in htmlhtml js how make gameeasy javascript games to makecreate a simple html gamecreate games with javascripthow to create a simple game in javascriptgame in jsgame using html and csscan i make a game using htmlhow to make a game in javascript for beginnershow to make a game in html css and javascriptbasic javascript game codejavascript create web gamelingo game create with javascriptmake game with jslearn html gamejavascript game code game in javascripthtml include gamesgame javascript functionshow can i make a game with javascriptjavascript game programminglearn make game in javascripthow to create a game using html and csscreate games beginner javascriptgame javascript whow to make a good game by javascripthow to make html gamesimple javascript game tutorialweb html gamegames to develop using html css and phpjava script game codesimple game in javascript source codehtml game codemake a js browser gamehow do you make a game with javascript game with javascriptcreate an html gamehow to create a game in htmlmaking a simple game in javascriptmaking game with only javascriptcreating game using javascriptjava script making a gamemaking a game in htmlbuild a game using htmlhtml gamecanvas javascript gametrist javascript gameshow to create a game from javascriptmake game javascriptgame html codehow to make a make game in jssimple games to make in javascriptmake a game with jsjavascript making games tutorialsimple js gamehow to code a game in htmlhow to make a game in javascript tutorialgame jshow to make a simple js gamemaking a game with javsacriptmaking a game with javascript codejs gmaehow to create bakamon game in javascriptcreate a video game app w3 schoolscoding a javascript gamehow to add javascrpt game in htmljava script gamedsjavascript code of a gamesimple game using htmlhow to make games on htmlvideo game javascrip beginnerjavascript game enginesimple game in htmlhow to make games with htmlfirst simple game coding in htmlgame in html5javascript building gamedesigning game with javascripthtml 5 game tutorialhow to make agame in javascrihow to make a game in javascript codehow to make a game in html applicationhow to code a game in html5javascript game tutorial for beginnershow to make game on htmlhow to make a game jssimple js gamesjava script how to make a gamehow to make a online game usinfg htmlbuild game using javascripthtml javascript gamegames with javascriptcreate a default game in html and use in betweenhow to make a javascript game in htmlcan you make a game with javascripthow to make an html gamejava script game examplesgame programming javascripthow to make a game using htmlsimple javascript gamesgame javascriptgame program in javascriptis making a javascript game easycodes for javascript to make an gamejavascript game basicsputting a python game in javascriptjavascript gmejavascript game in jsjavascript as a gamehow to codea js gamejs gamesgame code in javascriptcreate game with javascriptmake your own game with jsmake a javascript gamerunner game with html css and javascript tutorialhow to develop a game using htmlpython snake game w3 schoolgames using html css and bootsraphow to create a game in javascriptcreate js game examplehow javascript gamebuild html gamescreating javascript gamessimple game html javascriptbuild a simple game in javascripthtml programs for gameshow to make js gamescreate a javascript gamesimple html gamesimple game for htmlhow to make a game in phpcan i create games in javascriptmaking a game in cssjavascript games tutorialsjavascript how to make gamereally simple game html and csshow to make a basic game in jsgames in java scriptgame made with javascriptmake a game in javascriptmake game with htmlhow to build a javascript game without htmlcreate game javascripthow to make a game in html and javascriptcreate game in html create simple web gamehow to create a easy game in javascripthow to make simple html gamegames created with javascriptmake a game with javascripthow do you create a video game injs 3fhow to code a js gamesjavascript game development code referencejavascript web game tutorialjavascript making a game tutorialcreate game in javascriptcreate a simple game javascriptlearn how to make a game with htmlmini game htmlhow to code a javascript gamegame jshow to code a game on javascriptcan you make a game in htmlhow to code a game in html js csshow to create a game in jshow to code a game javascriptjavascript making a tag gamebuild a simple javascript gamegame development in javascriptjavascript coding minigamegames create javascriptbuilding games in javascriptcreate a game with javascript quicklyhow to build a video game in javascriptbest way to do game in htmlgame like tutorial for jsjs game examplebuild game with javascriptmakeing a javscript gamehow to make a simple game with javascriptcanvas gamehtml register gamegame with javascripthow to create games in html js and cssmaking games using javascriptgames for pc in html cssbuild a basic js gamejavascript gamescan you create a game using html cssgame using javascript codejavascript game development tutorialgame with jshtml css js gamesmake a game jshow to include a game in htmlmake html gamescodes for java script to make an gamehow to make a game in jsmaking games with jscreate js gamesimple game using html and cssjavascript game program exemplehow to create game in htmlwrite games in javascriptmake js gamecan u make a game with jsjavascript videogamewrite a bsic html gamegames in jscreate a game using html and jsgame development w3how to code games in javascripthow to make a game with javascript and html5 csshow to make game in javascriptgame cssmake a game in jssample games javascriptsimple game in jsbuild simple game jshow do i make a game in html cssis it possible to create a gamewith html and csscode a game htmlgame in javascript codebuild a game in javascripthow to make a web game with javascriptgames in htmlgame java scriptw3schools html gamedevelop game in javascriptwhat do i need to build a game with javascripthtml code to make a gamegame example in javascriptmake a game javascripthow to make games using js3how to code an html gamejavascript game codehow to make a game with javascript and phpbasic games javascripthow you can to create game from html and csssimple web game htmlgame htmlhtml gamge simplejs gamecreate game using java scriptbuild a game javascriptfirst javascript gamew3schools game htmlhow to make games with javascripthow do you create a video game i js 3fjavascript game development tutorialsjavascript build a web gamejavasript gamemake games in javascriptcreate game javascript html5how to make a game using javascripthow make a game with javascriptcodes for html to make gamehow to create a js and html gamehow to make javascript gamesjavascript simple gameswho to program html canvas gamesjs simple gamehtml css and javascript basic gamehow to make a game in with htmllingo game create with javascript tutorialsimple game in javascripthow to make a game with javascript and html5how to build a javascript gamehtml5 javascript gamehow to develop game in jsmake a game using javascriptcreate a game using javascriptmak a game using html 2c css and js how to make game with htmljavascript game examplebuilding a game with javascriptcreate game canvas html5how to code a js gamebasic game in jsmaking html gameshtml game code funcreate game with html and csscreate game with html 5can we make games using javascriptcreating game in jscreate a game in htmlhow to make a gmae using htmlbuilding a game using javascript and htmlmaking a game with jscreate ganes with javascriptgame development in javascript 3fbuilding a simple game with javascripthow to create game javascripthow to make a game htmlmake games using html css and jshow do you create a game in javascript 27create a game using javascript 5chtml gameshtml building game codeusing javascript to make a gamehow to make a game in html5 and javascriptweb made in js html gmaemake games with javascripthow to make a 3d game in htmlmake a game in js websitegame code in jshow to make a game wiht htmlhtml game makingmake a js gamejavascript html gamescan you make games using javascripthow to make a game in htmlgame in javascriptcreate a game in html 5could you make a simple game with javascriptonline game devolpment javascript htmlcreating a javascript gamehow to create game in javascriptmake game by jsmake a simple game with javascripthow to make a n onlin html gameweb games in javascriptsimple html game codegame javascript codecreating a game with javascripthow to make a game with htmljavascript make gamesjavascript make a gamegame using html css javascripthow to make games using javascriptjavascript game with htmldevelop a game in htmljavascript functions gamecode a game in htmlbuilding game javascriptbuild games with jsgame code in htmlhow to create a javascript gamesimple game using javascripthow to code a game in jshtml how to make gamehow to make games in the html css jshow to create a game using htmlcreate a game in javascriptminigame javascripteasiest javascript gameshow can i build game by jshow to make a vr game in unityhow javascript games makejavascript html gammesmake game htmlhow to code a game with javascripthow to code a game in javascri 5btsimple javascript gamejavascript game makinghow to create a game with javascriptgame making javascriptjavascript game tutorialhtml game css jsbrowser based game website using html 2c css 2c javascript 2c bootstraphow to make a 2d game in htmlhtml game programmingcreate a game html and jshow make a game with java scriptjavascript game code tutorialgame in htmlhow to make game using html and csssimple games in jssimple game code in javascriptcreate simple games with javascriptwrite javascript gamesmaking game in javascriptmake a game with javascript and html5build a javascript gamegames using html css javascripthtml5 game codemaking games in jshtml game examplebasic javascript gamehow to make games with only jsgame creator html css javascriptmaking a js gamehow to make games in html 5build game in javascripthow to code a simple javascript gamecodes for java script to make games simple javascript game examplecss html gamehow to make a javascript gamejavascript simple game codemaking a game wid htmlcan you make a game in javascripthow to make game in js2d game in html and cssghow to make games with htmlhow to make game with javascriptmaking a game with java scriptcan you make a game with htmlcreate a new game jshtml 2d ga 2cemaking game in jsjavascript making a tag game