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 50 online users.
» 0 Member(s) | 49 Guest(s)
Bing

Latest Threads
S3D : the devil's triangl...
Forum: NaaLaa 7 Questions
Last Post: 1micha.elok
Today, 07:26 AM
» Replies: 9
» Views: 107
Just for the Star Wars fa...
Forum: Everything else
Last Post: johnno56
05-05-2024, 10:40 PM
» Replies: 7
» Views: 142
Convex hull, quick algori...
Forum: NaaLaa 7 Code
Last Post: johnno56
05-04-2024, 07:23 PM
» Replies: 7
» Views: 277
Wolf3D
Forum: NaaLaa 7 Questions
Last Post: johnno56
05-02-2024, 07:57 PM
» Replies: 24
» Views: 1,393
Small pinball game using ...
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
05-02-2024, 01:41 AM
» Replies: 2
» Views: 145
That 3d thing
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
04-30-2024, 02:32 AM
» Replies: 14
» Views: 1,041
Raycaster
Forum: NaaLaa 6 Questions
Last Post: johnno56
04-29-2024, 09:08 AM
» Replies: 5
» Views: 255
The Maze II
Forum: NaaLaa 7 Code
Last Post: Marcus
04-28-2024, 11:53 AM
» Replies: 4
» Views: 333
Wolf3D test
Forum: NaaLaa 7 Code
Last Post: Marcus
04-27-2024, 03:05 PM
» Replies: 3
» Views: 282
The Maze
Forum: NaaLaa 7 Code
Last Post: Marcus
04-24-2024, 06:46 AM
» Replies: 15
» Views: 1,625

 
  HELP. The Mummy in s3d
Posted by: 1micha.elok - 04-18-2024, 12:52 PM - Forum: NaaLaa 7 Questions - Replies (3)

New S3d Library

           
click each image to zoom - in

The mummy is everywhere when I am facing North, South, West etc ... lol .....
Is there a way to put the mummy somewhere in certain coordinate (x,y,z) ?

Code:
'==================================================
' THE MAZE II
' Part 1. Sand Desert
' Part 2. to be
' Part 3. to be
'
' Control :
' SPACE     = move forward
' Mouse     = see around
'
' Reference :
' - s3d.n7 library, ex6_heightmap.n7 by Marcus
'
' Sand texture https://images.app.goo.gl/QwsHZq7hZVdyNXB76
' Mummy1 https://images.app.goo.gl/uiosCKdMHraZPfoC7
' Title https://images.app.goo.gl/AGLmRC8g9vQDg21Q6
'==================================================


'----------------
' INITIALIZATION
'----------------
include "data_maze2/heightmap_library.n7"
include "s3d.n7"; S3D_SetView(primary, rad(90), 0.1, 5)
set window "Maze 2 - Part 1.Sand Desert",400,200,false,3
set mouse off
set redraw off

'color definition
gray         = [128,128,128]
black        = [0,0,0]
white        = [255,255,255]
red          = [255,0,0]
green        = [0,255,0]
darkgreen    = [0,128,0,120]

' Heightmap and Ground
heightmapImg = loadimage("data_maze2/heightmap.png");hm = CreateHeightmap(heightmapImg, 8)
groundImg    = loadimage("data_maze2/ground.png")

' Camera
camX         = 32   ; camY          = 0 ; camZ      = 32 'position
camYaw       = 0    ; camPitch      = 0                  'rotation
camBobAngle  = 0    ; camBobEffect  = 0                  'when the user moves

' Mummy
mummy = []
mummy[1] = []
mummy[1].img = loadimage("data_maze2/mummy1.png")

' misc initial value
dt = 0.003
map = [] 'little map
map.x = width(primary)-100
map.z = height(primary)-80
map.w = width(heightmapImg)
map.h = height(heightmapImg)
map.r = map.w/2        'radius
map.cx = map.x+map.w/2 'center
map.cz = map.z+map.h/2 'center
map.a  = 0             'angle
pos = [] 'player's position
pos.x = 0
pos.y = 0
pos.z = 0

'-----------
' GAME LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
    '----------
    ' control
    '----------
    ' Rotation
    mdx = mouserelx(); mdy = mouserely()
    camYaw = (camYaw + mdx*45*dt)%360 ; camPitch = min(max(camPitch - mdy*45*dt, -60), 60)
    set mouse width(primary)/2, height(primary)/2
   
    ' Movement
    dx = 0; dz = 0
    if keydown(KEY_SPACE)
        dx = dx + sin(rad(camYaw))
        dz = dz + cos(rad(camYaw))
    endif
    if dx or dz
        camBobAngle = camBobAngle + 500*dt          'when the user moves
        k = dt/sqr(dx*dx + dz*dz)
        camX = camX + k*dx                          'position X                 
        camZ = camZ + k*dz                          'position Z
        camBobEffect = min(camBobEffect + 4*dt, 1)  'when the user moves
    endif
    camY = hm.GetY(camX, camZ) - 0.5                'position Y
    pos.x = str(camX,0,1)
    pos.y = str(camY,0,1)
    pos.z = str(camZ,0,1)   
    map.a = 90-camYaw

    '------------
    ' rendering
    '------------
    ' Fill screen with the fog color.
    set color gray; cls

    ' Rendering Process
    S3D_Clear()
    S3D_SetSorting(S3D_BACK_TO_FRONT)
    S3D_SetDepthBuffer(S3D_Z_BUFFER_WRITE)
    S3D_RotateX(rad(-camPitch))
    S3D_RotateY(rad(-camYaw))
    S3D_Translate(-camX, -camY + 0.04*camBobEffect*sin(rad(camBobAngle)), -camZ)
    S3D_Texture(groundImg)
    S3D_Mesh(hm.mesh, 0)
    S3D_Render()
    S3D_RenderFog(gray[0],gray[1],gray[2],false)
       
    ' Just simple draw image
    set color white
    draw image mummy[1].img, 20,20               
       
    '------------
    ' navigation
    '------------
    set color black
        set caret 0,0; wln "Angle "+camYaw 'camYaw = 0 south, 90 east, 180 north, 270 west
        wln "Position "+pos.x+","+pos.y+","+pos.z
    set color darkgreen ; draw ellipse map.cx,map.cz,map.r,map.r,true
    set color green     
        draw ellipse map.cx,map.cz,map.r,map.r
        draw line    map.cx,map.cz,map.cx+map.r*cos(rad(map.a)),map.cz+map.r*sin(rad(map.a))
    set color red       ; draw ellipse (map.x+int(pos.x)),(map.z+int(pos.z)),2,2,true
    set color white     ; draw ellipse (map.x+int(pos.x)),(map.z+int(pos.z)),2,2
        set caret map.cx-18, map.z-13; wln "North" 
        set caret map.cx-18, map.z+map.h; wln "South"
        set caret map.x-35, map.cz-5; wln "West"
        set caret map.x+map.w+5, map.cz-5; wln "East"
   
    redraw
    wait 1
wend



Attached Files
.zip   maze2.zip (Size: 93.07 KB / Downloads: 5)
Print this item

  Circle-line collision
Posted by: Marcus - 04-16-2024, 03:59 PM - Forum: NaaLaa 7 Code - Replies (9)

I wrote a quick test for how collisions between moving objects (player and enemies) and the static walls should work in that 3d thing I'm working on. In the game/engine I will just check for collisions with walls close to the moving objects (a uniform grid will contain information about which walls passes through each cell). But maybe someone may still find this test useful for their own purposes:

Code:
set window "Collision", 640, 480
set redraw off

lines = []
randomize 11
for i = 1 to 8
    ln = [rnd(640), rnd(480), rnd(640), rnd(480)]
    dx = ln[2] - ln[0]; dy = ln[3] - ln[1]
    ln[6] = sqr(dx*dx + dy*dy)
    ln[4] = dx/ln[6]
    ln[5] = dy/ln[6]
    lines[sizeof(lines)] = ln
next

obj = Object(320, 240, 16)

while not keydown(KEY_ESCAPE, true)
    'obj.x = mousex(); obj.y = mousey()
    if keydown(KEY_LEFT)  obj.x = obj.x - 4
    if keydown(KEY_RIGHT)  obj.x = obj.x + 4
    if keydown(KEY_UP)  obj.y = obj.y - 4
    if keydown(KEY_DOWN)  obj.y = obj.y + 4   
    PushOut(obj, lines)
   
    set color 0, 0, 0
    cls
    set color 255, 255, 255
    DrawLines(lines)
    obj.Draw()
   
    set caret width(primary)/2, 0
    center "Use the arrow keys to move the circle around"
   
    redraw
    fwait 60
wend

function DrawLines(lines)
    foreach ln in lines  draw line ln[0], ln[1], ln[2], ln[3]
endfunc

function Object(x, y, r)
    return [x: x, y: y, r: r, rsqr: r*r,
            Draw: function(); draw ellipse .x, .y, .r, .r, false; endfunc]
endfunc

function PushOut(obj, lines)
    ' Let all lines push the object around a maximum of 10 times. This is not a recommended
    ' approach, just for testing.
    tests = 10
    for i = 1 to tests
        col = false
        foreach ln in lines
            dp = max(0, min(ln[6], (obj.x - ln[0])*ln[4] + (obj.y - ln[1])*ln[5]))
            px = ln[0] + dp*ln[4]; py = ln[1] + dp*ln[5]
            dx = obj.x - px; dy = obj.y - py
            d = dx*dx + dy*dy
            if d < obj.rsqr
                k = 1/sqr(d)
                obj.x = px + dx*k*obj.r
                obj.y = py + dy*k*obj.r
                col = true
            endif
        next
        if not col break
    next
endfunc

This is pretty much how I did it in the GLOOM library for n6 too, if my memory is correct (source code since long gone).

Print this item

  Flappy Bird
Posted by: johnno56 - 04-16-2024, 12:17 PM - Forum: NaaLaa 7 Code - Replies (4)

This is a project I started back on 19th October 2016 using SDLBasic...
Over the years it has been ported to QB64 and RCBasic (Jan 2022)

The game is simple. Left Mouse Button or Space to flap. Fly through the "gaps" in the pipes. Each pipe passed is one point. Warning: The game will speed up gradually (usually after every 5 pipes) to a maximum speed of "8"....


.zip   flappy.zip (Size: 95.22 KB / Downloads: 5)

Be careful... index finger fatigue warning!

(ps: Had to mute the "flapping" sound... so annoying... needs a type of timer mod...)

Print this item

  Pixeli Lander Test
Posted by: johnno56 - 04-15-2024, 12:48 AM - Forum: NaaLaa 7 Code - Replies (5)

Ok. This is a VERY crude Lander test. It uses "pixeli()" for collision with the Landing Pad and normal AABB for the ground...

I would appreciate an examination of how I have implemented the pixeli command and suggest any and all corrections.

Note: The ship can land from beneath the pad... Not an error. The landing pad (except for a concept level) is always on the ground.

The usual controls: Arrow keys.
Note: BOTH landing struts MUST contact the pad.
Watch your landing velocity.


.zip   pixelTest.zip (Size: 70.7 KB / Downloads: 5)

Print this item

  n7 version 24.04.14 released
Posted by: Marcus - 04-14-2024, 10:28 AM - Forum: Announcements - Replies (2)

You can now use 'pixeli(x, y)' or 'pixeli(image_id, x, y)' to get the color of an image's pixel as a single number. You can also use 'set colori' to set the current drawing color using such a number.

If you need to convert RGB or RGBA values to a single number color, you can use functions like these:

Code:
function ToRGB(r, g, b)
    return 255*16777216 + r*65536 + g*256 + b
endfunc

function ToRGBA(r, g, b, a)
    return a*16777216 + r*65536 + g*256 + b
endfunc
 
And to get the RGBA components of a single number color:

Code:
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

2024-04-14
Added the 'pixeli' function and 'set colori' command to get and set colors as single numbers

Print this item

  Pixel Color Test
Posted by: johnno56 - 04-11-2024, 08:27 PM - Forum: NaaLaa 7 Questions - Replies (5)

Marcus,

I am still confused in regards to "how" the pixel() command works.

Are you able to explain the output produced? (see attached image)

   

Regards

J

Print this item

  pursuing object
Posted by: aliensoldier - 04-11-2024, 01:51 PM - Forum: NaaLaa 7 Questions - Replies (3)

A question, if I have two objects and one is the player who can move with the keys and the other is the enemy who is stationary in one place on the screen.

The question would be how can I make it so that when the player is close to the enemy he starts chasing the player and if the player moves away the enemy stops chasing him and returns to the starting position.

Print this item

  N6 Lander
Posted by: johnno56 - 04-09-2024, 10:52 PM - Forum: NaaLaa 7 Code - Replies (3)

With all this discussion about Lunar Lander stuff, why not go back to the source, and recreate the original N6 Lander using N7?

Warning: Docking can be a little flaky and keep your eye on that fuel level...


.zip   landerN6.zip (Size: 6.76 KB / Downloads: 6)

ps: Look familiar, Marcus? Wink

Print this item

  The Maze
Posted by: 1micha.elok - 04-09-2024, 09:50 AM - Forum: NaaLaa 7 Code - Replies (15)

THE MAZE
I'm still working on the game, and soon it will be released
Herewith some preview snapshots :

           
click the image to zoom in

Big Grin Big Grin Big Grin

Print this item

  Pixel Collision
Posted by: johnno56 - 04-09-2024, 09:08 AM - Forum: NaaLaa 7 Questions - Replies (11)

I figured that I might try some 'old school' collision detection...

The concept is... A falling box. An area to land on. Using the 'pixel()' command, instruct the box to stop, as it "hits" the ground.

In this example, I am testing the pixel below the box's left bottom edge. (I have placed a reference pixel under the box at the same "y" co-ordinate.)

Press SPACE to drop...

Code:
' Open a window and enable double buffering.
set window "Pixel Collision", 640, 480
set redraw off

visible Box = [255, 255, 0, 64]
visible BoxW = 32
visible BoxH = 48
visible BoxX = (width(primary) - BoxW) / 2
visible BoxY = 0
visible vSpeed = 0
visible drop = false

visible ground = [0, 255, 0]

do

    set color 0, 0, 0
    cls
   
    Update()
    Draw()
   
    redraw
    fwait 30
   
until keydown(KEY_ESCAPE, true)

function Update()
    '   vSpeed
    if keydown(KEY_SPACE, true)     drop = true
    if drop = true  vSpeed = vSpeed + 0.03
   
    '   Box
    BoxY = BoxY + vSpeed
   
    '   Pixel Collision
    if pixel(BoxX, BoxY + BoxH) = ground
        vSpeed = 0
    endif
   
    '   Just in case 'pixel' fails... lol
    if BoxY > height(primary)
        vSpeed = 0
        wait 1000
        end
    endif
endfunc

function Draw()
    '   Ground
    set color ground
    draw rect 0, 460, 640, 20, 0
   
    '   Box
    set color Box
    draw rect BoxX, BoxY, BoxW, BoxH, 0
   
    '   Pixel
   
    '   This indicator pixel is drawn one pixel below the box center.
    '   The actual pixel being tested is below the left corner of the box.
    set color 255, 0, 255
    draw pixel BoxX + 15, BoxY + BoxH
endfunc

Unfortunately this did not work... "Read the manual", I hear you say... "pixel(x,y) Returns the color at position (x, y) as an array [r, g, b, a] with RGBA intensities in the range [0 .. 255].

I am hoping that my programing skills are the source of the problem otherwise this maybe another "can of worms".... sorry...

Print this item