PDA

View Full Version : Mirror


Kirko
11-01-2015, 06:10 PM
Since testbed back I'm trying to make some new stuff and thought I could try to make a mirror but I no idea on how I would make the tiles show on the mirror. The only way I could think of is to make a screenshot of a specific spot of where I want a mirror.
I thought I would ask here if anyone has any idea how to do this. I just seem to stuck on the tile issue. I sorta have an idea on how to show the player in the mirror with showani possibly but want to get the hard things out of the way first.

Cubes
11-06-2015, 12:24 PM
just use a npc that mimics the players gani and look.

fowlplay4
11-06-2015, 07:16 PM
Get the tile data: this.level.tiles[tx, ty]

Use these functions:


gettileset(); // returns the current tileset image

//credit to dusty
function TilesToImage(t) {
if (t.type() == 0) {
temp.px = (int(t%16)*16)+(int(t/512)*256);
temp.py = (int(t/16)*16)%512;
return {px,py};
} else if (t.type() == 3) {
temp.imgarray = new[0];
for (temp.i : t) {
temp.px = (int(i%16)*16)+(int(i/512)*256);
temp.py = (int(i/16)*16)%512;
imgarray.add({px,py});
}
return imgarray;
} else return -1;
}


use stretchy = -1; to flip an the tile image.

Just make your mirror image dimensions match the tiles so you don't have to do any clipping.

Kirko
11-07-2015, 06:11 PM
Get the tile data: this.level.tiles[tx, ty]

Use these functions:


gettileset(); // returns the current tileset image

//credit to dusty
function TilesToImage(t) {
if (t.type() == 0) {
temp.px = (int(t%16)*16)+(int(t/512)*256);
temp.py = (int(t/16)*16)%512;
return {px,py};
} else if (t.type() == 3) {
temp.imgarray = new[0];
for (temp.i : t) {
temp.px = (int(i%16)*16)+(int(i/512)*256);
temp.py = (int(i/16)*16)%512;
imgarray.add({px,py});
}
return imgarray;
} else return -1;
}


use stretchy = -1; to flip an the tile image.

Just make your mirror image dimensions match the tiles so you don't have to do any clipping.

Thanks, tiles show now!! Just gotta make them appear in correct spot now.

edit: I got everything to work but just looks weird to me.
Only problem I have is only yourself will show on mirror and when you swing your sword the gani doesn't play fully.
https://gyazo.com/9e7307948b06d80594ae8893710f22fe.png

fowlplay4
11-07-2015, 09:05 PM
Do a check so you aren't updating the ani every time your script times out.

e.g. if (ani != player.ani) ani = player.ani;

Kirko
11-08-2015, 02:30 PM
Do a check so you aren't updating the ani every time your script times out.

e.g. if (ani != player.ani) ani = player.ani;

Thanks it works!
I Still got one or two small problems but I'll try to figure it out on my own.

xXziroXx
11-08-2015, 04:04 PM
I'd suggest drawing a black polygon or something at the bottom of the mirror to visually separate it from the ground.

Kirko
11-08-2015, 04:59 PM
I'd suggest drawing a black polygon or something at the bottom of the mirror to visually separate it from the ground.

I did something a little different. I made a image instead and then just stretched the x and y to fit the size of the mirror I gave. I attached image below.

this is how it came out.
https://gyazo.com/83ff9af9cf515ed0c55cf38a089b7fa7.png


Also for gani not showing fully you could do this also
player.ani.name @ "[" @ player.anistep @ "]"
I'm guessing all it does is get the exact frame of your gani and starts from there instead of the beginning.

BlueMelon
11-08-2015, 05:23 PM
Include a video or gif! Looks good!

Tim_Rocks
11-08-2015, 08:46 PM
Really cool guys!

xAndrewx
11-12-2015, 01:43 PM
I had to do it this way for the players on Era-


function onTimeout() {
temp.timer = 1;
if (player.x in |this.x - 15, this.x + 15| &&
player.y in |this.y - 10, this.y + 15|)
temp.timer = 0.05;

if ((player.x + 1.5) in |this.x + 1.5, this.x + (this.width - 1.5)| &&
player.y in |this.y + 3, this.y + 6|) {
temp.dir = (player.dir == 0? 2: (player.dir == 2? 0: player.dir));
temp.x = player.x;
temp.y = this.y + 4 - ((player.y - thiso.y) - 2);
temp.ani = player.ani;

with (findimg(200)) {
this.x = temp.x;
this.y = temp.y;

if (this.ani != temp.ani)
this.ani = temp.ani;

this.layer = 2;
this.dir = temp.dir;
playerlook = false;
actor.head = playero.head;
actor.body = playero.body;
actor.colors[0] = playero.colors[0];
actor.colors[1] = playero.colors[1];
actor.colors[2] = playero.colors[2];
actor.colors[3] = playero.colors[3];
actor.colors[4] = playero.colors[4];
actor.attr[1] = playero.attr[1];
actor.shield = playero.shield;
}
} else {
hideimg(200);
}
setTimer(temp.timer);
}

Kirko
07-26-2016, 06:40 PM
oops I never posted the code :o

been a while since I made it so I decided to rewrite it just now to shorten it up.
Only problem is that it only shows your character


//#CLIENTSIDE
function onPlayerEnters() {
setshape(1, this.mirror_width * 16, this.mirror_height * 16);
showTiles();
onTimeOut();
}

function onTimeOut() {
if (player.x in |thiso.x - 1.5, thiso.x + this.mirror_width - 1.5| &&
player.y in |thiso.y + this.mirror_height - 1.5, y + (this.mirror_height * 2) - 2|){
with (findimg(50)) {
x = player.x;
y = thiso.y + (thiso.y - playero.y) + thiso.mirror_height + 2.5;
layer = 1;

ani = player.ani.name @ "[" @ player.anistep @ "]";
dir = player.dir == 0 ? 2 : player.dir == 2 ? 0 : player.dir;
head = player.head;
shield = player.shield;
for (temp.i = 0; temp.i < 5; temp.i ++) colors[i] = player.colors[i];
for (temp.i = 0; temp.i < 20; temp.i ++) attr[i] = player.attr[i];
}
} else
hideimg(50);

setTimer(0.05);
}

function showTiles(){
temp.mw = this.mirror_width;
temp.mh = this.mirror_height;

temp.area = temp.mw * temp.mh;
temp.y = this.y + temp.mh - 1;

for(temp.i = 0; temp.i < temp.area; temp.i ++) {
temp.y += (temp.i % temp.mw) == 0 ? 1 : 0;

with (findimg(201 + temp.i)) {
x = (thiso.x) + ((temp.i % temp.mw) * 1);
y = (thiso.y + temp.mh - 1) - (int(temp.i / temp.mh) * 1);

image = gettileset();
partx = TilesToImage(this.level.tiles[x, temp.y])[0];
party = TilesToImage(this.level.tiles[x, temp.y])[1];
partw = parth = 16;
stretchy = -1;
layer = 0;
}
}
}

//credit to dusty
function TilesToImage(t) {
if (t.type() == 0) {
temp.px = (int(t%16)*16)+(int(t/512)*256);
temp.py = (int(t/16)*16)%512;
return {px,py};
} else if (t.type() == 3) {
temp.imgarray = new[0];
for (temp.i : t) {
temp.px = (int(i%16)*16)+(int(i/512)*256);
temp.py = (int(i/16)*16)%512;
imgarray.add({px,py});
}
return imgarray;
} else return -1;
}

callimuc
07-27-2016, 02:06 PM
Only problem is that it only shows your character

for (temp.pl: players) {
if (!temp.pl.x in .... || !temp.pl.y in ...) continue;
with (findimg(200+temp.count)) {

}
}

Used continue so it would still display the characters to all players, even if they aren't in the mirror. Don't know if you only want to show your own character on purpose. If not, this would fix it :)

MysticalDragon
07-27-2016, 10:50 PM
Kirko I'm amazed by you, you have come a long way my friend.

Kirko
07-28-2016, 11:53 PM
for (temp.pl: players) {
if (!temp.pl.x in .... || !temp.pl.y in ...) continue;
with (findimg(200+temp.count)) {

}
}

Used continue so it would still display the characters to all players, even if they aren't in the mirror. Don't know if you only want to show your own character on purpose. If not, this would fix it :)
Thanks!


Kirko I'm amazed by you, you have come a long way my friend.
:blush: