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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 35
» Latest member: coronaman
» Forum threads: 137
» Forum posts: 1,163

Full Statistics

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

Latest Threads
Manual
Forum: Everything else
Last Post: 1micha.elok
2 hours ago
» Replies: 1
» Views: 26
Xmas New Year
Forum: Suggestions
Last Post: Marcus
11-22-2024, 03:36 PM
» Replies: 17
» Views: 3,041
Santa by Marcus
Forum: NaaLaa 6 Code
Last Post: johnno56
11-18-2024, 05:41 PM
» Replies: 7
» Views: 157
How to code efficiently
Forum: NaaLaa 7 Questions
Last Post: 1micha.elok
11-17-2024, 09:31 AM
» Replies: 4
» Views: 171
How to make a race track ...
Forum: NaaLaa 7 Questions
Last Post: kevin
11-10-2024, 04:02 PM
» Replies: 8
» Views: 431
Start of a silly Galaga s...
Forum: NaaLaa 7 Code
Last Post: johnno56
11-08-2024, 08:22 AM
» Replies: 3
» Views: 201
Theme Editor
Forum: Everything else
Last Post: johnno56
11-05-2024, 06:45 PM
» Replies: 2
» Views: 156
Scrolling Text
Forum: Everything else
Last Post: kevin
11-04-2024, 02:17 PM
» Replies: 10
» Views: 487
Naalaa origins
Forum: Everything else
Last Post: johnno56
10-25-2024, 07:21 AM
» Replies: 2
» Views: 296
Maze generation
Forum: NaaLaa 7 Code
Last Post: johnno56
10-23-2024, 09:05 AM
» Replies: 17
» Views: 1,687

 
  Tiny Adventure
Posted by: 1micha.elok - 02-16-2024, 10:17 AM - Forum: NaaLaa 7 Code - Replies (5)

TINY ADVENTURE

 Objective of the game :
 Touch "Q" to finish the game

 Controls
 Movement : Left, Right
 Jump    : Up

 Hints :
 "Q" will be displayed if you eat
 the forbidden fruits "x" and reach score 20


Code:
'----------------
' INITIALIZATION
'----------------
'#win32
set window "Tiny Adventure",200,100,false,4
set redraw off

player   = []
fruit    = []
q        = []
camera   = []

'Initial Value
randomize clock()
player.x=width(primary)/2;player.y=height(primary)-15;player.img="P"
player.dx=2;player.dy=5;player.jump = 0
for i = 0 to 19; fruit[i] = [x:rnd(-80,280),y:rnd(50,80),img:"x"];next
q = [x:rnd(-80,280),y:rnd(20,50),img:"Q"]
camera.x = 0
score = 0

'--------------
' MAIN PROGRAM
'--------------
do   
    set color 0,0,0 ; cls 'clear screen
    Say(40,1,"Tiny Adventure")
   
    'camera's position on top left while the initial player's position in the middle
    camera.x = player.x - width(primary)/2
    camera.y = player.y - height(primary)/2

    'update mountain's position relative to the camera.x
    mountain =[-100-camera.x,90,0-camera.x,50,100-camera.x,70,200-camera.x,50,300-camera.x,90]
    
    'player's control   
    if keydown(KEY_LEFT) then
        player.x = player.x - player.dx 
    elseif keydown(KEY_RIGHT) then
        player.x = player.x + player.dx
    elseif keydown(KEY_UP) then
        player.y = player.y - player.dy; player.jump = 1 'jump
    endif  
   
    'collision detection between player and fruits
    for i = 0 to 19
        if (player.x>= fruit[i].x-10-camera.x and player.x <= fruit[i].x+10-camera.x) and
        (player.y >= fruit[i].y-10-camera.y and player.y <= fruit[i].y+10-camera.y) then
            score = score + 1
            fruit[i].y = -10 'out of screen
        endif
    next
   
    'collision detection between player and "Q"
    if (player.x>=q.x-10-camera.x and player.x<=q.x+10-camera.x) and
    (player.y>=q.y-10-camera.y and player.y<=q.y+10-camera.y) then
        Say(40,24,"Completed")
        q.y = -10 'out of screen
        redraw
        do;wait 1;until keydown(KEY_RETURN)
        end   
    endif
   
    'if the player jumps then goes down slowly
    if player.jump and player.y<=(height(primary)-15) then
        player.y = player.y + 1
        if player.y <=-4 then player.y = 0 'don't fly to outer space :-)
    endif   

    'boundaries
    if player.x <5 then 'left boundary
        player.x = player.x+5 
        Say(5,40,"Rrr")
    elseif player.x >width(primary)-5 then 'right boundary
        player.x = player.x-5
        Say(width(primary)-35,40,"Rrr")          
    endif

    'draw blue mountains , green fruits , white player and red "Q"
    set color 255,255,255; set caret width(primary)/2,12; center "Score :"+score
    set color 0,0,70 ; draw poly mountain,1 
    set color 0,150,0
        foreach i in fruit
            set caret fruit[i].x-camera.x,fruit[i].y
            wln fruit[i].img
        next
    if score >= 20 then
        set color 150,0,0;set caret q.x-camera.x,q.y; wln q.img
    endif
    set color 255,255,255; set caret player.x,player.y; wln player.img

    redraw
    fwait 30
until keydown(KEY_ESCAPE)

'-----------
' FUNCTIONS
'-----------
function Say(x,y,msg)
    set color 255,0,0; set caret x,y; wln msg
endfunc

You are welcomed to try the game, 
if you make some improvements on the game, 
please share on this thread 
so we can have fun together

Thank you   
Big Grin

Print this item

  camera
Posted by: aliensoldier - 02-14-2024, 04:29 PM - Forum: NaaLaa 7 Questions - Replies (8)

How can I make the camera follow the player on a large stage.

Print this item

  Turtle graphics
Posted by: Tomaaz - 02-13-2024, 05:13 PM - Forum: NaaLaa 7 Code - Replies (14)

So, here is my simple (and very basic) Turtle graphics library with two examples.

Library (sorry for Polish variable names Smile ):

Code:
visible katzolwia = 0
visible pozycjax = 300
visible pozycjay = 300
visible rysowanie = 1
visible pi = 3.14159

function forward (dlugosc)
    a = int (sin (katzolwia * pi / 180) * dlugosc)
    b = int (cos (katzolwia * pi / 180) * dlugosc)
    x = pozycjax + a
    y = pozycjay - b
    if rysowanie = 1 then
        draw line pozycjax, pozycjay, x, y
    endif
    pozycjax = x
    pozycjay = y
endfunc

function backward (dlugosc)
    a = int (sin (katzolwia * pi / 180) * dlugosc)
    b = int (cos (katzolwia * pi / 180) * dlugosc)
    x = pozycjax - a
    y = pozycjay + b
    if rysowanie = 1 then
        draw line pozycjax, pozycjay, x, y
    endif
    pozycjax = x
    pozycjay = y
endfunc

function turnright (zmiana)
    katzolwia = katzolwia + zmiana
    sprawdz ()
endfunc

function turnleft (zmiana)
    katzolwia = katzolwia - zmiana
    sprawdz ()
endfunc    

function penup ()
    rysowanie = 0
endfunc

function pendown ()
    rysowanie = 1
endfunc

function goxy (zmianax, zmianay)
    pozycjax = zmianax
    pozycjay = zmianay
endfunc

function gox (zmianax)
    pozycjax = pozycjax + zmianax
endfunc

function goy (zmianay)
    pozycjay = pozycjay + zmianay
endfunc

function reset ()
    katzolwia = 0
endfunc

function sprawdz ()
    if katzolwia > 360 then
        katzolwia = katzolwia - 360
    endif
    if katzolwia < 0 then
        katzolwia = katzolwia + 360
    endif
endfunc

A simple example:

Code:
include "turtle.n7"

set window "Turtle Example", 900, 600
set color 0, 0, 0
cls

set color 255, 0, 0

reset ()
goxy (110, 300)
for x = 1 to 100
    forward (250)
    turnleft (198)
next

set color 0, 0, 255

reset ()
goxy (230, 440)
for k = 1 to 10
gox (2)
goy (2)
for x = 1 to 36
    if x % 2 = 0
        penup ()
    endif
    backward (20)
    pendown ()
    turnright (10)
next
next

reset ()

set color 0, 255, 0
goxy (350, 550)
k = 2
while (k < 496)
    forward (500 - k)
    turnright (90.5)
    k = k + 2
    c = c + 1
wend

wait 5000

Koch Curve:

Code:
include "turtle.n7"
set window "Koch", 520, 480
goxy (10, 300)
turnright(90)
function koch(x, t)
    if t > 0 then
        t = t - 1
        x = x / 3
        koch(x, t)
        turnleft(60)
        koch(x, t)
        turnright(120)
        koch(x, t)
        turnleft(60)
        koch(x, t)
    else
        forward(3 * x)
    endif
    
endfunc

koch(200, 5)
wait 5000

All files are attached.



Attached Files
.zip   turtle.zip (Size: 1.26 KB / Downloads: 4)
Print this item

  No computer
Posted by: Marcus - 02-13-2024, 07:44 AM - Forum: Announcements - Replies (17)

Better make an announcement about this, in case you're wondering why I'm not very active on the forum.

At the moment I don't have a computer. The cat ate the charger cord for my laptop, which was already in a terrible state (some keys missing). But I'll buy a new one, hopefully next week.

Print this item

  How to create a board game
Posted by: aliensoldier - 02-11-2024, 09:09 PM - Forum: NaaLaa 7 Questions - Replies (10)

I was thinking about how I could create a game similar to the game of checkers but I have no idea how to start.

Does anyone know how to create this type of game or something similar to have a base and be able to create more games of that style.

I put a link to a video in case I was not understood correctly.

https://www.youtube.com/watch?v=r-7R2sCW3Ro

Print this item

  Scaling and rotating?
Posted by: Tomaaz - 02-11-2024, 06:56 PM - Forum: NaaLaa 7 Questions - Replies (6)

Is it possible to scale and rotate images in N7 or not yet? If not then when can we expect that?

Print this item

  Example of using tables
Posted by: Tomaaz - 02-09-2024, 01:47 PM - Forum: NaaLaa 7 Code - Replies (9)

Again, it's not the type of program NaaLaa has been designed for, but it's one from my long list of simple programs I test every single language I try with. Some the members here may remember the word count challenge we had on basicprogramming.org. N6 was pretty useless at this task, but N7 is a completely different beast. I was impressed by how easy (thanx to tables, the split function and the free val procedure) was to write this program, considering the fact that NaaLaa doesn't have sorting algorithms built-in.

The task is to read a text file, remove all non-word characters, count all words, count unique words, count how many times each word appears in the text, sort the words by occurrence an save the result to the file.  And here is the code:

Code:
open file 1, "Hamlet.txt"

whole_text = ""
x = freadc(1)
while x
    if x < 48 or (x > 57 and x < 65) or (x > 90 and x < 97) or x > 122
        whole_text = whole_text + chr(32)
    elseif x > 64 and x < 91 then
        whole_text = whole_text + chr(x + 32)
    else
        whole_text = whole_text + chr(x)
    endif
    x = freadc(1)
wend

all_words = split(whole_text, " ")

words_number = 0
unique_words = []
foreach n in all_words
    if len(n) > 1 or n = "a" or n ="i"
        unique_words[n] = unique_words[n] + 1
        words_number = words_number + 1
    endif
next

create file 2, "Words.txt"
wln file 2, "All words - " + words_number
wln file 2, "Unique words - " + sizeof(unique_words)
wln file 2, ""

y = 1
while sizeof(unique_words)
    foreach a, b in unique_words
        if b = y then
            wln file 2, a + " - " + b
        endif
    next    
    free val unique_words, y
    y = y + 1
wend

OK. And now let's move to graphics and games. I won't bore you with this kind of programs, anymore. Wink



Attached Files
.zip   words.zip (Size: 72.74 KB / Downloads: 7)
Print this item

  Calculating 10000 digits of Pi
Posted by: Tomaaz - 02-07-2024, 06:07 PM - Forum: NaaLaa 7 Code - Replies (3)

OK. I know this is not the kind of program NaaLaa has been created for, but I use it to test the speed of any language I try. Well, NaaLaa is doing a pretty good job here and runing this example as fast as other fast interpreters. Smile 

Code:
n = 35001
a = 10000
d = 0
k = 0
g = 0
l = 0
f = []

for x = 0 to n
    f[x] = 2000
next

for c = n to 14 step -14
        d = 0
        for b = c to 1 step -1
            d = d * b
            g = b * 2 - 1
            d = d + f[b] * a
            f[b] = d % g
            d = floor(d / g)
            k = l + floor(d / a)
        next
        k2 = right("0000" + k, 4)
        write k
        l = d % a
next

EDIT: On my machine it takes about 1 min. to complete the task and this is the speed I'm expecting from an interpreted language. Python is slightly faster, while Perl being 25% faster than Python. Tcl is 10+ times slower than NaaLaa. It's worth to remember that NaaLaa runs through Wine, while Python, Perl and Tcl run natively.

Print this item

  Draw pixel and alpha channel
Posted by: Tomaaz - 02-07-2024, 05:50 PM - Forum: NaaLaa 7 Questions - Replies (13)

Here is the Bubble Universe example. It seems that alpha element doesn't affect drawing single pixels:

Code:
set window "Bubble Universe", 512, 512
r = 6.283185307179586 / 235
mw = 512
mh = 512
hw = mw / 2
hh = mh / 2
x = 0
v = 0
u = 0
t = 0
k = rnd(190) + 64
set redraw 0
while 1
    set color 0, 0, 0, 255
    draw rect 0, 0, 512, 512, 1
    for i = 0 to 255
        for j= 0 to 255
            u = sin(i + v) + sin(r * i + x)
            v = cos(i + v) + cos(r * i + x)
            x = u + t
            set color i, j, 255 - i, k
            draw pixel int(hw + u * hw * 0.4), int(hh + v * hh * 0.4)
        next
    next
    redraw
    t = t + 0.01
    k = rnd(190) + 64
wend
 
Is this a bug? I've tried draw pixel, set pixel and even both.

Print this item

  Does "everything else" include other programming languages?
Posted by: Tomaaz - 02-07-2024, 03:45 PM - Forum: Everything else - Replies (1)

Recently, I have been banned from a forum and my nickname has been added to censored words, so other users can't even mention my name. So, is it OK to talk here about other languages, projects etc.?

Sorry, I must have had a temporary brain malfunction. Big Grin There is already a section for discussing other languages and programming in general.

Print this item