Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
JavaScript Exercise - Tank Shooter Game from Scratch
Rating: 4.7 out of 5(15 ratings)
2,280 students

JavaScript Exercise - Tank Shooter Game from Scratch

Build a JavaScript Game from scratch using only JavaScript no libraries no canvas - DOM manipulation Practice exercise
Created byLaurence Svekis
Last updated 11/2024
English
English [Auto],

What you'll learn

  • Apply JavaScript and move elements within a page using JavaScript
  • Run animations within JavaScript
  • Create elements within the DOM
  • Manipulate HTML elements using JavaScript

Course content

2 sections34 lectures2h 25m total length
  • Introduction to Game Play and what you can expect from the course2:02

    Learn to build a vanilla JavaScript game from scratch by dynamically generating and updating DOM elements, styling them, and creating random fire shots, focusing on HTML setup and core JavaScript.

  • Web development environment setup4:32

    Set up your web development environment with Brackets live preview and Chrome dev tools to write, render, and debug HTML, CSS, and JavaScript for a tank shooter game from scratch.

  • HTML CSS page Setup2:41

    Set up the HTML page, link a stylesheet and script file, and create style.css and script.js to enable live preview and testing in Brackets.

  • Add Style and Elements HTML13:37

    Style a browser-based tank shooter game by importing a Google font, structuring a dashboard and play area with HTML and CSS, and using JavaScript to dynamically update score and progress.

  • HTML source code0:16
  • CSS source Code0:45
  • JavaScript Start the Game5:38

    Hook up the start button with JavaScript to begin the game, using querySelector and getElementById to grab elements, add a click listener, and start a continuous animation loop with requestAnimationFrame.

  • Play the Game JavaScript3:40

    Set up the game container and input handling, implement mouse down firing, and manage play state to fire bullets, move shots, and update the dashboard while spawning enemies.

  • Create a Tank CSS4:22

    Create and style a tank using CSS, building a static base with a spinning turret and blue box, configuring absolute positioning, borders, colors, and transitions for upcoming JavaScript movement.

  • JavaScript Math CSS transform explained3:55

    Learn JavaScript math and CSS transform to compute the mouse angle for rotating a turret around the box center, using atan2, sin, cos, and degree-based rotate transforms.

  • Move along with Mouse7:40

    Learn to make a tank turret follow the mouse inside a container by calculating the angle from the tank center to the cursor using arctan.

  • JavaScript Move Turret3:38

    Move the turret by tracking the mouse, calculate the rotation angle in degrees, and apply a css transform rotate to the turret element, updating its position for browser compatibility.

  • Source Code0:26
  • Shooter Bullets Create Elements JavaScript10:10

    Create bullet elements with document.createElement, assign the fire me class, position them absolutely, and move them toward the mouse angle using sin and cos.

  • Remove elements from document JavaScript3:43

    Learn how to manage bullets in a tank shooter game by calculating movement from angle, updating styles, and removing offscreen bullets to prevent endless elements and prepare for collision detection.

  • Source Code0:41
  • Setup Bad Guys JavaScript17:29

    Import font awesome icons via CDN, use an icons array, and create ten bad guys with a dynamic bad maker function, each randomly sized and positioned with basic movement.

  • Source Code1:11
  • Moving Elements JavaScript Game7:23

    Move the enemies by selecting all elements with the badie class and updating their top and left positions using offset top, offset left, and x move and y move.

  • Source Code1:18
  • JavaScript Element Collision detection8:01

    Learn to implement collision detection in a JavaScript game using getBoundingClientRect to compare elements’ left, right, top, and bottom values, build an isCollide function, and trigger life loss on collision.

  • Detect Collision with Player and Enemy4:49

    Implement collision detection between player and enemies, reduce player lives on hit, and color the base red to reflect damage as the collision loop processes.

  • Source Code1:33
  • Update Stats Dashboard values Element manipulation3:21

    Implement the update dash function to refresh the scoreboard and progress bar, calculate the lives percentage, and adjust the bar width to reflect player health.

  • Game Over Function JavaScript5:48

    Create a game over function to stop the animation loop, show the game over screen with the score, reset lives, clear enemies and shots, and return to the start menu.

  • Source Code1:45
  • Color the elements randomly JavaScript3:42

    Add random hex colors to enemies with a random color function applied before rendering, returning two-digit hex values. Reinforce collision detection for shooting and destroying enemies in upcoming lessons.

  • Blast the Bad Guys JavaScript Collision detection between two elements4:53

    Apply collision detection between shots and enemies to register hits, remove collided elements, and update the score with 1–5 points while spawning new enemies to extend the game.

  • Final Game Tweaks and bug fixes2:41

    Apply final tweaks and bug fixes to the tank shooter game, test gameplay to prevent errors when removing elements after game over, and guard collisions with an active gameplay flag.

  • Source Code Game Review10:26

    Review the tank shooter game's source code to set up HTML, CSS, and JavaScript structure, implement a start button, play area, progress bar, animation loop, collision detection, and dashboard updates.

  • Final JavaScript Source1:50
  • Source Code and Resources0:13

Requirements

  • Fundamental JavaScript concepts
  • Access to computer
  • Use of editor to write code
  • HTML and CSS knowledge

Description

Practice and learn more about JavaScript while building a fun interactive tank shooting game from scratch.  Prefect course for beginners to learn JavaScript!!! Step by step learning with all steps includedNo libraries, no shortcuts just learning JavaScript!

Learn how you can use JavaScript to create, manipulate and make interactive HTML page elements.  Using JavaScript scripting you can create a fully interactive dynamic game from scratch.  Source code is included to get you started quickly.

This course is designed to help you practice JavaScript, you should have a functional understanding of the JavaScript language before taking this course. Please note that the course covers only JavaScript relevant to the building of the game.   Also HTML and CSS knowledge is essential as scope of this course is all JavaScript focused.  

Course covers

  • Learn how to setup your gameplay area using HTML and CSS
  • Setup page elements and prepare variables.  
  • Create interaction with JavaScript event listeners to invoke functions on mouse actions
  • Run animationframe to change HTML elements style attributes and calculate positions of shots and enemies
  • Calculate angles for the turret to follow the mouse movements and shot in the angled direction of where the mouse is.
  • Create elements using JavaScript and add/remove them from the page
  • Setup start game functionality with values to create game play
  • Access the JavaScript Document Object Model to manipulate element properties
  • Setup a dashboard to output variables for the user like score and life left
  • Setup helper functions to reuse within the game play
  • Check for element overlap and detect collisions which is essential for any game.  

All this is included and a whole lot more.  

Along with friendly support in the Q&A to help you learn and answer any questions you may have.

Try it now you have nothing to lose, comes with a 30 day money back guarantee.  

Start building your own version of the game today!!!!

See what you can build while you practice JavaScript!


Who this course is for:

  • Beginners to JavaScript
  • Anyone who wants to practice writing JavaScript
  • Anyone who wants to learn to make a JavaScript game without any libraries
  • Web developers
  • Webmasters