Skip to content
This repository was archived by the owner on Mar 31, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added GameEngine2D/img/Blocks_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/hills.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/level_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/mountains.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/paper_airplane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/paper_idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/paper_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/paper_special.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/platforms16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/platforms16x16_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/platforms16x16_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/platforms16x16_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/rock_attack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/rock_idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/rock_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/rock_special.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/scissor_idle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/scissor_move.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/scissor_special.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/skellyattack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/skellydeath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/skellyhit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/skellyidle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/skellyreact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added GameEngine2D/img/skellywalk.png
Binary file added GameEngine2D/img/sky.png
67 changes: 67 additions & 0 deletions GameEngine2D/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<!-- http-server -a localhost -p 8000 -c-1 -->
<html>
<head>
<title> 2D Game Engine Test </title>
<script src="js/game.js"></script>
<script src="js/material.js"></script>
<script src="js/math.js"></script>
<script src="js/entity.js"></script>
<style>
* {margin:0 ; padding:0;}
body {overflow:hidden}
canvas{background:black;}
</style>

<script>
window.addEventListener("load", function()
{
window.game = new Game();

window.game.resize(window.innerWidth, window.innerHeight);

loop();
});

window.addEventListener("resize", function()
{
window.game.resize(window.innerWidth, window.innerHeight);
});

window.addEventListener('keydown', function(event) { Key.onKeydown(event); }, false);
window.addEventListener('keyup', function(event) {
Key.onKeyup(event);
}, false);
window.addEventListener('keyup', function(event) { Key.isUp(event); }, false);
</script>

<script type="vertext_shader" id="vs_01">
attribute vec2 a_position;
attribute vec2 a_texCoord;

uniform mat3 u_world;
uniform mat3 u_object;
uniform vec2 u_frame;

varying vec2 v_texCoord;
void main()
{
gl_Position = vec4( u_world * u_object * vec3(a_position, 1), 1); // order matters!
v_texCoord = a_texCoord + u_frame;
}
</script>

<script type="fragment_shader" id="fs_01">
precision mediump float;
uniform sampler2D u_image;
varying vec2 v_texCoord;

void main()
{
gl_FragColor = texture2D(u_image, v_texCoord);
}
</script>
</head>
<body>
</body>
</html>
304 changes: 304 additions & 0 deletions GameEngine2D/js/entity.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading