Skip to content

Commit

Permalink
cyclin
Browse files Browse the repository at this point in the history
  • Loading branch information
SpazElectro committed Mar 25, 2024
1 parent 95aa1a6 commit 44db062
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 1 deletion.
1 change: 0 additions & 1 deletion .vscode/plus.code-snippets.disable

This file was deleted.

156 changes: 156 additions & 0 deletions levels/cycling/STVcycling.j2as
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#pragma require "STVutil.asc"

#include "STVutil.asc"

#pragma region perlin noise
class PerlinNoise
{
array<int> p(256);

PerlinNoise()
{
for (int i = 0; i < 256; i++)
{
p[i] = i;
}

for (int i = 0; i < 256; i++)
{
int j = gameRNG() & 255;
int temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}

float lerp(float a, float b, float t)
{
return a + t * (b - a);
}

float fade(float t)
{
return t * t * t * (t * (t * 6 - 15) + 10);
}

float noise(float x)
{
// return 1;
int X = int(x) & 255;
x -= int(x);
float u = fade(x);

int A = p[X];
int B = p[X + 1];
return lerp(A, B, u) / 255.0f;
}
};
#pragma endregion

// drawing
int screenWidth = 640;
int screenHeight = 480;

jjPIXELMAP@ gamePixelMap = jjPIXELMAP(screenWidth, screenHeight);
jjPAL gamePalette = jjPAL();

// logic
jjRNG gameRNG = jjRNG();
PerlinNoise@ gamePerlin = PerlinNoise();

int playerX = 0;

void onLevelLoad() {
jjConsole("Started!");

// grass
gamePalette.color[1] = jjPALCOLOR(0, 255, 0); // green
gamePalette.color[2] = jjPALCOLOR(50, 205, 50); // dark green

// road
gamePalette.color[3] = jjPALCOLOR(255, 0, 0); // red
gamePalette.color[4] = jjPALCOLOR(255, 255, 255); // white

// sky
gamePalette.color[5] = jjPALCOLOR(176, 224, 230); // powder blue
gamePalette.color[6] = jjPALCOLOR(73, 216, 230); // light blue

// ground
gamePalette.color[7] = jjPALCOLOR(127, 127, 127); // gray

array<uint8> indexMapping;
indexMapping.insertLast(0);
indexMapping.insertLast(1);
indexMapping.insertLast(2);
indexMapping.insertLast(3);
indexMapping.insertLast(4);
indexMapping.insertLast(5);
indexMapping.insertLast(6);

jjSpriteModeSetMapping(1, indexMapping, gamePalette);
jjConsole("INIT: Mappings");
}

int quarterScreenHeight = screenHeight/8;

void setTerrainPoint(int pos, int height, int color = -1) {
// 1 == bright, 2 == dark
// jjConsole("Setting pos: " + pos + " height: " + height);
// }
// if(playerX >= 10800) {
// jjSpy("" + playerX);
// return;
// }

for (int y = screenHeight - 1; y >= height; y--)
gamePixelMap[pos, y] = (color == -1 ? ((y >= height + quarterScreenHeight) ? 2 : 1) : color);
}


const float frequency = 0.001;
const float amplitude = 100;
const int terrainOffset = screenWidth/2;

int difference = 2;
int timeDifference = 4;

void onMain() {
if(jjGameTicks % timeDifference == 0) {
// Clear! this crashes the game with an access violation after a few seconds
// if only we could delete gamePixelMap;
@gamePixelMap = jjPIXELMAP(screenWidth, screenHeight);

for (int x = 0; x < screenWidth; x += difference) {
for(int i = 0; i < difference; i++) {
setTerrainPoint(x + i, int(
terrainOffset - (
amplitude * gamePerlin.noise(
(x + i + playerX) * frequency
)
)
));
}
}
}

playerX += timeDifference*4;
}

bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ screen) {
gamePixelMap.save(jjAnimFrames[jjAnimations[jjAnimSets[ANIM::CUSTOM[0]].firstAnim].firstFrame]);

screen.drawRectangle(0, 0, jjResolutionWidth, jjResolutionHeight, 0);
screen.drawSprite(0, 0, ANIM::CUSTOM[0], 0, 0, /* direction */ 0, SPRITE::MAPPING, 1);
screen.drawString(10, 30, "screenWidth: " + screenWidth + " - screenHeight: " + screenHeight);
screen.drawString(10, 45, "frequency: " + frequency + " - amplitude: " + amplitude + " - terrainOffset: " + terrainOffset);
screen.drawString(10, 60, "difference: " + difference + " - timeDifference: " + timeDifference);
screen.drawString(10, 75, "playerX: " + playerX);

return true;
}

bool onDrawHealth(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
bool onDrawLives(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
bool onDrawPlayerTimer(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
bool onDrawScore(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
bool onDrawGameModeHUD(jjPLAYER@ player, jjCANVAS@ canvas) { return true; }
Binary file added levels/cycling/STVcycling.j2l
Binary file not shown.
41 changes: 41 additions & 0 deletions levels/cycling/run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@echo off

REM Read variables from run.ini
for /f "tokens=1* delims==" %%a in ('type "..\..\run.ini" ^| find "="') do (
if /i "%%a"=="GAME_DIRECTORY" set "GAME_DIRECTORY=%%b"
if /i "%%a"=="GAME_NAME" set "GAME_NAME=%%b"
)

echo Copying files...
copy "../../scripts/" "%GAME_DIRECTORY%" /y

for %%i in (*.j2l *.j2t) do (
copy "%%i" "%GAME_DIRECTORY%" /y
)
for %%i in (./assets/*.*) do (
copy ".\assets\%%i" "%GAME_DIRECTORY%\STVcycling.j2as_%%i" /y
)
for %%i in (*.j2as *.mut *.asc) do (
python ../../experiments/angelscriptpp/angelscriptpp.py "%%i" "%GAME_DIRECTORY%\%%i"
)

set "J2L_LEVEL="
set "MUTATOR="

echo Starting
for %%i in (*.j2l) do (
set "J2L_LEVEL=%%i"
goto :check_mutator
)

:check_mutator
for %%i in (*.mut) do (
set "MUTATOR=-mutators=%%i"
goto :start_game
)

:start_game
if not defined J2L_LEVEL set "J2L_LEVEL=battle1"
"%GAME_DIRECTORY%%GAME_NAME%" -server %MUTATOR% %J2L_LEVEL%
@echo on

0 comments on commit 44db062

Please sign in to comment.