programming guidelines
This commit is contained in:
parent
bd38da663d
commit
7328107b11
5
docs/assets/js/constants.js
Normal file
5
docs/assets/js/constants.js
Normal file
@ -0,0 +1,5 @@
|
||||
var constants = {
|
||||
testOrganizer: {
|
||||
EXAMPLE_DELETE_ME_LATER : 1277336
|
||||
}
|
||||
};
|
@ -1,4 +1,3 @@
|
||||
|
||||
// Handle starting the pre-load animation
|
||||
var page_preloader = new Preloader();
|
||||
page_preloader.show(true);
|
||||
@ -11,8 +10,38 @@ audio = [
|
||||
""
|
||||
];
|
||||
|
||||
function update() {
|
||||
var globalStates = {
|
||||
titleScreen:0,
|
||||
starting:1,
|
||||
playing:2,
|
||||
paused:3,
|
||||
end:4
|
||||
};
|
||||
var globalState = globalStates.titleScreen;
|
||||
|
||||
function update() {
|
||||
switch(globalState) {
|
||||
// title screen
|
||||
case globalStates.titleScreen:
|
||||
|
||||
break;
|
||||
// starting
|
||||
case globalStates.starting:
|
||||
|
||||
break;
|
||||
// playing
|
||||
case globalStates.playing:
|
||||
|
||||
break;
|
||||
// paused
|
||||
case globalStates.paused:
|
||||
|
||||
break;
|
||||
// end
|
||||
case globalStates.end:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function input() {
|
||||
|
41
docs/assets/js/utils.js
Normal file
41
docs/assets/js/utils.js
Normal file
@ -0,0 +1,41 @@
|
||||
// clamps a value between min and max
|
||||
function clamp(value, min, max) {
|
||||
return Math.min(max, Math.max(min, value));
|
||||
}
|
||||
|
||||
// linear interpolation towards somewhere
|
||||
function lerp(start, end, amt) { return (1 - amt) * start + amt * end; }
|
||||
|
||||
// returns a new value with friction applied
|
||||
function friction(value, amount) {
|
||||
if (value > 0) { value -= amount; }
|
||||
if (value < 0) { value += amount; }
|
||||
if (Math.abs(value) < amount * 2) { value = 0; }
|
||||
return value;
|
||||
}
|
||||
|
||||
var tau = Math.PI * 2;
|
||||
var pi = Math.PI;
|
||||
// returns a new angle that gets closer to the target angle
|
||||
function turn(cur, target, speed) {
|
||||
if (target < 0) { target = tau + target; }
|
||||
if ((cur % tau) > target) {
|
||||
if ((cur % tau) - target > pi) {
|
||||
cur += speed;
|
||||
} else {
|
||||
cur -= speed;
|
||||
}
|
||||
} else {
|
||||
if (target - (cur % tau) > pi) {
|
||||
cur -= speed;
|
||||
} else {
|
||||
cur += speed;
|
||||
}
|
||||
}
|
||||
if (Math.abs(cur - target) < speed * 1.1) {
|
||||
cur = target;
|
||||
}
|
||||
if (cur > tau) { cur = cur - tau; }
|
||||
if (cur < 0) { cur = tau + cur; }
|
||||
return cur;
|
||||
}
|
@ -21,6 +21,8 @@
|
||||
<body>
|
||||
<canvas width="1000" height="800" id="game"></canvas>
|
||||
<script src="assets/js/game.js"></script>
|
||||
<script src="assets/js/constants.js"></script>
|
||||
<script src="assets/js/utils.js"></script>
|
||||
<script src="assets/js/preloader/preloader.js"></script>
|
||||
<script src="assets/js/index.js"></script>
|
||||
</body>
|
||||
|
17
programmingGuide.md
Normal file
17
programmingGuide.md
Normal file
@ -0,0 +1,17 @@
|
||||
# guide for how we should program
|
||||
|
||||
## states
|
||||
|
||||
every separate of the game (title, transition, paused, etc.) should have a separate spot in a main switch statement, and have a separate folder where all code relating to that state should be
|
||||
|
||||
## magic numbers
|
||||
|
||||
no magic numbers, numbers that potentially might need to be changed should be a constant in constants.js
|
||||
|
||||
## comments
|
||||
|
||||
I don't care how you comment, just make sure we can all understand your code
|
||||
|
||||
## source control
|
||||
|
||||
Work on your own branch, which should be named what you are working on. Master should always be working
|
Reference in New Issue
Block a user