Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 31
» Latest member: nartex
» Forum threads: 105
» Forum posts: 823

Full Statistics

Online Users
There are currently 33 online users.
» 0 Member(s) | 32 Guest(s)
Bing

Latest Threads
S3D : the devil's triangl...
Forum: NaaLaa 7 Questions
Last Post: 1micha.elok
1 hour ago
» Replies: 9
» Views: 99
Just for the Star Wars fa...
Forum: Everything else
Last Post: johnno56
05-05-2024, 10:40 PM
» Replies: 7
» Views: 134
Convex hull, quick algori...
Forum: NaaLaa 7 Code
Last Post: johnno56
05-04-2024, 07:23 PM
» Replies: 7
» Views: 270
Wolf3D
Forum: NaaLaa 7 Questions
Last Post: johnno56
05-02-2024, 07:57 PM
» Replies: 24
» Views: 1,368
Small pinball game using ...
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
05-02-2024, 01:41 AM
» Replies: 2
» Views: 139
That 3d thing
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
04-30-2024, 02:32 AM
» Replies: 14
» Views: 1,028
Raycaster
Forum: NaaLaa 6 Questions
Last Post: johnno56
04-29-2024, 09:08 AM
» Replies: 5
» Views: 245
The Maze II
Forum: NaaLaa 7 Code
Last Post: Marcus
04-28-2024, 11:53 AM
» Replies: 4
» Views: 324
Wolf3D test
Forum: NaaLaa 7 Code
Last Post: Marcus
04-27-2024, 03:05 PM
» Replies: 3
» Views: 273
The Maze
Forum: NaaLaa 7 Code
Last Post: Marcus
04-24-2024, 06:46 AM
» Replies: 15
» Views: 1,613

 
  draw image xform, asteroids example
Posted by: Marcus - 03-07-2024, 05:32 PM - Forum: NaaLaa 7 Code - Replies (6)

This is not a full game, just a player that you can control and some asteroids that fly around. But there are lots of transformed image drawing going on, including the spinning and zooming background image. I'm curious about the fps on your machines? I have a solid 250fps here, but maybe this craptop is a laptop after all.



Attached Files
.zip   asteroids_example.zip (Size: 138.54 KB / Downloads: 7)
Print this item

  Textured polygons helper functions
Posted by: Marcus - 03-06-2024, 03:58 PM - Forum: NaaLaa 7 Code - Replies (1)

'draw poly image' can be hard to use and make sense of, so here is an example program with some helper functions.



Attached Files
.zip   poly_helper.zip (Size: 6.59 KB / Downloads: 4)
Print this item

  N7 logo on email
Posted by: 1micha.elok - 03-06-2024, 01:15 AM - Forum: Suggestions - Replies (1)

Hi, Marcus

I am a fan of Naalaa, you know it  Big Grin
I subcribe and receive email notification of new replies from the Naalaa's forum.
I notice that it is still N6 logo
   
click the image to zoom in

Perhaps ... it is time to change to new N7 logo ...  Cool

.png   logo_N7.png (Size: 8.96 KB / Downloads: 20)
click the image to zoom in

Print this item

  N7 version 24.03.05 released
Posted by: Marcus - 03-05-2024, 07:15 PM - Forum: Announcements - Replies (7)

https://naalaa.com/n7/N7_240305.zip

I haven't experimented with (or even tested, to be honest) the new commands much yet, and the included examples are minimal. But I will provide game examples soon.

Release notes
2024-03-05

  • 'this.' can now be written as just '.'
  • Added the commands 'draw image xform' and 'draw poly image'. You can find two small examples under examples/help: draw_image_xform.n7 and draw_poly_image.n7

'draw image xform' is for drawing transformed (scaled and rotated) images. 'draw poly image' is for drawing texture mapped polygons.

Print this item

  Physics
Posted by: johnno56 - 03-04-2024, 05:50 AM - Forum: NaaLaa 7 Questions - Replies (10)

I cannot recall if I have raised this question before... forgive if I have... What is involved in creating a simple physics engine / library? Say something like Box2D or Box2D-lite? The big question(s)... Can N7 do it... and how?

J

Print this item

  Rotated and scaled image drawing
Posted by: Marcus - 03-03-2024, 10:49 AM - Forum: NaaLaa 7 Code - Replies (27)

I wrote a quick prototype of drawing images with arbitrary rotation and scaling in n7. The code may look a bit too complicated for just drawing a transformed image. But when I add this stuff to the core (implement it in C and add new commands to n7), I will also let you draw textured polygons with any number of points. Here I just draw a textured rectangle, four points.

It's slow, but it's gonna get a lot faster, of course.

I'm already thinking about adding support for z coordinates and perspective correct interpolation (for polygons). Would be fun to allow some 3d rendering as in naalaa 5.

Code:
include "list.n7"

'#win32
#dbg

visible vPoints = fill([x: 0, y: 0, u: 0, v: 0], 4)
visible vXval = List()
vXval.Add([0, 0, 0])
vXval.Add([0, 0, 0])

set window "test", 640, 480
set redraw off

img = loadimage("logo.png")
pln width(img) + ", " + height(img)

a = 0
while not keydown(KEY_ESCAPE, true)
    a = (a + 1)%360
    set color 0, 0, 0
    cls
    set color 255, 255, 255, 0
    ' DrawImageTransformed(image, x, y, scale_x, scaleY, angle, pivot_x, pivot_y)
    ' draw scaled and centered (= pivot at center of image).
    DrawImageTransformed(img, 120, 240, 2, 2, 0, width(img)/2, height(img)/2)
    ' draw rotated and centered
    DrawImageTransformed(img, 320, 240, 1, 1, rad(a), width(img)/2, height(img)/2)
    ' draw rotated and scaled but put pivot at top left corner of image.
    DrawImageTransformed(img, 520, 240, 4, 4, rad(a), 0, 0)
    redraw
    fwait 60   
wend

function DrawImageTransformed(img, drawX, drawY, scaleX, scaleY, angle, pivotX, pivotY)
    srcX = 0
    srcY = 0
    srcW = width(img)
    srcH = height(img)
   
    xLeft = -pivotX*scaleX
    xRight = (srcW - pivotX)*scaleX
    yTop = -pivotY*scaleY
    yBottom = (srcH - pivotY)*scaleY
   
    vPoints[0].x = xLeft; vPoints[0].y = yTop; vPoints[0].u = 0; vPoints[0].v = 0
    vPoints[1].x = xRight; vPoints[1].y = yTop; vPoints[1].u = 1; vPoints[1].v = 0
    vPoints[2].x = xRight; vPoints[2].y = yBottom; vPoints[2].u = 1; vPoints[2].v = 1
    vPoints[3].x = xLeft; vPoints[3].y = yBottom; vPoints[3].u = 0; vPoints[3].v = 1
    for i = 0 to sizeof(vPoints) - 1
        x = vPoints[i].x*cos(angle) - vPoints[i].y*sin(angle)
        y = vPoints[i].y*cos(angle) + vPoints[i].x*sin(angle)
        vPoints[i].x = round(drawX + x)
        vPoints[i].y = round(drawY + y)
        if i = 0
            minX = vPoints[i].x
            maxX = vPoints[i].x
            minY = vPoints[i].y
            maxY = vPoints[i].y
        else
            minX = min(vPoints[i].x, minX)
            maxX = max(vPoints[i].x, maxX)
            minY = min(vPoints[i].y, minY)
            maxY = max(vPoints[i].y, maxY)
        endif
    next   
    if maxX < 0 or minX >= width(primary) or maxY < 0 or minY >= height(primary)  return
    set color 255, 255, 255, 0
    for y = minY to maxY
        numx = 0
        for i = 0 to sizeof(vPoints) - 1
            p0 = vPoints[i]
            p1 = vPoints[(i + 1)%sizeof(vPoints)]
            if p0.y <= y and p1.y > y or
                    p0.y > y and p1.y <= y
                dy = p1.y - p0.y
                if dy = 0
                    vXval[numx][0] = p0.x; vXval[numx][1] = p0.u; vXval[numx][2] = p0.v
                    numx = numx + 1
                    vXval[numx][0] = p1.x; vXval[numx][1] = p1.u; vXval[numx][2] = p1.v
                    numx = numx + 1
                else
                    f = (y - p0.y)/(p1.y - p0.y)
                    vXval[numx][0] = p0.x + f*(p1.x - p0.x)
                    vXval[numx][1] = p0.u + f*(p1.u - p0.u)
                    vXval[numx][2] = p0.v + f*(p1.v - p0.v)
                    numx = numx + 1
                endif
            endif
        next
        if numx
            vXval.size = numx
            vXval.SortByField(0, vXval.ASCENDING)
            for i = 0 to vXval.size - 2 step 2
                draw hraster img, y, vXval[i][0], vXval[i + 1][0],
                        vXval[i][1], vXval[i][2], vXval[i + 1][1], vXval[i + 1][2]
            next
        endif
    next   
   
    draw poly vPoints, false
endfunc



Attached Files
.zip   image_transform.zip (Size: 637.72 KB / Downloads: 10)
Print this item

  Some spinning balls
Posted by: Marcus - 03-02-2024, 07:24 PM - Forum: NaaLaa 7 Code - Replies (4)

Remember something very similar from n6, some balls spinning around in space.

Code:
' balls.n7
' --------

include "list.n7"

#win32

set window "Balls", 640, 480
set redraw off

balls = List()
for z = -2 to 2  for y = -2 to 2  for x = -2 to 2  balls.Add(Ball(x, y, z))

additiveMode = false
a1 = 0; a2 = 0; az = 0
while not keydown(KEY_ESCAPE, true)
    if keydown(KEY_SPACE, true)  additiveMode = not additiveMode
    a1 = (a1 + 0.02)%(PI*2)
    a2 = (a2 + 0.013)%(PI*2)
    az = (az + 0.009)%(PI*2)
    for i = 0 to balls.size - 1
        ball = balls[i]
        ball.px = ball.x; ball.py = ball.y; ball.pz = ball.z
        x = ball.px*cos(a1) - ball.py*sin(a1); y = ball.py*cos(a1) + ball.px*sin(a1)
        ball.px = x; ball.py = y
        z = ball.pz*cos(a2) - ball.py*sin(a2); y = ball.py*cos(a2) + ball.pz*sin(a2)
        ball.pz = z; ball.py = y
        ball.pz = ball.pz + 5.5 + sin(az)*0.5
        ball.px = 320 + 200*ball.px/ball.pz; ball.py = 240 + 200*ball.py/ball.pz
    next
    balls.SortByField("pz", balls.DESCENDING)
    set color 0, 0, 0, 64
    cls
    set additive additiveMode
    for i = 0 to balls.size - 1
        s = 100/balls[i].pz
        intens = 255 - (balls[i].pz - 1)*50
        set color intens/2, intens/2, intens/2
        draw ellipse balls[i].px, balls[i].py, s, s, true
        set color intens*0.75, intens*0.75, intens*0.75
        draw ellipse balls[i].px - s*0.4, balls[i].py - s*0.4, s*0.25, s*0.25, true
    next
    set additive false
    set color 255, 255, 255
    set caret width(primary)/2, 480 - fheight()*2
    center "Press spacebar to toggle additive drawing"
    
    redraw
    fwait 60
wend

function Ball(x, y, z)
    return [x: x, y: y, z: z, px: 0, py: 0, pz: 0]
endfunc

Print this item

  PolyLine library
Posted by: Marcus - 02-29-2024, 04:25 PM - Forum: NaaLaa 7 Code - Replies (20)

Here's a small library that could be used for enemy movement in space shootemups (that's the only use I can think of), example included.

The truth is that I had made quite a nice shootemup that used the library. But when I was going to zip it I wanted to delete all built files (exe, n7a, n7b ...). Instead of deleting the exe file, I deleted the source code Sad


Edit  I updated the zip with a new version of the library and some more examples of how it can be used in a shootemup.



Attached Files
.zip   polyline.zip (Size: 7.05 KB / Downloads: 7)
Print this item

  Sleepy tunnel
Posted by: Marcus - 02-29-2024, 03:44 PM - Forum: NaaLaa 7 Code - Replies (8)

A 3d tunnel effect.

Code:
' sleepy_tunnel.n7
' ----------------

#win32
constant WIN_W = 640, WIN_H = 480
set window "Sleepy Tunnel", WIN_W, WIN_H
set redraw off
aa = 0
while not keydown(KEY_ESCAPE, true)
    aa = aa + 0.05
    zoffset = (zoffset + 0.001)%0.01
    set color 0, 0, 0
    cls
    set color 255, 255, 255
    maxz = 0.1 + 150*0.01
    for i = 150 to 0
        z = 0.1 + i*0.01 - zoffset
        s = 50/z
        x = cos(z*5 + aa)*(z - 0.1)*50
        y = sin(z*5 + aa)*(z - 0.1)*25
        intens = 255 - 255*z*1.5/maxz
        set color intens*0.5, intens, intens*0.75
        draw pixel WIN_W/2 + x/z + cos(rad(0))*s, WIN_H/2 + y/z + sin(rad(0))*s
        a = 15
        while a <= 360
            draw line to WIN_W/2 + x/z + cos(rad(a))*s, WIN_H/2 + y/z + sin(rad(a))*s
            a = a + 15
        wend
    next
    redraw
    fwait 60
wend



Attached Files
.n7   sleepy_tunnel.n7 (Size: 868 bytes / Downloads: 2)
Print this item

  Simple Scaling and Rotating
Posted by: 1micha.elok - 02-28-2024, 11:57 AM - Forum: NaaLaa 7 Code - Replies (7)

Just a simple scaling and rotating  Cool

Possible use in games, such as
- Space Invaders, Gargoyle Attack
- Tetris

Code:
'==========================================
'       SIMPLE SCALING AND ROTATING
'
'Possible use in games, such as
'- Space Invaders, Gargoyle Attack
'- Tetris
'
'Limitation
'Rotate : only multiplication of 90 degree
'==========================================


'----------------
' INITIALIZATION
'----------------
set window "Pixel Art", 150, 150, false,4
set redraw off

'Color definition
visible cBlack  = [0,0,0]
visible cGreen  = [0,255,0]

'Sprite class definition
Sprite =
[
    '--- Properties ---
    data: [
    [0,0,0,0,0,0,0,0],
    [0,0,1,0,0,1,0,0],
    [0,1,1,1,1,1,1,0],
    [0,1,1,0,0,1,1,0],
    [0,0,1,1,1,1,0,0],
    [0,1,1,1,1,1,1,0],
    [0,1,0,0,0,0,1,0],
    [0,0,0,0,0,0,0,0]
    ],
   
    img: 0, x:0, y:0,    
   
    '--- Methods ---
    Transform_Scale : function(s)
                        this.img = Scale(this.data,s)
                        this.x   = (width(primary)-8*s)/2
                        this.y   = (height(primary)-8*s)/2
                       endfunc, 
    Transform_Rotate : function(s,r)
                        this.img = Rotate(this.data,s,r)
                        this.x   = (width(primary)-8*s)/2
                        this.y   = (height(primary)-8*s)/2
                       endfunc
]

'--------------
' MAIN PROGRAM
'--------------
TitleScreen()
scale   = 1
rotate  = 0
do
    'Prepare screen
    set color cBlack; cls
    set color cGreen

    'Draw Sprite
    'Sprite.Transform_Scale(scale)
    Sprite.Transform_Rotate(scale,rotate)
    draw image Sprite.img,Sprite.x,Sprite.y

    'Pause and wait until SPACE BAR is pressed, ESCAPE to quit
    set caret width(primary)/2, height(primary)-20
    center "SPACE BAR"; redraw
    do;wait 1;if keydown(KEY_ESCAPE,true) end;until keydown(KEY_SPACE,true)
    if scale < 10 then
        scale = scale + 1
    else
        scale = 1
    endif
    if rotate < 3 then
        rotate = rotate + 1
    else
        rotate = 0
    endif  

    free image Sprite.img 'free image from memory
loop

'-----------
' FUNCTIONS
'-----------
function Scale(data,s)
    img = createimage(8*s,8*s); set image img
    for y = 0 to 7
        for x = 0 to 7
            if data[y][x] then
                set color cGreen
            else 
                set color cBlack
            endif
            draw rect x*s,y*s,s,s,1
        next
    next
    set image primary; return img
endfunc

function Rotate(data,s,r)
    img = createimage(8*s,8*s); set image img
    for y = 0 to 6
        for x = 0 to 6
            if data[y][x] then
                set color cGreen
            else 
                set color cBlack
            endif
                       
            '(a,b)  = center point of rotation
            '(x,y)  is rotated into (m,n)
            'd      = angle of rotation in radian
            'm      = cos(d)*(x-a)-sin(d)*(y-b)+a
            'n      = sin(d)*(x-a)+cos(d)*(y-b)+b
            a = 3
            b = 3
            d = r*90*(22/7)/180
            m = (round((cos(d)*(x-a))-(sin(d)*(y-b))+a))
            n = (round((sin(d)*(x-a))+(cos(d)*(y-b))+b))
                     
            draw rect m*s,n*s,s,s,1
        next
    next
    set image primary; return img
endfunc

function TitleScreen()
    set caret width(primary)/2,5
    center "Scaling and"
    center "Rotating"
    set caret width(primary)/2, height(primary)-20
    center "Press ENTER"
    redraw
    do;wait 1;until keydown(KEY_RETURN,true)
endfunc

Print this item