-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gabuino flappy bird, melody player, init_array fix
- Loading branch information
Showing
11 changed files
with
634 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Play flappy bird in browser, press F1 on LA104 to jump | ||
// Based on Tiny flappy bird by Daniel Bark: | ||
// https://github.com/danba340/tiny-flappy-bird | ||
|
||
#include <library.h> | ||
|
||
int main(void) | ||
{ | ||
BIOS::DBG::Print(R"(<canvas id="c" width="400" height="400" style="background:gray"></canvas>)"); | ||
|
||
BIOS::DBG::Print(R"(<script> | ||
context = document.getElementById("c").getContext("2d"); | ||
bird = new Image(); | ||
bird.src = "https://raw.githubusercontent.com/danba340/tiny-flappy-bird/master/bird.png"; | ||
birdX = birdDY = score = bestScore = 0; | ||
interval = birdSize = pipeWidth = topPipeBottomY = 24; | ||
birdY = pipeGap = 200; | ||
canvasSize = pipeX = 400; | ||
c.onclick = () => (birdDY = 9); | ||
setInterval(() => { | ||
context.fillStyle = "skyblue"; | ||
context.fillRect(0,0,canvasSize,canvasSize); // Draw sky | ||
birdY -= birdDY -= 0.5; // Gravity | ||
context.drawImage(bird, birdX, birdY, birdSize * (524/374), birdSize); // Draw bird | ||
context.fillStyle = "green"; | ||
pipeX -= 8; // Move pipe | ||
pipeX < -pipeWidth && // Pipe off screen? | ||
((pipeX = canvasSize), (topPipeBottomY = pipeGap * Math.random())); // Reset pipe and randomize gap. | ||
context.fillRect(pipeX, 0, pipeWidth, topPipeBottomY); // Draw top pipe | ||
context.fillRect(pipeX, topPipeBottomY + pipeGap, pipeWidth, canvasSize); // Draw bottom pipe | ||
context.fillStyle = "black"; | ||
context.fillText(score++, 9, 25); // Increase and draw score | ||
bestScore = bestScore < score ? score : bestScore; // New best score? | ||
context.fillText('Best: '+bestScore, 9, 50); // Draw best score | ||
(((birdY < topPipeBottomY || birdY > topPipeBottomY + pipeGap) && pipeX < birdSize * (524/374))// Bird hit pipe? | ||
|| birdY > canvasSize) && // Bird falls off screen | ||
((birdDY = 0), (birdY = 200), (pipeX = canvasSize), (score = 0)); // Bird died | ||
}, interval) | ||
</script>)"); | ||
|
||
BIOS::KEY::EKey key; | ||
while ((key = BIOS::KEY::GetKey()) != BIOS::KEY::EKey::Escape) | ||
{ | ||
if (key == BIOS::KEY::EKey::Enter) | ||
BIOS::DBG::Print(R"(<script>birdDY=9</script>)"); | ||
} | ||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// plays Axel F on internal piezo speaker of LA104 | ||
#include <library.h> | ||
#include <math.h> | ||
|
||
void WriteTim8(int reg, uint16_t val) | ||
{ | ||
*((uint16_t*)(0x40013400 + reg)) = val; | ||
} | ||
|
||
void SoundOn() | ||
{ | ||
WriteTim8(0x20, 0x3000); | ||
WriteTim8(0x00, 0x0081); | ||
WriteTim8(0x40, 150); // volume | ||
} | ||
|
||
void SoundOff() | ||
{ | ||
WriteTim8(0x20, 0x0000); | ||
WriteTim8(0x00, 0x0080); | ||
} | ||
|
||
void Sound(int f) | ||
{ | ||
WriteTim8(0x24, 0); | ||
WriteTim8(0x28, 15-1); | ||
int div = 72e6/15/f; | ||
WriteTim8(0x2c, div-1); | ||
//BIOS::DBG::Print("f=%d, div=%d, ", f, div); | ||
SoundOn(); | ||
} | ||
|
||
int C=0, Cis=1, D=2, Dis=3, E=4, F=5, Fis=6, G=7, Gis=8, A=9, Ais=10, B=11, None=12; | ||
const int BPM = 120; | ||
|
||
const int Beat = 60000 / BPM; | ||
int Whole = Beat*4; | ||
int Half = Whole/2; | ||
int Quarter = Whole/4; | ||
int Eigth = Whole/8; | ||
int Sixteenth = Whole/16; | ||
int Thirtysecond = Whole/32; | ||
int WholeDot = Whole*1.5; | ||
int HalfDot = Half*1.5; | ||
int QuarterDot = Quarter*1.5; | ||
int EigthDot = Eigth*1.5; | ||
int SixteenthDot = Sixteenth*1.5; | ||
int ThirtysecondDot = Thirtysecond*1.5; | ||
|
||
int Frequency(int note, int octave) | ||
{ | ||
const int table[] = {4186, 4434, 4698, 4978, 5274, 5587, 5915, 6271, 6644, 7040, 7458, 7902}; | ||
return table[note] >> (4-octave); | ||
} | ||
|
||
void Play(int note, int octave, int length) | ||
{ | ||
if (note != None) | ||
Sound(Frequency(note, octave)); | ||
|
||
//BIOS::DBG::Print("len=%d, ", length); | ||
BIOS::SYS::DelayMs(length); | ||
SoundOff(); | ||
BIOS::SYS::DelayMs(10); | ||
} | ||
|
||
int main() | ||
{ | ||
// generated from http://x.valky.eu/klavirgen | ||
Play(G, 2, Quarter); | ||
Play(Ais, 2, EigthDot); | ||
Play(G, 2, Sixteenth); | ||
Play(None, 0, Sixteenth); | ||
Play(G, 2, Sixteenth); | ||
Play(C, 3, Eigth); | ||
Play(G, 2, Eigth); | ||
Play(F, 2, Eigth); | ||
Play(G, 2, Quarter); | ||
Play(D, 3, EigthDot); | ||
Play(G, 2, Sixteenth); | ||
Play(None, 0, Sixteenth); | ||
Play(G, 2, Sixteenth); | ||
Play(Dis, 3, Eigth); | ||
Play(D, 3, Eigth); | ||
Play(Ais, 2, Eigth); | ||
Play(G, 2, Eigth); | ||
Play(D, 3, Eigth); | ||
Play(G, 3, Eigth); | ||
Play(G, 2, Sixteenth); | ||
Play(F, 2, Sixteenth); | ||
Play(None, 0, Sixteenth); | ||
Play(F, 2, Sixteenth); | ||
Play(D, 2, Eigth); | ||
Play(A, 2, Eigth); | ||
Play(G, 2, Half); | ||
|
||
return 0; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.