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 ShawnSwander

/this is a script to look at a tile adjacent to the player in my game. In simple terms right clicking spawns an entity that is the size of the screen that is a blown up version of the tile clicked. Eventually I am going to have the game show any items on the ground there when zoomed in. The problem is some times the wrong tile is shown
I looked for a pattern to why its incorrect but couldn't find one. Any idea why the data on my map might not match what the screen displays?
if( ig.input.pressed('rightclick')){    
            if (ig.input.mouse.x>110&&ig.input.mouse.x<275&&ig.input.mouse.y>110&&ig.input.mouse.y<275){
					tiles = ig.game.getMapByName('hexes');
					tilex = parseInt((ig.input.mouse.x-165+this.pos.x)/HEX_SIZE);
					tiley = parseInt((ig.input.mouse.y-165+this.pos.y)/HEX_SIZE);
					console.log(tiles.data[tilex][tiley]+"@"+tilex+","+tiley)
					if (!ig.game.hexzoom){
						ig.game.hexzoom = ig.game.spawnEntity(EntityHexzoom, this.pos.x-165,this.pos.y-165,{});
						ig.input.unbindAll();
						ig.game.screenstate = 1;
					}
					ig.game.hexzoom.currentAnim = ig.game.hexzoom.anims[tiles.data[tilex][tiley]-1]
				}else{
					ig.game.player.messagebox = "You cannot see that far.";
				}
			}

hexzoom's draw function
      draw: function(){
		var ctx = ig.system.context;
		ctx.save();
		ctx.translate( ig.system.getDrawPos( this.pos.x.round() - this.offset.x - ig.game.screen.x ),
				 ig.system.getDrawPos( this.pos.y.round() - this.offset.y - ig.game.screen.y ) );
		ctx.scale( this.scale.x, this.scale.y );
		this.currentAnim.draw( 0, 0 );
		ctx.restore();
	}

1 decade ago by dominic

If you want the tile adjacent to the player, why do you take the mouse position into account?

Also, all Maps have a .getTile() method that takes pixel coordinates. No need to access .data and figure out the tile position yourself.

1 decade ago by ShawnSwander

@dominic
If the user is surrounded by 8 tiles he could look at any of the 8 and indicates which tile by right clicking... Also he can look at his own tile as well. Sorry for not explaining better.

Here is a visual
user can look at any tile including his own other tiles represented by * user tile represented by a U
* * *
* U *
* * *
right clicking on a tile further away will result in a "You can't see that far" message I want the user to have to get a closer look to see what items dropped.
Page 1 of 1
« first « previous next › last »