Just mucking around with 2d/3d landscapey thingies in 2d

Started by Matty, December 09, 2022, 20:24:25

Previous topic - Next topic

Matty

This is blitzplus code but it could easily be blitz3d or any other code....

I thought I'd show this off - sometimes I muck around with just trying things out - experimenting as you will.

I think this is a neat effect with some 3d calculations in 2d, and some vegetation sprites....I'm not sure if I'll use it for anything but I'm sharing the details here:

Media (and code) attached below

takepicture = 0
Graphics 1600,900,0,2
map = LoadImage("map05.png")
veg = LoadAnimImage("vegetation0.png",24,24,0,16)
tree = LoadAnimImage("trees.png",48,48,0,8)
Dim trees(1024,1024)
Dim hmap(1024,1024)
For x = 0 To 1023
For y = 0 To 1023
hmap(x,y) = ReadPixel(x,y,ImageBuffer(map)) And 255
If Rand(1,4000) < 4 Then trees(x,y) = 1
Next
Next
ClsColor 150,180,40
Repeat
Cls
;offz = offz + 10
;LockBuffer
rgb = 255 Shl 16 Or 255 Shl 8 Or 255
SeedRnd 1
For z=1 To 1023
For x=1 To 1023
h = hmap((x+offx) Mod 1024,(z+offz) Mod 1024)
h0 = hmap(x - 1,z)
h1 = hmap(x,z - 1)
scrx = 800.0 + 1600.0 * Float(x - 512) / Float(1024.0 - z)
scry = 450.0 + 900.0 * (Float(1024 - z) - 512.0) / Float(1024.0 - z)
scry = scry - 900.0 * Float(h) / Float(1024 - z)
Color 255,255,255
;Plot scrx,scry
If scrx>=0 And scry>=0 And scrx<1600 And scry<900 Then
; WritePixelFast scrx,scry,rgb
vv = Rand(0,15)
If vv>7 Then vv = Rand(0,15)
DrawImage veg,scrx,scry,vv
If trees((x+offx) Mod 1024,(z+offz) Mod 1024)=1 Then
; DrawImage tree,scrx,scry,Rand(0,7)
EndIf
EndIf
Next
Next
For z=1023 To 1 Step -1
For x=1 To 1023
h = hmap((x+offx) Mod 1024,(z+offz) Mod 1024)
h0 = hmap(x - 1,z)
h1 = hmap(x,z - 1)
scrx = 800.0 + 1600.0 * Float(x - 512) / Float(1024.0 - z)
scry = 450.0 + 900.0 * (Float(1024 - z) - 512.0) / Float(1024.0 - z)
scry = scry - 900.0 * Float(h) / Float(1024 - z)
Color 255,255,255
;Plot scrx,scry
If scrx>=0 And scry>=0 And scrx<1600 And scry<900 Then
; WritePixelFast scrx,scry,rgb
; DrawImage veg,scrx,scry,Rand(0,7)
If trees((x+offx) Mod 1024,(z+offz) Mod 1024)=1 Then
DrawImage tree,scrx,scry,Rand(0,7)
EndIf
EndIf
Next
Next
;UnlockBuffer
Color 32,32,48
Rect 0,700,1600,200,1
If takepicture = 1 Then
SaveBuffer BackBuffer(),"scene.bmp"
End
EndIf
Flip
Until KeyHit(1)
End

STEVIE G

Looks good for the small code. You should check out the Wave Function Collapse algorithm used for Bad North. I'm going to attempt it for my next project.  ;D

Pakz

The coding train on yt has a easy to understand tutorial on how to program the Wave Function Collapse.

I have slowly and sometimes intensively on some days trying to get a voxel world going in the browser for touch devices. Meaning to get a lot of generators in there.

RemiD

a good approach is to go from big to small.

first the terrain
then the big buildings / rooms
then the trees / furnitures
then the plants / equipments / tools

and instead of positionning the small things randomnly, position them depending on the bigger things (a potion on a table, a table in a room, a room in a building, etc...)

Pakz

I have a lot of game dev based books. There are really few step by step, start to finish guides.

Getting a project to look flashy, and shiny from the start, seems to give these the most attention. Likes and views and such.

3DzForMe

Looking Impressive Pakz, I've liked toying with 3d reprentations from heightmaps - found Vistapro in the loft recently.... hardware and softwares moved on a lot in the last 3 decades!
BLitz3D, IDEal, AGK Studio, BMax, Java Code, Cerberus
Recent Hardware: Dell Laptop
Oldest Hardware: Commodore Amiga 1200 with 1084S Monitor & Blitz Basic 2.1