diff --git a/playdate/.gitignore b/playdate/.gitignore new file mode 100644 index 0000000..303953b --- /dev/null +++ b/playdate/.gitignore @@ -0,0 +1,6 @@ +matrix_c/build/* +matrix_c/build-device/* + +*.pdx +pdex.dylib +pdex.bin diff --git a/playdate/matrix_c/Source/images/matrix-glyphs.png b/playdate/matrix_c/Source/images/matrix-glyphs.png index b328c08..99abdf8 100644 Binary files a/playdate/matrix_c/Source/images/matrix-glyphs.png and b/playdate/matrix_c/Source/images/matrix-glyphs.png differ diff --git a/playdate/matrix_c/main.c b/playdate/matrix_c/main.c index ebb11f8..1bce789 100644 --- a/playdate/matrix_c/main.c +++ b/playdate/matrix_c/main.c @@ -6,7 +6,6 @@ // Read the LICENSE file if you want to // -// #include #include #include @@ -29,7 +28,9 @@ static int numColumns; static int numRows; static int numCells; -static const int numGlyphs = 133; +static const int numStandardGlyphs = 133; +static const int numPDGlyphs = 10; +static const int numTotalGlyphs = numStandardGlyphs + numPDGlyphs; static const int numFades = 32; static const float minSpeed = 0.15; @@ -75,19 +76,12 @@ static void init() int fadeGradientWidth; pd->graphics->getBitmapData(fadeGradient, &fadeGradientWidth, NULL, NULL, NULL, NULL); - - LCDBitmap *fadeGradientTransparent = pd->graphics->loadBitmap("images/fade-gradient-transparent", NULL); - int wrongWidth; - pd->graphics->getBitmapData(fadeGradientTransparent, &wrongWidth, NULL, NULL, NULL, NULL); - pd->system->logToConsole("%i should be 512", wrongWidth); - - - glyphs = pd->system->realloc(NULL, sizeof(LCDBitmap *) * numGlyphs * numFades); + glyphs = pd->system->realloc(NULL, sizeof(LCDBitmap *) * numTotalGlyphs * numFades); LCDBitmap *glyph = pd->graphics->newBitmap(glyphWidth, glyphWidth, kColorBlack); pd->graphics->pushContext(glyph); - for (int i = 0; i < numGlyphs; i++) { + for (int i = 0; i < numTotalGlyphs; i++) { int column = i % spritesheetColumns; int row = i / spritesheetColumns; pd->graphics->drawBitmap(glyphSpritesheet, -column * glyphWidth, -row * glyphWidth, kBitmapUnflipped); @@ -121,7 +115,7 @@ static void init() cell->glyphCycle = randf(); cell->columnTimeOffset = columnTimeOffset; cell->columnSpeedOffset = columnSpeedOffset; - cell->glyphIndex = rand() % numGlyphs; + cell->glyphIndex = rand() % numStandardGlyphs; cell->fadeIndex = -1; } } @@ -148,6 +142,10 @@ static int update(void* ud) pd->system->resetElapsedTime(); time += delta; + PDButtons currentButtons; + pd->system->getButtonState(¤tButtons, NULL, NULL); + int addPDGlyphs = currentButtons & kButtonA && currentButtons & kButtonB; + for (int i = 0; i < numCells; i++) { int mustDraw = 0; Cell *cell = &cells[i]; @@ -171,13 +169,18 @@ static int update(void* ud) cell->glyphCycle = cell->glyphCycle + delta * 2; if (cell->glyphCycle > 1) { cell->glyphCycle = fmod(cell->glyphCycle, 1); - int glyphIndex = (cell->glyphIndex + (rand() % 20)) % numGlyphs; - if (cell->glyphIndex != glyphIndex) { - cell->glyphIndex = glyphIndex; - if (fadeIndex < numFades - 1) { - mustDraw = 1; + int lastGlyphIndex = cell->glyphIndex; + while (cell->glyphIndex == lastGlyphIndex) { + cell->glyphIndex = rand(); + if (addPDGlyphs && rand() % 4 == 0) { + cell->glyphIndex = numStandardGlyphs + cell->glyphIndex % numPDGlyphs; + } else { + cell->glyphIndex = cell->glyphIndex % numStandardGlyphs; } } + if (fadeIndex < numFades - 1) { + mustDraw = 1; + } } if (mustDraw) { diff --git a/playdate/matrix_lua/images/fade-gradient.png b/playdate/matrix_lua/Source/images/fade-gradient.png similarity index 100% rename from playdate/matrix_lua/images/fade-gradient.png rename to playdate/matrix_lua/Source/images/fade-gradient.png diff --git a/playdate/matrix_lua/images/matrix-glyphs.png b/playdate/matrix_lua/Source/images/matrix-glyphs.png similarity index 65% rename from playdate/matrix_lua/images/matrix-glyphs.png rename to playdate/matrix_lua/Source/images/matrix-glyphs.png index b328c08..99abdf8 100644 Binary files a/playdate/matrix_lua/images/matrix-glyphs.png and b/playdate/matrix_lua/Source/images/matrix-glyphs.png differ diff --git a/playdate/matrix_lua/main.lua b/playdate/matrix_lua/Source/main.lua similarity index 82% rename from playdate/matrix_lua/main.lua rename to playdate/matrix_lua/Source/main.lua index 2a50e65..35e3005 100644 --- a/playdate/matrix_lua/main.lua +++ b/playdate/matrix_lua/Source/main.lua @@ -9,7 +9,9 @@ local numColumns = floor(screenWidth / glyphWidth) local numRows = floor(screenHeight / glyphWidth) local numCells = numColumns * numRows -local numGlyphs = 133 +local numStandardGlyphs = 133 +local numPDGlyphs = 10 +local numTotalGlyphs = numStandardGlyphs + numPDGlyphs local numFades = 32 local glyphs = {} @@ -20,7 +22,7 @@ do local glyph = gfx.image.new(glyphWidth, glyphWidth, gfx.kColorBlack) gfx.pushContext(glyph) - for i = 1, numGlyphs do + for i = 1, numTotalGlyphs do local column = (i - 1) % spritesheetColumns local row = floor((i - 1) / spritesheetColumns) glyphSpritesheet:draw(-column * glyphWidth, -row * glyphWidth) @@ -48,18 +50,6 @@ for i = 1,360 do sineTable[i] = math.sin(math.pi / 180 * i) end --- function fastSin(x) --- x = x / 360 % 1 --- local sign --- if x < 0.5 then --- sign = -1 --- else --- sign = 1 --- end --- x = (x % 0.5) * 2 - 0.5 --- return sign * x * x * 4 - 1 --- end - local wobbleA = math.sqrt(2) / 50 local wobbleB = math.sqrt(5) / 50 @@ -74,14 +64,14 @@ for x = 1, numColumns do cell.glyphCycle = random() cell.columnTimeOffset = columnTimeOffset cell.columnSpeedOffset = columnSpeedOffset - cell.glyphIndex = floor(random() * numGlyphs) + 1 + cell.glyphIndex = random(numStandardGlyphs) cell.fadeIndex = -1 cells[#cells + 1] = cell end end -playdate.display.setRefreshRate(0) +playdate.display.setRefreshRate(30) playdate.resetElapsedTime() function playdate.update() @@ -96,6 +86,8 @@ function playdate.update() playdate.resetElapsedTime() time += delta + local addPDGlyphs = playdate.buttonIsPressed(playdate.kButtonA) and playdate.buttonIsPressed(playdate.kButtonB) + for i = 1, numCells do local mustDraw = false local cell = cells[i] @@ -119,13 +111,17 @@ function playdate.update() cell.glyphCycle = cell.glyphCycle + delta * 2 if cell.glyphCycle > 1 then cell.glyphCycle = cell.glyphCycle % 1 - local glyphIndex = (cell.glyphIndex + random(20)) % numGlyphs + 1 - if cell.glyphIndex ~= glyphIndex then - cell.glyphIndex = glyphIndex - if fadeIndex < numFades then - mustDraw = true + local lastGlyphIndex = cell.glyphIndex + while cell.glyphIndex == lastGlyphIndex do + if addPDGlyphs and random(4) == 1 then + cell.glyphIndex = random(numPDGlyphs) + numStandardGlyphs + else + cell.glyphIndex = random(numStandardGlyphs) end end + if fadeIndex < numFades then + mustDraw = true + end end if mustDraw then diff --git a/playdate/matrix_lua/pdxinfo b/playdate/matrix_lua/Source/pdxinfo similarity index 72% rename from playdate/matrix_lua/pdxinfo rename to playdate/matrix_lua/Source/pdxinfo index c98e9cd..fe07014 100644 --- a/playdate/matrix_lua/pdxinfo +++ b/playdate/matrix_lua/Source/pdxinfo @@ -1,7 +1,7 @@ -name=The Playtrix +name=The Playtrix (Lua build) author=Rezmason description=A familiar animation of mysterious raining symbols. -bundleID=net.rezmason.theplaytrix +bundleID=net.rezmason.theplaytrix_lua version=1.0 buildNumber=1 imagePath=path/to/launcher/assets