Whole project

This commit is contained in:
Gnarwhal 2024-08-07 05:01:16 +00:00
parent c737011314
commit a509a049b9
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
78 changed files with 3671 additions and 93 deletions

BIN
Pinball.exe Normal file

Binary file not shown.

BIN
Pinball.zip Normal file

Binary file not shown.

1
res/audio/harp.ceoil Normal file
View file

@ -0,0 +1 @@
3,0,0,0,115,16,4,3,46,0,4,128,0,256,46,0,4,128,0,113,56,0,2,128,0,73,15,0,0,0,4,1,36,4,0,0,0,0,0,1,4,13,36,1,2,0,36,1,3,0,36,1,5,0,36,1,6,0,36,1,7,0,36,1,8,0,36,1,9,0,36,1,10,0,36,1,11,0,36,1,12,0,36,1,13,0,36,1,15,0,37,1,14,0,0,0,0,0,4,3,36,4,0,0,36,2,13,0,36,2,10,0,0,0,0,1,4,13,36,1,2,0,36,1,3,0,36,1,5,0,36,1,7,0,36,1,9,0,36,1,11,0,36,1,12,0,37,1,14,0,39,1,15,0,36,1,13,0,36,1,10,0,36,1,8,0,36,1,6,0,0,0,0,1,4,13,36,1,2,0,36,1,3,0,36,1,5,0,36,1,6,0,36,1,7,0,36,1,8,0,36,1,9,0,36,1,10,0,36,1,11,0,36,1,12,0,34,1,13,0,36,1,14,0,37,1,15,0,0,0,0,0,4,7,36,4,0,0,37,4,4,0,39,4,8,0,41,1,12,0,48,1,15,0,43,1,13,0,46,1,14,0,0,0,0,0,4,3,36,4,0,0,36,2,10,0,36,2,13,0,0,0,0,0,4,8,36,4,0,0,43,1,4,0,41,1,5,0,43,6,6,0,41,1,12,0,39,1,13,0,41,1,14,0,43,1,15,0,0,0,0,0,4,12,46,1,1,0,48,1,3,0,38,1,6,0,39,1,5,0,36,3,7,0,34,1,10,0,51,1,5,0,50,1,6,0,48,3,7,0,46,1,10,0,48,1,13,0,36,1,13,0,0,0,0,1,4,15,36,1,0,0,36,1,1,0,36,1,3,0,36,1,4,0,36,1,6,0,36,1,7,0,36,1,10,0,36,1,9,0,36,1,12,0,36,1,13,0,36,1,15,0,48,1,12,0,48,1,13,0,60,1,9,0,60,1,10,0,0,0,0,1,4,3,55,1,0,0,56,4,2,0,55,4,6,0,0,0,0,1,4,3,48,1,13,0,48,1,14,0,36,4,0,0,0,0,0,1,4,3,55,1,0,0,56,4,2,0,55,4,6,0,0,0,0,1,4,4,60,1,0,0,60,1,1,0,60,1,3,0,60,1,6,0,0,0,0,1,4,4,48,1,0,0,48,1,1,0,48,1,3,0,48,1,6,0,0,20,0,20,0,1,-1,-1,-1,-1,-1,-1,0,1,-1,-1,-1,-1,-1,-1,0,3,-1,-1,-1,-1,-1,-1,0,4,-1,-1,-1,-1,-1,-1,2,1,-1,-1,-1,-1,-1,-1,0,1,-1,-1,-1,-1,-1,-1,5,3,-1,-1,-1,-1,-1,-1,6,1,-1,-1,-1,-1,-1,-1,6,1,-1,-1,-1,-1,-1,-1,0,1,-1,-1,-1,-1,-1,-1,7,3,-1,-1,-1,-1,-1,-1,8,4,-1,-1,-1,-1,-1,-1,9,1,-1,-1,-1,-1,-1,-1,10,1,-1,-1,-1,-1,-1,-1,11,3,-1,-1,-1,-1,-1,-1,12,4,-1,-1,-1,-1,-1,-1,13,1,-1,-1,-1,-1,-1,-1,14,1,-1,-1,-1,-1,-1,-1,0,3,-1,-1,-1,-1,-1,-1,0,4,-1,-1,-1,-1,-1,-1,

BIN
res/audio/harp.wav Normal file

Binary file not shown.

BIN
res/img/Background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

BIN
res/img/Continue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
res/img/Info1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

BIN
res/img/Info1Glow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
res/img/Info2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 KiB

BIN
res/img/Info2Glow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
res/img/InfoBorder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
res/img/IntroLevel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

BIN
res/img/Level1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
res/img/Level2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

BIN
res/img/Pinball.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

BIN
res/img/StartingGlow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
res/img/StartingNonglow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
res/img/Win.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
res/img/WinGlow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

View file

@ -0,0 +1,53 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#version 330 core
uniform vec2 resolution;
uniform sampler2D tex;
uniform sampler2D background;
uniform bool horizontal = true;
uniform float brightness = 0.55;
uniform float distance = 15.0;
in vec2 texCoords;
layout (location = 0) out vec4 color;
void main() {
vec2 pixel = 1.0 / resolution;
int numPixels = int(distance * resolution.y / 1080.0);
float weight = 1.0 / numPixels;
vec2 transform = vec2(pixel.x * int(horizontal), pixel.y * int(!horizontal));
color = texture(tex, texCoords);
vec3 result = texture(tex, texCoords).rgb * weight;
for(int i = 1; i < numPixels; ++i) {
result += texture(tex, texCoords + transform * i).rgb * weight;
result += texture(tex, texCoords - transform * i).rgb * weight;
}
color.rgb = mix(result, texture(background, vec2(texCoords.x, 1.0 - texCoords.y)).rgb, 1 - brightness);
}

View file

@ -0,0 +1,37 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#version 330 core
layout (location = 0) in vec3 vertices;
layout (location = 1) in vec2 textureCoords;
out vec2 texCoords;
void main() {
gl_Position = vec4(vertices, 1);
texCoords = textureCoords;
}

View file

@ -0,0 +1,38 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#version 330 core
uniform vec4 inputColor = vec4(1, 0.5, 0.9, 1);
uniform sampler2D tex;
in vec2 texCoords;
layout (location = 0) out vec4 color;
void main() {
color = texture(tex, texCoords) * inputColor;
}

View file

@ -0,0 +1,39 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#version 330 core
uniform mat4 mvp;
layout (location = 0) in vec3 vertices;
layout (location = 1) in vec2 textureCoords;
out vec2 texCoords;
void main() {
gl_Position = mvp * vec4(vertices, 1);
texCoords = textureCoords;
}

View file

@ -65,6 +65,10 @@ void GenoAudioSource::loop(bool loop) {
alSourcei(source, AL_LOOPING, loop); alSourcei(source, AL_LOOPING, loop);
} }
void GenoAudioSource::setSpeed(float scale) {
alSourcef(source, AL_PITCH, scale);
}
GenoAudioSource::~GenoAudioSource() { GenoAudioSource::~GenoAudioSource() {
alDeleteSources(1, &source); alDeleteSources(1, &source);
} }

View file

@ -42,6 +42,7 @@ class GenoAudioSource {
void stop(); void stop();
void setBuffer(GenoAudioBuffer * buffer); void setBuffer(GenoAudioBuffer * buffer);
void loop(bool loop); void loop(bool loop);
void setSpeed(float scale);
~GenoAudioSource(); ~GenoAudioSource();
}; };

View file

@ -70,8 +70,10 @@ void GenoLoop::start() {
for (uint32 i = 0; i < callbackCount; ++i) { for (uint32 i = 0; i < callbackCount; ++i) {
frames[i] = 0; frames[i] = 0;
pastTimes[i] = GenoTime::getTime(milliseconds); pastTimes[i] = GenoTime::getTime(milliseconds);
truePastTimes[i] = GenoTime::getTime(milliseconds);
} }
pastTimes[callbackCount] = GenoTime::getTime(milliseconds); pastTimes[callbackCount] = GenoTime::getTime(milliseconds);
truePastTimes[callbackCount] = GenoTime::getTime(milliseconds);
looping = true; looping = true;
while (looping) { while (looping) {
@ -86,7 +88,7 @@ void GenoLoop::start() {
for (uint32 i = 0; i < callbackCount; ++i) { for (uint32 i = 0; i < callbackCount; ++i) {
if (curTime - pastTimes[i + 1] >= millisPerFrames[i]) { if (curTime - pastTimes[i + 1] >= millisPerFrames[i]) {
callbacks[i](); callbacks[i]();
deltas[i] = (curTime - truePastTimes[i + 1]) * deltaScales[i]; deltas[i] = (curTime - truePastTimes[i + 1]) * deltaScales[i] / milliseconds;
pastTimes[i + 1] += millisPerFrames[i]; pastTimes[i + 1] += millisPerFrames[i];
truePastTimes[i + 1] = curTime; truePastTimes[i + 1] = curTime;
++frames[i]; ++frames[i];

View file

@ -46,7 +46,7 @@ class GenoShader {
public: public:
void enable(); void enable();
void disable(); void disable();
~GenoShader(); virtual ~GenoShader();
}; };
class GenoMvpShader : public GenoShader { class GenoMvpShader : public GenoShader {

View file

@ -165,7 +165,8 @@ void GenoSpritesheet::bind(uint8 textureNum) const {
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
} }
void GenoSpritesheet::unbind() const { void GenoSpritesheet::unbind(uint8 textureNum) const {
glActiveTexture(GL_TEXTURE0 + textureNum);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }

View file

@ -83,7 +83,7 @@ class GenoSpritesheet : public GenoTexture {
GenoMatrix4f getTransform(const GenoVector2i & coords) const; GenoMatrix4f getTransform(const GenoVector2i & coords) const;
virtual void bind(uint8 textureNum = 0) const; virtual void bind(uint8 textureNum = 0) const;
virtual void unbind() const; virtual void unbind(uint8 textureNum = 0) const;
~GenoSpritesheet(); ~GenoSpritesheet();
}; };

View file

@ -37,7 +37,7 @@ class GenoTexture {
GenoTexture(uint32 id); GenoTexture(uint32 id);
public: public:
virtual void bind(uint8 textureNum = 0) const = 0; virtual void bind(uint8 textureNum = 0) const = 0;
virtual void unbind() const = 0; virtual void unbind(uint8 textureNum = 0) const = 0;
virtual ~GenoTexture(); virtual ~GenoTexture();
}; };

View file

@ -87,7 +87,8 @@ void GenoTexture2D::bind(uint8 textureNum) const {
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
} }
void GenoTexture2D::unbind() const { void GenoTexture2D::unbind(uint8 textureNum) const {
glActiveTexture(GL_TEXTURE0 + textureNum);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }

View file

@ -65,7 +65,7 @@ class GenoTexture2D : public GenoTexture {
uint32 getWidth() const; uint32 getWidth() const;
uint32 getHeight() const; uint32 getHeight() const;
virtual void bind(uint8 textureNum = 0) const; virtual void bind(uint8 textureNum = 0) const;
virtual void unbind() const; virtual void unbind(uint8 textureNum = 0) const;
~GenoTexture2D(); ~GenoTexture2D();
friend class GenoFramebuffer; friend class GenoFramebuffer;

View file

@ -24,40 +24,27 @@
* *
*******************************************************************************/ *******************************************************************************/
#include "GenoGL.h"
#include "GenoVao.h" #include "GenoVao.h"
template <typename T> GenoVao::GenoVao() {}
struct GenoVertexAttribType {};
template<> struct GenoVertexAttribType< int8 > { const static uint32 TYPE = GL_UNSIGNED_BYTE; }; GenoVao::GenoVao(const GenoVao & vao) :
template<> struct GenoVertexAttribType<uint8 > { const static uint32 TYPE = GL_BYTE; }; vao(vao.vao),
template<> struct GenoVertexAttribType< int16> { const static uint32 TYPE = GL_UNSIGNED_SHORT; }; ibo(vao.ibo),
template<> struct GenoVertexAttribType<uint16> { const static uint32 TYPE = GL_SHORT; }; count(vao.count),
template<> struct GenoVertexAttribType< int32> { const static uint32 TYPE = GL_UNSIGNED_INT; }; attribs(vao.attribs) {
template<> struct GenoVertexAttribType<uint32> { const static uint32 TYPE = GL_INT; }; for (uint32 i = 0; i < attribs; ++i)
template<> struct GenoVertexAttribType<float > { const static uint32 TYPE = GL_FLOAT; }; vbos[i] = vao.vbos[i];
template<> struct GenoVertexAttribType<double> { const static uint32 TYPE = GL_DOUBLE; };
GenoVao::GenoVao(uint32 num, float verts[], uint32 count, uint32 indices[]) {
this->count = count;
glGenVertexArrays(1, &vao);
addAttrib(num, 3, verts);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(int32), indices, GL_STATIC_DRAW);
} }
template <typename T> GenoVao & GenoVao::operator=(const GenoVao & vao) {
void GenoVao::addAttrib(uint32 num, uint32 stride, T data[]) { this->vao = vao.vao;
glBindVertexArray(vao); for (uint32 i = 0; i < attribs; ++i)
glGenBuffers(1, vbos + attribs); vbos[i] = vao.vbos[i];
glBindBuffer(GL_ARRAY_BUFFER, vbos[attribs]); this->ibo = vao.ibo;
glBufferData(GL_ARRAY_BUFFER, stride * num * sizeof(T), data, GL_STATIC_DRAW); this->count = vao.count;
glVertexAttribPointer(attribs, stride, GenoVertexAttribType<T>::TYPE, GL_FALSE, 0, (void*) 0); this->attribs = vao.attribs;
glEnableVertexAttribArray(attribs); return *this;
++attribs;
} }
void GenoVao::render() { void GenoVao::render() {

View file

@ -28,14 +28,60 @@
#define GNARLY_GENOME_VAO #define GNARLY_GENOME_VAO
#include "../GenoInts.h" #include "../GenoInts.h"
#include "GenoGL.h"
class GenoVao { class GenoVao {
private: private:
uint32 vao, vbos[15], ibo, count;
template <typename T>
struct GenoVertexAttribType {};
template<> struct GenoVertexAttribType< int8 > { const static uint32 TYPE = GL_UNSIGNED_BYTE; };
template<> struct GenoVertexAttribType<uint8 > { const static uint32 TYPE = GL_BYTE; };
template<> struct GenoVertexAttribType< int16> { const static uint32 TYPE = GL_UNSIGNED_SHORT; };
template<> struct GenoVertexAttribType<uint16> { const static uint32 TYPE = GL_SHORT; };
template<> struct GenoVertexAttribType< int32> { const static uint32 TYPE = GL_UNSIGNED_INT; };
template<> struct GenoVertexAttribType<uint32> { const static uint32 TYPE = GL_INT; };
template<> struct GenoVertexAttribType<float > { const static uint32 TYPE = GL_FLOAT; };
template<> struct GenoVertexAttribType<double> { const static uint32 TYPE = GL_DOUBLE; };
uint32 vao;
uint32 vbos[15];
uint32 ibo;
uint32 count;
uint8 attribs = 0; uint8 attribs = 0;
public: public:
GenoVao(uint32 num, float verts[], uint32 count, uint32 indices[]); GenoVao();
template <typename T> void addAttrib(uint32 num, uint32 stride, T data[]); GenoVao(const GenoVao & vao);
template <typename T> GenoVao(uint32 num, const T * verts, uint32 count, const uint32 * indices) :
count(count) {
glGenVertexArrays(1, &vao);
addAttrib(num, 3, verts);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(int32), indices, GL_STATIC_DRAW);
}
GenoVao & operator=(const GenoVao & vao);
template <typename T> void addAttrib(uint32 num, uint32 stride, const T * data) {
glBindVertexArray(vao);
glGenBuffers(1, vbos + attribs);
glBindBuffer(GL_ARRAY_BUFFER, vbos[attribs]);
glBufferData(GL_ARRAY_BUFFER, stride * num * sizeof(T), data, GL_STATIC_DRAW);
glVertexAttribPointer(attribs, stride, GenoVertexAttribType<T>::TYPE, GL_FALSE, 0, (void*) 0);
glEnableVertexAttribArray(attribs);
++attribs;
}
template <typename T> void rebuffer(uint32 attrib, uint32 num, uint32 stride, const T * data) {
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbos[attribs]);
glBufferSubData(GL_ARRAY_BUFFER, 0, stride * num * sizeof(T), data);
}
void render(); void render();
~GenoVao(); ~GenoVao();
}; };

View file

@ -47,15 +47,6 @@ class GenoVector {
} }
public: public:
static GenoVector<N, T> * newArray(uint32 length) {
T * v = new T[N * length];
GenoVector<N, T> * ret = new GenoVector<N, T>[length];
ret[0] = GenoVector<N, T>(v);
for (uint32 i = 1; i < length; ++i)
ret[i] = GenoVector<N, T>(v + i * N, false);
return ret;
}
T * v; T * v;
GenoVector() : GenoVector() :
@ -88,6 +79,7 @@ class GenoVector {
GenoVector(const GenoVector<N, T> & vector) : GenoVector(const GenoVector<N, T> & vector) :
v(new T[N]) { v(new T[N]) {
std::cout << "aoeu" << std::endl;
for (uint32 i = 0; i < N; ++i) for (uint32 i = 0; i < N; ++i)
v[i] = vector.v[i]; v[i] = vector.v[i];
} }
@ -95,16 +87,19 @@ class GenoVector {
GenoVector(GenoVector<N, T> && vector) noexcept : GenoVector(GenoVector<N, T> && vector) noexcept :
owner(vector.owner), owner(vector.owner),
v(vector.v) { v(vector.v) {
std::cout << "aoeu" << std::endl;
vector.owner = false; vector.owner = false;
} }
GenoVector<N, T> & operator=(const GenoVector<N, T> & vector) { GenoVector<N, T> & operator=(const GenoVector<N, T> & vector) {
std::cout << "aoeu" << std::endl;
for (uint32 i = 0; i < N; ++i) for (uint32 i = 0; i < N; ++i)
v[i] = vector.v[i]; v[i] = vector.v[i];
return *this; return *this;
} }
GenoVector<N, T> & operator=(GenoVector<N, T> && vector) noexcept { GenoVector<N, T> & operator=(GenoVector<N, T> && vector) noexcept {
std::cout << "aoeu" << std::endl;
if (owner) { if (owner) {
clean(); clean();
owner = vector.owner; owner = vector.owner;
@ -201,6 +196,23 @@ class GenoVector {
return *this; return *this;
} }
GenoVector<N, T> & bisect(const GenoVector<N, T> & vector) {
return *this = getLength() * vector + *this * vector.getLength();
}
GenoVector<N, T> & lerp(const GenoVector<N, T> & end, double interpAmount) {
for (uint32 i = 0; i < N; ++i)
v[i] = (T) (v[i] + (end.v[i] - v[i]) * interpAmount);
return *this;
}
bool isZeroVector() {
for (uint32 i = 0; i < N; ++i)
if (v[i] != 0)
return false;
return true;
}
GenoVector<N, T> & set(const GenoVector<N, T> & set) { GenoVector<N, T> & set(const GenoVector<N, T> & set) {
for (uint32 i = 0; i < N; ++i) for (uint32 i = 0; i < N; ++i)
v[i] = set.v[i]; v[i] = set.v[i];
@ -397,6 +409,31 @@ GenoVector<N, T> & project(const GenoVector<N, T> & vector, const GenoVector<N,
return target; return target;
} }
template <uint32 N, typename T>
GenoVector<N, T> bisect(const GenoVector<N, T> & vector1, const GenoVector<N, T> & vector2) {
return vector1.getLength() * vector2 + vector1 * vector2.getLength();
}
template <uint32 N, typename T>
GenoVector<N, T> bisect(const GenoVector<N, T> & vector1, const GenoVector<N, T> & vector2, GenoVector<N, T> & target) {
return target = vector1.getLength() * vector2 + vector1 * vector2.getLength();
}
template <uint32 N, typename T>
GenoVector<N, T> lerp(const GenoVector<N, T> & start, const GenoVector<N, T> & end, double interpAmount) {
auto newV = new T[N];
for (uint32 i = 0; i < N; ++i)
newV[i] = (T) (start.v[i] + (end.v[i] - start.v[i]) * interpAmount);
return newV;
}
template <uint32 N, typename T>
GenoVector<N, T> & lerp(const GenoVector<N, T> & start, const GenoVector<N, T> & end, double interpAmount, GenoVector<N, T> & target) {
for (uint32 i = 0; i < N; ++i)
target.v[i] = (T) (start.v[i] + (end.v[i] - start.v[i]) * interpAmount);
return target;
}
template <uint32 N, typename T> template <uint32 N, typename T>
T angleBetween(const GenoVector<N, T> & vector1, const GenoVector<N, T> & vector2) { T angleBetween(const GenoVector<N, T> & vector1, const GenoVector<N, T> & vector2) {
return acos(dot(vector1, vector2) / (vector1.getLength() * vector2.getLength())); return acos(dot(vector1, vector2) / (vector1.getLength() * vector2.getLength()));

View file

@ -77,15 +77,6 @@ class GenoVector<2, T> {
} }
public: public:
static GenoVector<2, T> * newArray(uint32 length) {
T * v = new T[2 * length];
GenoVector<2, T> * ret = new GenoVector<2, T>[length];
ret[0] = GenoVector<2, T>(v);
for (uint32 i = 1; i < length; ++i)
ret[i] = GenoVector<2, T>(v + i * 2, false);
return ret;
}
T * v; T * v;
GenoVector() : GenoVector() :
@ -277,6 +268,21 @@ class GenoVector<2, T> {
return *this; return *this;
} }
GenoVector<2, T> & bisect(const GenoVector<2, T> & vector) {
return *this = getLength() * vector + *this * vector.getLength();
}
GenoVector<2, T> & lerp(const GenoVector<2, T> & end, double interpAmount) {
v[0] = (T) (v[0] + (end.v[0] - v[0]) * interpAmount);
v[1] = (T) (v[1] + (end.v[1] - v[1]) * interpAmount);
return *this;
}
bool isZeroVector() {
return v[0] == 0 &&
v[1] == 0;
}
GenoVector<2, T> & shear(T axisAngle, T shearAngle) { GenoVector<2, T> & shear(T axisAngle, T shearAngle) {
auto sinAxis = sin(axisAngle); auto sinAxis = sin(axisAngle);
auto cosAxis = cos(axisAngle); auto cosAxis = cos(axisAngle);
@ -765,6 +771,21 @@ GenoVector<2, T> & project(const GenoVector<2, T> & vector, const GenoVector<2,
return target; return target;
} }
template <typename T>
GenoVector<2, T> lerp(const GenoVector<2, T> & start, const GenoVector<2, T> & end, double interpAmount) {
return {
(T) (start.v[0] + (end.v[0] - start.v[0]) * interpAmount),
(T) (start.v[1] + (end.v[1] - start.v[1]) * interpAmount)
};
}
template <typename T>
GenoVector<2, T> & lerp(const GenoVector<2, T> & start, const GenoVector<2, T> & end, double interpAmount, GenoVector<2, T> & target) {
target.v[0] = (T) (start.v[0] + (end.v[0] - start.v[0]) * interpAmount);
target.v[1] = (T) (start.v[1] + (end.v[1] - start.v[1]) * interpAmount);
return target;
}
template <typename T> template <typename T>
GenoVector<2, T> shear(const GenoVector<2, T> & vector, T axisAngle, T shearAngle) { GenoVector<2, T> shear(const GenoVector<2, T> & vector, T axisAngle, T shearAngle) {
auto sinAxis = sin(axisAngle); auto sinAxis = sin(axisAngle);

View file

@ -76,15 +76,6 @@ class GenoVector<3, T> {
} }
public: public:
static GenoVector<3, T> * newArray(uint32 length) {
T * v = new T[3 * length];
GenoVector<3, T> * ret = new GenoVector<3, T>[length];
ret[0] = GenoVector<3, T>(v);
for (uint32 i = 1; i < length; ++i)
ret[i] = GenoVector<3, T>(v + i * 3, false);
return ret;
}
T * v; T * v;
GenoVector() : GenoVector() :
@ -278,6 +269,23 @@ class GenoVector<3, T> {
return *this; return *this;
} }
GenoVector<3, T> & bisect(const GenoVector<3, T> & vector) {
return *this = getLength() * vector + *this * vector.getLength();
}
GenoVector<3, T> & lerp(const GenoVector<3, T> & end, double interpAmount) {
v[0] = (T) (v[0] + (end.v[0] - v[0]) * interpAmount);
v[1] = (T) (v[1] + (end.v[1] - v[1]) * interpAmount);
v[2] = (T) (v[2] + (end.v[2] - v[2]) * interpAmount);
return *this;
}
bool isZeroVector() {
return v[0] == 0 &&
v[1] == 0 &&
v[2] == 0;
}
GenoVector<3, T> & cross(const GenoVector<3, T> & cross) { GenoVector<3, T> & cross(const GenoVector<3, T> & cross) {
T v0 = v[1] * cross.v[2] - v[2] * cross.v[1]; T v0 = v[1] * cross.v[2] - v[2] * cross.v[1];
T v1 = v[2] * cross.v[0] - v[0] * cross.v[2]; T v1 = v[2] * cross.v[0] - v[0] * cross.v[2];
@ -1580,6 +1588,23 @@ GenoVector<3, T> & project(const GenoVector<3, T> & vector, const GenoVector<3,
return target; return target;
} }
template <typename T>
GenoVector<3, T> lerp(const GenoVector<3, T> & start, const GenoVector<3, T> & end, double interpAmount) {
return {
(T) (start.v[0] + (end.v[0] - start.v[0]) * interpAmount),
(T) (start.v[1] + (end.v[1] - start.v[1]) * interpAmount),
(T) (start.v[2] + (end.v[2] - start.v[2]) * interpAmount)
};
}
template <typename T>
GenoVector<3, T> & lerp(const GenoVector<3, T> & start, const GenoVector<3, T> & end, double interpAmount, GenoVector<3, T> & target) {
target.v[0] = (T) (start.v[0] + (end.v[0] - start.v[0]) * interpAmount);
target.v[1] = (T) (start.v[1] + (end.v[1] - start.v[1]) * interpAmount);
target.v[2] = (T) (start.v[2] + (end.v[2] - start.v[2]) * interpAmount);
return target;
}
template <typename T> template <typename T>
GenoVector<3, T> cross(const GenoVector<3, T> & vector, const GenoVector<3, T> & cross) { GenoVector<3, T> cross(const GenoVector<3, T> & vector, const GenoVector<3, T> & cross) {
return { return {

View file

@ -76,15 +76,6 @@ class GenoVector<4, T> {
} }
public: public:
static GenoVector<4, T> * newArray(uint32 length) {
T * v = new T[4 * length];
GenoVector<4, T> * ret = new GenoVector<4, T>[length];
ret[0] = GenoVector<4, T>(v);
for (uint32 i = 1; i < length; ++i)
ret[i] = GenoVector<4, T>(v + i * 4, false);
return ret;
}
T * v; T * v;
GenoVector() : GenoVector() :
@ -300,6 +291,25 @@ class GenoVector<4, T> {
return *this; return *this;
} }
GenoVector<4, T> & bisect(const GenoVector<4, T> & vector) {
return *this = getLength() * vector + *this * vector.getLength();
}
GenoVector<4, T> & lerp(const GenoVector<4, T> & end, double interpAmount) {
v[0] = (T) (v[0] + (end.v[0] - v[0]) * interpAmount);
v[1] = (T) (v[1] + (end.v[1] - v[1]) * interpAmount);
v[2] = (T) (v[2] + (end.v[2] - v[2]) * interpAmount);
v[3] = (T) (v[3] + (end.v[3] - v[3]) * interpAmount);
return *this;
}
bool isZeroVector() {
return v[0] == 0 &&
v[1] == 0 &&
v[2] == 0 &&
v[3] == 0;
}
GenoVector<4, T> & set(const GenoVector<4, T> & set) { GenoVector<4, T> & set(const GenoVector<4, T> & set) {
v[0] = set.v[0]; v[0] = set.v[0];
v[1] = set.v[1]; v[1] = set.v[1];
@ -3352,6 +3362,25 @@ GenoVector<4, T> & project(const GenoVector<4, T> & vector, const GenoVector<4,
return target; return target;
} }
template <typename T>
GenoVector<4, T> lerp(const GenoVector<4, T> & start, const GenoVector<4, T> & end, double interpAmount) {
return {
(T) (start.v[0] + (end.v[0] - start.v[0]) * interpAmount),
(T) (start.v[1] + (end.v[1] - start.v[1]) * interpAmount),
(T) (start.v[2] + (end.v[2] - start.v[2]) * interpAmount),
(T) (start.v[3] + (end.v[3] - start.v[3]) * interpAmount)
};
}
template <typename T>
GenoVector<4, T> & lerp(const GenoVector<4, T> & start, const GenoVector<4, T> & end, double interpAmount, GenoVector<4, T> & target) {
target.v[0] = (T) (start.v[0] + (end.v[0] - start.v[0]) * interpAmount);
target.v[1] = (T) (start.v[1] + (end.v[1] - start.v[1]) * interpAmount);
target.v[2] = (T) (start.v[2] + (end.v[2] - start.v[2]) * interpAmount);
target.v[3] = (T) (start.v[3] + (end.v[3] - start.v[3]) * interpAmount);
return target;
}
template <typename T> template <typename T>
GenoVector<4, T> translate(const GenoVector<4, T> & vector, const GenoVector<4, T> & translate) { GenoVector<4, T> translate(const GenoVector<4, T> & vector, const GenoVector<4, T> & translate) {
return { return {

View file

@ -39,4 +39,8 @@ void GenoShader2c::setColor(float r, float g, float b, float a) {
glUniform4f(colorLoc, r, g, b, a); glUniform4f(colorLoc, r, g, b, a);
} }
void GenoShader2c::setColor(const GenoVector4f & color) {
glUniform4f(colorLoc, color.x(), color.y(), color.z(), color.w());
}
GenoShader2c::~GenoShader2c() {} GenoShader2c::~GenoShader2c() {}

View file

@ -28,14 +28,17 @@
#define GNARLY_GENOME_SHADER2C #define GNARLY_GENOME_SHADER2C
#include "../GenoInts.h" #include "../GenoInts.h"
#include "../math/linear/GenoVector4.h"
#include "../gl/GenoShader.h" #include "../gl/GenoShader.h"
class GenoShader2c : public GenoMvpShader { class GenoShader2c : public GenoMvpShader {
private: private:
uint32 colorLoc; uint32 colorLoc;
public: public:
GenoShader2c(); GenoShader2c();
void setColor(float r, float g, float b, float a); void setColor(float r, float g, float b, float a);
void setColor(const GenoVector4f & color);
~GenoShader2c(); ~GenoShader2c();
}; };

View file

@ -33,6 +33,7 @@
class GenoShader2ss : public GenoMvpShader { class GenoShader2ss : public GenoMvpShader {
private: private:
uint32 textureTransformLoc; uint32 textureTransformLoc;
public: public:
GenoShader2ss(); GenoShader2ss();
void setTextureTransform(const GenoMatrix4f & matrix); void setTextureTransform(const GenoMatrix4f & matrix);

View file

@ -31,7 +31,6 @@
GenoShader2t::GenoShader2t() : GenoShader2t::GenoShader2t() :
GenoMvpShader("src/geno/shaders/src/Shader2t/Shader2tv.gls", GenoMvpShader("src/geno/shaders/src/Shader2t/Shader2tv.gls",
"src/geno/shaders/src/Shader2t/Shader2tf.gls", "src/geno/shaders/src/Shader2t/Shader2tf.gls",
GENO_SHADER_STRING_IS_PATH) { GENO_SHADER_STRING_IS_PATH) {}
}
GenoShader2t::~GenoShader2t() {} GenoShader2t::~GenoShader2t() {}

View file

@ -0,0 +1,115 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_GENOME_ARRAY_LOOP
#define GNARLY_GENOME_ARRAY_LOOP
#include <initializer_list>
template <typename T>
class GenoArrayLoop {
private:
uint32 length;
T * array;
void clean() noexcept {
delete [] array;
}
public:
GenoArrayLoop(uint32 length, T * array) :
length(length),
array(array) {
}
GenoArrayLoop(uint32 length) :
length(length),
array(new T[length]) {
}
GenoArrayLoop(std::initializer_list<T> list) :
length(list.size()),
array(new T[length]) {
T * init = list.begin();
for (uint32 i = 0; i < length; ++i)
array[i] = init[i];
}
GenoArrayLoop(const GenoArrayLoop<T> & array) :
length(array.length),
array(new T[length]) {
for (uint32 i = 0; i < length; ++i)
array[i] = array.array[i];
}
GenoArrayLoop(GenoArrayLoop<T> && array) :
length(array.length),
array(array.array) {
array.array = 0;
}
GenoArrayLoop & operator=(const GenoArrayLoop<T> & array) {
clean();
length = array.length;
this->array = new T[length];
for (uint32 i = 0; i < length; ++i)
this->array[i] = array.array[i];
return *this;
}
GenoArrayLoop & operator=(GenoArrayLoop<T> && array) {
clean();
length = array.length;
this->array = array.array;
array.array = 0;
return *this;
}
T & operator[](int32 index) {
if (index < 0)
return array[((index + 1) % length) + length - 1];
else
return array[index % length];
}
const T & operator[](int32 index) const {
if (index < 0)
return array[((index + 1) % length) + length - 1];
else
return array[index % length];
}
uint32 getLength() {
return length;
}
~GenoArrayLoop() {
clean();
}
};
#define GNARLY_GENOME_ARRAY_LOOP_FORWARD
#endif // GNARLY_GENOME_ARRAY_LOOP

View file

@ -137,6 +137,10 @@ class GenoQueue {
return std::move(array[index]); return std::move(array[index]);
} }
bool hasNext() {
return length > 0;
}
void pack() { void pack() {
reallocate(length); reallocate(length);
} }

View file

@ -122,6 +122,14 @@ class GenoStack {
return std::move(array[--length]); return std::move(array[--length]);
} }
bool hasNext() {
return length > 0;
}
void pack() {
reallocate(length);
}
~GenoStack() { ~GenoStack() {
clean(); clean();
} }

View file

@ -30,24 +30,60 @@
#include "geno/GenoInts.h" #include "geno/GenoInts.h"
#include "geno/GenoMacros.h" #include "geno/GenoMacros.h"
#include "geno/math/linear/GenoMatrix4.h"
#include "geno/thread/GenoTime.h" #include "geno/thread/GenoTime.h"
#include "geno/engine/GenoEngine.h" #include "geno/engine/GenoEngine.h"
#include "geno/engine/GenoLoop.h" #include "geno/engine/GenoLoop.h"
#include "geno/engine/GenoInput.h" #include "geno/engine/GenoInput.h"
#include "geno/engine/GenoWindow.h" #include "geno/engine/GenoWindow.h"
#include "geno/engine/GenoCamera2D.h" #include "geno/engine/GenoCamera2D.h"
#include "geno/gl/GenoGL.h"
#include "geno/gl/GenoFramebuffer.h" #include "geno/gl/GenoFramebuffer.h"
#include "geno/gl/GenoVao.h"
#include "geno/shaders/GenoShader2c.h"
#include "geno/audio/GenoAudioDevice.h"
#include "geno/audio/GenoAudioSource.h"
#include "geno/audio/GenoAudioBuffer.h"
#include "pinball/shaders/GlowShader.h"
#include "pinball/Scene.h"
#include "pinball/Image.h"
#include "pinball/Intro.h"
#include "pinball/Level.h"
#include "pinball/levels/StartSplash.h"
#include "pinball/levels/Info1.h"
#include "pinball/levels/IntroLevel.h"
#include "pinball/levels/Info2.h"
#include "pinball/levels/Level1.h"
#include "pinball/levels/Level2.h"
#include "pinball/levels/Win.h"
bool init(); bool init();
void begin(); void begin();
void loop(); void loop();
void load(uint32 level);
void update(); void update();
void render(); void render();
void cleanup(); void cleanup();
bool toggle = true;
GenoWindow * window; GenoWindow * window;
GenoCamera2D * camera; GenoCamera2D * camera;
GenoFramebuffer * framebuffer1;
GenoFramebuffer * framebuffer2;
GlowShader * glow;
GenoVao * vao;
GenoAudioSource * source;
GenoAudioBuffer * audio;
Image * image;
Scene * scene;
int32 main(int32 argc, char ** argv) { int32 main(int32 argc, char ** argv) {
init(); init();
@ -67,23 +103,17 @@ int32 main(int32 argc, char ** argv) {
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end1 - begin1).count() << std::endl; std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end1 - begin1).count() << std::endl;
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end2 - begin2).count() << std::endl; std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end2 - begin2).count() << std::endl;
*/ */
//////// DO NOT REMOVE BELOW ////////
#ifdef _DEBUG
std::cout << "Press enter to continue . . ." << std::endl;
std::cin.get();
#endif // _DEBUG
return 0; return 0;
} }
bool init() { bool init() {
GenoEngine::init(); GenoEngine::init();
GenoMonitor * monitor = GenoMonitors::getPrimaryMonitor();
GenoVideoMode * videoMode = monitor->getDefaultVideoMode();
GenoLoopCreateInfo loopInfo = {}; GenoLoopCreateInfo loopInfo = {};
loopInfo.targetFps = GenoMonitors::getPrimaryMonitor()->getDefaultVideoMode()->getRefreshRate(); loopInfo.targetFps = videoMode->getRefreshRate();
loopInfo.deltaScale = 1; loopInfo.deltaScale = 1;
loopInfo.callback = loop; loopInfo.callback = loop;
loopInfo.numSubLoops = 0; loopInfo.numSubLoops = 0;
@ -95,7 +125,8 @@ bool init() {
GLFW_CONTEXT_VERSION_MAJOR, 3, GLFW_CONTEXT_VERSION_MAJOR, 3,
GLFW_CONTEXT_VERSION_MINOR, 3, GLFW_CONTEXT_VERSION_MINOR, 3,
GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE,
GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE,
GLFW_SAMPLES, 4
}; };
GenoWindowCreateInfo winInfo = {}; GenoWindowCreateInfo winInfo = {};
@ -104,7 +135,7 @@ bool init() {
winInfo.title = "Genome"; winInfo.title = "Genome";
winInfo.numHints = GENO_ARRAY_SIZE(winHints) / 2; winInfo.numHints = GENO_ARRAY_SIZE(winHints) / 2;
winInfo.hints = winHints; winInfo.hints = winHints;
winInfo.depth = true; winInfo.depth = false;
winInfo.clearRed = 0; winInfo.clearRed = 0;
winInfo.clearGreen = 0; winInfo.clearGreen = 0;
winInfo.clearBlue = 0; winInfo.clearBlue = 0;
@ -120,9 +151,67 @@ bool init() {
GenoEngine::setSwapInterval(1); GenoEngine::setSwapInterval(1);
GenoEngine::initGlew(); GenoEngine::initGlew();
camera = new GenoCamera2D(0, 1, 1, 0, 0, 1); glEnable(GL_MULTISAMPLE);
GenoFramebuffer::bindDefault(); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
camera = new GenoCamera2D(0, 1920, 1080, 0, 0, 1);
uint32 textureParams[] = {
GL_TEXTURE_MIN_FILTER, GL_NEAREST,
GL_TEXTURE_MAG_FILTER, GL_NEAREST,
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE,
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
};
GenoFramebufferCreateInfo bufferInfo = {};
bufferInfo.width = videoMode->getWidth();
bufferInfo.height = videoMode->getHeight();
bufferInfo.numColorAttachments = 1;
bufferInfo.depthAttachmentType = GENO_FRAMEBUFFER_DEPTH_BUFFER;
bufferInfo.numTextureParams = GENO_ARRAY_SIZE(textureParams) / 2;
bufferInfo.textureParams = textureParams;
framebuffer1 = new GenoFramebuffer(bufferInfo);
framebuffer2 = new GenoFramebuffer(bufferInfo);
glow = new GlowShader();
float vertices[] = {
1, -1, 0, // Top left
1, 1, 0, // Bottom left
-1, 1, 0, // Bottom right
-1, -1, 0 // Top right
};
uint32 indices[] = {
0, 1, 3,
1, 2, 3
};
float texCoords[] = {
1, 0,
1, 1,
0, 1,
0, 0
};
vao = new GenoVao(4, vertices, 6, indices);
vao->addAttrib(4, 2, texCoords);
GenoAudioDevices::getDefaultOutputDevice()->setActive();
audio = new GenoAudioBuffer("res/audio/harp.wav");
source = new GenoAudioSource(audio);
source->loop(true);
source->play();
Scene::init();
Intro::init(camera);
Level::init(camera);
Info::init(camera);
load(0);
image = new Image(camera, { 1, 1 }, { 5, 5 }, "res/img/Background.png");
return true; return true;
} }
@ -136,19 +225,69 @@ void loop() {
render(); render();
} }
void load(uint32 level) {
using SceneLoader = Scene * (*)(GenoCamera2D *, GlowShader *);
const static SceneLoader loaders[] = {
loadSplash,
loadInfo1,
loadIntroLevel,
loadInfo2,
loadLevel1,
loadLevel2,
loadWin
};
if (level == GENO_ARRAY_SIZE(loaders))
GenoEngine::stopLoop();
else {
delete scene;
scene = loaders[level](camera, glow);
}
}
void update() { void update() {
if (window->shouldClose()) if (window->shouldClose())
GenoEngine::stopLoop(); GenoEngine::stopLoop();
scene->update();
if (scene->isComplete())
load(scene->nextScene());
camera->update(); camera->update();
} }
void render() { void render() {
framebuffer1->bind();
GenoFramebuffer::clear(); GenoFramebuffer::clear();
scene->renderGlow();
framebuffer2->bind();
GenoFramebuffer::clear();
framebuffer1->getColorTexture()->bind();
image->getTexture()->bind(1);
glow->enable();
glow->setMvp(GenoMatrix4f::makeIdentity());
glow->setResolution(window->getWidth(), window->getHeight());
glow->setHorizontal(true);
vao->render();
GenoFramebuffer::bindDefault();
GenoFramebuffer::clear();
framebuffer2->getColorTexture()->bind();
scene->bindBackground(1);
glow->enable();
glow->setMvp(GenoMatrix4f::makeIdentity());
glow->setResolution(window->getWidth(), window->getHeight());
glow->setHorizontal(false);
vao->render();
scene->render();
window->swap(); window->swap();
} }
void cleanup() { void cleanup() {
delete image;
delete scene;
delete vao;
delete glow;
delete framebuffer1;
delete framebuffer2;
delete camera; delete camera;
delete window; delete window;

90
src/pinball/Image.cpp Normal file
View file

@ -0,0 +1,90 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "../geno/GenoMacros.h"
#include "../geno/math/linear/GenoMatrix4.h"
#include "Image.h"
GenoShader2t * Image::shader;
GenoVao * Image::vao;
void Image::init() {
shader = new GenoShader2t();
float vertices[] = {
1, 0, 0, // Top left
1, 1, 0, // Bottom left
0, 1, 0, // Bottom right
0, 0, 0 // Top right
};
uint32 indices[] = {
0, 1, 3,
1, 2, 3
};
float texCoords[] = {
1, 0,
1, 1,
0, 1,
0, 0
};
vao = new GenoVao(4, vertices, 6, indices);
vao->addAttrib(4, 2, texCoords);
}
Image::Image(GenoCamera2D * camera, const GenoVector2f & position, const GenoVector2f & dimensions, const char * path) :
camera(camera),
position(position),
dimensions(dimensions) {
uint32 textureParams[] = {
GL_TEXTURE_MIN_FILTER, GL_LINEAR,
GL_TEXTURE_MAG_FILTER, GL_LINEAR,
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE,
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
};
GenoTexture2DCreateInfo textureInfo = {};
textureInfo.type = GENO_TEXTURE2D_TYPE_PNG;
textureInfo.texture = path;
textureInfo.numParams = GENO_ARRAY_SIZE(textureParams) / 2;
textureInfo.params = textureParams;
texture = GenoTexture2D::create(textureInfo);
}
GenoTexture2D * Image::getTexture() {
return texture;
}
void Image::render() {
texture->bind();
shader->enable();
shader->setMvp(translate2D(camera->getVPMatrix(), position).scale2D(dimensions));
vao->render();
}
Image::~Image() {}

58
src/pinball/Image.h Normal file
View file

@ -0,0 +1,58 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_IMAGE
#define GNARLY_PINBALL_IMAGE
#include "../geno/math/linear/GenoVector2.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/gl/GenoTexture2D.h"
#include "../geno/gl/GenoVao.h"
#include "../geno/shaders/GenoShader2t.h"
class Image {
private:
static GenoShader2t * shader;
static GenoVao * vao;
GenoCamera2D * camera;
public:
static void init();
GenoTexture2D * texture;
GenoVector2f position;
GenoVector2f dimensions;
Image(GenoCamera2D * camera, const GenoVector2f & position, const GenoVector2f & dimensions, const char * string);
GenoTexture2D * getTexture();
void render();
~Image();
};
#define GNARLY_PINBALL_IMAGE
#endif // GNARLY_PINBALL_IMAGE

88
src/pinball/Info.cpp Normal file
View file

@ -0,0 +1,88 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "../geno/engine/GenoEngine.h"
#include "../geno/engine/GenoInput.h"
#include "../geno/math/GenoConstants.h"
#include "Info.h"
Image * Info::next;
Image * Info::border;
Rectangle * Info::overlay;
void Info::init(GenoCamera2D * camera) {
next = new Image(camera, { 1324.471, 980.964 }, { 536.973, 68.997 }, "res/img/Continue.png");
border = new Image(camera, { 0.0f, 0.0f }, { 1920.0f, 1080.f }, "res/img/InfoBorder.png");
overlay = new Rectangle(camera, { 0.0f, 0.0f }, { 1920, 1080 }, { 0, 0, 0, 1 });
}
Info::Info(GenoCamera2D * camera, GlowShader * glow, uint32 next, const char * info, const char * infoGlow) :
Scene(camera, glow, next, info, 0, 0, 0, 0),
glowImage(new Image(camera, { 0.0f, 0.0f }, { 1920.0f, 1080.f }, infoGlow)) {}
void Info::update() {
if (state == FADE_IN) {
overlayTime += GenoEngine::getLoop()->getDelta();
if (overlayTime > 1) {
state = WAITING;
overlayTime = 0;
overlay->setAlpha(0);
}
else
overlay->setAlpha(1 - overlayTime);
}
else if (state == WAITING) {
time += GenoEngine::getLoop()->getDelta() * 2.23;
if (time > GENO_TAU<float>)
time -= GENO_TAU<float>;
next->position.x() = 1324.471 + sin(time) * 15;
if (GenoInput::getKeyState(GLFW_KEY_R) == GENO_INPUT_PRESSED)
state = FADE_OUT;
}
else if (state == FADE_OUT) {
overlayTime += GenoEngine::getLoop()->getDelta();
if (overlayTime > 1)
complete = true;
overlay->setAlpha(overlayTime);
}
}
void Info::renderGlow() {
glowImage->render();
border->render();
}
void Info::render() {
glowImage->render();
next->render();
border->render();
overlay->render();
}
Info::~Info() {
delete glowImage;
}

62
src/pinball/Info.h Normal file
View file

@ -0,0 +1,62 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_INFO
#define GNARLY_PINBALL_INFO
#include "Rectangle.h"
#include "Scene.h"
class Info : public Scene {
private:
const static uint32 FADE_IN = 0;
const static uint32 WAITING = 1;
const static uint32 FADE_OUT = 2;
static Image * next;
static Image * border;
static Rectangle * overlay;
Image * glowImage;
float time;
float alpha;
float overlayTime;
uint32 state;
public:
static void init(GenoCamera2D * camera);
Info(GenoCamera2D * camera, GlowShader * glow, uint32 next, const char * info, const char * infoGlow);
virtual void update();
virtual void renderGlow();
virtual void render();
~Info();
};
#define GNARLY_PINBALL_INFO_FORWARD
#endif // GNARLY_PINBALL_INFO

246
src/pinball/Intro.cpp Normal file
View file

@ -0,0 +1,246 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <iostream>
#include "../geno/engine/GenoEngine.h"
#include "../geno/engine/GenoInput.h"
#include "../geno/engine/GenoLoop.h"
#include "Intro.h"
Image * Intro::startingGlow;
Image * Intro::startingNonglow;
Rectangle * Intro::overlay;
void Intro::init(GenoCamera2D * camera) {
startingGlow = new Image(camera, { 0.0f, 0.0f }, { 1920, 1080 }, "res/img/StartingGlow.png");
startingNonglow = new Image(camera, { 0.0f, 0.0f }, { 1920, 1080 }, "res/img/StartingNonglow.png");
overlay = new Rectangle(camera, { 0.0f, 0.0f }, { 1920, 1080 }, { 0, 0, 0, 1 });
}
extern bool rangeCheck(float t);
Intro::Intro(GenoCamera2D * camera, GlowShader * glow, uint32 next, uint32 reset, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls, uint32 wallDrawColor, uint32 ballColor, const GenoVector2f & ballStart, const GenoVector2f & ballVelocity) :
Scene(camera, glow, next, path, numColors, palette, numWallLists, walls),
reset(reset),
wallDraw(new WallDraw(camera, palette, wallDrawColor)) {
pinball = new Pinball(camera, palette, ballColor, ballStart, ballVelocity);
}
void Intro::update() {
if (GenoInput::getKeyState(GLFW_KEY_N) == GENO_INPUT_PRESSED)
complete = true;
if (state == FADE_IN) {
const static auto SHADE = 0.5f;
time += GenoEngine::getLoop()->getDelta();
if (time < 1)
overlay->setAlpha((1 - time) * (1 - SHADE) + SHADE);
else {
overlay->setAlpha(SHADE);
time = 0;
state = STARTING;
}
}
else if (state == STARTING) {
if (GenoInput::getKeyState(GLFW_KEY_R) == GENO_INPUT_PRESSED) {
state = IN_MOTION;
overlay->setAlpha(0);
}
}
else if (state == IN_MOTION) {
if (GenoInput::getKeyState(GLFW_KEY_R) == GENO_INPUT_PRESSED) {
state = FADE_OUT;
next = reset;
}
wallDraw->update();
auto scale = float{ 1 };
if (GenoInput::getKeyState(GLFW_KEY_SPACE) >= GENO_INPUT_PRESSED)
scale = 0.25f;
auto delta = float( GenoEngine::getLoop()->getDelta() );
auto collision = true;
auto tempVelocity = pinball->velocity * delta * scale;
auto remove = -1;
while (collision && state == IN_MOTION) {
collision = false;
auto smallestT = float{ 1.0f };
auto reflect = GenoVector2f{ 0.0f };
auto angular = float { 0.0f };
for (uint32 i = 0; i < numWallLists; ++i) {
WallList * walls = wallLists[i];
for (uint32 j = 0; j < walls->numVertices; ++j) {
if (j < walls->numWalls) {
auto normal = dot(walls->normals[j], tempVelocity) > 0 ? -walls->normals[j] : walls->normals[j];
auto wallOrigin = walls->vertices[j];
auto wallDirection = walls->vertices[j + 1] - wallOrigin;
wallOrigin += normal * (Pinball::RADIUS + WallList::HALF_WALL_THICKNESS);
auto t1 = (tempVelocity.y() * wallOrigin.x() - tempVelocity.x() * wallOrigin.y() + tempVelocity.x() * pinball->position.y() - tempVelocity.y() * pinball->position.x()) /
(tempVelocity.x() * wallDirection.y() - tempVelocity.y() * wallDirection.x());
auto t2 = float{ 0 };
if (tempVelocity.x() == 0)
t2 = (wallOrigin.y() + wallDirection.y() * t1 - pinball->position.y()) / tempVelocity.y();
else
t2 = (wallOrigin.x() + wallDirection.x() * t1 - pinball->position.x()) / tempVelocity.x();
if (rangeCheck(t1) && rangeCheck(t2) && t2 < smallestT) {
if (i == numWallLists - 1)
state = FADE_OUT;
else {
collision = true;
smallestT = t2;
auto m = tempVelocity * (1 - t2);
reflect = 2.0f * project(m, wallDirection) - m;
angular = project(setLength(m, pinball->velocity.getLength()), wallDirection).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { normal.y(), -normal.x() }) > 0)
angular = -angular;
}
}
}
{
auto & vertex = walls->vertices[j];
auto a = tempVelocity.x() * tempVelocity.x() +
tempVelocity.y() * tempVelocity.y();
auto b = 2.0f * pinball->position.x() * tempVelocity.x() - 2.0f * vertex.x() * tempVelocity.x() +
2.0f * pinball->position.y() * tempVelocity.y() - 2.0f * vertex.y() * tempVelocity.y();
auto c = pinball->position.x() * pinball->position.x() - 2.0f * pinball->position.x() * vertex.x() + vertex.x() * vertex.x() +
pinball->position.y() * pinball->position.y() - 2.0f * pinball->position.y() * vertex.y() + vertex.y() * vertex.y() -
(Pinball::RADIUS + WallList::HALF_WALL_THICKNESS) * (Pinball::RADIUS + WallList::HALF_WALL_THICKNESS);
auto radical = b * b - 4.0f * a * c;
if (radical > 0) {
auto t = (-b - sqrt(radical)) / (2.0f * a);
if (rangeCheck(t) && t < smallestT) {
if (i == numWallLists - 1)
state = FADE_OUT;
else {
collision = true;
smallestT = t;
auto reflectAxis = pinball->position + tempVelocity * t - vertex;
auto m = tempVelocity * (1 - t);
reflect = 2.0f * project(m, { -reflectAxis.y(), reflectAxis.x() }) - m;
angular = project(setLength(m, pinball->velocity.getLength()), { -reflectAxis.y(), reflectAxis.x() }).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { reflectAxis.y(), -reflectAxis.x() }) > 0)
angular = -angular;
}
}
}
}
}
}
if (state == IN_MOTION) {
for (uint32 j = 0; j < wallDraw->walls.getLength() - wallDraw->skipLast(); ++j) {
auto vertexIndex = j * 2;
{
auto normal = dot(wallDraw->normals[j], tempVelocity) > 0 ? -wallDraw->normals[j] : wallDraw->normals[j];
auto wallOrigin = wallDraw->vertices[vertexIndex];
auto wallDirection = wallDraw->vertices[vertexIndex + 1] - wallOrigin;
wallOrigin += normal * (Pinball::RADIUS + WallList::HALF_WALL_THICKNESS);
auto t1 = (tempVelocity.y() * wallOrigin.x() - tempVelocity.x() * wallOrigin.y() + tempVelocity.x() * pinball->position.y() - tempVelocity.y() * pinball->position.x()) /
(tempVelocity.x() * wallDirection.y() - tempVelocity.y() * wallDirection.x());
auto t2 = float{ 0 };
if (tempVelocity.x() == 0)
t2 = (wallOrigin.y() + wallDirection.y() * t1 - pinball->position.y()) / tempVelocity.y();
else
t2 = (wallOrigin.x() + wallDirection.x() * t1 - pinball->position.x()) / tempVelocity.x();
if (rangeCheck(t1) && rangeCheck(t2) && t2 < smallestT) {
collision = true;
smallestT = t2;
auto m = tempVelocity * (1 - t2);
reflect = 2.0f * project(m, wallDirection) - m;
angular = project(setLength(m, pinball->velocity.getLength()), wallDirection).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { normal.y(), -normal.x() }) > 0)
angular = -angular;
}
}
{
for (uint32 k = 0; k < 2; ++k) {
auto & vertex = wallDraw->vertices[vertexIndex + k];
auto a = tempVelocity.x() * tempVelocity.x() +
tempVelocity.y() * tempVelocity.y();
auto b = 2.0f * pinball->position.x() * tempVelocity.x() - 2.0f * vertex.x() * tempVelocity.x() +
2.0f * pinball->position.y() * tempVelocity.y() - 2.0f * vertex.y() * tempVelocity.y();
auto c = pinball->position.x() * pinball->position.x() - 2.0f * pinball->position.x() * vertex.x() + vertex.x() * vertex.x() +
pinball->position.y() * pinball->position.y() - 2.0f * pinball->position.y() * vertex.y() + vertex.y() * vertex.y() -
Pinball::RADIUS * Pinball::RADIUS;
auto radical = b * b - 4.0f * a * c;
if (radical > 0) {
auto t = (-b - sqrt(radical)) / (2.0f * a);
if (rangeCheck(t) && t < smallestT) {
collision = true;
smallestT = t;
auto reflectAxis = pinball->position + tempVelocity * t - vertex;
auto m = tempVelocity * (1 - t);
reflect = 2.0f * project(m, { -reflectAxis.y(), reflectAxis.x() }) - m;
angular = project(setLength(m, pinball->velocity.getLength()), { -reflectAxis.y(), reflectAxis.x() }).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { reflectAxis.y(), -reflectAxis.x() }) > 0)
angular = -angular;
}
}
}
}
}
if (collision) {
pinball->position += tempVelocity * smallestT;
tempVelocity = reflect;
setLength(tempVelocity, pinball->velocity.getLength(), pinball->velocity);
pinball->angularVelocity = angular;
}
}
};
pinball->position += tempVelocity;
pinball->rotation += pinball->angularVelocity * scale * delta;
}
else if (state == FADE_OUT) {
time += GenoEngine::getLoop()->getDelta();
if (time < 1)
overlay->setAlpha(time);
else
complete = true;
}
}
void Intro::renderGlow() {
pinball->render();
for (uint32 i = 0; i < numWallLists; ++i)
wallLists[i]->render();
wallDraw->render();
//if (state == STARTING)
//startingGlow->render();
}
void Intro::render() {
pinball->render();
for (uint32 i = 0; i < numWallLists; ++i)
wallLists[i]->render();
wallDraw->render();
overlay->render();
if (state == STARTING) {
startingNonglow->render();
//startingGlow->render();
}
}
Intro::~Intro() {
delete pinball;
}

71
src/pinball/Intro.h Normal file
View file

@ -0,0 +1,71 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_INTRO
#define GNARLY_PINBALL_INTRO
#include "../geno/math/linear/GenoVector4.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/audio/GenoAudioBuffer.h"
#include "../geno/audio/GenoAudioSource.h"
#include "shaders/GlowShader.h"
#include "Scene.h"
#include "Rectangle.h"
#include "Pinball.h"
#include "WallList.h"
#include "WallDraw.h"
class Intro : public Scene {
private:
const static uint32 FADE_IN = 0;
const static uint32 STARTING = 1;
const static uint32 IN_MOTION = 2;
const static uint32 FADE_OUT = 3;
static Image * startingGlow;
static Image * startingNonglow;
static Rectangle * overlay;
WallDraw * wallDraw;
Pinball * pinball;
uint32 reset;
uint32 state;
float time;
public:
static void init(GenoCamera2D * camera);
Intro(GenoCamera2D * camera, GlowShader * glow, uint32 next, uint32 reset, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls, uint32 wallDrawColor, uint32 ballColor, const GenoVector2f & ballStart, const GenoVector2f & ballVelocity);
virtual void update();
virtual void renderGlow();
virtual void render();
virtual ~Intro();
};
#define GNARLY_PINBALL_INTRO_SCENE
#endif // GNARLY_PINBALL_INTRO

339
src/pinball/Level.cpp Normal file
View file

@ -0,0 +1,339 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <iostream>
#include "../geno/engine/GenoEngine.h"
#include "../geno/engine/GenoInput.h"
#include "../geno/engine/GenoLoop.h"
#include "Level.h"
GenoVector4f fromHSV(float h, float s, float v);
Image * Level::startingGlow;
Image * Level::startingNonglow;
Rectangle * Level::overlay;
Rectangle * Level::left;
Rectangle * Level::right;
Rectangle * Level::bottom;
Rectangle * Level::bar;
Rectangle * Level::barInner;
void Level::init(GenoCamera2D * camera) {
startingGlow = new Image(camera, { 0.0f, 0.0f }, { 1920, 1080 }, "res/img/StartingGlow.png");
startingNonglow = new Image(camera, { 0.0f, 0.0f }, { 1920, 1080 }, "res/img/StartingNonglow.png");
overlay = new Rectangle(camera, { 0.0f, 0.0f }, { 1920, 1080 }, { 0, 0, 0, 1 });
left = new Rectangle(camera, { 0.0f, 942.5f }, { 7.5f, 130 }, { 1, 1, 1, 1 });
right = new Rectangle(camera, { 1912.5f, 942.5f }, { 7.5f, 130 }, { 1, 1, 1, 1 });
bottom = new Rectangle(camera, { 0.0f, 1072.5f }, { 1920, 7.5f }, { 1, 1, 1, 1 });
bar = new Rectangle(camera, { 37.5f, 975 }, { 1845, 70 }, { 1, 1, 1, 1 });
barInner = new Rectangle(camera, { 45, 982.5f }, { 1830, 55 }, { 0, 0, 0, 1 });
}
bool rangeCheck(float t) {
return 0 <= t && t <= 1;
}
Level::Level(GenoCamera2D * camera, GlowShader * glow, uint32 next, uint32 reset, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls, float timeLimit, uint32 wallDrawColor, uint32 ballColor, const GenoVector2f & ballStart, const GenoVector2f & ballVelocity) :
Scene(camera, glow, next, path, numColors, palette, numWallLists, walls),
reset(reset),
timeLimit(timeLimit),
wallDraw(new WallDraw(camera, palette, wallDrawColor)) {
pinball = new Pinball(camera, palette, ballColor, ballStart, ballVelocity);
}
void Level::update() {
if (GenoInput::getKeyState(GLFW_KEY_N) == GENO_INPUT_PRESSED)
complete = true;
if (state == FADE_IN) {
bar->setColor(fromHSV(120, 0.8f, 1));
bar->dimensions.x() = 1845;
barInner->dimensions.x() = bar->dimensions.x() - 15;
const static auto SHADE = 0.5f;
time += GenoEngine::getLoop()->getDelta();
if (time < 1)
overlay->setAlpha((1 - time) * (1 - SHADE) + SHADE);
else {
overlay->setAlpha(SHADE);
time = 0;
state = STARTING;
}
}
else if (state == STARTING) {
if (GenoInput::getKeyState(GLFW_KEY_R) == GENO_INPUT_PRESSED) {
state = IN_MOTION;
overlay->setAlpha(0);
}
}
else if (state == IN_MOTION) {
auto scale = float{ 1 };
if (GenoInput::getKeyState(GLFW_KEY_SPACE) >= GENO_INPUT_PRESSED)
scale = 0.25f;
wallDraw->update();
time += GenoEngine::getLoop()->getDelta() * (scale == 1 ? 1 : 1.15f);
time += wallDraw->wallCompleted() * 0.15f;
auto percent = (1 - time / timeLimit);
if (percent < 0)
percent = 0;
bar->setColor(fromHSV(120 * percent, 0.8f, 1));
bar->dimensions.x() = 1845 * percent;
barInner->dimensions.x() = bar->dimensions.x() - 15;
if (barInner->dimensions.x() < 0)
barInner->dimensions.x() = 0;
if (GenoInput::getKeyState(GLFW_KEY_R) == GENO_INPUT_PRESSED || time > timeLimit) {
state = FADE_OUT;
next = reset;
}
auto delta = float( GenoEngine::getLoop()->getDelta() );
auto collision = true;
auto tempVelocity = pinball->velocity * delta * scale;
auto remove = -1;
while (collision && state == IN_MOTION) {
collision = false;
auto smallestT = float{ 1.0f };
auto reflect = GenoVector2f{ 0.0f };
auto angular = float { 0.0f };
for (uint32 i = 0; i < numWallLists; ++i) {
WallList * walls = wallLists[i];
for (uint32 j = 0; j < walls->numVertices; ++j) {
if (j < walls->numWalls) {
auto normal = dot(walls->normals[j], tempVelocity) > 0 ? -walls->normals[j] : walls->normals[j];
auto wallOrigin = walls->vertices[j];
auto wallDirection = walls->vertices[j + 1] - wallOrigin;
wallOrigin += normal * (Pinball::RADIUS + WallList::HALF_WALL_THICKNESS);
auto t1 = (tempVelocity.y() * wallOrigin.x() - tempVelocity.x() * wallOrigin.y() + tempVelocity.x() * pinball->position.y() - tempVelocity.y() * pinball->position.x()) /
(tempVelocity.x() * wallDirection.y() - tempVelocity.y() * wallDirection.x());
auto t2 = float{ 0 };
if (tempVelocity.x() == 0)
t2 = (wallOrigin.y() + wallDirection.y() * t1 - pinball->position.y()) / tempVelocity.y();
else
t2 = (wallOrigin.x() + wallDirection.x() * t1 - pinball->position.x()) / tempVelocity.x();
if (rangeCheck(t1) && rangeCheck(t2) && t2 < smallestT) {
if (i == numWallLists - 1)
state = FADE_OUT;
else {
collision = true;
smallestT = t2;
auto m = tempVelocity * (1 - t2);
reflect = 2.0f * project(m, wallDirection) - m;
angular = project(setLength(m, pinball->velocity.getLength()), wallDirection).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { normal.y(), -normal.x() }) > 0)
angular = -angular;
}
}
}
{
auto & vertex = walls->vertices[j];
auto a = tempVelocity.x() * tempVelocity.x() +
tempVelocity.y() * tempVelocity.y();
auto b = 2.0f * pinball->position.x() * tempVelocity.x() - 2.0f * vertex.x() * tempVelocity.x() +
2.0f * pinball->position.y() * tempVelocity.y() - 2.0f * vertex.y() * tempVelocity.y();
auto c = pinball->position.x() * pinball->position.x() - 2.0f * pinball->position.x() * vertex.x() + vertex.x() * vertex.x() +
pinball->position.y() * pinball->position.y() - 2.0f * pinball->position.y() * vertex.y() + vertex.y() * vertex.y() -
(Pinball::RADIUS + WallList::HALF_WALL_THICKNESS) * (Pinball::RADIUS + WallList::HALF_WALL_THICKNESS);
auto radical = b * b - 4.0f * a * c;
if (radical > 0) {
auto t = (-b - sqrt(radical)) / (2.0f * a);
if (rangeCheck(t) && t < smallestT) {
if (i == numWallLists - 1)
state = FADE_OUT;
else {
collision = true;
smallestT = t;
auto reflectAxis = pinball->position + tempVelocity * t - vertex;
auto m = tempVelocity * (1 - t);
reflect = 2.0f * project(m, { -reflectAxis.y(), reflectAxis.x() }) - m;
angular = project(setLength(m, pinball->velocity.getLength()), { -reflectAxis.y(), reflectAxis.x() }).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { reflectAxis.y(), -reflectAxis.x() }) > 0)
angular = -angular;
}
}
}
}
}
}
if (state == IN_MOTION) {
for (uint32 j = 0; j < wallDraw->walls.getLength() - wallDraw->skipLast(); ++j) {
auto vertexIndex = j * 2;
{
auto normal = dot(wallDraw->normals[j], tempVelocity) > 0 ? -wallDraw->normals[j] : wallDraw->normals[j];
auto wallOrigin = wallDraw->vertices[vertexIndex];
auto wallDirection = wallDraw->vertices[vertexIndex + 1] - wallOrigin;
wallOrigin += normal * (Pinball::RADIUS + WallList::HALF_WALL_THICKNESS);
auto t1 = (tempVelocity.y() * wallOrigin.x() - tempVelocity.x() * wallOrigin.y() + tempVelocity.x() * pinball->position.y() - tempVelocity.y() * pinball->position.x()) /
(tempVelocity.x() * wallDirection.y() - tempVelocity.y() * wallDirection.x());
auto t2 = float{ 0 };
if (tempVelocity.x() == 0)
t2 = (wallOrigin.y() + wallDirection.y() * t1 - pinball->position.y()) / tempVelocity.y();
else
t2 = (wallOrigin.x() + wallDirection.x() * t1 - pinball->position.x()) / tempVelocity.x();
if (rangeCheck(t1) && rangeCheck(t2) && t2 < smallestT) {
collision = true;
smallestT = t2;
auto m = tempVelocity * (1 - t2);
reflect = 2.0f * project(m, wallDirection) - m;
angular = project(setLength(m, pinball->velocity.getLength()), wallDirection).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { normal.y(), -normal.x() }) > 0)
angular = -angular;
}
}
{
for (uint32 k = 0; k < 2; ++k) {
auto & vertex = wallDraw->vertices[vertexIndex + k];
auto a = tempVelocity.x() * tempVelocity.x() +
tempVelocity.y() * tempVelocity.y();
auto b = 2.0f * pinball->position.x() * tempVelocity.x() - 2.0f * vertex.x() * tempVelocity.x() +
2.0f * pinball->position.y() * tempVelocity.y() - 2.0f * vertex.y() * tempVelocity.y();
auto c = pinball->position.x() * pinball->position.x() - 2.0f * pinball->position.x() * vertex.x() + vertex.x() * vertex.x() +
pinball->position.y() * pinball->position.y() - 2.0f * pinball->position.y() * vertex.y() + vertex.y() * vertex.y() -
Pinball::RADIUS * Pinball::RADIUS;
auto radical = b * b - 4.0f * a * c;
if (radical > 0) {
auto t = (-b - sqrt(radical)) / (2.0f * a);
if (rangeCheck(t) && t < smallestT) {
collision = true;
smallestT = t;
auto reflectAxis = pinball->position + tempVelocity * t - vertex;
auto m = tempVelocity * (1 - t);
reflect = 2.0f * project(m, { -reflectAxis.y(), reflectAxis.x() }) - m;
angular = project(setLength(m, pinball->velocity.getLength()), { -reflectAxis.y(), reflectAxis.x() }).getLength() / Pinball::RADIUS;
if (dot(tempVelocity, { reflectAxis.y(), -reflectAxis.x() }) > 0)
angular = -angular;
}
}
}
}
}
if (collision) {
pinball->position += tempVelocity * smallestT;
tempVelocity = reflect;
setLength(tempVelocity, pinball->velocity.getLength(), pinball->velocity);
pinball->angularVelocity = angular;
}
}
};
pinball->position += tempVelocity;
pinball->rotation += pinball->angularVelocity * scale * delta;
if (state == FADE_OUT)
time = 0;
}
else if (state == FADE_OUT) {
time += GenoEngine::getLoop()->getDelta();
if (time < 1)
overlay->setAlpha(time);
else
complete = true;
}
}
void Level::renderGlow() {
left->render();
right->render();
bottom->render();
pinball->render();
for (uint32 i = 0; i < numWallLists; ++i)
wallLists[i]->render();
wallDraw->render();
//if (state == STARTING)
//startingGlow->render();
}
void Level::render() {
left->render();
right->render();
bottom->render();
bar->render();
barInner->render();
pinball->render();
for (uint32 i = 0; i < numWallLists; ++i)
wallLists[i]->render();
wallDraw->render();
overlay->render();
if (state == STARTING) {
startingNonglow->render();
//startingGlow->render();
}
}
Level::~Level() {
delete pinball;
}
GenoVector4f fromHSV(float h, float s, float v) {
float hh, p, q, t, ff;
float r, g, b;
int64 i;
if (s <= 0.0) {
r = v;
g = v;
b = v;
}
else {
hh = h;
if (hh >= 360.0)
hh = 0.0;
hh /= 60.0;
i = (int64) hh;
ff = hh - i;
p = v * (1.0 - s);
q = v * (1.0 - (s * ff));
t = v * (1.0 - (s * (1.0 - ff)));
switch (i) {
case 0:
r = v;
g = t;
b = p;
break;
case 1:
r = q;
g = v;
b = p;
break;
case 2:
r = p;
g = v;
b = t;
break;
case 3:
r = p;
g = q;
b = v;
break;
case 4:
r = t;
g = p;
b = v;
break;
default:
r = v;
g = p;
b = q;
break;
}
}
return { r, g, b, 1 };
}

78
src/pinball/Level.h Normal file
View file

@ -0,0 +1,78 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_LEVEL
#define GNARLY_PINBALL_LEVEL
#include "../geno/math/linear/GenoVector4.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/audio/GenoAudioBuffer.h"
#include "../geno/audio/GenoAudioSource.h"
#include "shaders/GlowShader.h"
#include "Scene.h"
#include "Rectangle.h"
#include "Pinball.h"
#include "WallList.h"
#include "WallDraw.h"
class Level : public Scene {
private:
const static uint32 FADE_IN = 0;
const static uint32 STARTING = 1;
const static uint32 IN_MOTION = 2;
const static uint32 FADE_OUT = 3;
static Image * startingGlow;
static Image * startingNonglow;
static Rectangle * overlay;
static Rectangle * left;
static Rectangle * right;
static Rectangle * bottom;
static Rectangle * bar;
static Rectangle * barInner;
WallDraw * wallDraw;
Pinball * pinball;
uint32 reset;
uint32 state;
float time;
float timeLimit;
public:
static void init(GenoCamera2D * camera);
Level(GenoCamera2D * camera, GlowShader * glow, uint32 next, uint32 reset, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls, float timeLimit, uint32 wallDrawColor, uint32 ballColor, const GenoVector2f & ballStart, const GenoVector2f & ballVelocity);
virtual void update();
virtual void renderGlow();
virtual void render();
virtual ~Level();
};
#define GNARLY_PINBALL_LEVEL_SCENE
#endif // GNARLY_PINBALL_LEVEL

89
src/pinball/Pinball.cpp Normal file
View file

@ -0,0 +1,89 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "../geno/GenoMacros.h"
#include "Pinball.h"
const float Pinball::RADIUS = 25;
GenoTexture2D * Pinball::texture;
GenoVao * Pinball::vao;
MixShader * Pinball::shader;
void Pinball::init() {
uint32 textureParams[] = {
GL_TEXTURE_MIN_FILTER, GL_LINEAR,
GL_TEXTURE_MAG_FILTER, GL_LINEAR,
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE,
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
};
GenoTexture2DCreateInfo textureInfo = {};
textureInfo.type = GENO_TEXTURE2D_TYPE_PNG;
textureInfo.texture = "res/img/Pinball.png";
textureInfo.numParams = GENO_ARRAY_SIZE(textureParams) / 2;
textureInfo.params = textureParams;
texture = GenoTexture2D::create(textureInfo);
shader = new MixShader();
float vertices[] = {
1, -1, 0, // Top left
1, 1, 0, // Bottom left
-1, 1, 0, // Bottom right
-1, -1, 0 // Top right
};
uint32 indices[] = {
0, 1, 3,
1, 2, 3
};
float texCoords[] = {
1, 0,
1, 1,
0, 1,
0, 0
};
vao = new GenoVao(4, vertices, 6, indices);
vao->addAttrib(4, 2, texCoords);
}
Pinball::Pinball(GenoCamera2D * camera, GenoVector4f * palette, uint32 color, const GenoVector2f & position, const GenoVector2f & velocity) :
camera(camera),
palette(palette),
color(color),
position(position),
velocity(velocity) {}
void Pinball::render() {
texture->bind();
shader->enable();
shader->setColor(palette[color]);
shader->setMvp(translate2D(camera->getVPMatrix(), position).rotate2D(rotation).scale(RADIUS));
vao->render();
}
Pinball::~Pinball() {}

63
src/pinball/Pinball.h Normal file
View file

@ -0,0 +1,63 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_PINBALL
#define GNARLY_PINBALL_PINBALL
#include "../geno/math/linear/GenoVector2.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/gl/GenoTexture2D.h"
#include "../geno/gl/GenoVao.h"
#include "../geno/shaders/GenoShader2t.h"
#include "shaders/MixShader.h"
class Pinball {
private:
static GenoTexture2D * texture;
static GenoVao * vao;
static MixShader * shader;
GenoCamera2D * camera;
GenoVector4f * palette;
uint32 color;
public:
const static float RADIUS;
static void init();
GenoVector2f position;
GenoVector2f velocity;
float rotation;
float angularVelocity;
Pinball(GenoCamera2D * camera, GenoVector4f * palette, uint32 color, const GenoVector2f & position, const GenoVector2f & velocity);
void render();
~Pinball();
};
#define GNARLY_PINBALL_PINBALL_FORWARD
#endif // GNARLY_PINBALL_PINBALL

71
src/pinball/Rectangle.cpp Normal file
View file

@ -0,0 +1,71 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "../geno/math/linear/GenoMatrix4.h"
#include "Rectangle.h"
GenoShader2c * Rectangle::shader;
GenoVao * Rectangle::vao;
void Rectangle::init() {
shader = new GenoShader2c();
float vertices[] = {
1, 0, 0, // Top left
1, 1, 0, // Bottom left
0, 1, 0, // Bottom right
0, 0, 0 // Top right
};
uint32 indices[] = {
0, 1, 3,
1, 2, 3
};
vao = new GenoVao(4, vertices, 6, indices);
}
Rectangle::Rectangle(GenoCamera2D * camera, const GenoVector2f & position, const GenoVector2f & dimensions, const GenoVector4f & color) :
camera(camera),
color(color),
position(position),
dimensions(dimensions) {}
void Rectangle::setColor(const GenoVector4f & color) {
this->color = color;
}
void Rectangle::setAlpha(float alpha) {
color.w() = alpha;
}
void Rectangle::render() {
shader->enable();
shader->setColor(color);
shader->setMvp(translate2D(camera->getVPMatrix(), position).scale2D(dimensions));
vao->render();
}
Rectangle::~Rectangle() {}

59
src/pinball/Rectangle.h Normal file
View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_RECTANGLE
#define GNARLY_PINBALL_RECTANGLE
#include "../geno/math/linear/GenoVector2.h"
#include "../geno/math/linear/GenoVector4.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/gl/GenoVao.h"
#include "../geno/shaders/GenoShader2c.h"
class Rectangle {
private:
static GenoShader2c * shader;
static GenoVao * vao;
GenoCamera2D * camera;
public:
static void init();
GenoVector4f color;
GenoVector2f position;
GenoVector2f dimensions;
Rectangle(GenoCamera2D * camera, const GenoVector2f & position, const GenoVector2f & dimensions, const GenoVector4f & color);
void setColor(const GenoVector4f & color);
void setAlpha(float alpha);
void render();
~Rectangle();
};
#define GNARLY_PINBALL_RECTANGLE_FORWARD
#endif // GNARLY_PINBALL_RECTANGLE

67
src/pinball/Scene.cpp Normal file
View file

@ -0,0 +1,67 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "Rectangle.h"
#include "Pinball.h"
#include "Scene.h"
void Scene::init() {
WallList::init();
WallDraw::init();
Pinball::init();
Rectangle::init();
Image::init();
}
Scene::Scene(GenoCamera2D * camera, GlowShader * glow, uint32 next, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls) :
numColors(numColors),
glow(glow),
palette(palette),
numWallLists(numWallLists),
wallLists(walls),
next(next),
background(new Image(camera, { 0.0f, 0.0f }, { 1920.0f, 1080.f }, path)) {}
bool Scene::isComplete() {
return complete;
}
uint32 Scene::nextScene() {
return next;
}
void Scene::bindBackground(uint8 unit) {
background->getTexture()->bind(unit);
}
Scene::~Scene() {
for (uint32 i = 0; i < numWallLists; ++i)
delete wallLists[i];
delete [] wallLists;
delete [] palette;
delete background;
}

70
src/pinball/Scene.h Normal file
View file

@ -0,0 +1,70 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_SCENE
#define GNARLY_PINBALL_SCENE
#include "../geno/math/linear/GenoVector4.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/audio/GenoAudioBuffer.h"
#include "../geno/audio/GenoAudioSource.h"
#include "shaders/GlowShader.h"
#include "Image.h"
#include "WallList.h"
#include "WallDraw.h"
class Scene {
protected:
Image * background;
uint32 numColors;
GenoVector4f * palette;
GlowShader * glow;
uint32 numWallLists;
WallList ** wallLists;
bool complete;
uint32 next;
public:
static void init();
Scene(GenoCamera2D * camera, GlowShader * glow, uint32 next, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls);
virtual void update() = 0;
virtual void renderGlow() = 0;
virtual void render() = 0;
bool isComplete();
uint32 nextScene();
void bindBackground(uint8 unit);
virtual ~Scene();
};
#define GNARLY_PINBALL_SCENE
#endif // GNARLY_PINBALL_SCENE

60
src/pinball/Splash.cpp Normal file
View file

@ -0,0 +1,60 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "../geno/engine/GenoEngine.h"
#include "../geno/engine/GenoLoop.h"
#include "Splash.h"
SplashScene::SplashScene(GenoCamera2D * camera, GlowShader * glow, uint32 next, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls) :
Scene(camera, glow, next, path, numColors, palette, numWallLists, walls),
overlay(new Rectangle(camera, { 0.0f, 0.0f }, { 1920, 1080 }, { 0, 0, 0, 1 })) {}
void SplashScene::update() {
time += GenoEngine::getLoop()->getDelta();
if (time < 1)
alpha = time;
else if (time >= 4)
complete = true;
else if (time > 3)
alpha = 4 - time;
else
alpha = 1;
overlay->setAlpha(1 - alpha);
}
void SplashScene::renderGlow() {
for (uint32 i = 0; i < numWallLists; ++i)
wallLists[i]->render();
}
void SplashScene::render() {
for (uint32 i = 0; i < numWallLists; ++i)
wallLists[i]->render();
overlay->render();
}
SplashScene::~SplashScene() {}

48
src/pinball/Splash.h Normal file
View file

@ -0,0 +1,48 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_SPLASH
#define GNARLY_PINBALL_SPLASH
#include "Rectangle.h"
#include "Scene.h"
class SplashScene : public Scene {
private:
float time;
float alpha;
Rectangle * overlay;
public:
SplashScene(GenoCamera2D * camera, GlowShader * glow, uint32 next, const char * path, uint32 numColors, GenoVector4f * palette, uint32 numWallLists, WallList ** walls);
virtual void update();
virtual void renderGlow();
virtual void render();
virtual ~SplashScene();
};
#define GNARLY_PINBALL_SPLASH
#endif // GNARLY_PINBALL_SPLASH

148
src/pinball/WallDraw.cpp Normal file
View file

@ -0,0 +1,148 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <iostream>
#include <algorithm>
#include <cmath>
#include "../geno/engine/GenoInput.h"
#include "../geno/shaders/GenoShader2c.h"
#include "WallList.h"
#include "WallDraw.h"
GenoShader2c * sshader;
void WallDraw::init() {
sshader = new GenoShader2c();
}
void WallDraw::generateWall() {
auto index = normals.getLength();
auto segment = vertices[vertices.getLength() - 1] - vertices[vertices.getLength() - 2];
normals.add(GenoVector2f{ -segment.y(), segment.x() }.normalize());
const static uint32 INDICES[] = {
0, 2, 3,
0, 3, 5,
0, 1, 2,
5, 3, 4
};
GenoVector2f localNormal = setLength(normals[index], WallList::HALF_WALL_THICKNESS);
auto vertexIndex = vertices.getLength() - 2;
auto endPointBeg = (vertices[vertexIndex] - vertices[vertexIndex + 1]).setLength(WallList::HALF_WALL_THICKNESS);
auto endPointEnd = (vertices[vertexIndex + 1] - vertices[vertexIndex]).setLength(WallList::HALF_WALL_THICKNESS);
float verts[] = {
vertices[vertexIndex ].x() - localNormal.x(), vertices[vertexIndex ].y() - localNormal.y(), 0,
vertices[vertexIndex ].x() + endPointBeg.x(), vertices[vertexIndex ].y() + endPointBeg.y(), 0,
vertices[vertexIndex ].x() + localNormal.x(), vertices[vertexIndex ].y() + localNormal.y(), 0,
vertices[vertexIndex + 1].x() + localNormal.x(), vertices[vertexIndex + 1].y() + localNormal.y(), 0,
vertices[vertexIndex + 1].x() + endPointEnd.x(), vertices[vertexIndex + 1].y() + endPointEnd.y(), 0,
vertices[vertexIndex + 1].x() - localNormal.x(), vertices[vertexIndex + 1].y() - localNormal.y(), 0
};
walls.add(new GenoVao(6, verts, 12, INDICES));
}
void WallDraw::updateWall() {
auto index = normals.getLength() - 1;
auto segment = vertices[vertices.getLength() - 1] - vertices[vertices.getLength() - 2];
normals[index] = (GenoVector2f{ -segment.y(), segment.x() }.normalize());
const static uint32 INDICES[] = {
0, 2, 3,
0, 3, 5,
0, 1, 2,
5, 3, 4
};
GenoVector2f localNormal = setLength(normals[index], WallList::HALF_WALL_THICKNESS);
auto vertexIndex = vertices.getLength() - 2;
auto endPointBeg = (vertices[vertexIndex] - vertices[vertexIndex + 1]).setLength(WallList::HALF_WALL_THICKNESS);
auto endPointEnd = (vertices[vertexIndex + 1] - vertices[vertexIndex]).setLength(WallList::HALF_WALL_THICKNESS);
float verts[] = {
vertices[vertexIndex ].x() - localNormal.x(), vertices[vertexIndex ].y() - localNormal.y(), 0,
vertices[vertexIndex ].x() + endPointBeg.x(), vertices[vertexIndex ].y() + endPointBeg.y(), 0,
vertices[vertexIndex ].x() + localNormal.x(), vertices[vertexIndex ].y() + localNormal.y(), 0,
vertices[vertexIndex + 1].x() + localNormal.x(), vertices[vertexIndex + 1].y() + localNormal.y(), 0,
vertices[vertexIndex + 1].x() + endPointEnd.x(), vertices[vertexIndex + 1].y() + endPointEnd.y(), 0,
vertices[vertexIndex + 1].x() - localNormal.x(), vertices[vertexIndex + 1].y() - localNormal.y(), 0
};
walls[index]->rebuffer(0, 6, 3, verts);
}
WallDraw::WallDraw(GenoCamera2D * camera, GenoVector4f * palette, uint32 color) :
palette(palette),
color(color),
camera(camera) {}
void WallDraw::update() {
finishedWall = false;
if (GenoInput::getMouseButtonState(GLFW_MOUSE_BUTTON_1) == GENO_INPUT_PRESSED) {
vertices.add(GenoInput::getMouseCoords(camera));
vertices.add(GenoInput::getMouseCoords(camera) + GenoVector2f{ 1, 1 });
generateWall();
drawing = true;
}
else if (GenoInput::getMouseButtonState(GLFW_MOUSE_BUTTON_1) > GENO_INPUT_PRESSED) {
vertices[vertices.getLength() - 1] = GenoInput::getMouseCoords(camera);
updateWall();
}
else if (GenoInput::getMouseButtonState(GLFW_MOUSE_BUTTON_1) == GENO_INPUT_RELEASED) {
drawing = false;
finishedWall = true;
}
}
void WallDraw::render() {
sshader->enable();
sshader->setMvp(camera->getVPMatrix());
for (uint32 i = 0; i < walls.getLength(); ++i) {
sshader->setColor(palette[color]);
walls[i]->render();
}
}
void WallDraw::remove(uint32 index) {
vertices.remove(index * 2, index * 2 + 1);
normals.remove(index);
delete walls[index];
walls.remove(index);
}
bool WallDraw::skipLast() {
return drawing;
}
bool WallDraw::wallCompleted() {
return finishedWall;
}
WallDraw::~WallDraw() {
for (uint32 i = 0; i < walls.getLength(); ++i)
delete walls[i];
}

68
src/pinball/WallDraw.h Normal file
View file

@ -0,0 +1,68 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_WALL_DRAW
#define GNARLY_PINBALL_WALL_DRAW
#include "../geno/GenoInts.h"
#include "../geno/template/GenoArrayList.h"
#include "../geno/math/linear/GenoVector2.h"
#include "../geno/math/linear/GenoVector4.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/gl/GenoVao.h"
class WallDraw {
private:
GenoVector4f * palette;
uint32 color;
GenoCamera2D * camera;
bool loop;
void generateWall();
void updateWall();
bool drawing;
bool finishedWall;
public:
static void init();
GenoArrayList<GenoVector2f> vertices;
GenoArrayList<GenoVector2f> normals;
GenoArrayList<GenoVao*> walls;
WallDraw(GenoCamera2D * camera, GenoVector4f * palette, uint32 color);
void update();
void render();
void remove(uint32 index);
bool skipLast();
bool wallCompleted();
~WallDraw();
};
#define GNARLY_PINBALL_WALL_DRAW_FORWARD
#endif // GNARLY_PINBALL_WALL_DRAW

169
src/pinball/WallList.cpp Normal file
View file

@ -0,0 +1,169 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <iostream>
#include <algorithm>
#include <cmath>
#include "../geno/shaders/GenoShader2c.h"
#include "WallList.h"
GenoShader2c * shader;
const float WallList::HALF_WALL_THICKNESS = 7.5f / 2.0f;
void WallList::init() {
shader = new GenoShader2c();
}
void WallList::generateNormals() {
for (uint32 i = 0; i < numWalls; ++i) {
auto segment = vertices[i + 1] - vertices[i];
normals[i] = GenoVector2f{ -segment.y(), segment.x() }.normalize();
}
auto average = vertices[0];
for (uint32 i = 1; i < numWalls; ++i)
average += vertices[i];
average /= numVertices;
const auto EXTERNAL_NEEDED = numWalls / 2;
auto numExternal = uint32{ 0 };
for (uint32 i = 0; i < numWalls && numExternal < EXTERNAL_NEEDED; ++i)
numExternal += dot(normals[i], lerp(vertices[i] - average, vertices[i + 1] - average, 0.5)) < 0;
if (numExternal >= EXTERNAL_NEEDED)
for (uint32 i = 0; i < numWalls; ++i)
normals[i] = -normals[i];
}
void WallList::generateWalls() {
const uint32 INDICES[] = {
0, 2, 3,
0, 3, 5,
0, 1, 2,
5, 3, 4
};
for (uint32 i = 0; i < numWalls; ++i) {
auto bisect1 = bisect(normals[i], normals[i - 1]);
auto bisectLength1 = HALF_WALL_THICKNESS / sin(angleBetween(-bisect1, vertices[i + 1] - vertices[i]));
auto bisect2 = bisect(normals[i], normals[i + 1]);
auto bisectLength2 = HALF_WALL_THICKNESS / sin(angleBetween(-bisect2, vertices[i] - vertices[i + 1]));
GenoVector2f localNormals[] = {
bisect1.setLength(HALF_WALL_THICKNESS),
bisect1.setLength(bisectLength1),
bisect2.setLength(HALF_WALL_THICKNESS),
bisect2.setLength(bisectLength2),
setLength(normals[i], HALF_WALL_THICKNESS)
};
float verts[] = {
vertices[i ].x() - localNormals[1].x(), vertices[i ].y() - localNormals[1].y(), 0,
vertices[i ].x() + localNormals[0].x(), vertices[i ].y() + localNormals[0].y(), 0,
vertices[i ].x() + localNormals[4].x(), vertices[i ].y() + localNormals[4].y(), 0,
vertices[i + 1].x() + localNormals[4].x(), vertices[i + 1].y() + localNormals[4].y(), 0,
vertices[i + 1].x() + localNormals[2].x(), vertices[i + 1].y() + localNormals[2].y(), 0,
vertices[i + 1].x() - localNormals[3].x(), vertices[i + 1].y() - localNormals[3].y(), 0
};
if (!loop) {
if (i == 0) {
auto endPoint = (vertices[0] - vertices[1]).setLength(HALF_WALL_THICKNESS);
verts[0] = vertices[0].x() - localNormals[4].x();
verts[1] = vertices[0].y() - localNormals[4].y();
verts[3] = vertices[0].x() + endPoint.x();
verts[4] = vertices[0].y() + endPoint.y();
}
if (i == numWalls - 1) {
auto endPoint = (vertices[numVertices - 1] - vertices[numVertices - 2]).setLength(HALF_WALL_THICKNESS);
verts[12] = vertices[numVertices - 1].x() + endPoint.x();
verts[13] = vertices[numVertices - 1].y() + endPoint.y();
verts[15] = vertices[numVertices - 1].x() - localNormals[4].x();
verts[16] = vertices[numVertices - 1].y() - localNormals[4].y();
}
}
walls[i] = new GenoVao(6, verts, 12, INDICES);
}
}
WallList::WallList(GenoCamera2D * camera, GenoVector4f * palette, uint32 * colors, bool loop, uint32 numVertices, GenoVector2f * vertices) :
palette(palette),
colors(colors),
camera(camera),
loop(loop),
numVertices(numVertices),
numWalls(numVertices - !loop),
vertices(numVertices, vertices),
normals(numWalls),
walls(numWalls) {
generateNormals();
generateWalls();
checkBounds();
}
void WallList::checkBounds() {
for (uint32 i = 0; i < numVertices; ++i) {
if (vertices[i].x() < vertices[bounds.left].x())
bounds.left = i;
else if (vertices[i].x() > vertices[bounds.right].x())
bounds.right = i;
if (vertices[i].y() < vertices[bounds.top].y())
bounds.top = i;
else if (vertices[i].y() > vertices[bounds.bottom].y())
bounds.bottom = i;
}
}
GenoVector4f WallList::getBounds() {
return {
vertices[bounds.left ].x(),
vertices[bounds.top ].y(),
vertices[bounds.right ].x(),
vertices[bounds.bottom].y()
};
}
GenoVector4f WallList::getBounds(uint32 index) {
return {
std::min(vertices[index].x(), vertices[index + 1].x()),
std::min(vertices[index].y(), vertices[index + 1].y()),
std::max(vertices[index].x(), vertices[index + 1].x()),
std::max(vertices[index].y(), vertices[index + 1].y())
};
}
void WallList::render() {
shader->enable();
shader->setMvp(camera->getVPMatrix());
for (uint32 i = 0; i < numWalls; ++i) {
shader->setColor(palette[colors[i]]);
walls[i]->render();
}
}
WallList::~WallList() {
for (uint32 i = 0; i < numWalls; ++i)
delete walls[i];
}

75
src/pinball/WallList.h Normal file
View file

@ -0,0 +1,75 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_WALL_LIST
#define GNARLY_PINBALL_WALL_LIST
#include "../geno/GenoInts.h"
#include "../geno/template/GenoArrayLoop.h"
#include "../geno/math/linear/GenoVector2.h"
#include "../geno/math/linear/GenoVector4.h"
#include "../geno/engine/GenoCamera2D.h"
#include "../geno/gl/GenoVao.h"
class WallList {
private:
struct Bounds {
uint32 left;
uint32 right;
uint32 top;
uint32 bottom;
};
GenoVector4f * palette;
uint32 * colors;
GenoCamera2D * camera;
Bounds bounds;
bool loop;
void generateNormals();
void generateWalls();
public:
const static float HALF_WALL_THICKNESS;
static void init();
uint32 numVertices;
uint32 numWalls;
GenoArrayLoop<GenoVector2f> vertices;
GenoArrayLoop<GenoVector2f> normals;
GenoArrayLoop<GenoVao*> walls;
WallList(GenoCamera2D * camera, GenoVector4f * palette, uint32 * colors, bool loop, uint32 numVertices, GenoVector2f * vertices);
void checkBounds();
GenoVector4f getBounds();
GenoVector4f getBounds(uint32 index);
void render();
~WallList();
};
#define GNARLY_PINBALL_WALL_LIST_FORWARD
#endif // GNARLY_PINBALL_WALL_LIST

View file

@ -0,0 +1,36 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_INFO1
#define GNARLY_PINBALL_INFO1
#include "../Info.h"
Scene * loadInfo1(GenoCamera2D * camera, GlowShader * glow) {
return new Info(camera, glow, 2, "res/img/Info1.png", "res/img/Info1Glow.png");
}
#endif // GNARLY_PINBALL_INFO1

View file

@ -0,0 +1,36 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_INFO2
#define GNARLY_PINBALL_INFO2
#include "../Info.h"
Scene * loadInfo2(GenoCamera2D * camera, GlowShader * glow) {
return new Info(camera, glow, 4, "res/img/Info2.png", "res/img/Info2Glow.png");
}
#endif // GNARLY_PINBALL_INFO2

View file

@ -0,0 +1,111 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_INTRO_LEVEL
#define GNARLY_PINBALL_INTRO_LEVEL
#include "../../geno/math/linear/GenoVector2.h"
#include "../../geno/math/linear/GenoVector4.h"
#include "../shaders/GlowShader.h"
#include "../Intro.h"
#include "../WallList.h"
Scene * loadIntroLevel(GenoCamera2D * camera, GlowShader * glow) {
uint32 numColors = 4;
GenoVector4f * palette = new GenoVector4f[numColors] {
{ 1.0, 1.0, 1.0, 1.0 },
{ 1.0, 0.5176471, 0.85490197, 1.0 },
{ 0.0, 1.0, 0.5686275, 1.0 },
{ 0.17254902, 0.7019608, 0.83137256, 1.0 }
};
uint32 numWalls = 5;
WallList ** walls = new WallList*[numWalls] {
new WallList(camera, palette,
new uint32[3] {
1, 1, 1
},
true, 3,
new GenoVector2f[12] {
{ 691.75, 3.5 },
{ 1228.25, 3.5 },
{ 1228.25, 540 }
}
),
new WallList(camera, palette,
new uint32[3] {
1, 1, 1
},
true, 3,
new GenoVector2f[12] {
{ 691.75, 540 },
{ 1228.25, 1076.5 },
{ 691.75, 1076.5 }
}
),
new WallList(camera, palette,
new uint32[3] {
1, 1, 1
},
true, 3,
new GenoVector2f[12] {
{ 1916.5, 540 },
{ 1380, 1076.5 },
{ 1916.5, 1076.5 }
}
),
new WallList(camera, palette,
new uint32[4] {
0, 0, 0, 0
},
true, 4,
new GenoVector2f[4] {
{ 3.5, 3.5 },
{ 1916.5, 3.5 },
{ 1916.5, 1076.5 },
{ 3.5, 1076.5 }
}
),
new WallList(camera, palette,
new uint32[4] {
2, 2, 2, 2
},
true, 4,
new GenoVector2f[12] {
{ 1511.946, 164.803 },
{ 1511.946, 237.412 },
{ 1784.554, 237.412 },
{ 1784.554, 164.803 }
}
)
};
return new Intro(camera, glow, 3, 2, "res/img/IntroLevel.png", numColors, palette, numWalls, walls, 0, 3, { 271.75, 808.25 }, { 0.0f, -300 });
}
#define GNARLY_PINBALL_INTRO_LEVEL_FORWARD
#endif // GNARLY_PINBALL_INTRO_LEVEL

100
src/pinball/levels/Level1.h Normal file
View file

@ -0,0 +1,100 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_LEVEL1
#define GNARLY_PINBALL_LEVEL1
#include "../../geno/math/linear/GenoVector2.h"
#include "../../geno/math/linear/GenoVector4.h"
#include "../shaders/GlowShader.h"
#include "../Intro.h"
#include "../WallList.h"
Scene * loadLevel1(GenoCamera2D * camera, GlowShader * glow) {
uint32 numColors = 4;
GenoVector4f * palette = new GenoVector4f[numColors] {
{ 1.0, 1.0, 1.0, 1.0 },
{ 0.0, 0.0, 0.8, 1.0 },
{ 0.0, 1.0, 0.5686275, 1.0 },
{ 0.8, 0.0, 0.0, 1.0 }
};
uint32 numWalls = 4;
WallList ** walls = new WallList*[numWalls] {
new WallList(camera, palette,
new uint32[4] {
1, 1, 1, 1
},
true, 4,
new GenoVector2f[4] {
{ 3.75, 3.75 },
{ 1388.346, 3.75 },
{ 963.75, 428.346 },
{ 3.75, 428.346 }
}
),
new WallList(camera, palette,
new uint32[3] {
1, 1, 1
},
true, 3,
new GenoVector2f[3] {
{ 1916.75, 670.431 },
{ 1916.25, 942.5 },
{ 1647.931, 942.5 }
}
),
new WallList(camera, palette,
new uint32[4] {
0, 0, 0, 0
},
true, 4,
new GenoVector2f[4] {
{ 3.75, 3.75 },
{ 1916.25, 3.75 },
{ 1916.25, 942.25 },
{ 3.75, 942.25 }
}
),
new WallList(camera, palette,
new uint32[4] {
2, 2, 2, 2
},
true, 4,
new GenoVector2f[4] {
{ 1494.4, 36.087 },
{ 1427.572, 102.915 },
{ 1573.852, 249.196 },
{ 1640.681, 182.367 }
}
)
};
return new Level(camera, glow, 5, 4, "res/img/Level1.png", numColors, palette, numWalls, walls, 7, 0, 3, { 184.5, 724.793 }, { 300, 0 });
}
#define GNARLY_PINBALL_LEVEL1_FORWARD
#endif // GNARLY_PINBALL_LEVEL1

222
src/pinball/levels/Level2.h Normal file
View file

@ -0,0 +1,222 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_LEVEL2
#define GNARLY_PINBALL_LEVEL2
#include "../../geno/math/linear/GenoVector2.h"
#include "../../geno/math/linear/GenoVector4.h"
#include "../shaders/GlowShader.h"
#include "../Intro.h"
#include "../WallList.h"
Scene * loadLevel2(GenoCamera2D * camera, GlowShader * glow) {
uint32 numColors = 9;
GenoVector4f * palette = new GenoVector4f[numColors] {
{ 1.0, 1.0, 1.0, 1.0 },
{ 0.07058824, 0.34901962, 0.23137255, 1.0 },
{ 0.0, 0.78431374, 1.0, 1.0 },
{ 0.0, 0.6, 1.0, 1.0 },
{ 0.0, 0.46666667, 1.0, 1.0 },
{ 0.0, 0.33333334, 1.0, 1.0 },
{ 0.36078432, 0.36078432, 0.36078432, 1.0 },
{ 0.7019608, 0.7019608, 0.7019608, 1.0 },
{ 1.0, 0.1, 0.1, 1.0 }
};
uint32 numWalls = 15;
WallList ** walls = new WallList*[numWalls] {
new WallList(camera, palette,
new uint32[2] {
6, 6
},
false, 2,
new GenoVector2f[2] {
{ 492.279, 521.25 },
{ 492.279, 942.25 }
}
),
new WallList(camera, palette,
new uint32[2] {
0, 0
},
false, 2,
new GenoVector2f[2] {
{ 1262.104, 521.25 },
{ 1262.104, 942.25 }
}
),
new WallList(camera, palette,
new uint32[3] {
2, 2, 2
},
true, 3,
new GenoVector2f[3] {
{ 226.953, 194.972 },
{ 313.556, 194.972 },
{ 270.255, 269.972 }
}
),
new WallList(camera, palette,
new uint32[3] {
3, 3, 3
},
true, 3,
new GenoVector2f[3] {
{ 671.015, 194.972 },
{ 757.617, 194.972 },
{ 714.316, 269.972 }
}
),
new WallList(camera, palette,
new uint32[3] {
4, 4, 4
},
true, 3,
new GenoVector2f[3] {
{ 996.834, 194.972 },
{ 1083.437, 194.972 },
{ 1040.136, 269.972 }
}
),
new WallList(camera, palette,
new uint32[3] {
5, 5, 5
},
true, 3,
new GenoVector2f[3] {
{ 1440.896, 194.972 },
{ 1527.498, 194.972 },
{ 1484.197, 269.972 }
}
),
new WallList(camera, palette,
new uint32[3] {
6, 6, 6
},
true, 3,
new GenoVector2f[3] {
{ 448.978, 521.25 },
{ 492.279, 446.25 },
{ 535.581, 521.25 }
}
),
new WallList(camera, palette,
new uint32[3] {
7, 7, 7
},
true, 3,
new GenoVector2f[3] {
{ 833.89, 422.583 },
{ 920.492, 422.583 },
{ 877.191, 497.583 }
}
),
new WallList(camera, palette,
new uint32[3] {
0, 0, 0
},
true, 3,
new GenoVector2f[3] {
{ 1218.802, 521.25 },
{ 1262.104, 446.25 },
{ 1305.405, 521.25 }
}
),
new WallList(camera, palette,
new uint32[3] {
2, 2, 2
},
true, 3,
new GenoVector2f[3] {
{ 226.953, 750.288 },
{ 313.556, 750.288 },
{ 270.255, 675.288 }
}
),
new WallList(camera, palette,
new uint32[3] {
3, 3, 3
},
true, 3,
new GenoVector2f[3] {
{ 612.989, 750.288 },
{ 699.592, 750.288 },
{ 656.29, 675.288 }
}
),
new WallList(camera, palette,
new uint32[3] {
4, 4, 4
},
true, 3,
new GenoVector2f[3] {
{ 1055.955, 750.288 },
{ 1142.558, 750.288 },
{ 1099.256, 675.288 }
}
),
new WallList(camera, palette,
new uint32[3] {
5, 5, 5
},
true, 3,
new GenoVector2f[3] {
{ 1440.896, 750.288 },
{ 1527.498, 750.288 },
{ 1484.197, 675.288 }
}
),
new WallList(camera, palette,
new uint32[4] {
0, 0, 0, 0
},
true, 4,
new GenoVector2f[4] {
{ 3.75, 3.75 },
{ 1916.25, 3.75 },
{ 1916.25, 942.25 },
{ 3.75, 942.25 }
}
),
new WallList(camera, palette,
new uint32[3] {
1, 1, 1
},
true, 3,
new GenoVector2f[3] {
{ 1647.014, 404.503 },
{ 1647.014, 537.997 },
{ 1762.622, 471.25 }
}
)
};
return new Level(camera, glow, 6, 5, "res/img/Level2.png", numColors, palette, numWalls, walls, 9.5f, 0, 8, { 107.366, 471.25 }, { 400, 0 });
}
#define GNARLY_PINBALL_LEVEL2_FORWARD
#endif // GNARLY_PINBALL_LEVEL2

View file

@ -0,0 +1,221 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_START_SPLASH
#define GNARLY_PINBALL_START_SPLASH
#include "../../geno/math/linear/GenoVector2.h"
#include "../../geno/math/linear/GenoVector4.h"
#include "../shaders/GlowShader.h"
#include "../Splash.h"
#include "../WallList.h"
Scene * loadSplash(GenoCamera2D * camera, GlowShader * glow) {
uint32 numColors = 8;
GenoVector4f * palette = new GenoVector4f[numColors] {
{ 1.0, 1.0, 1.0, 1.0 },
{ 0.12156863, 0.14117648, 0.16078432, 1.0 },
{ 0.43529412, 0.4745098, 0.5176471, 1.0 },
{ 1.0, 0.28235295, 0.8392157, 1.0 },
{ 0.93333334, 0.33333334, 0.2, 1.0 },
{ 0.96862745, 0.5686275, 0.13333334, 1.0 },
{ 0.0, 0.5882353, 0.0, 1.0 },
{ 0.0, 0.5882353, 1.0, 1.0 }
};
uint32 numWalls = 11;
WallList ** walls = new WallList*[numWalls] {
new WallList(camera, palette,
new uint32[4] {
0, 0, 0, 0
},
true, 4,
new GenoVector2f[4] {
{ 3.75, 3.75 },
{ 1916.25, 3.75 },
{ 1916.25, 1076.25 },
{ 3.75, 1076.25 }
}
),
new WallList(camera, palette,
new uint32[12] {
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
},
true, 12,
new GenoVector2f[12] {
{ 149.879, 350.969 },
{ 237.625, 350.969 },
{ 237.625, 263.224 },
{ 325.37, 263.224 },
{ 325.37, 350.969 },
{ 413.116, 350.969 },
{ 413.116, 438.715 },
{ 325.37, 438.715 },
{ 325.37, 526.461 },
{ 237.625, 526.461 },
{ 237.625, 438.715 },
{ 149.879, 438.715 }
}
),
new WallList(camera, palette,
new uint32[3] {
4, 4, 4
},
false, 4,
new GenoVector2f[4] {
{ 588.109, 350.969 },
{ 588.109, 155.604 },
{ 711.103, 155.604 },
{ 711.103, 350.969 }
}
),
new WallList(camera, palette,
new uint32[5] {
4, 4, 4, 4, 4
},
false, 6,
new GenoVector2f[6] {
{ 588.109, 438.715 },
{ 588.109, 634.08 },
{ 945.091, 634.08 },
{ 945.091, 503.587 },
{ 711.103, 503.587 },
{ 711.103, 438.715 }
}
),
new WallList(camera, palette,
new uint32[7] {
5, 5, 5, 5, 5, 5, 5
},
false, 8,
new GenoVector2f[8] {
{ 1044.086, 350.969 },
{ 1044.086, 155.604 },
{ 1273.575, 155.604 },
{ 1401.068, 286.098 },
{ 1401.068, 503.587 },
{ 1273.575, 634.08 },
{ 1044.086, 634.08 },
{ 1044.086, 438.715 }
}
),
new WallList(camera, palette,
new uint32[7] {
2, 2, 2, 2, 2, 2, 2
},
true, 7,
new GenoVector2f[7] {
{ 543.111, 350.969 },
{ 1189.579, 350.969 },
{ 1168.09, 286.098 },
{ 1297.084, 394.842 },
{ 1168.09, 503.587 },
{ 1189.579, 438.715 },
{ 543.111, 438.715 }
}
),
new WallList(camera, palette,
new uint32[4] {
6, 6, 6, 6
},
false, 4,
new GenoVector2f[4] {
{ 1590.361, 283.028 },
{ 1590.361, 223.545 },
{ 1649.844, 223.545 },
{ 1649.844, 283.028 }
}
),
new WallList(camera, palette,
new uint32[4] {
6, 6, 6, 6
},
false, 4,
new GenoVector2f[4] {
{ 1590.361, 526.788 },
{ 1590.361, 586.271 },
{ 1649.844, 586.271 },
{ 1649.844, 526.788 }
}
),
new WallList(camera, palette,
new uint32[8] {
6, 6, 6, 6, 6, 6, 6, 6
},
true, 8,
new GenoVector2f[8] {
{ 1620.103, 254.875 },
{ 1727.103, 361.875 },
{ 1620.103, 361.875 },
{ 1727.103, 449.53 },
{ 1620.103, 556.53 },
{ 1513.103, 449.53 },
{ 1620.103, 449.53 },
{ 1513.103, 351.875 }
}
),
new WallList(camera, palette,
new uint32[10] {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4
},
true, 10,
new GenoVector2f[10] {
{ 788.086, 712.846 },
{ 847.522, 712.846 },
{ 847.522, 802 },
{ 906.957, 802 },
{ 906.957, 712.846 },
{ 966.393, 712.846 },
{ 966.393, 950.589 },
{ 906.957, 950.589 },
{ 906.957, 861.436 },
{ 788.086, 861.436 }
}
),
new WallList(camera, palette,
new uint32[10] {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5
},
true, 10,
new GenoVector2f[10] {
{ 1017.772, 712.846 },
{ 1077.208, 712.846 },
{ 1077.208, 802 },
{ 1136.643, 802 },
{ 1136.643, 712.846 },
{ 1196.079, 712.846 },
{ 1196.079, 950.589 },
{ 1136.643, 950.589 },
{ 1136.643, 861.436 },
{ 1017.772, 861.436 }
}
)
};
return new SplashScene(camera, glow, 1, "res/img/SplashBackground.png", numColors, palette, numWalls, walls);
}
#endif // GNARLY_PINBALL_START_SPLASH

36
src/pinball/levels/Win.h Normal file
View file

@ -0,0 +1,36 @@
/*******************************************************************************
*
* Copyright (c) 2019 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_PINBALL_WIN
#define GNARLY_PINBALL_WIN
#include "../Info.h"
Scene * loadWin(GenoCamera2D * camera, GlowShader * glow) {
return new Info(camera, glow, 7, "res/img/Win.png", "res/img/WinGlow.png");
}
#endif // GNARLY_PINBALL_WIN

View file

@ -0,0 +1,67 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <iostream>
#include "../../geno/gl/GenoGL.h"
#include "GlowShader.h"
GlowShader::GlowShader() :
GenoMvpShader("res/shaders/GlowShader/GlowShaderv.gls",
"res/shaders/GlowShader/GlowShaderf.gls",
GENO_SHADER_STRING_IS_PATH) {
resolutionLoc = glGetUniformLocation(program, "resolution");
horizontalLoc = glGetUniformLocation(program, "horizontal");
brightnessLoc = glGetUniformLocation(program, "brightness");
distanceLoc = glGetUniformLocation(program, "distance");
uint32 texLoc = glGetUniformLocation(program, "tex");
uint32 backgroundLoc = glGetUniformLocation(program, "background");
enable();
glUniform1i(texLoc, 0);
glUniform1i(backgroundLoc, 1);
}
void GlowShader::setResolution(float width, float height) {
glUniform2f(resolutionLoc, width, height);
}
void GlowShader::setHorizontal(bool horizontal) {
glUniform1i(horizontalLoc, horizontal);
}
void GlowShader::setBrightness(float brightness) {
glUniform1f(brightnessLoc, brightness);
}
void GlowShader::setDistance(float distance) {
glUniform1f(distanceLoc, distance);
}
GlowShader::~GlowShader() {}

View file

@ -0,0 +1,49 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_GENOME_GLOW_SHADER
#define GNARLY_GENOME_GLOW_SHADER
#include "../../geno/gl/GenoShader.h"
class GlowShader : public GenoMvpShader {
private:
uint32 resolutionLoc;
uint32 horizontalLoc;
uint32 brightnessLoc;
uint32 distanceLoc;
public:
GlowShader();
void setResolution(float width, float height);
void setHorizontal(bool horizontal);
void setBrightness(float brightness);
void setDistance(float distance);
~GlowShader();
};
#define GNARLY_GENOME_GLOW_SHADER_FORWARD
#endif // GNARLY_GENOME_GLOW_SHADER

View file

@ -0,0 +1,42 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include "../../geno/gl/GenoGL.h"
#include "MixShader.h"
MixShader::MixShader() :
GenoMvpShader("res/shaders/MixShader/MixShaderv.gls",
"res/shaders/MixShader/MixShaderf.gls",
GENO_SHADER_STRING_IS_PATH) {
colorLoc = glGetUniformLocation(program, "inputColor");
}
void MixShader::setColor(const GenoVector4f & color) {
glUniform4f(colorLoc, color.v[0], color.v[1], color.v[2], color.v[3]);
}
MixShader::~MixShader() {}

View file

@ -0,0 +1,44 @@
/*******************************************************************************
*
* Copyright (c) 2018 Gnarly Narwhal
*
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files(the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#ifndef GNARLY_GENOME_MIX_SHADER
#define GNARLY_GENOME_MIX_SHADER
#include "../../geno/GenoInts.h"
#include "../../geno/gl/GenoShader.h"
class MixShader : public GenoMvpShader {
private:
uint32 colorLoc;
public:
MixShader();
void setColor(const GenoVector4f & color);
~MixShader();
};
#define GNARLY_GENOME_MIX_SHADER_FORWARD
#endif // GNARLY_GENOME_MIX_SHADER