Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: asivitz/mld-game
base: 00912acdc8
...
head fork: asivitz/mld-game
compare: 70bef5eaa8
  • 5 commits
  • 9 files changed
  • 0 commit comments
  • 1 contributor
View
70 ext/Platform.cpp
@@ -15,25 +15,6 @@
using namespace Rice;
using namespace std;
-void checkGLError()
-{
- for (int e = glGetError(); e != GL_NO_ERROR; e = glGetError())
- {
- cout << "******************GLERROR****************";
- switch (e)
- {
- case GL_INVALID_ENUM: cout << "OpenGL: Invalid enum" << endl; break;
- case GL_INVALID_VALUE: cout << "OpenGL: Invalid value" << endl; break;
- case GL_INVALID_OPERATION: cout << "OpenGL: Invalid operation" << endl; break;
- case GL_STACK_OVERFLOW: cout << "OpenGL: Stack overflow" << endl; break;
- case GL_STACK_UNDERFLOW: cout << "OpenGL: Stack underflow" << endl; break;
- case GL_OUT_OF_MEMORY: cout << "OpenGL: Out of memory" << endl; break;
- default: cout << "OpenGL: Unknown Error" << endl;
- }
- }
-}
-
-
Platform::Platform(Object self) : Rice::Director(self)
{
window = new sf::Window(sf::VideoMode(600, 600), "OpenGL");
@@ -124,13 +105,9 @@ void Platform::draw()
glViewport(0, 0, 600, 600);
renderer->drawLights();
glBindFramebuffer(GL_FRAMEBUFFER,0);
- //lightMap->display();
-
- //lightMap->getTexture().copyToImage().saveToFile("out.png");
bool draw_debug = false;
- window->setActive(true);
glViewport(0, 0, 600, 600);
renderer->draw();
@@ -139,7 +116,6 @@ void Platform::draw()
0, -60, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1};
- //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
{
@@ -147,8 +123,10 @@ void Platform::draw()
glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D, lightImage);
glUniform1i(prog->locationOfTex(), 0);
- //glUniform4f(prog->locationOfUniform("color"), 1.0, 1.0, 1.0, 1.0);
- //glUniformMatrix4fv(prog->locationOfUniform("viewMat"), 1, GL_FALSE, renderer->viewMatrix);
+ glUniform2f(prog->locationOfUniform("loc"), 0.0, 0.0);
+ glUniform2f(prog->locationOfUniform("size"), 1.0, 1.0);
+ glUniform4f(prog->locationOfUniform("color"), 1.0, 1.0, 1.0, 1.0);
+ glUniformMatrix4fv(prog->locationOfUniform("viewMat"), 1, GL_FALSE, renderer->viewMatrix);
glUniformMatrix4fv(prog->locationOfModelMat(), 1, GL_FALSE, lightModel);
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, 0);
glDisable(GL_BLEND);
@@ -164,6 +142,8 @@ void Platform::draw()
0,0,0,1};
glUniformMatrix4fv(prog->locationOfUniform("viewMat"), 1, GL_FALSE, renderer->viewMatrix);
glUniformMatrix4fv(prog->locationOfUniform("modelMat"), 1, GL_FALSE, model);
+ glUniform2f(prog->locationOfUniform("loc"), 0.0, 0.0);
+ glUniform2f(prog->locationOfUniform("size"), 1.0, 1.0);
physics->debugDraw();
}
window->display();
@@ -190,6 +170,37 @@ void Platform::addDrawCommand(int texid, Array a)
command->m[i] = (float)NUM2DBL(carr[i]);
}
command->texId = texid;
+
+ command->texLoc[0] = 0;
+ command->texLoc[1] = 0;
+ command->texSize[0] = 1;
+ command->texSize[1] = 1;
+
+ renderer->addCommand(command);
+ }
+}
+
+void Platform::addSpriteDrawCommand(int texid, Array a, Array texTransform)
+{
+ if (a.size() == 16)
+ {
+ DrawCommand * command = new DrawCommand();
+ VALUE * carr = a.to_c_array();
+ for (int i = 0; i < 16; i++)
+ {
+ command->m[i] = (float)NUM2DBL(carr[i]);
+ }
+ command->texId = texid;
+
+ if (texTransform.size() == 4)
+ {
+ VALUE * texVals = texTransform.to_c_array();
+ command->texLoc[0] = (float)NUM2DBL(texVals[0]);
+ command->texLoc[1] = (float)NUM2DBL(texVals[1]);
+ command->texSize[0] = (float)NUM2DBL(texVals[2]);
+ command->texSize[1] = (float)NUM2DBL(texVals[3]);
+ }
+
renderer->addCommand(command);
}
}
@@ -205,6 +216,12 @@ void Platform::addLightCommand(int texid, Array a)
command->m[i] = (float)NUM2DBL(carr[i]);
}
command->texId = texid;
+
+ command->texLoc[0] = 0.0;
+ command->texLoc[1] = 0.0;
+ command->texSize[0] = 1.0;
+ command->texSize[1] = 1.0;
+
renderer->addLightCommand(command);
}
}
@@ -255,6 +272,7 @@ void Init_engine()
define_class<Platform>("Platform")
.define_constructor(Constructor<Platform, Rice::Object>())
.define_method("addDrawCommand", &Platform::addDrawCommand)
+ .define_method("addSpriteDrawCommand", &Platform::addSpriteDrawCommand)
.define_method("addLightCommand", &Platform::addLightCommand)
.define_method("setViewMatrix", &Platform::setViewMatrix)
.define_method("physics=", &Platform::setPhysics)
View
1  ext/Platform.h
@@ -30,6 +30,7 @@ class Platform : public Rice::Director
Object getPhysics();
void addDrawCommand(int texid, Array a);
void addLightCommand(int texid, Array a);
+ void addSpriteDrawCommand(int texid, Array a, Array texTransform);
void setViewMatrix(Array a);
bool isWindowOpen();
int loadImage(string fileName);
View
32 ext/Renderer.cpp
@@ -33,6 +33,24 @@ const GLshort boxTextureCoords[] = {
1, 0,
};
+void checkGLError()
+{
+ for (int e = glGetError(); e != GL_NO_ERROR; e = glGetError())
+ {
+ cout << "******************GLERROR****************";
+ switch (e)
+ {
+ case GL_INVALID_ENUM: cout << "OpenGL: Invalid enum" << endl; break;
+ case GL_INVALID_VALUE: cout << "OpenGL: Invalid value" << endl; break;
+ case GL_INVALID_OPERATION: cout << "OpenGL: Invalid operation" << endl; break;
+ case GL_STACK_OVERFLOW: cout << "OpenGL: Stack overflow" << endl; break;
+ case GL_STACK_UNDERFLOW: cout << "OpenGL: Stack underflow" << endl; break;
+ case GL_OUT_OF_MEMORY: cout << "OpenGL: Out of memory" << endl; break;
+ default: cout << "OpenGL: Unknown Error" << endl;
+ }
+ }
+}
+
void Renderer::setupSquareDrawing()
{
@@ -93,10 +111,17 @@ void Renderer::executeCommands(queue<DrawCommand *> * commands)
DrawCommand * command = commands->front();
glUniformMatrix4fv(program->locationOfModelMat(), 1, GL_FALSE, command->m);
+
+ glUniform2fv(program->locationOfUniform("loc"), 1, command->texLoc);
+ glUniform2fv(program->locationOfUniform("size"), 1, command->texSize);
+
glBindTexture(GL_TEXTURE_2D, command->texId);
glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, 0);
delete command;
commands->pop();
+
+
+ checkGLError();
}
}
@@ -115,7 +140,6 @@ void Renderer::draw()
glVertexAttribPointer(program->indexForAttribute("position"), 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(program->indexForAttribute("position"));
-
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
executeCommands(&drawCommands);
@@ -124,7 +148,7 @@ void Renderer::draw()
void Renderer::drawLights()
{
- glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
+ glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
glClear( GL_COLOR_BUFFER_BIT );
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
@@ -132,13 +156,11 @@ void Renderer::drawLights()
program->setAsActive();
glUniformMatrix4fv(program->locationOfUniform("viewMat"), 1, GL_FALSE, viewMatrix);
- glUniform4f(program->locationOfUniform("color"), 1.0, 1.0, 1.0, 1.0);
+ glUniform4f(program->locationOfUniform("color"), 1.0, 0.0, 1.0, 1.0);
glVertexAttribPointer(program->indexForAttribute("position"), 2, GL_FLOAT, 0, 0, 0);
glEnableVertexAttribArray(program->indexForAttribute("position"));
-
- //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND);
executeCommands(&lightCommands);
View
4 ext/Renderer.h
@@ -12,6 +12,8 @@ struct DrawCommand
{
float m[16];
GLuint texId;
+ float texLoc[2];
+ float texSize[2];
};
class Renderer
@@ -38,4 +40,6 @@ class Renderer
float viewMatrix[16];
};
+void checkGLError();
+
#endif
View
740 images/red_anims.json
@@ -0,0 +1,740 @@
+{"frames": {
+
+"red-idle0001.png":
+{
+ "frame": {"x":162,"y":42,"w":38,"h":56},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0002.png":
+{
+ "frame": {"x":82,"y":450,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0003.png":
+{
+ "frame": {"x":386,"y":158,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":6,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0004.png":
+{
+ "frame": {"x":372,"y":308,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":7,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0005.png":
+{
+ "frame": {"x":318,"y":302,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0006.png":
+{
+ "frame": {"x":264,"y":264,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":8,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0007.png":
+{
+ "frame": {"x":314,"y":342,"w":38,"h":50},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":10,"w":38,"h":50},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0008.png":
+{
+ "frame": {"x":256,"y":344,"w":38,"h":48},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":12,"w":38,"h":48},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0009.png":
+{
+ "frame": {"x":206,"y":344,"w":38,"h":48},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":12,"w":38,"h":48},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0010.png":
+{
+ "frame": {"x":466,"y":354,"w":38,"h":48},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":12,"w":38,"h":48},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0011.png":
+{
+ "frame": {"x":416,"y":354,"w":38,"h":48},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":11,"w":38,"h":48},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0012.png":
+{
+ "frame": {"x":366,"y":348,"w":38,"h":48},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":11,"w":38,"h":48},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0013.png":
+{
+ "frame": {"x":462,"y":2,"w":38,"h":48},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":11,"w":38,"h":48},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0014.png":
+{
+ "frame": {"x":262,"y":304,"w":38,"h":50},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":10,"w":38,"h":50},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0015.png":
+{
+ "frame": {"x":154,"y":306,"w":38,"h":50},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":10,"w":38,"h":50},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0016.png":
+{
+ "frame": {"x":156,"y":266,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":8,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0017.png":
+{
+ "frame": {"x":210,"y":264,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0018.png":
+{
+ "frame": {"x":330,"y":120,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":6,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0019.png":
+{
+ "frame": {"x":274,"y":120,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":5,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0020.png":
+{
+ "frame": {"x":82,"y":392,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-idle0021.png":
+{
+ "frame": {"x":160,"y":122,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":5,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0001.png":
+{
+ "frame": {"x":434,"y":274,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":8,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0002.png":
+{
+ "frame": {"x":82,"y":334,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0003.png":
+{
+ "frame": {"x":42,"y":42,"w":38,"h":58},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":6,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0004.png":
+{
+ "frame": {"x":402,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":6,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0005.png":
+{
+ "frame": {"x":342,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":5,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0006.png":
+{
+ "frame": {"x":282,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0007.png":
+{
+ "frame": {"x":82,"y":276,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":5,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0008.png":
+{
+ "frame": {"x":222,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0009.png":
+{
+ "frame": {"x":162,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":3,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0010.png":
+{
+ "frame": {"x":102,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0011.png":
+{
+ "frame": {"x":42,"y":2,"w":38,"h":58},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":3,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0012.png":
+{
+ "frame": {"x":380,"y":268,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0013.png":
+{
+ "frame": {"x":210,"y":304,"w":38,"h":50},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":38,"h":50},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0014.png":
+{
+ "frame": {"x":434,"y":234,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0015.png":
+{
+ "frame": {"x":218,"y":120,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0016.png":
+{
+ "frame": {"x":444,"y":156,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":5,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0017.png":
+{
+ "frame": {"x":82,"y":218,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0018.png":
+{
+ "frame": {"x":326,"y":262,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0019.png":
+{
+ "frame": {"x":380,"y":228,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0020.png":
+{
+ "frame": {"x":156,"y":226,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":8,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0021.png":
+{
+ "frame": {"x":326,"y":222,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":8,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0022.png":
+{
+ "frame": {"x":216,"y":224,"w":38,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":8,"w":38,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0023.png":
+{
+ "frame": {"x":388,"y":118,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":6,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-jump0024.png":
+{
+ "frame": {"x":122,"y":42,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0001.png":
+{
+ "frame": {"x":332,"y":80,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":6,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0002.png":
+{
+ "frame": {"x":276,"y":80,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0003.png":
+{
+ "frame": {"x":452,"y":74,"w":40,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":40,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0004.png":
+{
+ "frame": {"x":272,"y":222,"w":40,"h":52},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":3,"w":40,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0005.png":
+{
+ "frame": {"x":162,"y":82,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":5,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0006.png":
+{
+ "frame": {"x":86,"y":100,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":6,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0007.png":
+{
+ "frame": {"x":82,"y":160,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0008.png":
+{
+ "frame": {"x":42,"y":450,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":7,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0009.png":
+{
+ "frame": {"x":42,"y":392,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":5,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0010.png":
+{
+ "frame": {"x":220,"y":80,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0011.png":
+{
+ "frame": {"x":426,"y":314,"w":38,"h":50},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":3,"w":38,"h":50},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0012.png":
+{
+ "frame": {"x":450,"y":116,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":4,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0013.png":
+{
+ "frame": {"x":42,"y":334,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":5,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-run0014.png":
+{
+ "frame": {"x":2,"y":442,"w":38,"h":58},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":5,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0001.png":
+{
+ "frame": {"x":42,"y":218,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0002.png":
+{
+ "frame": {"x":394,"y":42,"w":34,"h":56},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":19,"y":4,"w":34,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0003.png":
+{
+ "frame": {"x":384,"y":198,"w":28,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":26,"y":6,"w":28,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0004.png":
+{
+ "frame": {"x":272,"y":160,"w":30,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":25,"y":6,"w":30,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0005.png":
+{
+ "frame": {"x":160,"y":162,"w":30,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":25,"y":6,"w":30,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0006.png":
+{
+ "frame": {"x":216,"y":160,"w":30,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":25,"y":6,"w":30,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0007.png":
+{
+ "frame": {"x":328,"y":192,"w":28,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":26,"y":6,"w":28,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0008.png":
+{
+ "frame": {"x":272,"y":192,"w":28,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":25,"y":6,"w":28,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0009.png":
+{
+ "frame": {"x":452,"y":42,"w":30,"h":56},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":23,"y":4,"w":30,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0010.png":
+{
+ "frame": {"x":278,"y":42,"w":36,"h":56},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":17,"y":4,"w":36,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-shoot0011.png":
+{
+ "frame": {"x":220,"y":42,"w":36,"h":56},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":17,"y":4,"w":36,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0001.png":
+{
+ "frame": {"x":42,"y":276,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0002.png":
+{
+ "frame": {"x":42,"y":102,"w":42,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":19,"y":4,"w":42,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0003.png":
+{
+ "frame": {"x":442,"y":196,"w":36,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":21,"y":6,"w":36,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0004.png":
+{
+ "frame": {"x":122,"y":268,"w":30,"h":52},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":24,"y":7,"w":30,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0005.png":
+{
+ "frame": {"x":160,"y":194,"w":30,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":24,"y":6,"w":30,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0006.png":
+{
+ "frame": {"x":122,"y":214,"w":32,"h":52},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":23,"y":7,"w":32,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0007.png":
+{
+ "frame": {"x":126,"y":100,"w":32,"h":52},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":23,"y":7,"w":32,"h":52},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0008.png":
+{
+ "frame": {"x":216,"y":192,"w":30,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":25,"y":6,"w":30,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0009.png":
+{
+ "frame": {"x":328,"y":160,"w":30,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":25,"y":6,"w":30,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0010.png":
+{
+ "frame": {"x":122,"y":158,"w":36,"h":54},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":19,"y":5,"w":36,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0011.png":
+{
+ "frame": {"x":336,"y":42,"w":36,"h":56},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":17,"y":4,"w":36,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-throw0012.png":
+{
+ "frame": {"x":394,"y":78,"w":38,"h":54},
+ "rotated": true,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":5,"w":38,"h":54},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0001.png":
+{
+ "frame": {"x":42,"y":160,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0002.png":
+{
+ "frame": {"x":82,"y":42,"w":38,"h":56},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":4,"w":38,"h":56},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0003.png":
+{
+ "frame": {"x":2,"y":382,"w":38,"h":58},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":5,"w":38,"h":58},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0004.png":
+{
+ "frame": {"x":2,"y":320,"w":38,"h":60},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":4,"w":38,"h":60},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0005.png":
+{
+ "frame": {"x":2,"y":194,"w":38,"h":62},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":2,"w":38,"h":62},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0006.png":
+{
+ "frame": {"x":2,"y":130,"w":38,"h":62},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":2,"w":38,"h":62},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0007.png":
+{
+ "frame": {"x":2,"y":66,"w":38,"h":62},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":2,"w":38,"h":62},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0008.png":
+{
+ "frame": {"x":2,"y":2,"w":38,"h":62},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":15,"y":1,"w":38,"h":62},
+ "sourceSize": {"w":64,"h":64}
+},
+"red-walk0009.png":
+{
+ "frame": {"x":2,"y":258,"w":38,"h":60},
+ "rotated": false,
+ "trimmed": true,
+ "spriteSourceSize": {"x":16,"y":2,"w":38,"h":60},
+ "sourceSize": {"w":64,"h":64}
+}},
+"meta": {
+ "app": "http://www.texturepacker.com",
+ "version": "1.0",
+ "image": "red_anims.png",
+ "format": "RGBA8888",
+ "size": {"w":512,"h":512},
+ "scale": "1",
+ "smartupdate": "$TexturePacker:SmartUpdate:9867249e4af39a939dd4cba70ecb92da$"
+}
+}
View
BIN  images/red_anims.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
63 main.rb
@@ -5,20 +5,11 @@
require_relative 'ext/engine'
require_relative 'matrix_graphics'
require_relative 'engine'
+require_relative 'sprites'
# maps physics body ids to game objects
$body_map = {}
$drawables = []
-$tex_map = {}
-
-def load_image name
- texid = $tex_map[name]
- if not texid
- texid = $platform.loadImage name
- $tex_map[name] = texid
- end
- texid
-end
MAX_VEL = 10.0
MOVE_IMP = 4.0
@@ -28,14 +19,16 @@ class Player < WorldObj
attr_accessor :num_standing_on_solid
def initialize pos
- @texid = load_image "2player\ shooter/images/redGuyLeft.png"
- #@texid = $platform.loadImage "images/triangle.png"
+ @sprite = SpriteSheet.new "red_anims"
@body = $physics.addPlayer(pos, 2.0)
$body_map[@body.id] = self
@num_standing_on_solid = 0
@jump_time = Time.now
@fire_time = Time.now
@last_faced_direction = 1
+ @animation_start = Time.now
+ @animation_time = 0
+ @current_animation = "red-idle"
end
def begin_contact other
@@ -54,11 +47,33 @@ def mat
m = Matrix.identity(4)
pos = @body.pos
m = m.translate(pos[0],pos[1],0)
- m = m.scale(-2 * @last_faced_direction,4,1)
+ m = m.scale(-1 * @last_faced_direction,1,1)
end
def draw
- $platform.addDrawCommand(@texid, self.mat.flatten)
+ m = self.mat
+
+ frame = @sprite.timed_frame(@current_animation, (@animation_time - @animation_time.to_i))
+
+ w = frame.w
+ h = frame.h
+
+ m = m.translate(-0.4,-1.9,1)
+ m = m.scale(0.08,0.08,1)
+
+ if frame.rotated
+ w = frame.h
+ h = frame.w
+ m = m.rotate(-Math::PI/2.0)
+
+ m = m.translate(w/2.0,0,0)
+ m = m.scale(w, h, 1)
+ else
+ m = m.translate(0,h/2.0,0)
+ m = m.scale(w, h, 1)
+ end
+
+ $platform.addSpriteDrawCommand(@sprite.texid, m.flatten, [frame.x/@sprite.size[0], frame.y/@sprite.size[1], w/@sprite.size[0], h/@sprite.size[1]])
end
def move_right
@@ -77,6 +92,7 @@ def move_left
def jump
if @num_standing_on_solid > 0 && (Time.now - @jump_time).to_f > 0.5
+ @animation_time = 0.0
@body.push([0.0,JUMP_IMP])
@jump_time = Time.now
end
@@ -92,6 +108,25 @@ def update time
vel = $one.body.vel
vel.x *= 1.0 - 1.0 * time #* factor
$one.body.vel = vel
+
+
+ delta = (Time.now - @animation_start).to_f
+ @animation_start = Time.now
+
+ if @num_standing_on_solid > 0
+ speed = (vel.x).abs
+ if speed > 2.5
+ @current_animation = "red-run"
+ delta *= speed / 8.0
+ else
+ @current_animation = "red-idle"
+ end
+ @animation_time += delta
+ else
+ @current_animation = "red-jump"
+ @animation_time += delta
+ @animation_time = [@animation_time, 0.99].min
+ end
end
def fire
View
5 shaders/Shader.vsh
@@ -12,10 +12,13 @@ attribute vec2 texCoords;
uniform mat4 modelMat;
uniform mat4 viewMat;
+uniform vec2 loc;
+uniform vec2 size;
+
varying vec2 texCoordsVarying;
void main()
{
gl_Position = viewMat * modelMat * position;
- texCoordsVarying = texCoords;
+ texCoordsVarying = (texCoords * size) + loc;
}
View
66 sprites.rb
@@ -0,0 +1,66 @@
+require 'json'
+
+$tex_map = {}
+
+def load_image name
+ texid = $tex_map[name]
+ if not texid
+ texid = $platform.loadImage name
+ $tex_map[name] = texid
+ end
+ texid
+end
+
+class SpriteFrame
+ attr_accessor :x, :y, :w, :h, :rotated
+end
+
+class SpriteSheet
+ attr_accessor :texid
+ attr_reader :size
+
+ def initialize name
+ @metadata = JSON.load File.new("images/#{name}.json")
+ @texid = load_image "images/#{name}.png"
+ info = @metadata["meta"]
+ @size = [info["size"]["w"], info["size"]["h"]]
+
+ @frames = {}
+
+ @anim_counts = {}
+
+ @metadata["frames"].keys.each do |key|
+ data = /(.*)(\d{4})/.match(key)
+ name = data[1]
+ prev = @anim_counts[name]
+ prev = 0 if prev.nil?
+ @anim_counts[name] = [prev, data[2].to_i].max
+ end
+ p @anim_counts
+ end
+
+ def timed_frame(name, fraction)
+ count = @anim_counts[name]
+ idx = (fraction * count).floor + 1
+ key = name + "%04d" % idx
+ self.frame key
+ end
+
+ def frame name
+ frame = @frames[name]
+ if not frame
+ info = @metadata["frames"]["#{name}.png"]
+ frame_info = info["frame"]
+
+ frame = SpriteFrame.new
+ frame.x = Float(frame_info["x"])
+ frame.y = Float(frame_info["y"])
+ frame.w = Float(frame_info["w"])
+ frame.h = Float(frame_info["h"])
+
+ frame.rotated = info["rotated"]
+ @frames[name] = frame
+ end
+ frame
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.