Added the 'draw poly xform' command (examples/help/draw_poly_xform.n7)
Added the 'draw poly image xform' command (examples/help/draw_poly_image_xform.n7)
Added support for loading music and sound effects in mp3 format
The new versions of the polygon commands let you specify position, scaling, rotation and pivot when you draw a polygon, meaning that you can use the same array of points to draw polygons all over the place.
You may reply me on weekend when you are not at work. It's not urgent
I am making an animation of a night driving with the wolf3d library.
click the images to zoom in
Could you please help me :
- I don't know how to fixed some bugs
1. the car is not turned smoothly on turn#4 and turn#3
2. the zombie animation is overlapped
- I don't know how to put the sky image as a background ( not as a tileset)
Code:
'====================================================
'
' ......
'
' Acknowlegements :
' -Haunted Night by Hot Dope
' https://pixabay.com/music/search/mood/scary/
' -Zombie
' https://opengameart.org/content/zombie-rpg-sprites
'====================================================
'----------------
' INITIALIZATION
'----------------
'#win32
set window "The Shadow", 1000,500,false
set redraw off; set mouse off
include "wolf3d.n7"
w3d = Wolf3D()
w3d.SetView(0, 0, width(primary), height(primary), rad(72))
visible vBricks = fill(unset, 15, 10, 3)
for x = 0 to 14 for z = 0 to 9 for y = 0 to 2
if y = 0 and rnd(2) = 0 or y > 0 and vBricks[x][z][y - 1] and rnd(2) = 0
select rnd(3)
case 0 vBricks[x][z][y] = [st: 1, m: cube, t: vRedBrickImage, offs: 0, ht: 0]
case 1 vBricks[x][z][y] = [st: 2, m: cube, t: vGreenBrickImage, offs: 0, ht: 0]
case 2 vBricks[x][z][y] = [st: 3, m: cube, t: vBlueBrickImage, offs: 0, ht: 0]
endsel
endif
next
S3D_Render()
set caret 0, 0
set color 255, 255, 255
wln int(1/dt)
redraw
' no fps cap might affect mouse input on fast computers, maybe wait more than 1?
if FPS_CAP > 0 fwait FPS_CAP
else wait 1
wend
' UpdateBall
' ----------
function UpdateBall(ball, dt)
' Move in z.
ball.z = ball.z + dt*ball.dz*ball.spd
if ball.dz < 0
iz = floor(ball.z - 0.25)
if iz >= 0 and iz < 10
ixl = floor(ball.x - 0.25); ixr = floor(ball.x + 0.25)
if ixl >= 0 and ixl < 15 and vBricks[ixl][iz][0]
HitBrick(ixl, iz)
ball.z = iz + 1 + 0.251; ball.dz = |ball.dz|
endif
if ixr >= 0 and ixr < 15 and vBricks[ixr][iz][0]
HitBrick(ixr, iz)
ball.z = iz + 1 + 0.251; ball.dz = |ball.dz|
endif
elseif iz < -10
ball.z = -10 + 0.251; ball.dz = |ball.dz|
endif
elseif ball.dz > 0
iz = floor(ball.z + 0.25)
if iz >= 0 and iz < 10
ixl = floor(ball.x - 0.25); ixr = floor(ball.x + 0.25)
if ixl >= 0 and ixl < 15 and vBricks[ixl][iz][0]
HitBrick(ixl, iz)
ball.z = iz - 0.251; ball.dz = -|ball.dz|
endif
if ixr >= 0 and ixr < 15 and vBricks[ixr][iz][0]
HitBrick(ixr, iz)
ball.z = iz - 0.251; ball.dz = -|ball.dz|
endif
elseif iz >= 10
ball.z = 10 - 0.251; ball.dz = -|ball.dz|
PlaySound3D(vWallSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
endif
' Move in x.
ball.x = ball.x + dt*ball.dx*ball.spd
if ball.dx < 0
ix = floor(ball.x - 0.25)
if ix >= 0 and ix < 15
izt = floor(ball.z - 0.25); izb = floor(ball.z + 0.25)
if izt >= 0 and izt < 10 and vBricks[ix][izt][0]
HitBrick(ix, izt)
ball.x = ix + 1 + 0.251; ball.dx = |ball.dx|
endif
if izb >= 0 and izb < 10 and vBricks[ix][izb][0]
HitBrick(ix, izb)
ball.x = ix + 1 + 0.251; ball.dx = |ball.dx|
endif
elseif ix < 0
ball.x = 0.251; ball.dx = |ball.dx|
PlaySound3D(vWallSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
elseif ball.dx > 0
ix = floor(ball.x + 0.25)
if ix >= 0 and ix < 15
izt = floor(ball.z - 0.25); izb = floor(ball.z + 0.25)
if izt >= 0 and izt < 10 and vBricks[ix][izt][0]
HitBrick(ix, izt)
ball.x = ix - 0.251; ball.dx = -|ball.dx|
endif
if izb >= 0 and izb < 10 and vBricks[ix][izb][0]
HitBrick(ix, izb)
ball.x = ix - 0.251; ball.dx = -|ball.dx|
endif
elseif ix >= 15
ball.x = 15 - 0.251; ball.dx = -|ball.dx|
PlaySound3D(vWallSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
endif
dx = (ball.x - vPaddleX)/(vPaddleW*0.5 + 0.25)
if |dx| < 1 and ball.dz < 0 and ball.z > vPaddleZ and ball.z - vPaddleZ < 0.5
ball.dx = dx*2.5
ball.dz = 1
k = 1/sqr(ball.dx^2 + ball.dz^2)
ball.dx = ball.dx*k; ball.dz = ball.dz*k
PlaySound3D(vPaddleSound, 1, ball.x, 0.25, ball.z, vSoundMaxD)
endif
return true
endfunc
' HitBrick
' --------
function HitBrick(x, z)
b = vBricks[x][z][0]
if b and b.ht = 0 and b.offs < 0.5
b.st = b.st - 1
if b.st > 0
b.ht = 10
PlaySound3D(vBrickHitSound, 1, x + 0.5, 0.5 + b.offs, z + 0.5, vSoundMaxD)
else
for i = 0 to 1
vBricks[x][z][i] = vBricks[x][z][i + 1]
if vBricks[x][z][i]
if vBricks[x][z][i].offs = 0
vBricks[x][z][i].spd = 0
endif
vBricks[x][z][i].offs = vBricks[x][z][i].offs + 1
endif
next
vBricks[x][z][2] = unset
PlaySound3D(vBrickDestroyedSound, 1, x + 0.5, 0.5 + b.offs, z + 0.5, vSoundMaxD)
endif
endif
endfunc
function DeltaTime()
t = clock()
dt = (min(t - vLastTick, 100))/1000
vLastTick = t
return dt
endfunc
' LoadAssets
' ----------
function LoadAssets()
' Make bricks less and less bright for each hit.
vRedBrickImage = createimage(32, 32)
set image vRedBrickImage
set color 32, 0, 32; cls
set color 255, 255, 255; draw rect 0, 0, 32, 32, false
set color 255, 0, 128; draw rect 1, 1, 30, 30, false
set color 128, 0, 0; draw rect 2, 2, 28, 28, false
set image primary
BoxBlur(vRedBrickImage, 3, 3)
vGreenBrickImage = createimage(32, 32)
set image vGreenBrickImage
set color 32, 16, 0; cls
set color 255, 255, 255; draw rect 0, 0, 32, 32, false
set color 255, 128, 0; draw rect 1, 1, 30, 30, false
set color 128, 0, 0; draw rect 2, 2, 28, 28, false
set image primary
BoxBlur(vGreenBrickImage, 3, 3)
vBlueBrickImage = createimage(32, 32)
set image vBlueBrickImage
set color 0, 16, 32; cls
set color 255, 255, 255; draw rect 0, 0, 32, 32, false
set color 0, 128, 255; draw rect 1, 1, 30, 30, false
set color 0, 0, 128; draw rect 2, 2, 28, 28, false
set image primary
BoxBlur(vBlueBrickImage, 3, 3)
vBallImage = createimage(31, 31)
set image vBallImage
set color 255, 255, 255; cls
set color 16, 16, 16; draw ellipse 15, 15, 11, 11, true
set image primary
BoxBlur(vBallImage, 4, 4)
set image vBallImage
set color 255, 0, 255
for y = 0 to 30 for x = 0 to 30
d = sqr((x - 15)^2 + (y - 15)^2)
if d >= 14.5 set pixel x, y
next
set image primary
set image colorkey vBallImage, 255, 0, 255
data = MD_Generate(257, 1, 0.1, 52)
vFloorImage = createimage(256, 256)
set image vFloorImage
for y = 0 to 255 for x = 0 to 255
c = data[x][y]
if int(y/17 + x/17)%2 = 0
set color c*4, c*16, c*32
else
set color c*2, c*8, c*16
endif
set pixel x, y
next
set image primary
BoxBlur(vFloorImage, 2, 2)
vPaddleImage = createimage(128, 32)
set image vPaddleImage
set color 0, 8, 32; cls
set color 204, 0, 0
draw rect 0, 0, 32, 32, true; draw rect 96, 0, 32, 32, true
set color 255, 255, 255, 204
draw rect 0, 0, 32, 32; draw rect 1, 1, 30, 30; draw rect 2, 2, 28, 28
draw rect 96, 0, 32, 32; draw rect 97, 1, 30, 30; draw rect 98, 2, 28, 28
set color 0, 64, 255, 128
draw rect 32, 0, 64, 32; draw rect 33, 1, 62, 30; draw rect 34, 2, 60, 28
set image primary
BoxBlur(vPaddleImage, 3, 3)
vWhiteImage = createimage(32, 32)
set image vWhiteImage
set color 255, 255, 255
cls
set image primary
' PlaySound3D
' -----------
function PlaySound3D(snd, vol, x, y, z, maxd)
dx = x - vCamX; dy = y - vCamY; dz = z - vCamZ
d = dx*dx + dy*dy + dz*dz
if d >= maxd*maxd return
if d > 0
d = sqr(d); k = 1.0/d
dx = dx*k; dy = dy*k; dz = dz*k
d = (maxd - min(maxd, d))/maxd
cp = cos(vCamPitch)
pan = (cos(vCamYaw)*cp*dx - sin(vCamYaw)*cp*dz)*0.9
else
d = 1
pan = 0
endif
play sound snd, vol*d, pan
endfunc
' BoxBlur
' -------
function BoxBlur(img, rx, ry)
rx = max(int(rx), 0); ry = max(int(ry), 0)
set image img
w = width(img); h = height(img)
data = dim(w, h)
' Blur vertically
for y = 0 to h - 1 for x = 0 to w - 1 data[x][y] = pixeli(img, x, y)
count = ry*2 + 1
for x = 0 to w - 1
sr = 0; sg = 0; sb = 0; sa = 0
for y = -ry to ry
p = data[x][y%h];
sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
next
for y = 0 to h - 1
set color sr/count, sg/count, sb/count, sa/count
set pixel x, y
p = data[x][(y - ry)%h]
sr = sr - Red(p); sg = sg - Green(p); sb = sb - Blue(p); sa = sa - Alpha(p)
p = data[x][(y + ry + 1)%h]
sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
next
next
' Blur horizontally.
for y = 0 to h - 1 for x = 0 to w - 1 data[x][y] = pixeli(img, x, y)
count = rx*2 + 1
for y = 0 to h - 1
sr = 0; sg = 0; sb = 0; sa = 0
for x = -rx to rx
p = data[x%w][y]
sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
next
for x = 0 to w - 1
set color sr/count, sg/count, sb/count, sa/count
set pixel x, y
p = data[(x - rx)%w][y]
sr = sr - Red(p); sg = sg - Green(p); sb = sb - Blue(p); sa = sa - Alpha(p)
p = data[(x + rx + 1)%w][y]
sr = sr + Red(p); sg = sg + Green(p); sb = sb + Blue(p); sa = sa + Alpha(p)
next
next
set image primary
' Pixeli helpers.
function Alpha(c); return int(c/16777216); endfunc
function Red(c); return int((c/65536))%256; endfunc
function Green(c); return int((c/256))%256; endfunc
function Blue(c); return c%256; endfunc
endfunc
I have not implemented your code yet... by the way, it looks very similar to the old drawing program routine - I think you may have provided that one as well... how quickly I forget... lol
I will provide you with what I have at the moment....
Functionality: Selecting colours; Drawing and Erasing to and from the main screen; Selecting tile size (8, 16 and 32) all work. When changing resolutions the main canvas is erased. I am planning on an 'Are you sure?' to be displayed if the main canvas is 'occupied'.
As it only makes one tile, other functions like 'Line'; 'Fill', 'Circle' etc., seemed to be a lot more work. All I needed was to be able to Draw, Save and Load...
As always... open to suggestions.
It's really 'bare bones' but closer to what I had originally planned...
I'm currently trying to make my drawing logic on an image of logical window dimensions then if the game runs in windowed mode, I just send this image on the window but if the game runs in fullscreen, I try to send this image on an image with the screen dimensions after applying code to calculate vertical or horizontal margins depending on the difference in aspect ratios between the physical screen and the window.
My windowed mode works fine.
In fullscreen :
-----------------
I succefully prepare graphics on the window sized image then send it to physical screen image then on the screen but I'm not able the fit the logical image on the screen size and place it accordingly with the margins.
Back in December of 2024, I mention that I was having difficulty(s), with my Sprite Editor. The fix you provided worked like a charm... The project has been "gathering dust" since then because of lack of planning on my part. Creating an editor without considering, "Do I have the skill set to complete it?" The answer was a resounding "NO."...
Then I got to thinking (Ok, you can stop laughing now... very funny...) that the Sprite Editor is very similar to a Tile Map Editor. Mind you, a bare-bones, editor... lol Functions like, New, Load, Save, Quit, Draw and Erase tile... Seeing that Wolf3D does not seem to have a Editor per se, maybe the Sprite Editor, could be repurposed?
Here is my idea: Wolf3D uses a standard 64x64 tiled "map". Single level (ie: no layers). The Sprite Editor is already configured for a 64x64 "pixel" display. Give the different walls etc a specific colour. "Draw" the wall "pixel" etc to create the "map". Scan the main grid to convert it to a 64x64 character text grid then convert that grid to the standard Wolf3D "map = [[ ]]" layout.
No prizes for guessing that I have already started... kind of... The four main function are working (sort of) and the selection of the "tiles" can be drawn and erased. Saving and loading are my biggest issues at the moment... After all - it's only been 1 day... lol
I realize that EngineA already has a Tile Based editor and was wondering if your intentions are focused more toward that type of game creation than the Wolf3D game style? Reason: If the focus is on EngineA then it would be illogical to continue with the W3D editor... What do you think? Is a W3D editor a kind of "re-inventing the wheel" type of deal?
Nothing finished here. This was one of my "test programs" when writing the enginea library and editor, so it's just a couple of enemies in some few rooms. The graphics and the music are ai generated, love the tune Some of the code might be of interest to others, so I'm posting it.