Jump to content

Push Classes to an array?


Ninjadoodle
 Share

Recommended Posts

Hi @enpu / Panda People

So, I have some robot classes and I would like to push them to an array, so I can randomly pick and create one when needed.

How would I go about doing this - I know what I need to do, just kinda stuck on how to implement it :(

Thank you in advance for any tips!

game.createClass('Robot1', {

    init: function() {
        
        this.id = 'robot1';
        
        this.circle1 = new game.ShapeCircle( -240, -240, 80, '#61C2C2');
        this.circle2 = new game.ShapeCircle(240, -240, 80, '#61C2C2');
        
        this.square1 = new game.ShapeSquare(0, -240, 320, 320, 1.25, '#66CCCC');
        this.square2 = new game.ShapeSquare(0, -400, 160, 160, 1.25, '#61C2C2');
    }
});

game.createClass('Robot2', {

    init: function() {
        
        this.id = 'robot2';
        
        this.circle1 = new game.ShapeCircle( -240, -240, 160, '#61C2C2');
        this.circle2 = new game.ShapeCircle(240, -240, 160, '#61C2C2');
        
        this.square1 = new game.ShapeSquare(0, -240, 320, 320, 1.25, '#66CCCC');
        this.square2 = new game.ShapeSquare(0, -400, 160, 160, 1.25, '#61C2C2');
    }
});

game.createClass('Robot3', {

    init: function() {
        
        this.id = 'robot3';
        
        this.circle1 = new game.ShapeCircle( -240, -240, 240, '#61C2C2');
        this.circle2 = new game.ShapeCircle(240, -240, 240, '#61C2C2');
        
        this.square1 = new game.ShapeSquare(0, -240, 320, 320, 1.25, '#66CCCC');
        this.square2 = new game.ShapeSquare(0, -400, 160, 160, 1.25, '#61C2C2');
    }
});

 

Link to comment
Share on other sites

@enpu- editors JS console - it works, i just get a warning

game.createScene('Game', {
    
    score: 0,
    parts: 0,
    count: 0,
    robotArray: ['Robot1', 'Robot2', 'Robot3'],
    
    init: function() {
        
        // SETUP
        this.stageSetup = new game.StageSetup();
        this.stageSetup.setupStage();
        
        // TIMER
        this.timerBar = new game.TimerBar(60);
        this.timerBar.start();
        
        // ROBOTS
        this.robotContainer = new game.Container().addTo(game.scene.mg);
        this.robotContainer.position.set(640, 1200);
        
        this.robot = new game[this.robotArray[this.count]];
    }
});

});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...