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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 36
» Latest member: bul71
» Forum threads: 169
» Forum posts: 1,360

Full Statistics

Online Users
There are currently 101 online users.
» 0 Member(s) | 99 Guest(s)
Bing, Google

Latest Threads
nPixel
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
8 hours ago
» Replies: 10
» Views: 776
The Shadow Master
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
Yesterday, 07:08 AM
» Replies: 4
» Views: 120
N7 version 25.02.16 relea...
Forum: Announcements
Last Post: 1micha.elok
Yesterday, 01:55 AM
» Replies: 2
» Views: 48
Suggestion: support dynam...
Forum: Suggestions
Last Post: Marcus
02-15-2025, 05:23 PM
» Replies: 8
» Views: 1,053
N7 version 25.02.15 relea...
Forum: Announcements
Last Post: 1micha.elok
02-15-2025, 10:54 AM
» Replies: 1
» Views: 50
Ask help to fix errors (g...
Forum: NaaLaa 7 Questions
Last Post: 1micha.elok
02-15-2025, 09:35 AM
» Replies: 7
» Views: 422
3D Breakout, just a quick...
Forum: NaaLaa 7 Code
Last Post: Marcus
02-02-2025, 07:42 AM
» Replies: 6
» Views: 483
Render on an image before...
Forum: NaaLaa 6 Questions
Last Post: Marcus
01-27-2025, 03:56 PM
» Replies: 4
» Views: 366
Repurposed Sprite Editor
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
01-27-2025, 11:58 AM
» Replies: 13
» Views: 1,067
Alien Breed 3D II: The Ki...
Forum: Everything else
Last Post: Marcus
01-26-2025, 07:58 AM
» Replies: 2
» Views: 310

 
  "A Game Jam is Coming Up"
Posted by: luwal - 05-18-2024, 03:49 PM - Forum: Programming - Replies (28)

Ha........I read an introduction post about a game jam in another forum. Maybe some members of our user community will be interested in creating a creative game for the jam. Big Grin  
https://forum.thegamecreators.com/thread/229610

Print this item

  Scrolling
Posted by: johnno56 - 05-15-2024, 07:37 AM - Forum: NaaLaa 7 Questions - Replies (3)

If one were to say, create a side scrolling Mario-type game that has a level much wider than the desktop, would there be such an example or tutorial on how to use the tilemap library to control the camera and scrolling? Just in case one were to consider such a project...

All I have is the Tilemap Editor PDF file as reference... No rush...

Print this item

  Enchanted Forest
Posted by: 1micha.elok - 05-14-2024, 04:16 AM - Forum: NaaLaa 7 Code - Replies (8)

ENCHANTED FOREST
Explore the enchanted forest with your own character, Barbarian or Knight.
And rearrange the forest as you like.

UPDATE Enchanted Forest v3
           
click each image to zoom in
1. Introduction Scene
2. Reset your character position
3. Closing Credits Scene

Code:
'==========================================================================
'THE ENCHANTED FOREST v.3
'Explore the enchanted forest with your own character, Barbarian or Knight.
'And rearrange the forest as you like.
'
'Need to be improved :
'- Position of the character relative to the objects
'- Collision detection between the character and the objects
'- Boundary of the screen
'
'Acknowledgment
's3d library - by Marcus
'KayKit - Adventurers by Kay Lousberg
'   https://kaylousberg.itch.io/kaykit-adventurers?download
'Trees Asset Pack by Aumarka
'   https://mark-auman.itch.io/low-poly-trees-asset-pack
'==========================================================================


'----------------
' INITIALIZATION
'----------------
'#win32
include "s3d.n7"; S3D_SetView(primary, rad(45), 0.1, 50)
include "data/s3d_addon.n7"

set window "The Enchanted Forest",1000,600,false
set redraw off
randomize clock()

'color definition
white   = [255,255,255]
black   = [40,42,54]
gray    = [200,200,200]
red     = [255,0,0]

'characters
character = []
character[0]        = []
character[1]        = []
character[0].model  = S3D_LoadMesh("data/Barbarian.obj", 0.7,-0.7,0.7, false)
character[1].model  = S3D_LoadMesh("data/Knight.obj", 0.7,-0.7,0.7, false)
character[0].name   = "Barbarian"
character[1].name   = "Knight"
character.rotate    = 0
character.rotype    = 2
character.x         = 3.8
character.y         = 2.8
character.z         = 7

'objects
object = []
object.number = 5
object.rotate = 0
object.rotype = 2
for j = 1 to object.number
    object[j] = []
    object[j].model = S3D_LoadMesh("data/Tree_Bare.obj", 0.01,-0.01,0.01, false)
    object[j].x = rnd(-5,2) ; object[j].y = rnd(1,2) ; object[j].z = rnd(5,15)
next


'------------
' DISCLAIMER
'------------
set color black; cls; set color white; set caret 50,50; set font 0
wln "DISCLAIMER"
wln                                                       
wln "This tiny game is a work of fiction."
wln "It is for eductional purpose only. "
wln "It is as a proof of 3D game concept using s3d library."                        
wln "It is not intended for commercial use and not for sale"                      
wln "No person or entity associated with this game received payment"   
wln "or anything of value, or entered into any agreement,"             
wln "in connection with any game assets used in this game."
wln 
wln "All trademarks and game assets are the property of their respective owners." 
wln "While every effort is made to acknowledge their works,"
wln "some of the game assets used in in this tiny game may not have"
wln "clear name of the artists/author/creator/developer to be referred with."
wln "It may not include all relevant facts or the most up-to-date information."
wln       
wln "Names, characters, places, events and incidents"
wln "are either the products of the author’s imagination"
wln "or used in a fictitious manner."
wln "Any resemblance to actual persons,"
wln "living or dead, or actual events is purely coincidental."
wln
wln "Press ENTER to continue"
redraw
do; wait 1; until keydown(KEY_RETURN,true)


'--------------
' INTRODUCTION
'--------------
i = 0
character.x         = 0
character.y         = 0
character.z         = 0
character.rotate    = 200
do     
    set color black; cls; set color white; S3D_Clear()
   
    'choose your character
    if keydown(KEY_C,true) then
        i = (i+1)%2
    endif

    'character.rotate -90=West, 90=East, 0=North, 180=South
    if keydown(KEY_LEFT) then
        character.rotate = (character.rotate+10)%360
    elseif keydown(KEY_RIGHT) then
        character.rotate = (character.rotate-10)%360
    endif
   
    S3D_Translate(0, 1, 3)
    S3D_Draw(character.x,character.y,character.z,character.rotype,character.rotate,character[i].model)
   
    'information
    set color white; set caret 10,10
    wln "===================="
    wln "INTRODUCTION"
    wln character[i].name
    wln "===================="
    wln
    wln "Instructions :"
    wln "LEFT, RIGHT  to rotate your character"   
    wln "C            to change your character"
    wln "ESCAPE       to quit this introduction"

    redraw
    fwait 10
until keydown(KEY_ESCAPE,true)


'-----------
' MAIN LOOP
'-----------
i = 0; j=1
character.x         = 2
character.y         = 2
character.z         = 5
character.rotate    = 210
do     
    set color black; cls; set color white; S3D_Clear()
   
    'choose your character
    if keydown(KEY_C,true) then
        i = (i+1)%2       
    endif
   
    'randomize objects
    if keydown(KEY_R,true) then
        for j = 1 to object.number
            object[j] = []
            object[j].model = S3D_LoadMesh("data/Tree_Bare.obj", 0.01,-0.01,0.01, false)
            object[j].x = rnd(-5,2) ; object[j].y = rnd(0,2)+1 ; object[j].z = rnd(5,15)
        next
    endif
   
    'show up your character if he is out of screen
    if keydown(KEY_U,true) then
        character.x         = 2
        character.y         = 2
        character.z         = 5
        character.rotate    = 210   
    endif
   
    'character.rotate -90=West, 90=East, 0=North, 180=South
    if keydown(KEY_LEFT,true) then
        character.rotate = (character.rotate+30)%360
    elseif keydown(KEY_RIGHT,true) then
        character.rotate = (character.rotate-30)%360
    endif
   
    if keydown(KEY_UP,true) then
        if character.rotate = 0 then
            character.z = character.z + 0.1
        elseif character.rotate = 90 then
            character.x = character.x + 0.1
        elseif character.rotate = 180 then
            character.z = character.z - 0.1
        elseif character.rotate = 270 then
            character.x = character.x - 0.1
        elseif character.rotate > 0 and character.rotate < 90 then
            character.x = character.x + 1.2*cos(rad(character.rotate))
            character.z = character.z + 1.2*sin(rad(character.rotate))
        elseif character.rotate > 90 and character.rotate < 180 then
            character.x = character.x - 1.2*cos(rad(character.rotate))
            character.z = character.z - 1.2*sin(rad(character.rotate))
        elseif character.rotate > 180 and character.rotate < 270 then
            character.x = character.x + 1.2*cos(rad(character.rotate))
            character.z = character.z + 1.2*sin(rad(character.rotate))    
        elseif character.rotate > 270 and character.rotate < 360 then
            character.x = character.x - 1.2*cos(rad(character.rotate))
            character.z = character.z - 1.2*sin(rad(character.rotate))              
        endif
       
        'boundary
        if character.z > 20 then character.z = character.z - 0.5
        if character.z < 2.8 then character.z = character.z + 0.5
    endif

    'object animation
    object.rotate = object.rotate + 0.2
     
    'lines
    set color gray ;  cx = width(primary)/2 ; cy = height(primary)/2
    for a = 1 to 50 step 0.15  draw line 0,cy+pow(a,7),cx*2,cy+pow(a,7)
    for b = -1000 to cx*2+1000 step 230  draw line cx,cy/2,b,cy*2
    set color black; draw rect 0,0,cx*2,cy+2,1
     
    'Draw Objects and Character
    for j = 1 to object.number 
        S3D_Draw(object[j].x,object[j].y,object[j].z,object.rotype,object.rotate,object[j].model)
        set color white
        set caret width(primary)-100,30; wln "Objects";wln "Coordinates"
        set caret width(primary)-100,60+j*20
        wln j+":"+object[j].x+","+object[j].y+","+object[j].z
    next
    S3D_Draw(character.x,character.y,character.z,character.rotype,character.rotate,character[i].model)
       
    'information
    set color white; set caret 10,10
    wln "===================="
    wln "The Enchanted Forest"
    wln "===================="
    wln
    wln "Instructions :"
    wln "ESC          to quit"
    wln "R            to re-arrange objects"
    wln "LEFT, RIGHT  to rotate your character"
    wln "UP           to move forward"
    wln "C            to change your character"
    wln "U            to reset your position"
    wln  
    set caret width(primary)-300,30
    wln "You are a "+character[i].name
    wln
    wln "Your Coordinates"  
    wln int(character.x)+","+int(character.y)+","+int(character.z)
    wln
    wln "Compass "+character.rotate+ " degrees"
    x1 = width(primary)-240
    y1 = 190
    x2 = x1 + 50*cos(rad(270+character.rotate))
    y2 = y1 + 50*sin(rad(270+character.rotate))
    draw ellipse x1,y1,50,50
    draw line x1,y1,x2,y2    
      
    redraw
    wait 1
until keydown(KEY_ESCAPE,true)


'-----------------
' Closing Credits
'-----------------
words = []
words[1] = "CLOSING CREDITS"
words[2] = ""   
words[3] = ""
words[4] = "A special thanks to Marcus, the creator of Naalaa" 
words[5] = "for his dedication, support and encouragement"
words[6] = "in the making of this tiny game."
words[7] = ""
words[8] = "I really appreciate his stepping in"
words[9] = "to develop the fantastic s3d library"
words[10] = "I know he had to put in extra hours"
words[11] = "to catch up on his own work, so thank you very much."
words[12] = "Your expertise was vital for this tiny game."
words[13] = ""
words[14] = "Heartfelt thanks to all the talented artists"
words[15] = "who created the amazing 3D game assets"
words[16] = "I couldn't have made it without them"
words[17] = ""
words[18] = ""
words[19] = ""
words[20] = "s3d library - by Marcus"
words[21] = ""
words[22] = "KayKit - Adventurers by Kay Lousberg"
words[23] = "   https://kaylousberg.itch.io/kaykit-adventurers?download"
words[24] = ""
words[25] = "Trees Asset Pack by Aumarka"
words[26] = "   https://mark-auman.itch.io/low-poly-trees-asset-pack"                                                  

'text animation of the closing credits
for i = height(primary)-30 to 30
    set color black; cls; set color white
    set caret width(primary)/2,i
    for j = 1 to 26
        center words[j]
    next
    redraw
    fwait 40
next
do; wait 1; until keydown(KEY_RETURN,true)



Attached Files
.zip   Enchanted Forest.zip (Size: 460.22 KB / Downloads: 5)
.zip   Enchanted Forest_v3.zip (Size: 460.92 KB / Downloads: 4)
Print this item

  Devil's Triangle (The Game)
Posted by: 1micha.elok - 05-10-2024, 09:05 AM - Forum: NaaLaa 7 Code - Replies (1)

THE DEVIL'S TRIANGLE v3

Stages :
   
the bacground was moving from right to left
Stage 1. Dangerous Mission

       
click each image to zoom in
Yoke to left to shoot
Yoke to center to shoot
the background was moving toward you
Stage 2. Devil's Shadow

Update
There are some updates, mainly on Stage 2.
You may download [ devil_triangle_v3.zip ]

Code:
'==============================================================================================
'THE DEVIL'S TRIANGLE v3
'Stage 1. Dangerous Mission
'Stage 2. Devil's Shadow
'
'Control Keys :
'- UP, DOWN         move the plane      (stage 1)
'- UP, LEFT,RIGHT   move the jet's yoke (stage 2)
'- SPACE BAR        shoot               (stage 2)
'- ESC              quit
'- M                ON/OFF music
'- ENTER            continue
'
'Acknowledgement :
'- s3d library, thanx to Marcus for push and pop transformation
'
'3D Model :
'- Voxel Plane by maxparata https://maxparata.itch.io/voxel-plane?download
'- Ball by @Spacemonkeyl_1458647 https://www.printables.com/model/651543-low-poly-ball/files
'
'Images and Sound :
'- Background image https://images.app.goo.gl/J2SdZoV6YyNRPXBM6
'- Cool Slow Rock by Nick Valerson https://pixabay.com/music/search/rock%20background%20music/
'- Fighter Jet Cockpit https://images.app.goo.gl/ouzXGwgNkwcMgCkc7
'- Yoke steering wheel https://images.app.goo.gl/2k42XiBYfLt2Nfk16
'- Skull island https://images.app.goo.gl/qBy2hv1UtFmnRXV98
'
'DISCLAIMER                                                       
'This tiny game is a work of fiction.
'It is a proof of 3D game concept using s3d library.                        
'It is not intended for commercial use and not for sale                      
'No person or entity associated with this game received payment   
'or anything of value, or entered into any agreement,             
'in connection with any game assets used in this game.           
'Names, characters, places, events and incidents
'are either the products of the author’s imagination
'or used in a fictitious manner.
'Any resemblance to actual persons,
'living or dead, or actual events is purely coincidental.
'
'===============================================================================================


'----------------
' INITIALIZATION
'----------------
#win32
include "s3d.n7"; S3D_SetView(primary, rad(45), 0.1, 50)
include "plane/s3d_addon.n7"
include "plane/transform.n7"

set window "The Devil's Triangle",800,400,false
set redraw off
randomize clock()

'color definition
white   = [255,255,255]
black   = [0,0,0]
gray    = [200,200,200]
red     = [255,0,0,100]
yellow  = [255,255,0,120]

'plane
plane = []
plane.model = S3D_LoadMesh("plane/Plane01.obj", 0.5,-0.5,0.5, false)
plane.rotate = 30
plane.rotype = 1
plane.x = -5 ; plane.y = 0 ; plane.z = 0
plane.music_ = loadmusic("plane/rock.wav")
plane.unmute   = true

'explosion
explosion = []
explosion.model = S3D_LoadMesh("plane/explosion.obj",1,-1,1,false)
explosion.rotate = 0
explosion.rotype = 0
explosion.x = -5; explosion.y = 0 ; explosion.z = 0

'ball
ball = []
ball.count = 3
for i = 1 to ball.count
    ball[i] = []
    ball[i].model = S3D_LoadMesh("plane/icoball.obj",0.25,-0.25,0.25,false)
    ball[i].rotate = 0
    ball[i].rotype = 2
    ball[i].x = rnd(7,10)
    ball[i].y = rnd(-4,4)
    ball[i].z = 0
    ball[i].speed = rnd(3,5)/100
next

'background
back = []
back.sea = loadimage("plane/background.png")
back.x = 0 ; back.y = 0

'other initial value
info = []
info.score = 0
info.lifes = 5
info.font_ = loadfont("plane/meiryo24")


'------------
' DISCLAIMER
'------------
set color black; cls; set color white; set caret 50,50; set font 0
wln "DISCLAIMER"
wln                                                       
wln "This tiny game is a work of fiction."
wln "It is a proof of 3D game concept using s3d library."                        
wln "It is not intended for commercial use and not for sale"                      
wln "No person or entity associated with this game received payment"   
wln "or anything of value, or entered into any agreement,"             
wln "in connection with any game assets used in this game."           
wln "Names, characters, places, events and incidents"
wln "are either the products of the author’s imagination"
wln "or used in a fictitious manner."
wln "Any resemblance to actual persons,"
wln "living or dead, or actual events is purely coincidental."
wln
wln "Press ENTER to continue"
redraw
do; wait 1; until keydown(KEY_RETURN,true)


'opening title
words = []
words[1]  ="THE DEVIL'S TRIANGLE"
words[2]  =""
words[3]  ="In December 1945, Flight 19 - Avenger Torpedo Bombers"
words[4]  ="disappeared over the Bermuda Triangle."
words[5]  ="The Bermuda Triangle is known as The Devil's Triangle"
words[6]  ="It is on an area bounded by Florida,Bermuda and Puerto Rico."
words[7]  ="And now, you are assigned to investigate the area."
words[8]  ="Beware, it is a dangerous area !"
words[9]  =""
words[10] =""
words[11] =""
words[12] =""
words[13] =""
words[14] ="Please proceed to military airbase"


'--------
' TITLE
'--------
'text animation of opening title
set font info.font_
play music plane.music_,1 'loop
set music volume plane.music_, 0.25
for i = height(primary) to 30
    set color black; cls; set color white
    set caret width(primary)/2,i
    for j = 1 to 14
        center words[j]
    next
    redraw
    fwait 30
next

'just an animation of 3D plane
plane.y = 2
do     
    set color black; cls; set color white; S3D_Clear()
    set caret width(primary)/2,i
    for j = 1 to 14
        center words[j]
    next
    S3D_Translate(-1, 0, 5)
    if plane.x < 7 then
        plane.x = plane.x + 0.03
    else
        plane.x = -2
        plane.y = rnd(0,2)
        plane.rotype = 1
    endif
    plane.y = plane.y - 0.003
    plane.rotate = (plane.rotate + 30*0.005)%360
    S3D_Draw(plane.x,plane.y,plane.z,plane.rotype,plane.rotate,plane.model) 
   
    redraw
    wait 1
until keydown(KEY_RETURN,true)

'reset to initial value
plane.rotate = 30
plane.rotype = 1
plane.x = -5
plane.y = 0
plane.z = 0
info.message =""


'----------------------------
' STAGE 1. DANGEROUS MISSION
'----------------------------
set color black; cls; set color white
set caret 50,50
wln "Stage 1 : DANGEROUS JOURNEY"
wln
wln "Press UP or DOWN continuously"
wln "Just avoid bombs as long as possible"
wln "Till you reach the devil's island"
wln
wln "Press ENTER to continue"
redraw
do;wait 1; until keydown(KEY_RETURN,true)

do
    set color black; cls; set color white; S3D_Clear()
   
    if keydown(KEY_ESCAPE,true) then end
   
    'background music
    if keydown(KEY_M,true)
        plane.unmute = not plane.unmute
        if plane.unmute then
            play music plane.music_,1
            set music volume plane.music_, 0.5
        else
            stop music plane.music_
        endif
    endif
   
    'background image
    draw image back.sea,back.x,back.y
    draw image back.sea,back.x + width(primary),back.y
    if back.x <= -width(primary) then
        back.x = 0
    else   
        back.x = back.x - 1.3
    endif

    'information
    set color white
    set caret 5,10
    if plane.unmute then
        wln "Background Music : ON"
    else
        wln "Background Music : OFF"
    endif
    wln "Score : "+int(info.score) ; info.score = info.score + 0.01 

    if info.lifes <0 then
        do 
            set caret 5,height(primary)-50; wln "Insert COIN to continue (Y/N)";redraw
            if keydown(KEY_N,true) then end
            if keydown(KEY_Y,true) then info.lifes = 5
            wait 2
        until info.lifes = 5
    endif 
    wln "Lifes : "+info.lifes
   
    'x-axis, y-axis
    'set color gray
    'cx = width(primary)/2
    'cy = height(primary)/2
    'draw line cx,0,cx,cy*2
    'draw line 0,cy,cx*2,cy

    'plane control   
    if keydown(KEY_UP,true) then
        if plane.y > -5 then
            plane.y = plane.y - 0.08
            plane.rotate = (plane.rotate + 90*0.03)%360
        endif       
    endif       
    if keydown(KEY_DOWN,true) then
        if plane.y < 5 then
            plane.y = plane.y + 0.08
            plane.rotate = (plane.rotate - 90*0.03)%360
        endif
    endif
    if plane.y <= -5 then plane.y = 4
    if plane.y >= 5 then plane.y = -4
   
    ' Move everything 10 units into the screen, it affect all other drawing
    S3D_Translate(0, 0, 10)
    S3D_Draw(plane.x,plane.y,plane.z,plane.rotype,plane.rotate,plane.model)   
   
    'Ball
    for i = 1 to ball.count
        ball[i].rotate = (ball[i].rotate + 30*0.03)%360
        if ball[i].x >= -10 then
            ball[i].x = ball[i].x - ball[i].speed
        else
            ball[i].x = rnd(7,10)
            ball[i].y = rnd(-4,4)
            ball[i].speed = rnd(3,5)/100
        endif
        S3D_Draw(ball[i].x,ball[i].y,ball[i].z,ball[i].rotype,ball[i].rotate,ball[i].model)

        'Explosion
        dbp = sqr(pow((ball[i].x-plane.x),2)+pow((ball[i].y-plane.y),2))
        if dbp<=1  then
            temp = ball[i].x
            for j = 1 to ball.count
                ball[j].x = rnd(7,10) 'reset position
            next 
            set caret 5,height(primary)-50; wln "Press ENTER to continue"
            S3D_Draw(temp,plane.y,explosion.z,explosion.rotype, explosion.rotate,explosion.model)
            redraw
            do; wait 1; until keydown(KEY_RETURN,true)
            info.lifes = info.lifes - 1
        endif       
    next
   
    redraw
    wait 1
until info.score >= 50

set caret 5,height(primary)-60
wln "Be ready for Stage 2"
wln "Press ENTER to continue"
redraw
do; wait 1; until keydown(KEY_RETURN,true)


'----------------------------
' STAGE 2. DEVIL'S SHADOW
'----------------------------
set color black; cls; set color white
set caret 50,50;
wln "Stage 2 : DEVIL'S SHADOW"
wln
wln "There are 3 possible enemy's positions"
wln "  enemy on the left,   LEFT  then shoot with SPACE BAR"
wln "  enemy at the center, UP    then shoot with SPACE BAR"
wln "  enemy on the right,  RIGHT then shoot with SPACE BAR"
wln
wln "Shoot when an enemy is close enough"
wln "but not too close"
wln
wln
wln
wln "Press ENTER to continue"
redraw
do;wait 1; until keydown(KEY_RETURN,true)

'background image of stage 2
back.island = loadimage("plane/island.png")
back.scale = 1.2

'info
info.score = 0
info.status = ""
info.lifes = 3
info.shot = ""

'translate
translate = []
translate.x = 0

'jet
jet = []
jet.cockpit = loadimage("plane/cockpit.png")
jet.yoke = loadimage("plane/yoke.png")
jet.angle = 0
jet.position =""

'plane
plane.x1 = rnd(-3,3)
plane.x2 = rnd(-3,3)
plane.x3 = rnd(-3,3)
plane.y1 = rnd(-2,0)
plane.y2 = rnd(-2,0)
plane.y3 = rnd(-2,0)
plane.z1 = rnd(10,30)
plane.z2 = rnd(10,30)
plane.z3 = rnd(10,30)
plane.rotype = 2
plane.rotate = 90
plane.position1 =""
plane.position2 =""
plane.position3 =""

do
    set color black; cls; set color white; S3D_Clear()

    if keydown(KEY_ESCAPE,true) then end
      
    'background music
    if keydown(KEY_M,true)
        plane.unmute = not plane.unmute
        if plane.unmute then
            play music plane.music_,1
            set music volume plane.music_, 0.5
        else
            stop music plane.music_
        endif
    endif

    'control
    if keydown(KEY_RIGHT,true) then
        jet.angle = rad(15)
        jet.position = "right"
    elseif keydown(KEY_LEFT,true) then
        jet.angle = rad(-15)
        jet.position = "left"
    elseif keydown(KEY_UP,true) then
        jet.angle = rad(0)
        jet.position = "center"
    endif               

    'enemy's plane
    if plane.x1 = 0 then
        plane.position1 = "center"
    elseif plane.x1 > 0 then
        plane.position1 = "right"
    elseif plane.x1 < 0 then
        plane.position1 = "left"
    else
        plane.position1 = ""
    endif

    if plane.x2 = 0 then
        plane.position2 = "center"
    elseif plane.x2 > 0 then
        plane.position2 = "right"
    elseif plane.x2 < 0 then
        plane.position2 = "left"
    else
        plane.position2 = ""
    endif

    if plane.x3 = 0 then
        plane.position3 = "center"
    elseif plane.x3 > 0 then
        plane.position3 = "right"
    elseif plane.x3 < 0 then
        plane.position3 = "left"
    else
        plane.position3 = ""
    endif
                                     
    'enemy's plane animation
    S3D_Translate(translate.x, 0, 10)
    if plane.z1 >= -7 then
        plane.z1 = plane.z1 -0.1
        info.status =""
    elseif plane.z1 < -7 then
        plane.x1 = rnd(-3,3)
        plane.y1 = rnd(-2,0)
        plane.z1 = 10
        info.lifes = info.lifes - 1
        set color red
        draw rect 0,0,width(primary),height(primary),1
        set color white
        set caret 10,10
        wln "You've been attacked !"
        wln "You lost your life"
        wln
        wln "Press ENTER to continue"       
        redraw
        do; wait 1 ; until keydown(KEY_RETURN,true)
    endif
    if (plane.z1 >-7 and plane.z1<-3) then
        info.status = "SHOOT NOW !!!!"
        tempx1 = plane.x1
        tempy1 = plane.y1
        tempz1 = plane.z1       
        if keydown(KEY_SPACE,true) and jet.position = plane.position1 then
            info.score = info.score + 1
            plane.x1 = rnd(-3,3)
            plane.y1 = rnd(-2,0)
            plane.z1 = 10                   
            info.shot = "plane1"      
        endif
    else
       info.status = ""
    endif 

    if plane.z2 >= -7 then
        plane.z2 = plane.z2 -0.1
        info.status =""
    elseif plane.z2 < -7 then
        plane.x2 = rnd(-3,3)
        plane.y2 = rnd(-2,0)
        plane.z2 = 20
        info.lifes = info.lifes - 1
        set color red
        draw rect 0,0,width(primary),height(primary),1
        set color white
        set caret 10,10
        wln "You've been attacked !"
        wln "You lost your life"
        wln
        wln "Press ENTER to continue"       
        redraw
        do; wait 1 ; until keydown(KEY_RETURN,true)
    endif
    if (plane.z2 >-7 and plane.z2<-3) then
        info.status = "SHOOT NOW !!!!"
        tempx2 = plane.x2
        tempy2 = plane.y2
        tempz2 = plane.z2
        if keydown(KEY_SPACE,true) and jet.position = plane.position2 then
            info.score = info.score + 1
            plane.x2 = rnd(-3,3)
            plane.y2 = rnd(-2,0)
            plane.z2 = 20
            info.shot = "plane2"       
        endif
    else
       info.status = ""
    endif
   
    if plane.z3 >= -7 then
        plane.z3 = plane.z3 -0.1
        info.status =""
    elseif plane.z3 < -7 then
        plane.x3 = rnd(-3,3)
        plane.y3 = rnd(-2,0)
        plane.z3 = 30
        info.lifes = info.lifes - 1
        set color red
        draw rect 0,0,width(primary),height(primary),1
        set color white
        set caret 10,10
        wln "You've been attacked !"
        wln "You lost your life"
        wln
        wln "Press ENTER to continue"       
        redraw
        do; wait 1 ; until keydown(KEY_RETURN,true)
    endif
    if (plane.z3 >-7 and plane.z3<-3) then
        info.status = "SHOOT NOW !!!!"
        tempx3 = plane.x3
        tempy3 = plane.y3
        tempz3 = plane.z3
        if keydown(KEY_SPACE,true) and jet.position = plane.position3 then
            info.score = info.score + 1
            plane.x3 = rnd(-3,3)
            plane.y3 = rnd(-2,0)
            plane.z3 = 10
            info.shot = "plane3"       
        endif
    else
       info.status = ""
    endif 
                             
    'background animation
    back.scale = back.scale + 0.002      
           
    'Draw and Render      
    Draw(back.island,width(back.island)/2,height(back.island)/2-20,back.scale,jet.angle)
    S3D_Draw(plane.x1,plane.y1,plane.z1,plane.rotype,plane.rotate,plane.model)         
    S3D_Draw(plane.x2,plane.y2,plane.z2,plane.rotype,plane.rotate,plane.model)
    S3D_Draw(plane.x3,plane.y3,plane.z3,plane.rotype,plane.rotate,plane.model); S3D_Render()
    if info.shot = "plane1" then
        S3D_Draw(tempx1,tempy1,tempz1,0,0,explosion.model)
    elseif info.shot = "plane2" then
        S3D_Draw(tempx2,tempy2,tempz2,0,0,explosion.model)
    elseif info.shot = "plane3" then
        S3D_Draw(tempx3,tempy3,tempz3,0,0,explosion.model)
    endif
    Draw(jet.cockpit,width(primary)/2+10,230,1.6,jet.angle)
    Draw(jet.yoke,width(primary)/2+10,360,1,jet.angle)   
   
    'information
    set color white
    set caret 5,10
    if plane.unmute then
        wln "Background Music : ON"
    else
        wln "Background Music : OFF"
    endif
    wln "Score   : "+int(info.score)
    wln "Lifes   : "+info.lifes
    wln
    wln info.status
    if info.shot="plane1" or info.shot="plane2" or info.shot="plane3" then
        wln "Press ENTER to continue"
        redraw
        do; wait 1; until keydown(KEY_RETURN,true)
        info.shot = ""
    endif
    if info.lifes <0 then
        do 
            set caret 5,height(primary)-50; wln "Insert COIN to continue (Y/N)";redraw
            if keydown(KEY_N,true) then end
            if keydown(KEY_Y,true) then info.lifes = 3
            wait 2
        until info.lifes = 3
    endif 

    redraw
    wait 1
until info.score > 20

set caret 5,height(primary)-150
wln "Even though you've gone so far"
wln "The mystery is still unsolved"
wln "..."
wln
wln "Press ESCAPE to quit"
redraw
do; wait 1; until keydown(KEY_RETURN,true)



Attached Files
.zip   devil triangle_v2.zip (Size: 1.5 MB / Downloads: 8)
.zip   devil_triangle_v3.zip (Size: 1.5 MB / Downloads: 3)
Print this item

  S3D : the devil's triangle
Posted by: 1micha.elok - 05-05-2024, 02:12 PM - Forum: NaaLaa 7 Questions - Replies (9)

The Devil's Triangle

           
click each image to zoom in

Question #1
As you may see in the images above, I found a strange thing with the movement of the pyramid.
When I pressed UP or DOWN, the pyramid followed the plane direction.
What should be changed in the code ?

Question #2
The initial value of
plane.y      = 0
pyramid.y  = 6
But why are the plane and the pyramid in the same horizontal line at the beginning of the game ?

Code:
'=====================================================
'The Devil's Triangle
'
'3D Model :
'Voxel Plane assets by maxparata
'https://maxparata.itch.io/voxel-plane?download
'======================================================

'----------------
' INITIALIZATION
'----------------
include "s3d.n7"; S3D_SetView(primary, rad(45), 0.1, 50)

set window "The Devil's Triangle",800,400,false
set redraw off

'color definition
white = [255,255,255]
black = [0,0,0,120]
gray  = [200,200,200]

'plane
plane = []
plane.model = S3D_LoadMesh("plane/Plane01.obj", 0.5,-0.5,0.5, false)
plane.rotate = 30
plane.x = -5 ; plane.y = 0 ; plane.z = 10

'pyramid
pyramid = []
pyramid.rotate = 0
pyramid.x = 20; pyramid.y = 6 ; pyramid.z = 10
pyramid.texture = loadimage("plane/fire.png")
pyramid.mesh =
S3D_BeginMesh()
    S3D_Begin(S3D_TRIANGLES) 'sides
        S3D_Push()
        for i = 0 to 3
            S3D_Vertex(0, -1, 0, 0.5, 0)
            S3D_Vertex(1, 1, -1, 1, 1)
            S3D_Vertex(-1, 1, -1, 0, 1)
            S3D_RotateY(rad(90))
        next
        S3D_Pop()
    S3D_End()
   
    S3D_Begin(S3D_QUADS) 'bottom
        S3D_Vertex(1, 1, -1, 1, 0)
        S3D_Vertex(1, 1, 1, 1, 1)
        S3D_Vertex(-1, 1, 1, 0, 1)
        S3D_Vertex(-1, 1, -1, 0, 0)
    S3D_End()
S3D_EndMesh()


'-----------
' MAIN LOOP
'-----------
while not keydown(KEY_ESCAPE, true)
    set color black; cls; S3D_Clear()

    'information
    set color gray
    cx = width(primary)/2
    cy = height(primary)/2
    draw line cx,0,cx,cy*2
    draw line 0,cy,cx*2,cy

    'plane control   
    if keydown(KEY_UP,true) then
        if plane.y > -5 then
            plane.y = plane.y - 0.08
            plane.rotate = (plane.rotate + 90*0.03)%360
        else
            plane.y = 4
        endif         
    endif       
    if keydown(KEY_DOWN,true) then
        if plane.y < 5 then
            plane.y = plane.y + 0.08
            plane.rotate = (plane.rotate - 90*0.03)%360
        else
            plane.y = -4
        endif
    endif
    S3D_Translate(plane.x, plane.y, plane.z)
    S3D_RotateX(rad(plane.rotate))
    S3D_Mesh(plane.model, 0)   

    'pyramid   
    pyramid.rotate = (pyramid.rotate + 30*0.03)%360
    if pyramid.x < - 5 then
        pyramid.x = 20
    else
        pyramid.x = pyramid.x - 0.01
    endif
    S3D_Push()
        S3D_Translate(pyramid.x, pyramid.y, pyramid.z)
        S3D_RotateX(rad(pyramid.rotate))
        S3D_RotateZ(rad(270))
        S3D_Texture(pyramid.texture)
        S3D_Scale(0.5,0.5,0.5)
        S3D_Mesh(pyramid.mesh, 0)
    S3D_Pop()       

    redraw
    wait 1
wend



Attached Files
.zip   devil_triangle.zip (Size: 44.79 KB / Downloads: 2)
Print this item

  Just for the Star Wars fans...
Posted by: johnno56 - 05-04-2024, 12:29 PM - Forum: Everything else - Replies (7)

May the forth be with you.

Happy will you be, yes...

Print this item

  Convex hull, quick algorithm
Posted by: Marcus - 05-02-2024, 04:24 PM - Forum: NaaLaa 7 Code - Replies (7)

I need to calculate and display the convex hull of 2D polygons in the editor for that 3d thing, so I implemented a quick (as in "divide and conquer") algorithm for it. I remember writing a quick algorithm for the convex hull of a set of random points in 3D at the university, which is a bit trickier.

If you ever need to calculate the convex hull for a polygon or a bunch of points, you can use this Smile

Code:
' Convex hull test
' ----------------

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

do
    set color 0, 0, 0
    cls
    ' Create 100 random points.
    points = []
    for i = 1 to 100
        a = rnd()*2*PI
        r = rnd(200)
        points[sizeof(points)] = 320 + cos(a)*r
        points[sizeof(points)] = 240 + sin(a)*r
    next
    ' Draw points.
    set color 255, 255, 255
    pcount = sizeof(points)/2
    for i = 0 to pcount - 1
        draw pixel points[i*2], points[i*2 + 1]
    next
    ' Display and wait one second.
    redraw
    wait 1000
    ' Calculate convex hull and display it.
    hull = ConvexHull(points)
    draw poly hull
   
    set caret width(primary)/2, 4
    center "Press space bar to continue ..."
   
    redraw
    while not keydown(KEY_SPACE, true)  fwait 60
loop

' ConvexHull
' ----------
' Calculate the convex hull for a set of points in an array [x0, y0, x1, y1 ..], return as a polygon
' in the same format.
function ConvexHull(points)
    pcount = sizeof(points)/2
    xminIndex = 0; xmaxIndex = 0
    for i = 1 to pcount - 1
        x = points[i*2]
        if x < points[xminIndex*2] xminIndex = i
        if x > points[xmaxIndex*2] xmaxIndex = i
    next
    lpoints = []; rpoints = []
    for i = 0 to pcount - 1
        if i <> xminIndex and i <> xmaxIndex
            cp = CrossProd(points[xminIndex*2], points[xminIndex*2 + 1],
                    points[xmaxIndex*2], points[xmaxIndex*2 + 1],
                    points[i*2], points[i*2 + 1])
            if cp < 0
                lpoints[sizeof(lpoints)] = points[i*2]
                lpoints[sizeof(lpoints)] = points[i*2 + 1]
            elseif cp > 0
                rpoints[sizeof(rpoints)] = points[i*2]
                rpoints[sizeof(rpoints)] = points[i*2 + 1]
            endif
        endif
    next
    hull = []
    hull[sizeof(hull)] = points[xminIndex*2]
    hull[sizeof(hull)] = points[xminIndex*2 + 1]
    HullRec(hull, lpoints, points[xminIndex*2], points[xminIndex*2 + 1], points[xmaxIndex*2], points[xmaxIndex*2 + 1])
    hull[sizeof(hull)] = points[xmaxIndex*2]
    hull[sizeof(hull)] = points[xmaxIndex*2 + 1]
    HullRec(hull, rpoints, points[xmaxIndex*2], points[xmaxIndex*2 + 1], points[xminIndex*2], points[xminIndex*2 + 1])
   
    return hull
   
    function HullRec(hull, points, x0, y0, x1, y1)
        if not sizeof(points)  return
        pcount = sizeof(points)/2
        maxd = 0; maxdIndex = -1
        for i = 0 to pcount - 1
            x = points[i*2]; y = points[i*2 + 1]
            d = LinePointDist(x0, y0, x1, y1, x, y)
            if d > maxd
                maxd = d
                maxdIndex = i
            endif
        next
           
        npoints = []
        for i = 0 to pcount - 1
            if i <> maxdIndex
                x = points[i*2]; y = points[i*2 + 1]
                cp = CrossProd(x0, y0, points[maxdIndex*2], points[maxdIndex*2 + 1], x, y)
                if cp < 0
                    npoints[sizeof(npoints)] = x
                    npoints[sizeof(npoints)] = y
                endif
            endif
        next
        if sizeof(npoints)
            HullRec(hull, npoints, x0, y0, points[maxdIndex*2], points[maxdIndex*2 + 1])
        endif
        hull[sizeof(hull)] = points[maxdIndex*2]
        hull[sizeof(hull)] = points[maxdIndex*2 + 1]
       
        npoints = []
        for i = 0 to pcount - 1
            if i <> maxdIndex
                x = points[i*2]; y = points[i*2 + 1]
                cp = CrossProd(points[maxdIndex*2], points[maxdIndex*2 + 1], x1, y1, x, y)
                if cp < 0
                    npoints[sizeof(npoints)] = x
                    npoints[sizeof(npoints)] = y
                endif
            endif
        next
        if sizeof(npoints)
            HullRec(hull, npoints, points[maxdIndex*2], points[maxdIndex*2 + 1], x1, y1)
        endif
    endfunc
   
    function CrossProd(ax, ay, bx, by, cx, cy)
        return (bx - ax)*(cy - ay) - (by - ay)*(cx - ax)
    endfunc
   
    function LinePointDist(x0, y0, x1, y1, px, py)
        dx = x1 - x0; dy = y1 - y0; d = dx*dx + dy*dy
        if d <= 0  return 0
        return |(x1 - x0)*(py - y0) - (px - x0)*(y1 - y0)|/sqr(d)
    endfunc   
endfunc

Print this item

  Small pinball game using circle-line collision routines from Marcus
Posted by: kevin - 05-01-2024, 02:30 PM - Forum: NaaLaa 7 Code - Replies (2)

This is not meant to be a proper simulation (as you will see if you run it Smile), but just an experiment with the terrific circle-line functions that Marcus provided a while back. I've used the functions as they were originally written by Marcus, with one small alteration to the polygon function, where I have added a fifth argument to allow me to specify a point around which the polygon is rotated, rather than the center point of the polygon (I needed this for the 2 flippers).

There a few values that can be altered in the code to change the way that the ball reacts to certain lines - I've marked some of these as "arbitrary values", and I'm sure changing these will make for a smoother game, but I've decided to move on to a new project.

Control the flippers with the A and D keys, and launch the ball using the UP arrow.

   

Code:
' Experiment.

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

#win32
visible score = 0
' List of lines that objects can collide with.

left_flipper = []
right_flipper = []

l_flipper = Polygon([0,0,10,-10,60,30,60,40], 140,580,  true,[0,0])
r_flipper = Polygon([0,0,-10,-10,-60,30,-60,40], 300,580,  true,[0,0])
'=============================================================================
'Note  -added fifth argument to Polygon - 0 rotates around center point, or
'use a 2 part table to rotate around any point in the polygon - i.e. [32,34]
' to rotate around the fourth point in the polygon array here : -
'l_flipper = Polygon([0,0,10,0,32,24,32,34,22,34,0,10], 320, 240, true,[32,34])
'==============================================================================
l_flipper.AddTo(left_flipper)
left_flipper_timer = 0
left_ang = 0

r_flipper.AddTo(right_flipper)
right_flipper_timer = 0
right_ang = 0



bouncers = []
lines = []
circles = []
table1 = Polygon([180,0,300,0,360,20,420,60,460,120,480,180,480,640,
                    0,640,0,180,20,120,60,60,120,20,180,0],0,0,false,0)
table1.AddTo(lines)


visible circle_hit = unset
circle1 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],100,230,true,0)
circle1.AddTo(circles)

circle2 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],225,230,true,0)
circle2.AddTo(circles)

circle3 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],350,230,true,0)
circle3.AddTo(circles)

circle4 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],162,180,true,0)
circle4.AddTo(circles)

circle5 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],287,180,true,0)
circle5.AddTo(circles)

circle6 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],130,440,true,0)
circle6.AddTo(circles)

circle7 = Polygon([0,0,9,3,13,8,15,15,13,23,9,27,0,30,-9,27,-13,23,-15,15,-13,8,-9,3],310,440,true,0)
circle7.AddTo(circles)


'additional parts of table
'lines - no bouncing
lines[sizeof(lines)] = Line(440,640,440,180)
lines[sizeof(lines)] = Line(360,640,440,590)
lines[sizeof(lines)] = Line(0,590,80,640)
'left upper curve (inner) - no bouncing
lines[sizeof(lines)] = Line(65,330,40,290)
lines[sizeof(lines)] = Line(40,290,40,200)
lines[sizeof(lines)] = Line(40,200,55,150)
lines[sizeof(lines)] = Line(55,150,95,95)
lines[sizeof(lines)] = Line(95,95,150,60)
lines[sizeof(lines)] = Line(150,60,200,45)


'right upper curve (inner) - no bouncing
lines[sizeof(lines)] = Line(300,85,315,90)
lines[sizeof(lines)] = Line(315,90,360,120)
lines[sizeof(lines)] = Line(360,120,385,160)
lines[sizeof(lines)] = Line(385,160,400,200)


lines[sizeof(lines)] = Line(40,490,40,430)
lines[sizeof(lines)] = Line(400,430,400,490)

'triangles sticking out of side - not bouncing
lines[sizeof(lines)] = Line(0,380,40,380)
lines[sizeof(lines)] = Line(0,310,40,380)
lines[sizeof(lines)] = Line(440,380,400,380)
lines[sizeof(lines)] = Line(400,380,440,310)

'bouncers

bouncers[sizeof(bouncers)] = Line(40,490,130,550)
bouncers[sizeof(bouncers)] = Line(400,490,310,550)

bouncers[sizeof(bouncers)] = Line(40,430,70,435)
bouncers[sizeof(bouncers)] = Line(400,430,370,435)


' Player.
visible obj = Object(472, 632, 16)
obj.dx = 0
obj.dy = 0


############  to calculate FPS  ##########################
visible framecount,lasttime = 999,fps,frametime = 0,starttime = 0,endtime = 0,min_fps = 99999,max_fps = 0
##########################################################

while not keydown(KEY_ESCAPE)
###  for FPS calc #########
framecount = framecount + 1
starttime = clock()
###########################
    ' Rotate obstacles.
    circle1.SetAngle(circle1.Angle() + rad(3))
    circle2.SetAngle(circle2.Angle() + rad(3))
    circle3.SetAngle(circle3.Angle() + rad(3))
    circle4.SetAngle(circle4.Angle() + rad(3))
    circle5.SetAngle(circle5.Angle() + rad(3))
    circle6.SetAngle(circle5.Angle() + rad(3))
    circle7.SetAngle(circle5.Angle() + rad(3))
   
set mouse off   
if obj.y >= 624 and obj.x < 440 then game_over()   


    obj.x = obj.x + obj.dx
    obj.y = obj.y + obj.dy


    '-------   left flipper  ------------
    if keydown(KEY_A,true) and left_flipper_timer <= 0
        left_flipper_timer = 16
    endif
    if left_flipper_timer > 0
        left_flipper_timer = left_flipper_timer - 1
        l_flipper.SetAngle(max(l_flipper.Angle() - rad(4),-1.2))
    elseif left_flipper_timer <= 0
        l_flipper.SetAngle(0)
    endif
 
    PushOut(obj, left_flipper)
    if obj.pdy < 0
    if l_flipper.Angle() <> 0
        obj.dy = - 10
        left_ang = angle_rad(l_flipper.trans[1][0],l_flipper.trans[1][1],l_flipper.trans[2][0],l_flipper.trans[2][1])
        left_vecs = get_vecs(left_ang)
        obj.dx = obj.dx + left_vecs[0] * 16'arbitrary figure
    endif
    endif
    '==================================
    '-------   right flipper  ------------
    if keydown(KEY_D,true) and right_flipper_timer <= 0
        right_flipper_timer = 16
    endif
    if right_flipper_timer > 0
        right_flipper_timer = right_flipper_timer - 1
        r_flipper.SetAngle(max(r_flipper.Angle() + rad(4),-1.2))
    elseif right_flipper_timer <= 0
        r_flipper.SetAngle(0)
    endif

    PushOut(obj, right_flipper)
    if obj.pdy < 0
    if r_flipper.Angle() <> 0
        obj.dy = - 10
       right_ang = angle_rad(r_flipper.trans[2][0],r_flipper.trans[2][1],r_flipper.trans[1][0],r_flipper.trans[1][1])
        right_vecs = get_vecs(right_ang)
        obj.dx = obj.dx + right_vecs[0] * 32'arbitrary figure
    endif
    endif
    '==================================
    PushOut(obj, bouncers)' make them bounce a little
    if obj.pdx <> 0 or obj.pdy <> 0
       obj.dx = obj.dx + obj.pdx*12'arbitrary figure
       obj.dy = obj.dy + obj.pdy*12 'arbitrary figure
    endif

 
   
    PushOut(obj, lines)
  ' 
   if obj.y < 180 and obj.x > 240  and obj.dx < 0' help with initial lauch of ball
        if obj.pdx <> 0 or obj.pdy <> 0
            obj.dx = obj.dx + obj.pdx*4'arbitrary figure
         
        endif
   endif
   if obj.y < 180 and obj.x < 240 ' help with initial lauch of ball
        if obj.pdx <> 0 or obj.pdy <> 0
            obj.dx = obj.dx + obj.pdx*0.3'arbitrary figure
            obj.dy = obj.dy + obj.pdy*1
        endif
   endif
    ' obj.pdx and obj.pdy has now been set to the average "push direction" caused by all lines
    ' pushing the object around.
  
    ' Push direction y < 0 means the object is being pushed UP. In that case, set dy to 0.
    if obj.pdy < 0
        ' If push direction y < -0.25, let the player jump.
        if obj.pdy < -0.25 and keydown(KEY_UP, true) and obj.x >= 455
            obj.dy = -14
       endif
    endif
    ' Apply gravity.
    obj.dy = min(obj.dy + 0.1, 6)
    ' So ... stuff to dx.
    obj.dx = obj.dx + obj.pdx*0.25 ' I have no idea
    obj.dx = obj.dx*0.95
   
    PushOut(obj, circles)
        if obj.pdx <> 0 or obj.pdy <> 0
        score = score + 10
        obj.dx = obj.pdx * 8'arbitrary
        obj.dy = obj.pdy * 8'arbitrary
    endif
    
    set color 0, 0, 0
    cls
    set color 255, 255, 255
    DrawLines(lines)
    DrawLines(circles)
    DrawLines(bouncers)
    DrawLines(left_flipper)
    DrawLines(right_flipper)
    obj.Draw()
   
    set caret 20,10
    set justification left
    write "SCORE : " + score;wln
  

'    set caret 460,10
'    set justification right
'    write "FPS = " + str(fps);wln

'    write "MIN_FPS = " + str(min_fps);wln
'    write "MAX_FPS = " + str(max_fps);wln

    redraw
    fwait 60
   
    #######  FPS calc  ############################
endtime = clock()
frametime = frametime + endtime - starttime
if frametime > 1000 # 1 second
    fps = framecount
    framecount = 0
    frametime = 0
    if fps < min_fps then min_fps = fps
    if fps > max_fps then max_fps = fps
endif
################################################
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, pdx: 0, pdy: 0,
            Draw: function(); draw ellipse .x, .y, .r, .r, false; endfunc]
endfunc

' Pushout
' -------
function PushOut(obj, lines)
    tests = 4
    obj.pdx = 0
    obj.pdy = 0
    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
                obj.pdx = obj.pdx + dx*k
                obj.pdy = obj.pdy + dy*k
                col = true
         
            endif
        next
        if not col break
    next
    if obj.pdx or obj.pdy
        k = 1/sqr(obj.pdx*obj.pdx + obj.pdy*obj.pdy)
        obj.pdx = obj.pdx*k
        obj.pdy = obj.pdy*k
    endif
endfunc

' Polygon
' -------
' Return polygon at position x, y.
' Polygon
' -------
' Return polygon at position x, y.
'function Polygon(points, x, y, closed,rotation_point_x,rotation_point_y)
function Polygon(points, x, y, closed,rotation_point)
'========================================================================
'Note -  added fifth argument to Polygon - 0 rotates around center point, or
'use a 2 part table to rotate around any point in the polygon - i.e. [32,34]
' to rotate around the fourth point in the polygon array here :-
'l_flipper = Polygon([0,0,10,0,32,24,32,34,22,34,0,10], 320, 240, true,[32,34])
'========================================================================

    p = [trans: unset, org: [], x: x, y: y, a: 0, cx:0, cy: 0]
    pcount = sizeof(points)/2
    centerX = 0
    centerY = 0
    if closed  n = pcount - 1
    else    n = pcount - 2
    for i = 0 to n
        j = (i + 1)%pcount
        p.org[sizeof(p.org)] = Line(
                points[i*2], points[i*2 + 1],
                points[j*2], points[j*2 + 1])
    next
    for i = 0 to pcount - 1
        if rotation_point = 0
            p.cx = p.cx + points[i*2]; p.cy = p.cy + points[i*2 + 1]
        else
            p.cx = rotation_point[0] * pcount 'rotation_point_x
            p.cy = rotation_point[1] * pcount ' rotation_point_y
        endif
    next

    p.cx = p.cx/pcount; p.cy = p.cy/pcount
    p.trans = copy(p.org)
  
    ' AddTo
    ' -----
    ' Add to list of lines.
    p.AddTo = function(lines)
        foreach ln in .trans  lines[sizeof(lines)] = ln
    endfunc

    ' X
    ' -
    ' Return x coordinate.
    p.X = function()
        return .x
    endfunc
  
    ' Y
    ' -
    ' Return y coordinate.
    p.Y = function()
        return .y
    endfunc
  
    ' Angle
    ' -----
    ' Return angle.
    p.Angle = function()
        return .a
    endfunc
  
    ' SetTransform
    ' ------------
    ' Set position and angle and apply.      
    p.SetTransform = function(x, y, angle)
        .x = x
        .y = y
        .a = angle
        .Transform()
    endfunc
  
    ' SetPosition
    ' -----------
    ' Set position and apply.
    p.SetPosition = function(x, y)
        .x = x
        .y = y
        .Transform()
    endfunc
  
    ' SetAngle
    ' --------
    ' Set angle and apply.
    p.SetAngle = function(angle)
        .a = angle
        .Transform()
    endfunc
  
    ' Transform
    ' ---------
    ' Update transformed polygon.
    p.Transform = function()
        RotateLines(.org, .trans, .cx, .cy, .a)
        foreach ln in .trans
            ln[0] = ln[0] + .x; ln[1] = ln[1] + .y
            ln[2] = ln[2] + .x; ln[3] = ln[3] + .y
            ln[4] = (ln[2] - ln[0])/ln[6]; ln[5] = (ln[3] - ln[1])/ln[6]
        next
    endfunc
  
    p.Transform()
  
    return p
  
    ' RotateLines
    ' -----------
    ' Helper.
    function RotateLines(srcLines, dstLines, aroundX, aroundY, angle)
        c = cos(angle); s = sin(angle)
        for i = 0 to sizeof(srcLines) - 1
            srcLn = srcLines[i]; dstLn = dstLines[i]
            x = srcLn[0] - aroundX; y = srcLn[1] - aroundY
            dstLn[0] = aroundX + x*c - y*s; dstLn[1] = aroundY + y*c + x*s
            x = srcLn[2] - aroundX; y = srcLn[3] - aroundY
            dstLn[2] = aroundX + x*c - y*s; dstLn[3] = aroundY + y*c + x*s
        next
    endfunc  
endfunc


' Rectangle
' ---------
function Rectangle(x, y, w, h)
    w = w - 1
    h = h - 1
    return Polygon([0, 0, w, 0, w, h, 0, h], x, y, true,0)
endfunc

' Line
' ----
' Return a new line.
function Line(x0, y0, x1, y1)
    ln = [x0, y0, x1, y1]
    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]
    return ln
endfunc

'-------------------------
function angle_rad(x0,y0,x1,y1)
dx = x1 - x0
dy = y1 - y0
   
angle_r = atan2(dx,dy)
return angle_r
endfunc
'-----------------------
function get_vecs(angle_r)
vector_x =  -cos(angle_r - PI)
vector_y = sin(angle_r - PI)

return [vector_x,vector_y]
endfunc
'-----------------------
function game_over()
set caret 240,320
set justification center
write "GAME OVER"
'pln "GAME OVER"
redraw
wait 4000
obj.x = 472
obj.y = 632
score = 0
endfunc

Print this item

  Raycaster
Posted by: johnno56 - 04-28-2024, 10:08 PM - Forum: NaaLaa 6 Questions - Replies (5)

Building a level, walls; floors and ceilings, I can do... but I get a little confused with placing items... I can place item on the ceiling and floors ok. But the "indexes" for the items I am not all that familiar. Do the "item" indexes have to be the same as the image "indexes"?

   

Would there be a RC PDF squirreled away on some drive per chance?

Print this item

  Wolf3D test
Posted by: johnno56 - 04-27-2024, 02:27 AM - Forum: NaaLaa 7 Code - Replies (3)

This is just a walls, floor and ceiling layout of the first level modeled after the actual Wolf3D game... This is just a navigable concept level of 64x64 tiles... just to see how N7 copes performance wise...

I will probably use a different tileset for the complete game (assuming I can get that far... lol)... It would be a good idea not to step on Apogee's toes... lol

Of course, the usual constructive criticisms and suggestions, are always welcome....

J


.zip   level1a.zip (Size: 470.2 KB / Downloads: 11)

ps: I modified the display to "double" for "my" screen. Edit as you see fit...

Print this item