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

  • Home
  • SEARCH
  • 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 9216585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:26:58+00:00 2026-06-18T02:26:58+00:00

I currently finished a Pong game as a college assignment, but it’s only working

  • 0

I currently finished a Pong game as a college assignment, but it’s only working in Google Chrome. I’ve searched for a few hours on Google, but can’t seem to find the problem.

It’s not working in the newest Firefox, and also not workign in IE9.

This is the code:

        <script type="text/javascript">
            var canvas;
            var ctx;  

            var score1 = 0;
            var score2 = 0;

            // beginpositie plankjes
            var x = 200;
            var y = 380;
            var x2 = 200;
            var y2 = 10;

            // beginpositie en grootte van het balletje
            var x3 = 100;
            var y3 = 200;
            var size = 5;

            // snelheid balletje
            var sx = 0;
            var sy = 0;

            // snelheid plankjes
            var dx = 7;
            var dy = 7;

            // canvas afmeting
            var BREEDTE = 500;
            var HOOGTE = 400;

            function hervatSpel(){
                if(sx == 0 && sy == 0){
                    x3 = 100;
                    y3 = 200;
                    sx = 2;
                    sy = 2;
                }
            }

            function stopSpel(){
                if(sx != 0 || sy != 0){
                    x3 = 100;
                    y3 = 200;
                    sx = 0;
                    sy = 0;
                }
            }

            function resetScore(){
                score1 = 0;
                score2 = 0;
            }

            function rect(x,y,w,h){
                ctx.beginPath();
                ctx.rect(x,y,w,h);
                ctx.closePath();
                ctx.fill();
            }            

            function circ(){
                ctx.beginPath();
                ctx.fillStyle="#ffffff";
                ctx.arc(x3,y3,size,0,Math.PI*2,true);
                ctx.closePath();
                ctx.fill();

                // collision detection zijkanten
                if(x3<(size/2) || x3>(BREEDTE-size)){
                    sx = -sx;
                }

                // collision detection plankjes  
                if(y3 > (HOOGTE-20) && x3 > x && x3 < (x+100)){
                    sy = -sy;
                }

                if(y3 < 20 && x3 > x2 && x3 < (x2+100)){
                    sy =-sy;
                }

                // collision detection onder- en bovenkant
                if(y3<size){
                    // onderste speler scoort
                    // reset balletje
                    x3 = 100;
                    y3 = 200;
                    sx = 0;
                    sy = 0;
                    // reset plankjes
                    x = 200;
                    y = 380;
                    x2 = 200;
                    y2 = 10;
                    // update score
                    score2 += 1;
                }  
                if(y3>(HOOGTE-size)){
                    // bovenste speler scoort
                    x3 = 100;
                    y3 = 200;
                    sx = 0;
                    sy = 0;

                    x = 200;
                    y = 380;
                    x2 = 200;
                    y2 = 10;

                    score1 += 1;
                }

                x3+=sx;
                y3+=sy;
            }

            function clear(){
                ctx.clearRect(0,0,BREEDTE,HOOGTE);
            }

            function init(){
                canvas = document.getElementById("canvas");
                ctx = canvas.getContext("2d");
                return setInterval(draw, 10);
            }

            function draw(){
                clear();
                ctx.fillStyle = "9CC8F7";
                rect(0,0,BREEDTE,HOOGTE);
                ctx.fillStyle = "1A6CC4";
                rect(x,y,100,10);
                rect(x2,y2,100,10);
                circ();
                ctx.font="18px Trebuchet MS";
                ctx.fillText('Speler 1:',10,30);
                ctx.fillText('Speler 2:',10,380);
                ctx.fillText(score1,100,30);
                ctx.fillText(score2,100,380);
            }

            function doKeyDown(evt){
                switch (evt.keyCode) {
                    case 37:  /* linker pijltje wordt ingedrukt */
                    if (x > 0){
                        x -= dx;
                    }
                    break;
                    case 39:  /* rechter pijltje wordt ingedrukt */
                    if (x + 100 < BREEDTE){
                        x += dx;
                    }
                    break;
                    case 87: /* w-toets wordt ingedrukt */
                    if (x2 > 0){
                        x2 -= dx;
                    }
                    break;
                    case 83: /*s-toets wordt ingedrukt */
                    if (x2 + 100 < BREEDTE){
                        x2 += dx;
                    }
                    break;
                    case 13: /* ENTER wordt ingedrukt */
                    if(sx == 0 || sy == 0){
                    sx = 2;
                    sy = 2;
                    }
                }
            }

            init()
            window.addEventListener('keydown',doKeyDown,true);
        </script>

Some of it is in Dutch, but I don’t think this is relevant anyway.

  • 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-18T02:26:59+00:00Added an answer on June 18, 2026 at 2:26 am

    It looks like your colors need to have a beginning #:

                   ctx.fillStyle = "9CC8F7";
                   rect(0,0,BREEDTE,HOOGTE);
                   ctx.fillStyle = "1A6CC4";
    

    Should be:

                   ctx.fillStyle = "#9CC8F7";
                   rect(0,0,BREEDTE,HOOGTE);
                   ctx.fillStyle = "#1A6CC4";
    

    EXAMPLE

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

Sidebar

Related Questions

Currently I'm working on an Othello/Reversi game in c++. I have it finished except
I'm currently working on a page and it's almost finished. But there's one thing,
I'm currently working on a gallery to my photos. Besides some bugs, I'm finished
I just finished coding my program but am facing a few logic errors. I
I'm currently working on a small iPhone game, and am porting the 3d engine
Currently working with Oracle, but will also need a solution for MS SQL. I
I'm currently working / almost finished building the beta version of my communication application.
I am currently working on a Chrome Extension that mimics the behaviour and functionality
I'm currently working my way through the excellent Tour of Go . I finished
Currently, I'm working on a project where I have a server - client relationship

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.