Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNAKE IT BACK: Earn your immortality! #95

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# snake-it-back

![](img/image-big.jpg)

This is a Web game that I'm going to join [js13kgames 2019](https://js13kgames.com) with.

This year's theme is *back*. So I am making a Snake game that the dead snakes will come back to life again and become new obstacles for you.

You are welcomed to [play](http://zhangwenli.com/snake-it-back) and [give advice in issues](https://github.com/Ovilia/snake-it-back/issues)!

Binary file added img/image-big.jpg
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 img/image-thumbnail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><head><style>body{text-align:center;background-color:#504a4b}canvas{width:600px;height:420px;position:relative;margin:20px 0}#score-panel{visibility:hidden;font-size:18px;margin-top:10px;color:#d1c4af}#count-down{position:absolute;left:0;right:0;top:180px;height:80px;font-size:120px;z-index:100;text-align:center;color:#585356}#main{background:#d1c4af}#start{display:none;position:absolute;top:400px;left:50%;transform:translate(-50%, -50%);background:#585356;color:#d1c4af;font-weight:700;font-size:22px;cursor:pointer;padding:5px 10px;border-radius:8px}#about, #about a{color:#d1c4af}#m{position:fixed;top:10px;right:10px;color:#d1c4af}</style><meta name="monetization" content="$pay.stronghold.co/1a1bffc0951b4954fcf8d7d0710ce9b956b"></head><body><div id="info"><div id="score-panel"> Score: <span id="score">0</span>, HP: <span id="heart">3</span></div></div><div id="count-down"></div> <canvas id="main"></canvas><div id="start">START</div><div id="about">SNAKE IT BACK: The died snakes become new obstacles. Earn your immortality. <a href="https://github.com/Ovilia/snake-it-back" target="_blank">GitHub</a></div><a href="javascript:m()" id="m">Mute</a> <script src="minified.js"></script> </body></html>
16 changes: 8 additions & 8 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "Title of the game",
"description": "Description of the game, including controls and optional extras for Coil subscribers if you participate in the Web Monetization category.",
"name": "SNAKE IT BACK",
"description": "The died snakes become new obstacles. Earn your immortality.",
"images" : {
"image_large": "image-big.jpg",
"image_thumbnail": "image-small.jpg"
"image_large": "img/image-big.jpg",
"image_thumbnail": "img/image-thumbnail.jpg"
},
"categories": ["Desktop", "Mobile", "Server", "Web Monetization", "WebXR"],
"categories": ["Desktop", "WebXR"],
"user" : {
"name": "optional",
"website": "optional",
"twitter": "optional"
"name": "Ovilia",
"website": "http://zhangwenli.com",
"twitter": "OviliaZhang"
}
}
1 change: 1 addition & 0 deletions minified.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added snake-it-back.zip
Binary file not shown.
62 changes: 62 additions & 0 deletions src/audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
function Audio() {
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();

this.notePlayHandlers = [];
}

Audio.prototype.playNote = function (noteName, noteOnTime, sustain, callback) {
var oscillator = this.audioCtx.createOscillator();

oscillator.type = 'square';
var frequency = getHerzFromNoteName(noteName);
oscillator.frequency.setValueAtTime(frequency, this.audioCtx.currentTime);
oscillator.connect(this.audioCtx.destination);

var handler = setTimeout(function () {
oscillator.start();

setTimeout(function () {
oscillator.stop();

if (typeof callback === 'function') {
callback();
}
}, sustain * 1000);
}, noteOnTime * 1000);
this.notePlayHandlers.push(handler);
};

/**
* broken chord
*/
Audio.prototype.playChord = function (chordName, noteOnTime, sustain, callback) {
var noteSustain = sustain / 4;
var notes = getNotesFromChord(chordName);
this.playNote(notes[0], noteOnTime, noteSustain);
this.playNote(notes[2], noteOnTime + noteSustain, noteSustain);
this.playNote(notes[1], noteOnTime + noteSustain * 2, noteSustain);
this.playNote(notes[2], noteOnTime + noteSustain * 3, noteSustain, callback);
};

function getHerzFromNoteName(noteName) {
// http://pages.mtu.edu/~suits/notefreqs.html
return {
b4: 493.88,
c4: 261.63,
d4: 293.66,
e4: 329.63,
f4: 349.23,
g4: 392.00,
a4: 440.00,
x: 1000,
y: 800
}[noteName];
}

function getNotesFromChord(chordName) {
return {
c: ['c4', 'e4', 'g4'],
f: ['c4', 'f4', 'a4'],
g: ['b4', 'd4', 'g4']
}[chordName];
}
90 changes: 90 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<html>
<head>
<style>
body {
text-align: center;
background-color: #504a4b;
}

canvas {
width: 600px;
height: 420px;
position: relative;
margin: 20px 0;
}

#score-panel {
visibility: hidden;
font-size: 18px;
margin-top: 10px;
color: #d1c4af;
}

#count-down {
position: absolute;
left: 0;
right: 0;
top: 180px;
height: 80px;
font-size: 120px;
z-index: 100;
text-align: center;
color: #585356;
}

#main {
background: #d1c4af;
}

#start {
display: none;
position: absolute;
top: 400px;
left: 50%;
transform: translate(-50%, -50%);
background: #585356;
color: #d1c4af;
font-weight: 700;
font-size: 22px;
cursor: pointer;
padding: 5px 10px;
border-radius: 8px;
}

#about, #about a {
color: #d1c4af;
}

#m {
position: fixed;
top: 10px;
right: 10px;
color: #d1c4af;
}
</style>

<meta name="monetization" content="$pay.stronghold.co/1a1bffc0951b4954fcf8d7d0710ce9b956b">
</head>

<body>
<div id="info">
<div id="score-panel">
Score: <span id="score">0</span>,
HP: <span id="heart">3</span>
</div>
</div>
<div id="count-down"></div>
<canvas id="main"></canvas>
<div id="start">START</div>

<div id="about">SNAKE IT BACK: The died snakes become new obstacles. Earn your immortality. <a href="https://github.com/Ovilia/snake-it-back" target="_blank">GitHub</a></div>

<a href="javascript:m()" id="m">Mute</a>

<script src="util.js"></script>
<script src="snake.js"></script>
<script src="ui.js"></script>
<script src="audio.js"></script>
<script src="index.js"></script>
</body>
</html>
Loading