1 decade ago by readme
Hey Hey ... new to Impace (Book is on the way :) ) and impressed so far. To get into it I was thinking about making a Tetris like-game.
So, my idea for the pieces was to make one Entity called "Piece" with no collission,
one Entity for each type of piece with no collision and one Entity for the single Blocks of a piece with collision.
This does sort of work ... calling the spawnEntity in main.js does create a piece as I would expect, but it seems like the positioning of the piece does not work as I would expect ... I would have expected the piece to be at 20/20, but it is at 0/0 because, as I assume, the coordinated of Block/TeePice are global, not local.
Am I right with that? And is there something im getting wrong on a base level? Is it at all possible to use Entitys like that?
So, my idea for the pieces was to make one Entity called "Piece" with no collission,
one Entity for each type of piece with no collision and one Entity for the single Blocks of a piece with collision.
This does sort of work ... calling the spawnEntity in main.js does create a piece as I would expect, but it seems like the positioning of the piece does not work as I would expect ... I would have expected the piece to be at 20/20, but it is at 0/0 because, as I assume, the coordinated of Block/TeePice are global, not local.
Am I right with that? And is there something im getting wrong on a base level? Is it at all possible to use Entitys like that?
this.spawnEntity(Piece,20,20,{type:'TeePiece'});
ig.module ( 'game.entities.Piece' ) .requires ( 'impact.entity', 'game.entities.Block', 'game.entities.TeePiece' ) .defines(function() { Piece = ig.Entity.extend({ size : {x:80,y:80}, collides : ig.Entity.COLLIDES.NEVER, init : function(x,y,settings) { this.parent(x,y,settings); switch(settings.type) { case 'TeePiece': ig.game.spawnEntity(TeePiece,0,0); break; } } }); });
ig.module ( 'game.entities.TeePiece' ) .requires ( 'impact.entity', 'game.entities.Block' ) .defines(function() { TeePiece = ig.Entity.extend({ size : {x:80,y:80}, init : function(x,y,settings) { ig.game.spawnEntity(Block,0,0); ig.game.spawnEntity(Block,20,0); ig.game.spawnEntity(Block,40,0); ig.game.spawnEntity(Block,20,20); this.parent(x,y,settings); } }); });
ig.module ( 'game.entities.Block' ) .requires ( 'impact.entity' ) .defines(function() { Block = ig.Entity.extend({ size : {x:20,y:20}, collides : ig.Entity.COLLIDES.FIXED, animSheet : new ig.AnimationSheet('media/images/assets/block.png',20,20), init : function(x,y,settings) { this.addAnim('block',1,[0]); this.pos.x = x; this.pos.y = y; } }); });