Name | Author | Game Mode | Rating | |||||
---|---|---|---|---|---|---|---|---|
Miscellaneous stuff | Violet CLM | Multiple | N/A |
jjANIMATION@ GrassAnim;
array<array<uint>> GrassLengthsOfEachTile;
class Grass {
uint8 top = 0;
uint8 length = 0;
uint8 bounce = 0;
Grass(){}
}
array<array<Grass>> Grasses(jjLayerHeight[4], array<Grass>(jjLayerWidth[4]*32/4));
void onLevelLoad() {
const array<uint8> GrassColors = {174,174,162,140, 162,174,150,143, 150,174,140,142,
140,174,143,139,
143,162,142,139, 142,150,139,139, 139,140,139,139, 137,137,137,137, 145,145,145,145, 145,145,145,145, 149,149,149,149};
const uint MinimumGrassHeight = GrassColors.length / 4;
@GrassAnim = jjAnimations[jjAnimSets[ANIM::CUSTOM[0]].allocate(array<uint> = {32 + 5})];
for (uint i = MinimumGrassHeight; i < 32 + 5; ++i) {
jjPIXELMAP grass(4, i);
for (uint y = 0; y < i; ++y) {
const uint offset = (y < 3 ? y : y < i-7 ? 3 : y+MinimumGrassHeight-i) << 2;
for (uint x = 0; x < 4; ++x)
grass[x,y] = GrassColors[offset + x];
}
grass.save(jjAnimFrames[GrassAnim + i]);
}
const array<uint16> TilesToReplaceNaturalGrassIn = {70,71,72,73,74,75,76,77,78,79, 118, 120,121,122, 125,126,127, 130,131,132,133,134};
const jjPIXELMAP PlainWallTile(104);
for (uint i = 0; i < TilesToReplaceNaturalGrassIn.length; ++i) {
const auto tileID = TilesToReplaceNaturalGrassIn[i];
jjPIXELMAP newTile(tileID);
for (uint x4 = 0; x4 < 32; x4 += 4) {
int top = -1;
uint bottom = 32;
for (uint y = 0; y < bottom; ++y) {
if (top == -1) {
if (newTile[x4,y] == 174) //top left corner of grass
top = y;
}
if (top != -1) {
if (newTile[x4, y] == 139) {
bottom = y + 5;
if (bottom > 32) bottom = 32;
}
for (uint x = 0; x < 4; ++x) {
const auto xXPos = x4+x;
if (newTile[xXPos, y] != 0 && newTile[xXPos, y] != 134)
newTile[xXPos, y] = PlainWallTile[xXPos, y];
}
}
}
if (top != -1) {
GrassLengthsOfEachTile.resize(tileID+1);
GrassLengthsOfEachTile[tileID].resize(x4/4+1);
uint length = bottom - top;
if (length < MinimumGrassHeight) length = MinimumGrassHeight;
GrassLengthsOfEachTile[tileID][x4/4] = length | (top << 8);
}
}
newTile.save(tileID);
}
for (int y = jjLayerHeight[4]; --y >= 0;) {
array<Grass>@ grassRow = @Grasses[y];
for (int x = jjLayerWidth[4]; --x >= 0;) {
const uint16 tileID = jjTileGet(4, x, y);
if (TilesToReplaceNaturalGrassIn.find(tileID) >= 0) {
const auto lengths = GrassLengthsOfEachTile[tileID];
for (uint xx = 0; xx < 32/4 && xx < lengths.length; ++xx) {
Grass@ grass = @grassRow[x * 32/4 + xx];
grass.length = lengths[xx] & 0xFF;
grass.top = lengths[xx] >> 8;
}
}
}
}
}
void onDrawLayer4(jjPLAYER@ play, jjCANVAS@ canvas) {
//for (uint i = 0; i < 25; ++i)
// canvas.drawSpriteFromCurFrame(i * 4, 60, GrassAnim + i);
int top = int(play.cameraY);
const int bottom = top + jjSubscreenHeight;
const int left = int(play.cameraX);
const int right = left + jjSubscreenWidth;
for (int topDraw = top & ~31; topDraw < bottom; top += 32, topDraw += 32) {
array<Grass>@ grassRow = @Grasses[top >> 5];
for (int x = left, xOrg = left >> 2, xDraw = x & ~3; xDraw < right; x += 4, xOrg += 1, xDraw += 4) {
Grass@ grass = @grassRow[xOrg];
if (grass.length != 0) {
if (grass.bounce == 0 && (jjRandom() & 63) == 0) grass.bounce = 4;
canvas.drawSpriteFromCurFrame(xDraw, topDraw + grass.top - (grass.bounce == 0 ? 0 : int(jjSin((grass.bounce += 4)<<1)*4)), GrassAnim + grass.length);
}
}
}
}
Jazz2Online © 1999-INFINITY (Site Credits). We have a Privacy Policy. Jazz Jackrabbit, Jazz Jackrabbit 2, Jazz Jackrabbit Advance and all related trademarks and media are ™ and © Epic Games. Lori Jackrabbit is © Dean Dodrill. J2O development powered by Loops of Fury and Chemical Beats.
Eat your lima beans, Johnny.