Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8989487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:16:18+00:00 2026-06-15T22:16:18+00:00

For my education I have to make a basic game in HTML5 canvas. The

  • 0

For my education I have to make a basic game in HTML5 canvas. The game is a shooter game. When you can move left -> right and space is shoot. When I shoot the bullets will move up. The enemy moves down. When the bullet hits the enemy the enemy has to dissapear and it will gain +1 score. But the enemy will dissapear after it comes up the screen.

Demo: http://jordikroon.nl/test.html

space = shoot + enemy shows up

This is my code:

            for (i=0;i<enemyX.length;i++) {

                if(enemyX[i] > canvas.height) {

                    enemyY.splice(i,1);
                    enemyX.splice(i,1);
                 } else {

                    enemyY[i] += 5;
                    moveEnemy(enemyX[i],enemyY[i]);

                 }
            }

            for (i=0;i<bulletX.length;i++) {

                if(bulletY[i] < 0) {
                    bulletY.splice(i,1);
                    bulletX.splice(i,1);
                 } else {

                    bulletY[i] -= 5;
                    moveBullet(bulletX[i],bulletY[i]);

                    for (ib=0;ib<enemyX.length;ib++) {

                      if(bulletX[i] + 50 < enemyX[ib] ||
                              enemyX[ib] + 50 < bulletX[i] ||
                               bulletY[i] + 50 < enemyY[ib] ||
                               enemyY[ib] + 50 < bulletY[i]) 
                        {   
                            ++score;
                            enemyY.splice(i,1);
                            enemyX.splice(i,1);
                        }
                    }   
                 }
            }

Objects:

        function moveBullet(posX,posY) {
            //console.log(posY);
            ctx.arc(posX, (posY-150), 10, 0 , 2 * Math.PI, false);

        }

        function moveEnemy(posX,posY) {

            ctx.rect(posX, posY, 50, 50);
            ctx.fillStyle = '#ffffff';
            ctx.fill(); 
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:16:19+00:00Added an answer on June 15, 2026 at 10:16 pm

    Further to Ben’s correction, for future reference it’s better to do a line-line collision detection, rather than your point-box collision detection.

    The reason for this is, say your enemy is small and your bullet is moving fast. There is always a chance the bullet will appear BEFORE the enemy in one frame, and then behind the enemy in the next, therefore never registering as a hit.

    Testing for an intersect with the bullet path and an imaginary line on the enemy will be far more accurate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently if you have a rooted phone, you can make use of com.android.nfc_extras to
I'm trying to make canvas draw code for the purposes of electronics education. Please
Right now I'm developing a small canvas oriented 2D graphics engine for a game,
I have created a page Education For All in facebook. In my website i
i have users_details table with the following columns martial_status | religion | education i
I have a form that is basically a calculator. you can type an equation
We have to make a test for elementary school kids to test there skills
I have a div that contains a slideshow. ( http://film.robinhoodtax.org/issues/education ) I am using
I have a quadratic equation struct, and I'd like to make it look nicer
I have the following markup. <ul id=ticker> <li><q> Education, then, beyond all other devices

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.