Search
 
SCRIPT & CODE EXAMPLE
 

HTML

simple canvas car game

<!DOCTYPE html>
<html>
    <head>
    <title>Move Car In HTML5</title>
    <!-- Written by Hirndra sisodiya  for the authorcode.com-->
 
    <script type="text/javascript">
        var myImage = new Image();
        var back = new Image();
        var ctx;
        function displayImage() {
            canvas = document.getElementById("myCanvas");
            if (canvas.getContext) {
                ctx = canvas.getContext("2d");
                window.addEventListener('keydown', moveobj, true);
 
                ctx.beginPath();
                ctx.moveTo(25, 150);
                ctx.lineTo(145, 150);
                ctx.lineTo(145, 135);
                ctx.lineTo(115, 130);
                ctx.lineTo(115, 120);
                ctx.lineTo(115, 120);
                ctx.lineTo(50, 120);
                ctx.lineTo(50, 130);
                ctx.lineTo(50, 130);
                ctx.lineTo(40, 130);
                ctx.closePath();
                ctx.fillStyle = "#FF0000";
                ctx.fill();
 
                ctx.beginPath();
                ctx.arc(50, 150, 10, 360, true);
                ctx.fillStyle = "#696969";
                ctx.fill();
 
                ctx.beginPath();
                ctx.arc(110, 150, 10, 360, true);
                ctx.fillStyle = "#696969";
                ctx.fill();
                back = ctx.getImageData(25, 50, 200, 150);
            }
        }
 
          var old = new Image();
          var next = 35;
          function moveobj(evt) {
              switch (evt.keyCode) {
                  case 37:
                      if (next < 20) {
                          return;
                      }
                      next = next - 5;
                      break;
                  case 39:
                      if (next > 650) {
                          return;
                      }
                      next = next + 5;
                      break;
              }
              ctx.fillStyle = "#ffffff";
              ctx.rect(0, 5, 650, 300);
              ctx.fill();
              ctx.putImageData(back, next, 50);
          }
       </script>
  </head>
    <body onload="displayImage()">
       <canvas id="myCanvas" width="650px" height="400px">
    </canvas>
      </body>
</html>
Comment

PREVIOUS NEXT
Code Example
Html :: reverse timer in html 
Html :: collapsableTableColumns 
Html :: how to find out how big an elemnts totla width is in css 
Html :: controls in html list 
Html :: html type range show label 
Html :: file download button html 
Html :: easyui how to make panel collapsible 
Html :: what is mac cloudkit 
Html :: which attribute use in html show decided password site:stackoverflow.com 
Html :: How to group form inputs 
Html :: EgQSovLEGMb3spAGIhBB1Si11KUheY5Knc9YT5LMMgFy 
Html :: display pdf in html fastapi 
Html :: how over mouse play video hml 
Html :: display letter in html element letter by letter 
Html :: input type file accept image and video 
Html :: show html string in p tag 
Html :: fab view 
Html :: how to change style of specific part in html 
Html :: const uno = <h1hola, 1</h1 
Html :: moving text in html 
Html :: asciidoc anchor 
Html :: music from stick with it 
Html :: sdfsdfsd 
Html :: automatically closed menu after clicked event 
Html :: html viber telegram whatsapp buttons 
Html :: html commenting 
Html :: how to run yaml file 
Html :: html open html in new tab as plain text 
Css :: css center element on screen 
Css :: css underline color 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =