diff --git a/GameEngine2D/img/Blocks_01.png b/GameEngine2D/img/Blocks_01.png new file mode 100644 index 0000000..85dd169 Binary files /dev/null and b/GameEngine2D/img/Blocks_01.png differ diff --git a/GameEngine2D/img/grass.png b/GameEngine2D/img/grass.png new file mode 100644 index 0000000..5ce1caf Binary files /dev/null and b/GameEngine2D/img/grass.png differ diff --git a/GameEngine2D/img/hills.png b/GameEngine2D/img/hills.png new file mode 100644 index 0000000..9667b1a Binary files /dev/null and b/GameEngine2D/img/hills.png differ diff --git a/GameEngine2D/img/level_01.png b/GameEngine2D/img/level_01.png new file mode 100644 index 0000000..8706ef1 Binary files /dev/null and b/GameEngine2D/img/level_01.png differ diff --git a/GameEngine2D/img/mountains.png b/GameEngine2D/img/mountains.png new file mode 100644 index 0000000..b9f75de Binary files /dev/null and b/GameEngine2D/img/mountains.png differ diff --git a/GameEngine2D/img/paper_airplane.png b/GameEngine2D/img/paper_airplane.png new file mode 100644 index 0000000..328b5bc Binary files /dev/null and b/GameEngine2D/img/paper_airplane.png differ diff --git a/GameEngine2D/img/paper_idle.png b/GameEngine2D/img/paper_idle.png new file mode 100644 index 0000000..e73a71f Binary files /dev/null and b/GameEngine2D/img/paper_idle.png differ diff --git a/GameEngine2D/img/paper_move.png b/GameEngine2D/img/paper_move.png new file mode 100644 index 0000000..bfca551 Binary files /dev/null and b/GameEngine2D/img/paper_move.png differ diff --git a/GameEngine2D/img/paper_special.png b/GameEngine2D/img/paper_special.png new file mode 100644 index 0000000..f38a5f7 Binary files /dev/null and b/GameEngine2D/img/paper_special.png differ diff --git a/GameEngine2D/img/platforms16x16.png b/GameEngine2D/img/platforms16x16.png new file mode 100644 index 0000000..33bb413 Binary files /dev/null and b/GameEngine2D/img/platforms16x16.png differ diff --git a/GameEngine2D/img/platforms16x16_2.png b/GameEngine2D/img/platforms16x16_2.png new file mode 100644 index 0000000..4c405c9 Binary files /dev/null and b/GameEngine2D/img/platforms16x16_2.png differ diff --git a/GameEngine2D/img/platforms16x16_3.png b/GameEngine2D/img/platforms16x16_3.png new file mode 100644 index 0000000..9e71aa3 Binary files /dev/null and b/GameEngine2D/img/platforms16x16_3.png differ diff --git a/GameEngine2D/img/platforms16x16_4.png b/GameEngine2D/img/platforms16x16_4.png new file mode 100644 index 0000000..ea4a668 Binary files /dev/null and b/GameEngine2D/img/platforms16x16_4.png differ diff --git a/GameEngine2D/img/rock_attack.png b/GameEngine2D/img/rock_attack.png new file mode 100644 index 0000000..805da9c Binary files /dev/null and b/GameEngine2D/img/rock_attack.png differ diff --git a/GameEngine2D/img/rock_idle.png b/GameEngine2D/img/rock_idle.png new file mode 100644 index 0000000..f419789 Binary files /dev/null and b/GameEngine2D/img/rock_idle.png differ diff --git a/GameEngine2D/img/rock_move.png b/GameEngine2D/img/rock_move.png new file mode 100644 index 0000000..a9fc14b Binary files /dev/null and b/GameEngine2D/img/rock_move.png differ diff --git a/GameEngine2D/img/rock_special.png b/GameEngine2D/img/rock_special.png new file mode 100644 index 0000000..f53dcc1 Binary files /dev/null and b/GameEngine2D/img/rock_special.png differ diff --git a/GameEngine2D/img/scissor_idle.png b/GameEngine2D/img/scissor_idle.png new file mode 100644 index 0000000..d7cd269 Binary files /dev/null and b/GameEngine2D/img/scissor_idle.png differ diff --git a/GameEngine2D/img/scissor_move.png b/GameEngine2D/img/scissor_move.png new file mode 100644 index 0000000..b4eb70d Binary files /dev/null and b/GameEngine2D/img/scissor_move.png differ diff --git a/GameEngine2D/img/scissor_special.png b/GameEngine2D/img/scissor_special.png new file mode 100644 index 0000000..43799e4 Binary files /dev/null and b/GameEngine2D/img/scissor_special.png differ diff --git a/GameEngine2D/img/skellyattack.png b/GameEngine2D/img/skellyattack.png new file mode 100644 index 0000000..807443b Binary files /dev/null and b/GameEngine2D/img/skellyattack.png differ diff --git a/GameEngine2D/img/skellydeath.png b/GameEngine2D/img/skellydeath.png new file mode 100644 index 0000000..64f539d Binary files /dev/null and b/GameEngine2D/img/skellydeath.png differ diff --git a/GameEngine2D/img/skellyhit.png b/GameEngine2D/img/skellyhit.png new file mode 100644 index 0000000..b9c6c08 Binary files /dev/null and b/GameEngine2D/img/skellyhit.png differ diff --git a/GameEngine2D/img/skellyidle.png b/GameEngine2D/img/skellyidle.png new file mode 100644 index 0000000..9137085 Binary files /dev/null and b/GameEngine2D/img/skellyidle.png differ diff --git a/GameEngine2D/img/skellyreact.png b/GameEngine2D/img/skellyreact.png new file mode 100644 index 0000000..dbd9943 Binary files /dev/null and b/GameEngine2D/img/skellyreact.png differ diff --git a/GameEngine2D/img/skellywalk.png b/GameEngine2D/img/skellywalk.png new file mode 100644 index 0000000..17dfd1f Binary files /dev/null and b/GameEngine2D/img/skellywalk.png differ diff --git a/GameEngine2D/img/sky.png b/GameEngine2D/img/sky.png new file mode 100644 index 0000000..0cb49d2 Binary files /dev/null and b/GameEngine2D/img/sky.png differ diff --git a/GameEngine2D/index.html b/GameEngine2D/index.html new file mode 100644 index 0000000..380f76a --- /dev/null +++ b/GameEngine2D/index.html @@ -0,0 +1,67 @@ + + + + + 2D Game Engine Test + + + + + + + + + + + + + + + diff --git a/GameEngine2D/js/entity.js b/GameEngine2D/js/entity.js new file mode 100644 index 0000000..0c280d6 --- /dev/null +++ b/GameEngine2D/js/entity.js @@ -0,0 +1,304 @@ +class SpriteIndex +{ + constructor() + { + this.s_f_s = new Array(); + } + + addSprite(frame, speed) + { + this.s_f_s.push([frame, speed]); + } +} + +var Key = { + _pressed: {}, + + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + Q: 81, + E: 69, + + isDown: function(keyCode) { + return this._pressed[keyCode]; + }, + + onKeydown: function(event) { + this._pressed[event.keyCode] = true; + }, + + onKeyup: function(event) { + delete this._pressed[event.keyCode]; + } +}; + + + +class Paper_Player +{ + constructor(index, gl, vs, fs) + { + this.index = index; + this.pos = new Point(100, 80); + this.vel = new Point(); + this.acc = new Point(); + this.acc.y = 0.01; + this.frame = new Point(); + this.dt = 1/60; + this.mirrored = 1; + this.isGrounded = true; + + + this.walk = new Sprite(gl, "img/paper_move.png", vs, fs, {width:16, height:16}); + this.attack = new Sprite(gl, "img/paper_special.png", vs, fs, {width:16, height:16}); + this.idle = new Sprite(gl, "img/paper_idle.png", vs, fs, {width:16, height:16}); + + + this.curr = this.idle; + this.currNum = 2; + } + + update() + { + this.curr = this.idle; + this.currNum = 2; + + if (Key.isDown(Key.UP)) this.movement(0); + if (Key.isDown(Key.DOWN)) this.movement(1); + if (Key.isDown(Key.LEFT)) this.movement(2); + if (Key.isDown(Key.RIGHT)) this.movement(3); + if (Key.isDown(Key.Q)) this.movement(4); + + this.render(); + } + + movement(num) + { + if (num == 0) //move up + { + //this.pos.y -= 1; + } + if (num == 1) // move down + { + + } + if (num == 2) // move left + { + this.curr = this.walk; + this.currNum = 0; + this.mirrored = -1; + } + if (num == 3) // move right + { + this.curr = this.walk; + this.currNum = 0; + this.mirrored = 1; + } + if (num == 4) // attack + { + this.curr = this.attack; + this.currNum = 1; + } + } + + render() + { + this.vel.y += this.acc.y * this.dt; + this.pos.y += this.vel.y * this.dt; + + if (this.pos.y >= 80) + { + this.pos.y = 80; + } + + if (this.mirrored == -1) + { + this.pos.x = 116; + } + else this.pos.x = 100; + this.frame.x = ( new Date() * this.index.s_f_s[this.currNum][1]) % this.index.s_f_s[this.currNum][0]; + this.curr.render(this.pos, this.frame, this.mirrored); + } +} + +class Scissor_Player +{ + constructor(index, gl, vs, fs) + { + this.index = index; + this.pos = new Point(100, 80); + this.vel = new Point(); + this.acc = new Point(); + this.acc.y = 0.01; + this.frame = new Point(); + this.dt = 1/60; + this.mirrored = 1; + this.isGrounded = true; + + + this.walk = new Sprite(gl, "img/scissor_move.png", vs, fs, {width:16, height:16}); + this.attack = new Sprite(gl, "img/scissor_special.png", vs, fs, {width:16, height:16}); + this.idle = new Sprite(gl, "img/scissor_idle.png", vs, fs, {width:16, height:16}); + + + this.curr = this.idle; + this.currNum = 2; + } + + update() + { + this.curr = this.idle; + this.currNum = 2; + + if (Key.isDown(Key.UP)) this.movement(0); + if (Key.isDown(Key.DOWN)) this.movement(1); + if (Key.isDown(Key.LEFT)) this.movement(2); + if (Key.isDown(Key.RIGHT)) this.movement(3); + if (Key.isDown(Key.Q)) this.movement(4); + + this.render(); + } + + movement(num) + { + if (num == 0) //move up + { + //this.pos.y -= 1; + } + if (num == 1) // move down + { + + } + if (num == 2) // move left + { + this.curr = this.walk; + this.currNum = 0; + this.mirrored = -1; + } + if (num == 3) // move right + { + this.curr = this.walk; + this.currNum = 0; + this.mirrored = 1; + } + if (num == 4) // attack + { + this.curr = this.attack; + this.currNum = 1; + } + } + + render() + { + this.vel.y += this.acc.y * this.dt; + this.pos.y += this.vel.y * this.dt; + + if (this.pos.y >= 80) + { + this.pos.y = 80; + } + + if (this.mirrored == -1) + { + this.pos.x = 116; + } + else this.pos.x = 100; + this.frame.x = ( new Date() * this.index.s_f_s[this.currNum][1]) % this.index.s_f_s[this.currNum][0]; + this.curr.render(this.pos, this.frame, this.mirrored); + } +} + +class Rock_Player +{ + constructor(index, gl, vs, fs) + { + this.index = index; + this.pos = new Point(100, 80); + this.vel = new Point(); + this.acc = new Point(); + this.acc.y = 0.01; + this.frame = new Point(); + this.dt = 1/60; + this.mirrored = 1; + this.isGrounded = true; + + + this.walk = new Sprite(gl, "img/rock_move.png", vs, fs, {width:16, height:16}); + this.attack = new Sprite(gl, "img/rock_special.png", vs, fs, {width:16, height:16}); + this.idle = new Sprite(gl, "img/rock_idle.png", vs, fs, {width:16, height:16}); + + + this.curr = this.idle; + this.currNum = 2; + } + + update() + { + this.curr = this.idle; + this.currNum = 2; + + if (Key.isDown(Key.UP)) this.movement(0); + if (Key.isDown(Key.DOWN)) this.movement(1); + if (Key.isDown(Key.LEFT)) this.movement(2); + if (Key.isDown(Key.RIGHT)) this.movement(3); + if (Key.isDown(Key.Q)) this.movement(4); + + + if (this.pos.x >= 80) + { + this.isGrounded == true; + } + this.render(); + } + + movement(num) + { + if (num == 0) //move up + { + this.vel.y += 0.2 * this.dt; + this.pos.y -= this.vel.y * this.dt; + } + if (num == 1) // move down + { + + } + if (num == 2) // move left + { + this.curr = this.walk; + this.currNum = 0; + this.mirrored = -1; + } + if (num == 3) // move right + { + this.curr = this.walk; + this.currNum = 0; + this.mirrored = 1; + } + if (num == 4) // attack + { + this.curr = this.attack; + this.currNum = 1; + } + } + + render() + { + this.vel.y += this.acc.y * this.dt; + this.pos.y += this.vel.y * this.dt; + + if (this.pos.y >= 80) + { + this.pos.y = 80; + } + + if (this.mirrored == -1) + { + this.pos.x = 116; + } + else this.pos.x = 100; + this.frame.x = ( new Date() * this.index.s_f_s[this.currNum][1]) % this.index.s_f_s[this.currNum][0]; + this.curr.render(this.pos, this.frame, this.mirrored); + } +} \ No newline at end of file diff --git a/GameEngine2D/js/game.js b/GameEngine2D/js/game.js new file mode 100644 index 0000000..e8ef331 --- /dev/null +++ b/GameEngine2D/js/game.js @@ -0,0 +1,185 @@ +function loop() +{ + window.game.update(); + requestAnimationFrame(loop); +} + +var Key = { + _pressed: {}, + + LEFT: 37, + UP: 38, + RIGHT: 39, + DOWN: 40, + Q: 81, + E: 69, + + isDown: function(keyCode) { + return this._pressed[keyCode]; + }, + + isUp: function(keyCode) { + return this._pressed[keyCode]; + }, + + onKeydown: function(event) { + this._pressed[event.keyCode] = true; + }, + + onKeyup: function(event) { + delete this._pressed[event.keyCode]; + } +}; + +class Game +{ + constructor() + { + this.canvasElem = document.createElement("canvas"); + this.canvasElem.width = 64; + this.canvasElem.height = 64; + + this.worldSpaceMatrix = new M3x3(); + + this.gl = this.canvasElem.getContext("webgl2"); + this.gl.clearColor(0.5, 0.5, 0.8, 0.0); + + document.body.appendChild(this.canvasElem); + + let vs = document.getElementById("vs_01").innerHTML; + let fs = document.getElementById("fs_01").innerHTML; + + this.mountains = new Sprite(this.gl, "img/mountains.png", vs, fs, {width: 384, height: 128}); + this.mount_pos = new Point(-64, 0); + this.bg_frames = new Point(); + + this.hills = new Sprite(this.gl, "img/hills.png", vs, fs, {width: 768, height: 128}); + this.hills_pos = new Point(-384, 0); + + this.grass = new Sprite(this.gl, "img/grass.png", vs, fs, {width: 768, height: 128}); + this.grass_pos = new Point(-384, 0); + + this.paper_index = new SpriteIndex(); + this.paper_index.addSprite(12, 0.02); // move + this.paper_index.addSprite(9, 0.02); // special + this.paper_index.addSprite(2, 0.003); // idle + this.paper_player = new Paper_Player(this.paper_index, this.gl, vs, fs); + + this.rock_index = new SpriteIndex(); + this.rock_index.addSprite(4, 0.008); // move + this.rock_index.addSprite(4, 0.02); // special + this.rock_index.addSprite(2, 0.003); // idle + this.rock_player = new Rock_Player(this.rock_index, this.gl, vs, fs); + + this.scissor_index = new SpriteIndex(); + this.scissor_index.addSprite(8, 0.01); // move + this.scissor_index.addSprite(9, 0.02); // special + this.scissor_index.addSprite(4, 0.01); // idle + this.scissor_player = new Scissor_Player(this.scissor_index, this.gl, vs, fs); + + this.character = 0; + } + + resize(x,y) + { + this.canvasElem.width = x; + this.canvasElem.height = y; + + let wRatio = x / (y/240); + this.worldSpaceMatrix = new M3x3().transition(-1, 1).scale(2/wRatio, -2/240); + } + + move(num) + { + if (num == 0) + { + this.mount_pos.x += 1; + this.hills_pos.x += 2; + this.grass_pos.x += 2; + if (this.grass_pos.x == -128) + { + console.log(this.grass_pos.x); + this.grass_pos.x -= 128; + } + if (this.hills_pos.x % 64 == 0) + { + this.hills_pos.x -= 128; + } + if (this.mount_pos.x % 26 == 0) + { + this.mount_pos.x -= 128; + } + + } + if (num == 1) + { + this.mount_pos.x -= 1; + this.hills_pos.x -= 2; + this.grass_pos.x -= 2; + if (this.grass_pos.x == 128) + { + this.grass_pos.x += 128; + } + if (this.hills_pos.x % 64 == 0) + { + this.hills_pos.x += 128; + } + if (this.mount_pos.x % 64 == 0) + { + this.mount_pos.x += 128; + } + + } + } + + update() + { + this.gl.viewport(0,-510, this.canvasElem.width * 1.5, this.canvasElem.height * 1.5); // scales and moves the canvas + this.gl.clear(this.gl.COLOR_BUFFER_BIT); // bg color + + // allows transparency + this.gl.enable(this.gl.BLEND); + this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA); + + if (Key.isDown(Key.LEFT)) this.move(0); + if (Key.isDown(Key.RIGHT)) this.move(1); + + + + this.mountains.render(this.mount_pos, this.bg_frames, 1); + this.hills.render(this.hills_pos, this.bg_frames, 1); + + if (Key.isDown(Key.E)) + { + if (Key.isUp(Key.E)) + { + this.character++; + } + if (this.character >= 3) + { + this.character = 0; + } + } + + if (this.character == 0) + { + this.paper_player.update(); + } + else if (this.character == 1) + { + this.rock_player.update(); + } + else if (this.character == 2) + { + this.scissor_player.update(); + } + + this.grass.render(this.grass_pos, this.bg_frames, 1); + + + + + + this.gl.flush(); + } +} \ No newline at end of file diff --git a/GameEngine2D/js/material.js b/GameEngine2D/js/material.js new file mode 100644 index 0000000..dfa10e6 --- /dev/null +++ b/GameEngine2D/js/material.js @@ -0,0 +1,237 @@ +class Material +{ + constructor(gl, vs, fs) + { + this.gl = gl; + + let vsShader = this.getShader(vs, gl.VERTEX_SHADER); + let fsShader = this.getShader(fs, gl.FRAGMENT_SHADER); + + if(vsShader && fsShader) + { + this.program = gl.createProgram(); + gl.attachShader(this.program, vsShader); + gl.attachShader(this.program, fsShader); + gl.linkProgram(this.program); + + if(!gl.getProgramParameter(this.program, gl.LINK_STATUS)) + { + console.error("Cannot load shader \n"+gl.getProgramInfoLog(this.program)); + return null; + } + + this.gatherParameters(); + + gl.detachShader(this.program, vsShader); + gl.detachShader(this.program, fsShader); + gl.deleteShader(vsShader); + gl.deleteShader(fsShader); + + gl.useProgram(null); + } + } + + getShader(script, type) + { + let gl = this.gl; + var output = gl.createShader(type); + gl.shaderSource(output, script); + gl.compileShader(output); + + if(!gl.getShaderParameter(output, gl.COMPILE_STATUS)) + { + console.error("Shader error: \n:" + gl.getShaderInfoLog(output)); + return null; + } + + return output; + } + + gatherParameters() + { + let gl = this.gl; + let isUniform = 0; + + this.parameters = {}; + + while(isUniform < 2 ) + { + let paramType = isUniform ? gl.ACTIVE_UNIFORMS : gl.ACTIVE_ATTRIBUTES; + let count = gl.getProgramParameter(this.program, paramType); + + for(let i = 0; i < count; i++) + { + let details; + let location; + if(isUniform) + { + details = gl.getActiveUniform(this.program, i); + location = gl.getUniformLocation(this.program, details.name); + } + else + { + details = gl.getActiveAttrib(this.program, i); + location = gl.getAttribLocation(this.program, details.name); + } + + this.parameters[details.name] = + { + location : location, + uniform : !!isUniform, + type : details.type + } + } + isUniform++; + } + } + + set(name, a, b, c, d, e) + { + let gl = this.gl; + + if (name in this.parameters) + { + let param = this.parameters[name]; + if(param.uniform) + { + switch(param.type) + { + case gl.FLOAT: gl.uniform1f(param.location, a); break; + case gl.FLOAT_VEC2: gl.uniform2f(param.location, a, b); break; + case gl.FLOAT_VEC3: gl.uniform3f(param.location, a, b, c); break; + case gl.FLOAT_VEC4: gl.uniform4f(param.location, a, b, c, d); break; + case gl.FLOAT_MAT3: gl.uniformMatrix3fv(param.location, false, a); break; + case gl.FLOAT_MAT4: gl.uniformMatrix4fv(param.location, false, a); break; + case gl.SAMPLER_2D: gl.uniform1i(param.location, a); break; + + } + } + else + { + gl.enableVertexAttribArray(param.location); + + if(a == undefined) a = gl.FLOAT; + if(b == undefined) b = false; + if(c == undefined) c = 0; + if(d == undefined) d = 0; + + switch(param.type) + { + case gl.FLOAT: gl.vertexAttribPointer(param.location, 1, a, b, c, d); break; + case gl.FLOAT_VEC2: gl.vertexAttribPointer(param.location, 2, a, b, c, d); break; + case gl.FLOAT_VEC3: gl.vertexAttribPointer(param.location, 3, a, b, c, d); break; + case gl.FLOAT_VEC4: gl.vertexAttribPointer(param.location, 4, a, b, c, d); break; + } + } + } + } +} + +class Sprite +{ + constructor(gl, img_url, vs, fs, opts={}) + { + this.gl = gl; + this.isLoaded = false; + this.material = new Material(gl,vs,fs); + + this.size = new Point(64, 64); + if ("width" in opts) + { + this.size.x = opts.width * 1; + } + if ("height" in opts) + { + this.size.y = opts.height * 1; + } + + this.image = new Image(); + this.image.src = img_url; + this.image.sprite = this; + this.image.onload = function() + { + this.sprite.setup(); + } + + + } + + static createRectArray(x=0, y=0, w=1, h=1) + { + return new Float32Array + ([ + x, y, + x+w, y, + x, y+h, + x, y+h, + x+w, y, + x+w, y+h + ]); + } + + setup() + { + let gl = this.gl; + + gl.useProgram(this.material.program); + this.gl_tex = gl.createTexture(); + + gl.bindTexture(gl.TEXTURE_2D, this.gl_tex); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, this.image); + gl.bindTexture(gl.TEXTURE_2D, null); + + this.uv_x = this.size.x / this.image.width; + this.uv_y = this.size.y / this.image.height; + + this.tex_buff = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, this.tex_buff); + gl.bufferData(gl.ARRAY_BUFFER, Sprite.createRectArray(0, 0, this.uv_x, this.uv_y), gl.STATIC_DRAW); + + this.geo_buff = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, this.geo_buff); + gl.bufferData(gl.ARRAY_BUFFER, Sprite.createRectArray(0, 0, this.size.x, this.size.y), gl.STATIC_DRAW); + + gl.useProgram(null); + this.isLoaded = true; + + } + + render(position, frames, mirrored) + { + if(this.isLoaded) + { + let gl = this.gl; + + let frame_x = Math.floor(frames.x) * this.uv_x; + let frame_y = Math.floor(frames.y) * this.uv_y; + + //console.log(" rendering ... \n" ); + + let obj_mat = new M3x3().transition(position.x, position.y).scale(mirrored, 1); + + gl.useProgram(this.material.program); + + gl.activeTexture(gl.TEXTURE0); + gl.bindTexture(gl.TEXTURE_2D, this.gl_tex); + this.material.set("u_image", 0); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.tex_buff); + this.material.set("a_texCoord"); + + gl.bindBuffer(gl.ARRAY_BUFFER, this.geo_buff); + this.material.set("a_position"); + + this.material.set("u_frame", frame_x, frame_y); + this.material.set("u_world", window.game.worldSpaceMatrix.getFloatArray()); + this.material.set("u_object", obj_mat.getFloatArray()); + + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 6); + + gl.useProgram(null); + } + } +} \ No newline at end of file diff --git a/GameEngine2D/js/math.js b/GameEngine2D/js/math.js new file mode 100644 index 0000000..9e80d38 --- /dev/null +++ b/GameEngine2D/js/math.js @@ -0,0 +1,95 @@ +class Point +{ + constructor(x=0.0, y=0.0) + { + this.x = x; + this.y = y; + } +} + +class M3x3 +{ + constructor() + { + this.matrix = + [ + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + ]; + } + + multiply(m) + { + var output = new M3x3(); + output.matrix = + [ + this.matrix[M3x3.M00] * m.matrix[M3x3.M00] + this.matrix[M3x3.M10] * m.matrix[M3x3.M01] + this.matrix[M3x3.M20] * m.matrix[M3x3.M02], + this.matrix[M3x3.M01] * m.matrix[M3x3.M00] + this.matrix[M3x3.M11] * m.matrix[M3x3.M01] + this.matrix[M3x3.M21] * m.matrix[M3x3.M02], + this.matrix[M3x3.M02] * m.matrix[M3x3.M00] + this.matrix[M3x3.M12] * m.matrix[M3x3.M01] + this.matrix[M3x3.M22] * m.matrix[M3x3.M02], + + this.matrix[M3x3.M00] * m.matrix[M3x3.M10] + this.matrix[M3x3.M10] * m.matrix[M3x3.M11] + this.matrix[M3x3.M20] * m.matrix[M3x3.M12], + this.matrix[M3x3.M01] * m.matrix[M3x3.M10] + this.matrix[M3x3.M11] * m.matrix[M3x3.M11] + this.matrix[M3x3.M21] * m.matrix[M3x3.M12], + this.matrix[M3x3.M02] * m.matrix[M3x3.M10] + this.matrix[M3x3.M12] * m.matrix[M3x3.M11] + this.matrix[M3x3.M22] * m.matrix[M3x3.M12], + + this.matrix[M3x3.M00] * m.matrix[M3x3.M20] + this.matrix[M3x3.M10] * m.matrix[M3x3.M21] + this.matrix[M3x3.M20] * m.matrix[M3x3.M22], + this.matrix[M3x3.M01] * m.matrix[M3x3.M20] + this.matrix[M3x3.M11] * m.matrix[M3x3.M21] + this.matrix[M3x3.M21] * m.matrix[M3x3.M22], + this.matrix[M3x3.M02] * m.matrix[M3x3.M20] + this.matrix[M3x3.M12] * m.matrix[M3x3.M21] + this.matrix[M3x3.M22] * m.matrix[M3x3.M22] + ]; + return output; + } + + transition(x, y) + { + var output = new M3x3(); + output.matrix = + [ + this.matrix[M3x3.M00], + this.matrix[M3x3.M01], + this.matrix[M3x3.M02], + + this.matrix[M3x3.M10], + this.matrix[M3x3.M11], + this.matrix[M3x3.M12], + + x * this.matrix[M3x3.M00] + y * this.matrix[M3x3.M10] + this.matrix[M3x3.M20], + x * this.matrix[M3x3.M01] + y * this.matrix[M3x3.M11] + this.matrix[M3x3.M21], + x * this.matrix[M3x3.M02] + y * this.matrix[M3x3.M12] + this.matrix[M3x3.M22] + ]; + return output; + } + + scale(x, y) + { + var output = new M3x3(); + output.matrix = + [ + this.matrix[M3x3.M00] * x, + this.matrix[M3x3.M01] * x, + this.matrix[M3x3.M02] * x, + + this.matrix[M3x3.M10] * y, + this.matrix[M3x3.M11] * y, + this.matrix[M3x3.M12] * y, + + this.matrix[M3x3.M20], + this.matrix[M3x3.M21], + this.matrix[M3x3.M22] + ]; + return output; + } + getFloatArray() + { + return new Float32Array(this.matrix); + } +} + +M3x3.M00 = 0; +M3x3.M01 = 1; +M3x3.M02 = 2; +M3x3.M10 = 3; +M3x3.M11 = 4; +M3x3.M12 = 5; +M3x3.M20 = 6; +M3x3.M21 = 7; +M3x3.M22 = 8; diff --git a/art/oragami_dash.gal b/art/oragami_dash.gal new file mode 100644 index 0000000..4765790 Binary files /dev/null and b/art/oragami_dash.gal differ diff --git a/art/oragami_fold.gal b/art/oragami_fold.gal new file mode 100644 index 0000000..7a87425 Binary files /dev/null and b/art/oragami_fold.gal differ diff --git a/art/oragami_idle.gal b/art/oragami_idle.gal new file mode 100644 index 0000000..bcc6e43 Binary files /dev/null and b/art/oragami_idle.gal differ diff --git a/art/oragami_move.gal b/art/oragami_move.gal new file mode 100644 index 0000000..e8487a8 Binary files /dev/null and b/art/oragami_move.gal differ diff --git a/art/oragami_run_attack.gal b/art/oragami_run_attack.gal new file mode 100644 index 0000000..587dc16 Binary files /dev/null and b/art/oragami_run_attack.gal differ diff --git a/art/paper_airplane.gal b/art/paper_airplane.gal new file mode 100644 index 0000000..9412089 Binary files /dev/null and b/art/paper_airplane.gal differ diff --git a/art/pngs/Blocks_01.png b/art/pngs/Blocks_01.png new file mode 100644 index 0000000..85dd169 Binary files /dev/null and b/art/pngs/Blocks_01.png differ diff --git a/art/pngs/Grass.png b/art/pngs/Grass.png new file mode 100644 index 0000000..f797f51 Binary files /dev/null and b/art/pngs/Grass.png differ diff --git a/art/pngs/grass_2.png b/art/pngs/grass_2.png new file mode 100644 index 0000000..4392970 Binary files /dev/null and b/art/pngs/grass_2.png differ diff --git a/art/pngs/hills.png b/art/pngs/hills.png new file mode 100644 index 0000000..1c7c3b2 Binary files /dev/null and b/art/pngs/hills.png differ diff --git a/art/pngs/level_01.png b/art/pngs/level_01.png new file mode 100644 index 0000000..8706ef1 Binary files /dev/null and b/art/pngs/level_01.png differ diff --git a/art/pngs/long_grass.png b/art/pngs/long_grass.png new file mode 100644 index 0000000..3679bfb Binary files /dev/null and b/art/pngs/long_grass.png differ diff --git a/art/pngs/long_hills.png b/art/pngs/long_hills.png new file mode 100644 index 0000000..33edcad Binary files /dev/null and b/art/pngs/long_hills.png differ diff --git a/art/pngs/long_mountains.png b/art/pngs/long_mountains.png new file mode 100644 index 0000000..b9f75de Binary files /dev/null and b/art/pngs/long_mountains.png differ diff --git a/art/pngs/mountains.png b/art/pngs/mountains.png new file mode 100644 index 0000000..d97ce44 Binary files /dev/null and b/art/pngs/mountains.png differ diff --git a/art/pngs/paper_airplane.png b/art/pngs/paper_airplane.png new file mode 100644 index 0000000..328b5bc Binary files /dev/null and b/art/pngs/paper_airplane.png differ diff --git a/art/pngs/paper_dash.png b/art/pngs/paper_dash.png new file mode 100644 index 0000000..f38a5f7 Binary files /dev/null and b/art/pngs/paper_dash.png differ diff --git a/art/pngs/paper_idle.png b/art/pngs/paper_idle.png new file mode 100644 index 0000000..e73a71f Binary files /dev/null and b/art/pngs/paper_idle.png differ diff --git a/art/pngs/paper_move.png b/art/pngs/paper_move.png new file mode 100644 index 0000000..bfca551 Binary files /dev/null and b/art/pngs/paper_move.png differ diff --git a/art/pngs/platforms16x16.png b/art/pngs/platforms16x16.png new file mode 100644 index 0000000..33bb413 Binary files /dev/null and b/art/pngs/platforms16x16.png differ diff --git a/art/pngs/platforms16x16_2.png b/art/pngs/platforms16x16_2.png new file mode 100644 index 0000000..4c405c9 Binary files /dev/null and b/art/pngs/platforms16x16_2.png differ diff --git a/art/pngs/platforms16x16_3.png b/art/pngs/platforms16x16_3.png new file mode 100644 index 0000000..9e71aa3 Binary files /dev/null and b/art/pngs/platforms16x16_3.png differ diff --git a/art/pngs/platforms16x16_4.png b/art/pngs/platforms16x16_4.png new file mode 100644 index 0000000..ea4a668 Binary files /dev/null and b/art/pngs/platforms16x16_4.png differ diff --git a/art/pngs/rock_attack.png b/art/pngs/rock_attack.png new file mode 100644 index 0000000..805da9c Binary files /dev/null and b/art/pngs/rock_attack.png differ diff --git a/art/pngs/rock_idle.png b/art/pngs/rock_idle.png new file mode 100644 index 0000000..f419789 Binary files /dev/null and b/art/pngs/rock_idle.png differ diff --git a/art/pngs/rock_move.png b/art/pngs/rock_move.png new file mode 100644 index 0000000..a9fc14b Binary files /dev/null and b/art/pngs/rock_move.png differ diff --git a/art/pngs/rock_shield.png b/art/pngs/rock_shield.png new file mode 100644 index 0000000..f53dcc1 Binary files /dev/null and b/art/pngs/rock_shield.png differ diff --git a/art/pngs/sky.png b/art/pngs/sky.png new file mode 100644 index 0000000..0cb49d2 Binary files /dev/null and b/art/pngs/sky.png differ diff --git a/art/rock_attack.gal b/art/rock_attack.gal new file mode 100644 index 0000000..f51831c Binary files /dev/null and b/art/rock_attack.gal differ diff --git a/art/rock_move.gal b/art/rock_move.gal new file mode 100644 index 0000000..32b8092 Binary files /dev/null and b/art/rock_move.gal differ