Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enchanted Forest
#1
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)
Reply


Messages In This Thread
Enchanted Forest - by 1micha.elok - 05-14-2024, 04:16 AM
RE: Enchanted Forest - by johnno56 - 05-14-2024, 06:22 AM
RE: Enchanted Forest - by 1micha.elok - 05-14-2024, 07:09 AM
RE: Enchanted Forest - by johnno56 - 05-14-2024, 08:47 AM
RE: Enchanted Forest - by Marcus - 05-14-2024, 07:12 PM
RE: Enchanted Forest - by johnno56 - 05-14-2024, 11:33 PM
RE: Enchanted Forest - by 1micha.elok - 05-15-2024, 01:17 AM
RE: Enchanted Forest - by johnno56 - 05-15-2024, 07:28 AM
RE: Enchanted Forest - by 1micha.elok - 05-16-2024, 02:16 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)