Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by RationalGaze

Hi people,

i need again some help for my tetris-like game.

My cubes structures are composed by many 20x20 squares with differents names (imagine for example cubeA, cubeB, cubeC....) which are gathered by positionning process.

When i make them rotate, its about the same idea, i save their ancient positions into variables et move their positions to build the requested structure.

When they are not supposed to move, once fallen, i just kill these cube entities and replacing them by new entities (deadcubeA, deadcubeB...) to keep their structure but that can not move anymore.

Here's my problem : to build a new pattern of cubes, i want to reuse again my first entities (cubeA, cubeB...) but when i want to rotate them each position of each cube goes totally random and after a few test (using different cube entities for each pattern for example) i noticed that the problem was simply the fact that i reuse my old entities.

Any solution ?

1 decade ago by Joncom

Would you mind posting your code that you use to rotate your "cube structures"?

By the way, consider calling them blocks instead of cubes, since cubes are 3D shapes which can be confusing in this context...

1 decade ago by RationalGaze

Here's my code

update: function() {

        	var head = ig.game.getEntitiesByType(Head);
            var breast = ig.game.getEntitiesByType(Breast);
            var sex = ig.game.getEntitiesByType(Sex);
            var legs = ig.game.getEntitiesByType(Legs);
            var obhead = ig.game.getEntitiesByType(EntityObsoleteHead);
            var saveposx = 0;
            var saveposy = 0;
            console.log('saveposx' + saveposx);
           
            
            if (ig.input.pressed('rotate') && this.currentAnim.angle == 0) {              
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx + 40;
                    head[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx + 20;
                    breast[i].pos.y = saveposy;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx;
                    sex[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx - 20;
                    legs[i].pos.y = saveposy;
                }
                if(this.norotation == 0) {    
                    this.currentAnim.angle = this.currentAnim.angle + 90;
                    this.rotationcounter++;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }
                
            

            else if (ig.input.pressed('rotate') && this.currentAnim.angle == 90) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx - 20;
                    head[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx;
                    breast[i].pos.y = saveposy;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx + 20;
                    sex[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx;
                    legs[i].pos.y = saveposy - 40;
                }   
                if(this.norotation == 0) {                
                    this.currentAnim.angle = this.currentAnim.angle + 90;
                    this.rotationcounter++;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }


            else if (ig.input.pressed('rotate') && this.currentAnim.angle == 180) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx - 20;
                    head[i].pos.y = saveposy;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx;
                    breast[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx + 20;
                    sex[i].pos.y = saveposy + 40;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx + 40;
                    legs[i].pos.y = saveposy + 20;
                }
                if(this.norotation == 0) {    
                    this.currentAnim.angle = this.currentAnim.angle + 90;
                    this.rotationcounter++;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }

            else if (ig.input.pressed('rotate') && this.currentAnim.angle == 270) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx;
                    head[i].pos.y = saveposy - 40;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx - 20;
                    breast[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx - 40;
                    sex[i].pos.y = saveposy;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx - 20;
                    legs[i].pos.y = saveposy + 20;
                }
                if(this.norotation == 0) {  
                    this.currentAnim.angle = 0;
                    this.rotationcounter = 0;
                }
                else if(this.norotation == 1) {}
            }


here's now an other entity

update: function() {

    var head = ig.game.getEntitiesByType(Head);
    var breast = ig.game.getEntitiesByType(Breast);
    var sex = ig.game.getEntitiesByType(Sex);
    var legs = ig.game.getEntitiesByType(Legs);
    var feet = ig.game.getEntitiesByType(Feet);
    var saveposx = 0;
    var saveposy = 0;


       if (ig.input.pressed('rotate') && this.currentAnim.angle == 0) {              
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx + 40;
                    head[i].pos.y = saveposy + 40;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx + 20;
                    breast[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx;
                    sex[i].pos.y = saveposy;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx - 20;
                    legs[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < feet.length; i++) {
                    saveposx = feet[i].pos.x;
                    saveposy = feet[i].pos.y;
                    feet[i].pos.x = saveposx - 40;
                    feet[i].pos.y = saveposy - 40;
                }
                if(this.norotation == 0) {    
                    this.currentAnim.angle = this.currentAnim.angle + 90;
                    this.rotationcounter++;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }
                
            

            else if (ig.input.pressed('rotate') && this.currentAnim.angle == 90) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx - 40;
                    head[i].pos.y = saveposy + 40;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx - 20;
                    breast[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx;
                    sex[i].pos.y = saveposy;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx + 20;
                    legs[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < feet.length; i++) {
                    saveposx = feet[i].pos.x;
                    saveposy = feet[i].pos.y;
                    feet[i].pos.x = saveposx + 40;
                    feet[i].pos.y = saveposy - 40;
                }
                if(this.norotation == 0) {    
                    this.currentAnim.angle = this.currentAnim.angle + 90;
                    this.rotationcounter++;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }
                


            else if (ig.input.pressed('rotate') && this.currentAnim.angle == 180) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx - 40;
                    head[i].pos.y = saveposy - 40;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx - 20
                    breast[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx;
                    sex[i].pos.y = saveposy;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx + 20;
                    legs[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < feet.length; i++) {
                    saveposx = feet[i].pos.x;
                    saveposy = feet[i].pos.y;
                    feet[i].pos.x = saveposx + 40;
                    feet[i].pos.y = saveposy + 40
                }
                if(this.norotation == 0) {    
                    this.currentAnim.angle = this.currentAnim.angle + 90;
                    this.rotationcounter++;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }

            else if (ig.input.pressed('rotate') && this.currentAnim.angle == 270) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx + 40;
                    head[i].pos.y = saveposy - 40;
                }
                for (i = 0; i < breast.length; i++) {
                    saveposx = breast[i].pos.x;
                    saveposy = breast[i].pos.y;
                    breast[i].pos.x = saveposx + 20;
                    breast[i].pos.y = saveposy - 20;
                }
                for (i = 0; i < sex.length; i++) {
                    saveposx = sex[i].pos.x;
                    saveposy = sex[i].pos.y;
                    sex[i].pos.x = saveposx;
                    sex[i].pos.y = saveposy;
                }
                for (i = 0; i < legs.length; i++) {
                    saveposx = legs[i].pos.x;
                    saveposy = legs[i].pos.y;
                    legs[i].pos.x = saveposx - 20;
                    legs[i].pos.y = saveposy + 20;
                }
                for (i = 0; i < feet.length; i++) {
                    saveposx = feet[i].pos.x;
                    saveposy = feet[i].pos.y;
                    feet[i].pos.x = saveposx - 40;
                    feet[i].pos.y = saveposy + 40;
                }
                if(this.norotation == 0) {    
                    this.currentAnim.angle = 0;
                    this.rotationcounter = 0;
                }
                else if(this.norotation == 1) {
                    this.currentAnim.angle = this.currentAnim.angle + 0;
                }
            }

1 decade ago by RationalGaze

If i change the spawn order, the second entity is always the one who bugs.

1 decade ago by RationalGaze

Help please ? :(

Look at this =>

if(this.distanceTo(ig.game.boxes) == 0) {
            ig.game.player.kill();
        }

This line manages the fake collision between two squares. When a square touches an other square, it stops moving.

I have 5 differents squares. The first squares structure has 4 squares, and my second has 5 squares. The second structure, which spawns as soon as the first finishes to fall, use te same squares used by the first, but these squares wont collide, EXCEPT the only one who hasnt been used.
So, any idea ?

1 decade ago by Joncom

Quote from RationalGaze
here's now an other entity

update: function() {

    var head = ig.game.getEntitiesByType(Head);
    var breast = ig.game.getEntitiesByType(Breast);
    var sex = ig.game.getEntitiesByType(Sex);
    var legs = ig.game.getEntitiesByType(Legs);
    var feet = ig.game.getEntitiesByType(Feet);
    var saveposx = 0;
    var saveposy = 0;

       if (ig.input.pressed('rotate') && this.currentAnim.angle == 0) {
                for (i = 0; i < head.length; i++) {
                    saveposx = head[i].pos.x;
                    saveposy = head[i].pos.y;
                    head[i].pos.x = saveposx + 40;
                    head[i].pos.y = saveposy + 40;
                }
...


Here is a less repeatetive way to write the same thing.

update: function() {

    var head = ig.game.getEntitiesByType(Head);
    var breast = ig.game.getEntitiesByType(Breast);
    var sex = ig.game.getEntitiesByType(Sex);
    var legs = ig.game.getEntitiesByType(Legs);
    var feet = ig.game.getEntitiesByType(Feet);
    /*
    // No need for these.
    var saveposx = 0;
    var saveposy = 0;
    */
    var angle = this.currentAnim.angle;

    if (ig.input.pressed('rotate')) {              
        for (i = 0; i < head.length; i++) {
            head[i].pos.x += 40 * ((angle == 0 || angle == 270) ? 1 : -1);
            head[i].pos.y += 40 * ((angle == 0 || angle == 90) ? 1 : -1);
        }
        for (i = 0; i < breast.length; i++) {
            breast[i].pos.x += 20 * ((angle == 0 || angle == 270) ? 1 : -1);
            breast[i].pos.y += 20 * ((angle == 0 || angle == 90) ? 1 : -1);
        }
        /*
        // No need for this loop since it never changes anything.
        for (i = 0; i < sex.length; i++) {
            sex[i].pos.x = sex[i].pos.x;
            sex[i].pos.y = sex[i].pos.y;
        }
        */
        for (i = 0; i < legs.length; i++) {
            legs[i].pos.x += 20 * ((angle == 0 || angle == 270) ? -1 : 1);
            legs[i].pos.y += 20 * ((angle == 0 || angle == 90) ? -1 : 1);
        }
        for (i = 0; i < feet.length; i++) {
            feet[i].pos.x += 40 * ((angle == 0 || angle == 270) ? -1 : 1);
            feet[i].pos.y += 40 * ((angle == 0 || angle == 90) ? -1 : 1);
        }
        if(this.norotation == 0) {    
            this.currentAnim.angle = this.currentAnim.angle + 90;
            this.rotationcounter++;
        }
        /*
        // This 'else' does nothing. No need for it.
        else if(this.norotation == 1) {
            this.currentAnim.angle = this.currentAnim.angle + 0;
        }
        */
    }
}

I'm really sure what the problem is that you're having. So is your problem that when you rotate a block a few times, it works for the very first block.

But when you try to rotate a second block, it becomes "scrambled" and looks all wrong?

1 decade ago by RationalGaze

Actually, i found what the problem is...And that problem is the weirdest thing ever i've been confronted to with Impact.

It is not the fact of re-using an entity...actually when i spawn my 4/5 blocks, the last one is always the one who'll collide, the entities spawned before wont. Why ??

1 decade ago by Joncom

Per
Quote from RationalGaze
Actually, i found what the problem is...And that problem is the weirdest thing ever i've been confronted to with Impact.

It is not the fact of re-using an entity...actually when i spawn my 4/5 blocks, the last one is always the one who'll collide, the entities spawned before wont. Why ??

Perhaps the last one is the only one that's running collision checks on the correct entities...

1 decade ago by RationalGaze

its surely because i'm using ig.game.boxes = this; , its meant to be used only for one instance of an entity, but i wanted to use it for all the subclasses owned by the Boxes class (all my squares)

I think i must use ig.game.getEntitiesByType, but if i do this :


var boxes = ig.game.getEntitiesByType(Boxes);

for(i = 0; i < boxes.length; i++) {
if(this.distanceTo(boxes[i]) == ('my formula to make them collides')) {
            ig.game.player.kill();
        }
}


it just doesn't work.

1 decade ago by Joncom

Sounds like you need to rethink how your blocks become aware of other blocks...

By the way, did you mean to kill your player inside this loop?
var boxes = ig.game.getEntitiesByType(Boxes);

for(i = 0; i < boxes.length; i++) {
if(this.distanceTo(boxes[i]) == ('my formula to make them collides')) {
            ig.game.player.kill();
        }
}

1 decade ago by RationalGaze

I need to kill the structure (player) if one of these blocks hit an other block

But i think i have the solution. I will only use a if/if else iteration
Page 1 of 1
« first « previous next › last »