1
0

SPCOLを定義

This commit is contained in:
otya128
2015-08-29 11:51:45 +09:00
parent 9fc91d6f48
commit 015ee96197
2 changed files with 85 additions and 3 deletions

View File

@@ -774,7 +774,7 @@ class PetitComputer
buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT; buttonTable[SDL_SCANCODE_LEFT] = Button.LEFT;
buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT; buttonTable[SDL_SCANCODE_RIGHT] = Button.RIGHT;
buttonTable[SDL_SCANCODE_SPACE] = Button.A; buttonTable[SDL_SCANCODE_SPACE] = Button.A;
bool renderprofile = true; bool renderprofile;//e = true;
try try
{ {
version(Windows) version(Windows)
@@ -1030,9 +1030,8 @@ class PetitComputer
version(NDirectMode) version(NDirectMode)
{ {
parser = new Parser( parser = new Parser(
"FOR Y=0TO 240GLINE 0,Y,399,Y,RGB(0,Y,0)NEXT"
//readText("./SYS/GAME6TALK.TXT").to!wstring //readText("./SYS/GAME6TALK.TXT").to!wstring
//readText("./SYS/GAME4SHOOTER.TXT").to!wstring readText("./SYS/GAME4SHOOTER.TXT").to!wstring
//readText("./SYS/GAME2RPG.TXT").to!wstring //readText("./SYS/GAME2RPG.TXT").to!wstring
//readText("./SYS/GAME1DOTRC.TXT").to!wstring //readText("./SYS/GAME1DOTRC.TXT").to!wstring
//readText(input("LOAD PROGRAM:", true).to!string).to!wstring //readText(input("LOAD PROGRAM:", true).to!string).to!wstring

View File

@@ -136,6 +136,37 @@ struct SpriteDef
int u, v, w, h, hx, hy; int u, v, w, h, hx, hy;
SpriteAttr a; SpriteAttr a;
} }
struct SpriteCollision
{
SpriteData* data;
bool scale = true;//scale対応
int mask = -1;
short sx;
short sy;
ushort w;
ushort h;
bool detection(ref SpriteData sp)
{
if(sp.define && sp.col.mask & mask)
{
auto x = (sp.linkx + sp.homex + sp.col.sx);
auto y = (sp.linky + sp.homey + sp.col.sy);
return detection(x, y, cast(int)(sp.w * sp.scalex), cast(int)(sp.h * sp.scaley));
}
return false;
}
//(x,y,z,w)
//(x,y,w,h)と判定
bool detection(int x, int y, int w, int h)
{
auto x2 = (data.linkx + data.homex + sx);
auto y2 = (data.linky + data.homey + sy);
if(x <= x2 && y <= y2 && x + w > x2 + data.w * data.scalex && y + h > y2 + data.h * data.scaley)
return true;
return false;
}
}
struct SpriteData struct SpriteData
{ {
bool isAnim; bool isAnim;
@@ -157,6 +188,7 @@ struct SpriteData
this.id = id; this.id = id;
z = 0; z = 0;
define = false; define = false;
col = SpriteCollision(&this);
} }
this(int id, int defno) this(int id, int defno)
{ {
@@ -171,6 +203,7 @@ struct SpriteData
this.define = true; this.define = true;
scalex = 1; scalex = 1;
scaley = 1; scaley = 1;
col = SpriteCollision(&this);
} }
this(int id, int u, int v, int w, int h) this(int id, int u, int v, int w, int h)
{ {
@@ -188,6 +221,7 @@ struct SpriteData
this.define = true; this.define = true;
scalex = 1; scalex = 1;
scaley = 1; scaley = 1;
col = SpriteCollision(&this);
} }
this(int id, ref SpriteDef spdef, int defno) this(int id, ref SpriteDef spdef, int defno)
{ {
@@ -208,6 +242,7 @@ struct SpriteData
scalex = 1; scalex = 1;
scaley = 1; scaley = 1;
this.defno = defno; this.defno = defno;
col = SpriteCollision(&this);
} }
SpriteAnimData[][SpriteAnimTarget.V] anim; SpriteAnimData[][SpriteAnimTarget.V] anim;
int[SpriteAnimTarget.V] animindex; int[SpriteAnimTarget.V] animindex;
@@ -244,6 +279,9 @@ struct SpriteData
//SPLINKの親は子より小さい管理番号でしかなれないのでsprite->child->nextのX座標を加算すればなんとかなる //SPLINKの親は子より小さい管理番号でしかなれないのでsprite->child->nextのX座標を加算すればなんとかなる
//->挙動的に違う //->挙動的に違う
int linkx, linky; int linkx, linky;
//SPCOL
SpriteCollision col;
} }
class Sprite class Sprite
{ {
@@ -793,4 +831,49 @@ class Sprite
//parent==nullでもエラーでない //parent==nullでもエラーでない
sprites[id].parent = null; sprites[id].parent = null;
} }
void spcol(int id)
{
id = spid(id);
spcol(id, 0, 0, cast(ushort)sprites[id].w, cast(ushort)sprites[id].h, true, -1);
}
void spcol(int id, bool scale)
{
id = spid(id);
spcol(id, 0, 0, cast(ushort)sprites[id].w, cast(ushort)sprites[id].h, scale, -1);
}
void spcol(int id, bool scale, int mask)
{
id = spid(id);
spcol(id, 0, 0, cast(ushort)sprites[id].w, cast(ushort)sprites[id].h, scale, mask);
}
void spcol(int id, short sx, short sy, ushort w, ushort h, bool scale, int mask)
{
id = spid(id);
sprites[id].col.sx = sx;
sprites[id].col.sy = sy;
sprites[id].col.w = w;
sprites[id].col.h = h;
sprites[id].col.scale = scale;
sprites[id].col.mask = mask;
}
void getspcol(int id, out bool scale)
{
id = spid(id);
}
void getspcol(int id, out bool scale, out int mask)
{
id = spid(id);
}
void getspcol(int id, out int sx, out int sy, out int w, out int h)
{
id = spid(id);
}
void getspcol(int id, out int sx, out int sy, out int w, out int h, out bool scale)
{
id = spid(id);
}
void getspcol(int id, out int sx, out int sy, out int w, out int h, out bool scale, out int mask)
{
id = spid(id);
}
} }