For last week's Patreon First game, Cow Down, there's a nice little lighting effect that lights up the isometric grid.
I thought you might like to see how it's achieved.
-=-=-
We start with an isometric grid, built up using separate sides and a top.
The three sprites are Top, Left and Right, and when combined they make an isometric cube.
We can draw a screenfull of these isometric cubes in a fairly simple fashion, just be sure that, every other y-line, we offset the x-position of the cubes by half a cube.
That way, the cubes all tesselate nicely on the screen, and we get a nice isometric grid of cubes.
// Isometric Illumination
// by Jayenkai
// Created 2025/3/1
Symbol 0,"1__0/330_0,3!0@3_30.3_3?03_3/03_3?0.3_30@3!0_0,33";
Symbol 1,"1__0_0_0_0_0_0_0_0_0@30_0!3,0_0.3?0_003/0_3@0@3@0@3@0_3/0_003?0_0.3,0_0!3";
Symbol 2,"1__0_0_0_0_0_0_0_0_0_0_0?30_0.3,0_003?0_3/0@3@0@3@0@3@0@3/0_3?0_003,0_0.3";
Graphics 320,240,3
Repeat
CLS;AA False
for x=0 to 9
for y=0 to 9
dx=x*34;dy=y*26
if y%2==0 then dx=dx+17 // For every other y line, we offset the tiles by half
DrawImg dx,dy,0
DrawImg dx,dy,1
DrawImg dx,dy,2
next
next
Flip
Forever
Now for some light. Since we're drawing to a black background, we can use Alpha to make the cubes semi-transparent, which reduces the brightness of the cube.
Let's start with basic light and darkness.
We can use Pythagorus to work out the distance from the mouse, limit it between two values, and then invert the distance and divide to get a nice Alpha value.
(That sounds complicated but it's only two lines!)
// Isometric Illumination
// by Jayenkai
// Created 2025/3/1
Symbol 0,"1__0/330_0,3!0@3_30.3_3?03_3/03_3?0.3_30@3!0_0,33";
Symbol 1,"1__0_0_0_0_0_0_0_0_0@30_0!3,0_0.3?0_003/0_3@0@3@0@3@0_3/0_003?0_0.3,0_0!3";
Symbol 2,"1__0_0_0_0_0_0_0_0_0_0_0?30_0.3,0_003?0_3/0@3@0@3@0@3@0@3/0_3?0_003,0_0.3";
Graphics 320,240,3
Repeat
CLS;AA False
for x=0 to 9
for y=0 to 9
dx=x*34;dy=y*26
far=Limit(240-Pyth(dx-MouseX(),dy-MouseY()),0,240)
alpha=far/240
SetAlpha alpha
if y%2==0 then dx=dx+17 // For every other y line, we offset the tiles by half
DrawImg dx,dy,0
DrawImg dx,dy,1
DrawImg dx,dy,2
next
next
Flip
Forever
This gives us the ability to move the mouse around and see the cubes at different light values, but we've still no depth, so lets add that next.
For this example we'll keep things simplistic, but the general gist is, if the "light" is below the cube, the top should be half as bright.
Similarly if the "light" if to the left of a cube, the right of the cube should be darker, and if it's to the right of a cube, the left should be darker.
depth=0.5;
toplight=alpha;if MouseY()>dy then toplight=alpha*depth
leftlight=alpha;if MouseX()>dx then leftlight=alpha*depth
rightlight=alpha;if MouseX()<dx then rightlight=alpha*depth
We'll throw this in, and set the Alpha using these new values.
// Isometric Illumination
// by Jayenkai
// Created 2025/3/1
Symbol 0,"1__0/330_0,3!0@3_30.3_3?03_3/03_3?0.3_30@3!0_0,33";
Symbol 1,"1__0_0_0_0_0_0_0_0_0@30_0!3,0_0.3?0_003/0_3@0@3@0@3@0_3/0_003?0_0.3,0_0!3";
Symbol 2,"1__0_0_0_0_0_0_0_0_0_0_0?30_0.3,0_003?0_3/0@3@0@3@0@3@0@3/0_3?0_003,0_0.3";
Graphics 320,240,3
Repeat
CLS;AA False
depth=0.5
for x=0 to 9
for y=0 to 9
dx=x*34;dy=y*26
far=Limit(240-Pyth(dx-MouseX(),dy-MouseY()),0,240)
alpha=far/240
toplight=alpha;if MouseY()>dy then toplight=alpha*depth
leftlight=alpha;if MouseX()>dx then leftlight=alpha*depth
rightlight=alpha;if MouseX()<dx then rightlight=alpha*depth
if y%2==0 then dx=dx+17 // For every other y line, we offset the tiles by half
SetAlpha toplight; DrawImg dx,dy,0
SetAlpha leftlight; DrawImg dx,dy,1
SetAlpha rightlight;DrawImg dx,dy,2
next
next
Flip
Forever
And that's the general gist of how that works.
For the final game I added a little smoothness to the values, and on occasions it can look more than a little patchy, but it serves the purpose, and it's a nice enough effect.
.. I think.
... Maybe.
It's just a shame that JSE can't quite keep up with it at full speed with a larger environment.
That would be nice..
More Optimisationalism required, methinks.
Cow Down is currently a Patreon First game, but will be unlocked on Monday 2nd March 2025. (Tomorrow!)
Light it up. (light)
Light the cube. (light)
Light the path. (light)
Light it all. (light)
Light the way. (light)
Every day. (light)
With your mouse. (light)
In the house. (light)
Light it up!
[break]
Light it up!
[break]
[bridge]
Darkness to light (light)
Brightness is your fight (light)
It all looks alright (light)
Make day from the night (light)
Then take it away (light)
The light doesn't stay (light)
The shadow's at play (light)
Where is the pathway (light)
Light it up!
[break]
Light it up!
Yeah (Woo)
Light (light)
Bright!
[break]
Light it up. (light)
Light the cube. (light)
Light the path. (light)
Light it all. (light)
Light the way. (light)
Every day. (light)
With your mouse. (light)
In the house. (light)
"CGI render by blender, Cartoon CGI Derek shines a torch towards a grid of isometric retro neon cubes, lighting them up, cinematic lighting, volumetric" by Replicate/Flux
Int. Dave's Study - Early Morning
[Dave is bleary-eyed in front of an ancient Amstrad CPC. Empty coke cans everywhere. Green enters]
Dave: Just... one... more... castle...
Green: Have you been up all night?
Dave: Had to test the stock, didn't I? Oh no! What's the time?
Green: Just gone eight. Why?
Dave: I was meant to get a cake!
Green: A cake?
Dave: For later! For the... you know... Whatever it is out there.
Green: You're still doing that?
Dave: Of course I am. They're up to something, those neighbours of mine. But I got distracted by this stupid duck game...
Green: I can't believe you played it all night.
Dave: Not ALL night. I gave myself plenty of coke breaks.
Green: Well, that's sensible. [rolls eyes]
Dave: Right, where can I get a cake on a Sunday morning?
Green: Maybe Marks and Spencer?
Dave: Too expensive. Need somewhere cheaper.
Green: You spent fifty quid on a big pile of this Count Duckula game, but won't splash out on a cake?
Dave: That was an investment, though. I'll be able to sell each copy for an inflated "Retro Game" price.
Green: I'm sure you will, Dave.
Dave: Right, let's get a cake. I have to know what's going on with the cakes.
Green: Have you asked the neighbours?
Dave: Not yet. I don't have a cake.
Green: I'm sure they'll tell you where they're going, even without a cake.
Dave: [waves arms in the air] No, I must have a cake.
Green: I think you need a sleep!
Dave: Why are you even here?
Green: I'm here to guide you through your day, of course.
Dave: But it's Sunday. You're not normally here.
Green: Aaah, but I am.
[Dave pokes Greenie, who disappears in a cloud of smoke.]
Dave: Oh no!!!
[End Credits, as Dave wakes up, crouched over the keyboard, still playing Count Duckula 2]
Views 707, Upvotes 13
Daily Blog
,
Gamedev
New games every week!
Places
Archives
Site credits : Jayenkai, one crazy fool who has far too much time on his hands.
(c) Jayenkai 2023 and onwards, RSS feed
89