スプライトを追加.
This commit is contained in:
@@ -213,6 +213,7 @@
|
||||
<File path="node.d" />
|
||||
<File path="parser.d" />
|
||||
<File path="petitcomputer.d" />
|
||||
<File path="sprite.d" />
|
||||
<File path="systemvariable.d" />
|
||||
<File path="TEST.txt" />
|
||||
<File path="token.d" />
|
||||
|
||||
@@ -10,6 +10,7 @@ import std.string;
|
||||
import std.c.stdio;
|
||||
import core.sync.mutex;
|
||||
import otya.smilebasic.parser;
|
||||
import otya.smilebasic.sprite;
|
||||
enum Button
|
||||
{
|
||||
UP = 1,
|
||||
@@ -178,7 +179,7 @@ class PetitComputer
|
||||
{
|
||||
SDL_RWops* stream = SDL_RWFromFile(toStringz(file), toStringz("rb"));
|
||||
auto src = IMG_LoadPNG_RW(stream);
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0xFF);
|
||||
SDL_Surface* surface = SDL_CreateRGBSurface(0, src.w, src.h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);//0xff000000, 0x00ff0000, 0x0000ff00, 0xFF);
|
||||
SDL_Rect rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
@@ -186,21 +187,24 @@ class PetitComputer
|
||||
rect.h = src.h;
|
||||
// SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
|
||||
// SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
|
||||
|
||||
ubyte sr, sg, sb, sa;
|
||||
SDL_GetRGBA((cast(uint*)src.pixels)[0], src.format, &sr, &sg, &sb, &sa);
|
||||
auto color = SDL_MapRGBA(surface.format, sr, sg, sb, sa);
|
||||
SDL_SetColorKey(src, SDL_TRUE, (cast(uint*)src.pixels)[0]);
|
||||
SDL_SetColorKey(surface, SDL_TRUE, (cast(uint*)src.pixels)[0]);
|
||||
//SDL_SetColorKey(surface, SDL_TRUE, color);
|
||||
int i = SDL_BlitSurface(src, &rect, surface, &rect);
|
||||
auto srcpixels = (cast(uint*)src.pixels);
|
||||
auto pixels = (cast(uint*)surface.pixels);
|
||||
auto aaa = surface.format.Amask;
|
||||
//surface.format.Amask = 0xFF;
|
||||
/+for(int x = 0; x < src.w; x++)
|
||||
for(int x = 0; x < src.w; x++)
|
||||
{
|
||||
for(int y = 0; y < src.h; y++)
|
||||
{
|
||||
ubyte r, g, b, a;
|
||||
write(x,y, ',');
|
||||
SDL_GetRGBA(*pixels, surface.format, &r, &g, &b, &a);
|
||||
if(r == 158 && g == 0 && b == 93)
|
||||
if(r == sr && g == sg && b == sb)
|
||||
{
|
||||
r = 0;
|
||||
g = 0;
|
||||
@@ -208,14 +212,10 @@ class PetitComputer
|
||||
a = 0;
|
||||
*pixels = 0;
|
||||
*pixels = SDL_MapRGBA(surface.format, r, g, b, a);
|
||||
}/+
|
||||
else
|
||||
*pixels = SDL_MapRGBA(surface.format, r, g, b, a);
|
||||
+/ubyte _r, _g, _b, _a;
|
||||
SDL_GetRGBA(*pixels, surface.format, &_r, &_g, &_b, &_a);
|
||||
}
|
||||
pixels++;
|
||||
}
|
||||
}+/
|
||||
}
|
||||
SDL_RWclose(stream);
|
||||
SDL_FreeSurface(src);
|
||||
return new GraphicPage(surface);
|
||||
@@ -304,6 +304,7 @@ class PetitComputer
|
||||
}
|
||||
}
|
||||
SDL_Rect[] fontTable = new SDL_Rect[65536];
|
||||
int sppage, bgpage;
|
||||
void createFontTable()
|
||||
{
|
||||
string html = cast(string)get("http://smileboom.com/special/ptcm3/download/unicode/");
|
||||
@@ -417,7 +418,9 @@ class PetitComputer
|
||||
{
|
||||
GRP[i] = createEmptyPage();
|
||||
}
|
||||
sppage = 4;
|
||||
GRP[4] = createGRPF(spriteFile);
|
||||
bgpage = 5;
|
||||
GRP[5] = createGRPF(BGFile);
|
||||
writeln("OK");
|
||||
screenWidth = 400;
|
||||
@@ -499,6 +502,7 @@ class PetitComputer
|
||||
|
||||
}
|
||||
Button[] buttonTable;
|
||||
Sprite sprite;
|
||||
void render()
|
||||
{
|
||||
buttonTable = new Button[SDL_SCANCODE_SLEEP + 1];
|
||||
@@ -547,10 +551,12 @@ class PetitComputer
|
||||
//GRP[0] = GRPF;
|
||||
//glEnable(GL_BLEND);
|
||||
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glAlphaFunc(GL_GEQUAL, 0.5);
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
draw = new otya.smilebasic.draw.Draw(this);
|
||||
sprite = new Sprite(this);
|
||||
sprite.spset(0, 0);
|
||||
sprite.spofs(0, 9, 8);
|
||||
while(true)
|
||||
{
|
||||
auto profile = SDL_GetTicks();
|
||||
@@ -568,6 +574,7 @@ class PetitComputer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
renderGraphicPage();
|
||||
renderConsoleGL();
|
||||
sprite.render();
|
||||
SDL_GL_SwapWindow(window);
|
||||
auto renderticks = (SDL_GetTicks() - profile);
|
||||
if(renderprofile) writeln(renderticks);
|
||||
|
||||
99
SMILEBASIC/sprite.d
Normal file
99
SMILEBASIC/sprite.d
Normal file
@@ -0,0 +1,99 @@
|
||||
module otya.smilebasic.sprite;
|
||||
import otya.smilebasic.petitcomputer;
|
||||
import derelict.sdl2.sdl;
|
||||
import derelict.opengl3.gl;
|
||||
enum SpriteAttr
|
||||
{
|
||||
show = 1,
|
||||
rotate90 = 2,
|
||||
rotate180 = 4,
|
||||
rotate270 = 8,
|
||||
}
|
||||
struct SpriteData
|
||||
{
|
||||
int id;
|
||||
int defno;
|
||||
double x, y;
|
||||
double z;/*!*/
|
||||
int u, v, w, h;//個々で保持してるみたい,SPSETをして後でSPDEFをしても変化しない
|
||||
uint color;
|
||||
double[8] var;
|
||||
SpriteAttr attr;
|
||||
bool define;//定義されてればtrue
|
||||
this(int id, int defno)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
this.id = id;
|
||||
this.defno = defno;
|
||||
this.color = -1;
|
||||
this.attr = SpriteAttr.show;
|
||||
}
|
||||
this(int id, int u, int v, int w, int h)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
this.id = id;
|
||||
this.u = u;
|
||||
this.v = v;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.color = -1;
|
||||
this.attr = SpriteAttr.show;
|
||||
}
|
||||
}
|
||||
class Sprite
|
||||
{
|
||||
SDL_Rect[2048] UVTable;
|
||||
SpriteData[512] sprites;
|
||||
PetitComputer petitcom;
|
||||
void initUVTable()
|
||||
{
|
||||
UVTable[0] = SDL_Rect(0, 0, 16, 16);//Ichigo
|
||||
}
|
||||
this(PetitComputer petitcom)
|
||||
{
|
||||
initUVTable;
|
||||
this.petitcom = petitcom;
|
||||
}
|
||||
void animation()
|
||||
{
|
||||
}
|
||||
void render()
|
||||
{
|
||||
auto texture = petitcom.GRP[petitcom.sppage].glTexture;
|
||||
float z = -0.01f;
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
foreach(sprite; sprites)
|
||||
{
|
||||
if(sprite.attr & SpriteAttr.show)
|
||||
{
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
int x2 = cast(int)sprite.x + sprite.w;//-1
|
||||
int y2 = cast(int)sprite.y + sprite.h;
|
||||
int u2 = cast(int)sprite.u + sprite.w;//-1
|
||||
int v2 = cast(int)sprite.v + sprite.h;
|
||||
glTexCoord2f(sprite.u / 512f - 1 , v2 / 512f - 1);
|
||||
glVertex3f(sprite.x / 200f - 1, 1 - y2 / 120f, z);
|
||||
glTexCoord2f(sprite.u / 512f - 1, sprite.v / 512f - 1);
|
||||
glVertex3f(sprite.x / 200f - 1, 1 - sprite.y / 120f, z);
|
||||
glTexCoord2f(u2 / 512f - 1, sprite.v / 512f - 1);
|
||||
glVertex3f(x2 / 200f - 1, 1 - sprite.y / 120f, z);
|
||||
glTexCoord2f(u2 / 512f - 1, v2 / 512f - 1);
|
||||
glVertex3f(x2 / 200f - 1, 1 - y2 / 120f, z);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
void spset(int id, int defno)
|
||||
{
|
||||
sprites[id] = SpriteData(id, UVTable[defno].x, UVTable[defno].y, UVTable[defno].w, UVTable[defno].h);
|
||||
}
|
||||
void spofs(int id, int x, int y)
|
||||
{
|
||||
sprites[id].x = x;
|
||||
sprites[id].y = y;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user