(SOLVED) Mining mechanic not working?

Bombini

  • *
  • Posts: 1401
hi guys,

i am working on a digging mechanic and i am stuck.
I need your help guys.

How the current mechanic works:

The "diggable area" is just a background and has a border of actors (lets call them "dirt").
Hitting one of these "dirt actors" kills it and creates a new one in the direction needed (checking position of player).
It also changes the tile below so it looks like your are expanding the "walkable area" (just cosmetical):


It won't create a "dirt" actor when there is a tile on another layer (which is good):



I can add "dirt actors" above and below checking the players situation related to the dirt actor (which is good):



Here is the code (also attached):



My problem:

How do i tell the behaviour not to create "dirt actors" when in free space (aka "check if connected")?
Check somehow if there are dirt actors not attached?



I tired a lot but wont get it working.
Maybe its the wrong approach in general?

Thanks a lot for help!



« Last Edit: May 22, 2014, 08:16:54 am by Bombini »

infinitum3d

  • Posts: 89
My first thought is to use a Boolean.   Maybe something like "is dirt actor attached". If yes, create new?

Awesome looking game btw.


Bombini

  • *
  • Posts: 1401
Thanks!
Here is a kind of dev log btw: http://community.stencyl.com/index.php/topic,28359.0.html

Well using boolean is the right way. But i am stuck on the next step.
How do check if dirt is existing or not? Something like "for each actor type" combined with position check i guess.

But i need help ;)

« Last Edit: May 13, 2014, 06:49:32 am by Bombini »

letmethink

  • *
  • Posts: 2545
You could check if there was a tile at where you are moving the actor to and if there is not to create one.
~Letmethink

Bombini

  • *
  • Posts: 1401
hi guys,

i got it somehow (killing actors, checking if tile exists and place tiles):
But there is something i don't understand.

It works on a 22x17 tile scene:




But behaves totally weird  if i make the scene bigger 44x17 (works in upper left corner though):



Is this a bug in the tile api?
What am i doing wrong?

Code is attached.
Cheers!

rob1221

  • *
  • Posts: 9473
Try the normal x/y, not x/y on screen.

Bombini

  • *
  • Posts: 1401
I tried that before. The system behaves how it should until i walk 14 tiles to the right.
Actors and tiles are created in a very wrong way (too much too far ahead).



So x/y on screen is the view and not the whole scene?
No chance to expand it? Because if i go for normal x/y i related to the actor right?

Any other idea?

« Last Edit: May 22, 2014, 06:34:45 am by Bombini »

rob1221

  • *
  • Posts: 9473
What does the coordinate custom block look like?  Tile API rows and columns are relative to the scene, so scrolling shouldn't change the values you get back.

EDIT: Nevermind, it's part of the Tile API that I forgot about.

The code for that block does use the camera for some reason, so I guess you would have to use x/y on screen?  I don't know as I've never used that block.

Full code for that block:
Code: [Select]
public static function getTilePosition(axis:Dynamic, val:Dynamic):Int
{
var engine = Engine.engine;
var tileH = engine.scene.tileHeight;
var tileW = engine.scene.tileWidth;
var camX = Engine.cameraX;
var camY = Engine.cameraY;
var position:Int;
var offset:Int; //offset to add in camera X or Y if needed
if(axis == 0)
{
offset = -Std.int(camX);
position = Std.int(Math.floor( (val + offset) / tileW));
return position;
}
else
{
offset = -Std.int(camY);
position = Std.int(Math.floor( (val + offset) / tileH));
return position;
}
}

My first impression is that there should either be no reference to the camera, or the camera coordinate should be added, not subtracted.

« Last Edit: May 22, 2014, 07:23:53 am by rob1221 »

Bombini

  • *
  • Posts: 1401
Ok thanks!
Current state: No matter if i use "normal x" or "x on screen" i get the same result:

  • 22x17 tiles:  works fine
  • More tiles in width or height in scene...problems occur after moving around 10-14 tiles down or right
Very strange. If anyone has an idea please let me know.
I would also pay some cash for a solution.

@rob1221  Could you take a look?

Cheers!

rob1221

  • *
  • Posts: 9473
Go to your extension folder (either plaf/haxe/extensions or stencylworks/engine-extensions depending on your version) and open up TileAPI.hx inside the tileapi folder.  Find the lines offset = -Std.int(camX); and offset = -Std.int(camY); and change them both to offset = 0;  Then test again with the standard x/y coordinates and see if that solves the problem.

Bombini

  • *
  • Posts: 1401
Rob....that did it :)

I am very very happy...tried to solve this now 3 weeks, started asking myself if i should through away everything;)
Thank you very very much!

I am happy!

rob1221

  • *
  • Posts: 9473
I committed the change so the block no longer offsets by the camera (private build only until the next public build).

Hectate

  • *
  • Posts: 4643
I think that's the block that I added. I probably screwed up. If I remember correctly, initially I wanted users to be able to specify scene and screen coordinates, but couldn't get the screen one to work correctly so I pulled it out. I must have overlooked the camera code itself.

I might be remembering incorrectly also, :)
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

rob1221

  • *
  • Posts: 9473
Entering screen coordinates should work if adding the camera (since screen X + camera X = scene X), but in that code you were subtracting the camera.