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 8507187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:47:57+00:00 2026-06-11T02:47:57+00:00

I am sort of new to JavaScript (Just started using it in school) and

  • 0

I am sort of new to JavaScript (Just started using it in school) and I have been looking around to get this program done for class. For some reason I just cant get it to work properly (with whatever I currently am working on) I am trying to fill up an Player Object with an array of Missle Objects… Before switching my code to this use of objects, I was able to display the “missles” but now I’m stuck.

I am only placing my necessary code:

function Player(){
    this.x = c.width/2;
    this.y = c.height-20;
    this.w = 50;
    this.h = 10;
    this.dx = 30;
    this.score = 0;
    this.missles = new Array();}

function Missle(x, y){
    this.x = x;
    this.y = y;
    this.dy = 10;
    this.w = 8;
    this.h = 8;
    this.visible = "false";}


function init1P(){
if (playing == "true"){
    player = new Player();
    animate1P();
}}

function animate1P(){
cntxt.clearRect( 0, 0, c.width, c.height );

cntxt.fillStyle="#000000";
cntxt.fillRect(0,0,c.width,c.height);

cntxt.fillStyle="#ffffff";
cntxt.font="34px Verdana";
cntxt.fillText(player.score, 10, c.height-10);  

cntxt.fillStyle="#ffffff";

cntxt.fillRect(player.x,player.y,player.w,player.h);

//cntxt.fillRect(comp.x,comp.y,comp.w,comp.h);

if ( player.missles.visible == "true" ) {
    cntxt.fillStyle = "#FF0000";
    cntxt.fillRect( player.missles.x, player.missles.y, player.missles.w, player.missles.h );
    //isHit();
    if ( hit == "false" ) {
        player.missles.y -= player.missles.dy;
        if ( player.missles.y <= 0 ) {
            player.missles.visible = "false";
        }
    }
}

// request new frame
if ( playing == "true" ) {
    requestFrame( function() { animate1P(); } );
}

//moveComp();
checkBoundaries(player);
//checkBoundaries(comp);
//isHit(player);
//isHit(comp);  }

function shoot() {
player.missles.push(new Missle(player.x + player.w/2, player.y + 10));
player.missles.visible = "true";
hit = "false";}
  • 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-11T02:47:59+00:00Added an answer on June 11, 2026 at 2:47 am

    Your player is supposed to have several missles, which you denoted by using an array:

    this.missles = new Array();
    

    When using an array, you have to loop (using e.g. for) to apply something to each element. So, doing player.missles.visible = "false" really just sets a property on the array itself, and not on each element. You’d have to do:

    for(var i = 0; i < player.missles.length; i++) {
      player.missles[i].visible = "false";  // player.missles[i] is one item on each iteration
    }
    

    The same goes for the drawing: fetch and update data of each missle in a loop:

    for(var i = 0; i < player.missles.length; i++) {
      if ( player.missles[i].visible == "true" ) {
        // ...
    }
    

    Also, note that there are booleans in JavaScript. You can use just true/false, and you can then directly use an if like this:

    if(player.missles[i].visible) {
      // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sort of new to JavaScript and something has been bugging me. Say
I am new to Objective-C and iPhone I have to sort a NSDictionary using
I have been asked to post a new question about how to correctly sort
I'm quite new to develop on GAE. Need just sort out few questions about
I'm getting a compiler error for this line: Collections.sort(terms, new QuerySorter_TFmaxIDF(myInteger)); My customized Comparator
I have a select element, that posts (just fine) when changed using $.post. But
I have a PHP page with various forms I've been using jQuery to submit/verify
I'm new at jQuery (just picked up a book this morning!) and I'm trying
I've sort if fell into this organization of javascript and was wondering if I'm
I've created a JavaScript Class just as following: function MyClass() { this.myProp = '';

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.