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 104 online users.
» 0 Member(s) | 102 Guest(s)
Bing, Google

Latest Threads
Manual
Forum: Everything else
Last Post: 1micha.elok
23 minutes ago
» Replies: 1
» Views: 18
Xmas New Year
Forum: Suggestions
Last Post: Marcus
Yesterday, 03:36 PM
» Replies: 17
» Views: 3,039
Santa by Marcus
Forum: NaaLaa 6 Code
Last Post: johnno56
11-18-2024, 05:41 PM
» Replies: 7
» Views: 156
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: 426
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: 155
Scrolling Text
Forum: Everything else
Last Post: kevin
11-04-2024, 02:17 PM
» Replies: 10
» Views: 485
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,679

 
  No luck with Wine
Posted by: Tomaaz - 02-05-2024, 09:22 AM - Forum: NaaLaa 7 Questions - Replies (9)

So, I've tried to run NaaLaa 7 on Linux, but didn't  have much success. NED runs, but the text is overlapping. That wouldn't be a big problem (as I use Geany with everything), but more complex examples fail to compile an run due to some .dlls missing. I'm aware that NaaLaa is Windows only and the problems have more to do with Wine than NaaLaa itself, but I wonder why much more complex applications run under Wine and NaaLaa doesn't.

Print this item

  Warm Day
Posted by: johnno56 - 02-04-2024, 06:04 PM - Forum: Everything else - Replies (15)

Well, it has taken until 4th of February, for us to get what I call a warm Melbourne summer's day... A very nice 38C... at last... It is rare that we get hot days, 45C+, but it does happen... How warm does it get for other Forum members?

(Well, the forum IS listed as "Everything Else"... I suppose the weather would be included in that category... Moo Ha Ha Ha)

Print this item

  String Command
Posted by: johnno56 - 02-02-2024, 09:40 PM - Forum: NaaLaa 7 Code - Replies (7)

Does N7/6 have the ability or command to perform Basic's string(var, text$) command?

J

In the meantime... I can use something like...

function String(var, txt)
    tmp = ""
    for z = 1 to var
        tmp = tmp + txt
    next
    return tmp
endfunc

Print this item

  PROLAN
Posted by: aurel - 02-02-2024, 04:32 PM - Forum: Programming - Replies (11)

Hi Marcus

I am glad that you have forum back. Smile

Print this item

  my second game, naalaa invader
Posted by: aliensoldier - 02-01-2024, 07:51 PM - Forum: NaaLaa 7 Code - Replies (15)

The game starts on the title screen by pressing the return key to start, the "p" key to pause, the arrow keys to move the ship and the "z" key to shoot. You have to shoot the central square of the enemies to destroy them.

This comment is for Marcus, the game has an error that I have not been able to solve because I don't know what the error is, I have left you a screenshot with the error.
The game sometimes works well and other times the error occurs, it usually happens more times when you beat the game and start a second game again, although it can also happen in the first game and there are times when it doesn't happen and you can beat the game without let nothing happen.



Attached Files
.zip   invader-1.1.zip (Size: 486.67 KB / Downloads: 5)
Print this item

  The json library
Posted by: Marcus - 02-01-2024, 04:40 PM - Forum: NaaLaa 7 Code - Replies (1)

I don't remember if I ever posted something about the json library in the old forum - the one that crashed. But it's very easy to use and can be used for saving and loading most n7 tables. You can read more about the file format here: https://en.wikipedia.org/wiki/JSON

Code:
' json_example.n7
' ---------------
' Using the json library you can turn "any" table into a json string. You can save this string to
' file and load it again to get an exact replica of the original table. So it's a very handy library
' and file format.

include "json.n7"

' Let's say you want to save the player's progress in a game.
data = []
data.lastSaved = time()
data.score = 1349
data.name = "Marcus"
data.level = 5
data.levelScores = [1439, 5131, 1486, 394]
data.position = [x: 10, y: 15]

' Create a file for saving.
f = createfile("savedata.json")
if file(f)
    ' Use JSON_ToString to create a json string and write it to the file.
    write file f, JSON_ToString(data)
    free file f
   
    ' Use JSON_FromFile (there's also JSON_FromString) to load the data into a variable.
    data = JSON_FromFile("savedata.json")
    ' Print out the information loaded from file.
    t = datetime(data.lastSaved)
    pln "lastSaved      = " + t.year + "-" + str(t.month, 2) + "-" + str(t.day, 2) +
            " " + str(t.hour, 2) + ":" + str(t.minute, 2) + ":" + str(t.second)
    pln "score          = " + data.score
    pln "name           = " + data.name
    pln "level          = " + data.level
    pln "levelScores[2] = " + data.levelScores[2]
    pln "position       = " + data.position.x + ", " + data.position.y
else
    pln "Couldn't create file!"
endif

system "pause"

Edit I wrote "most tables". You can assign functions to variabels in an n7 table, and json doesn't support that ofcourse.



Attached Files
.n7   json_example.n7 (Size: 1.39 KB / Downloads: 7)
Print this item

  primitive graphics without padding with more thickness
Posted by: aliensoldier - 01-27-2024, 08:40 PM - Forum: Suggestions - No Replies

While I was doing the pong I tried to create the graphics without filling and I like how it looked but the outline was too thin.

The suggestion is that a new parameter be added to the primitive graphics functions to increase the thickness of the contour, and some new functions to create other types of primitive graphics would not be bad either.

Print this item

  my first game, naalaa pong
Posted by: aliensoldier - 01-27-2024, 04:46 PM - Forum: NaaLaa 7 Code - Replies (3)

I share all the code of my first simple game, naalaa pong.

The game starts with the title screen where you have to press return and wait for the countdown to finish, then play until one of you gets 10 points, and the letter "p" to pause the game.

At the top of each file the name of each file is written in a comment, everything is done with the resources that the naalaa language brings, there is nothing external.

Code:
'pong
include "player.n7"
include "player-cpu.n7"
include "ball.n7"
include "miscellaneous.n7"

set window "example pong",640,480,false
set redraw off


'instancias y variables---------------------------
Font = createfont("Consolas",64)
set font Font

visible state = 0
visible timer = 5

player = []
player_cpu = []
ball = []

while not keydown(KEY_ESCAPE,true)
    set color 0,0,0
    cls
   
    'objetos-----------------------------
    select state
    case 0
        'iniciar objetos y variables----------
        timer = 5
        set_score_player(0)
        set_score_player_cpu(0)
       
        player = Player()
        player_cpu = Player_Cpu()
        ball = Ball()
        'escena introducion------------------
        set color 255,0,204
        set caret 320,100
        center "NAALAA PONG"
        set color 255,204,0
        set caret 320,250
        center "start"
        'si pulsas return me mandas al estado 5
        if keydown(KEY_RETURN,true)
            state = 5
        endif
    case 5
        'escena introducion parte 2---------------
        set color 255,0,204
        set caret 320,100
        center "NAALAA PONG"
        set color 255,204,0
        set caret 320,250
        center timer
        'si llega a 0 me mandas al estado 10
        timer = timer - 1
        if timer < -1
            state = 10
        endif
        wait(1000)
    case 10
        'juego------------------------------
        player.update()
        player.Draw()
        player_cpu.update(ball)
        player_cpu.Draw()
        ball.update(player,player_cpu)
        ball.Draw()
       
        'puntuacion player-----------------------
        set color 255,0,204
        set caret 162,32
        wln(get_score_player())
        'puntuacion player cpu--------------------
        set color 255,204,0
        set caret 448,32
        wln(get_score_player_cpu())
       
        'lineas para el fondo------------------
        set color 255,255,255
        'linea en y
        draw line 315,32,315,448
        draw line 325,32,325,448
        'linea en x arriba
        draw line 32,22,608,22
        draw line 32,32,608,32
        'linea en x abajo
        draw line 32,448,608,448
        draw line 32,458,608,458
       
        'mandar a la pantalla de game over-------------
        if get_score_player() >= 10 or get_score_player_cpu() >= 10
            state = 20
        endif
    case 20
        'eliminar objetos y pantalla game over------------
        player.live = false
        player_cpu.live = false
        ball.live = false
       
        set color 255,255,255
        set caret 320,200
        center "GAME OVER"
        'esperar 1 segundo y me mandas al estado 25
        wait(1000)
        timer = 5
        state = 25
    case 25
        'pantalla game over parte 2-----------------------
        set color 255,255,255
        set caret 320,200
        center "GAME OVER"
       
        set color 255,204,0
        set caret 320,300
        center timer
        'si llega a 0 me mandas al estado 0
        timer = timer - 1
        if timer < -1
            state = 0
        endif
        wait(1000)
    endsel
   
    'pausar el juego-----------------------
    if state = 10 and keydown(KEY_P,true)
        set color 50,200,200
        set caret 320,200
        center "PAUSE"
        while not keydown(KEY_P,true)
            wait(10)
            redraw
        wend
    endif
           
    redraw
    fwait 60
wend

Code:
'player

function Player()
    player = []
    player.Width = 20
    player.Height = 100
    player.x = 32 - player.Width/2
    player.y = 240 - player.Height/2
    player.speed = 5
    player.live = true
   
    player.update = function()
        if this.live = true
            this.move()
        endif
    endfunc
   
    player.Draw = function()
        if this.live = true
            set color 255,0,204
            draw rect this.x,this.y,this.Width,this.Height,true
        endif
    endfunc
   
    player.move = function()
        if keydown(KEY_UP,false) and this.y > 0
            this.y = this.y - this.speed
        elseif keydown(KEY_DOWN,false) and this.y < 480-this.Height
            this.y = this.y + this.speed
        endif
    endfunc
   
    return player
endfunc

Code:
'player-cpu

function Player_Cpu()
    player_cpu = []
    player_cpu.Width = 20
    player_cpu.Height = 100
    player_cpu.x = 608 - player_cpu.Width/2
    player_cpu.y = 240 - player_cpu.Height/2
    player_cpu.speed = 5
    player_cpu.live = true
   
    player_cpu.update = function(ball)
        if this.live
            this.move(ball)
        endif
    endfunc
   
    player_cpu.Draw = function()
        if this.live
            set color 255,204,0
            draw rect this.x,this.y,this.Width,this.Height,true
        endif
    endfunc
   
    player_cpu.move = function(ball)
        if ball.x > 300
            if this.y > ball.y and this.y > 0
                this.y = this.y - (this.speed+ball.speedX)
            endif
           
            if this.y < ball.y and this.y < 480-this.Height
                this.y = this.y + (this.speed+ball.speedX)
            endif
        endif   
    endfunc
   
    return player_cpu
endfunc

Code:
'ball
include "miscellaneous.n7"

visible sound_bounce = CreateSineSfx(0.1,125,100,0.9,11025)
visible sound_over = CreateSineSfx(0.2,1150,600,0.9,11025)

function Ball()
    ball = []
    ball.Width = 16
    ball.Height = 16
    ball.x = 320 - ball.Width / 2
    ball.y = 240 - ball.Height / 2
    ball.speedX = 2
    ball.speedY = 2
    ball.live = true
    ball.state = 0
    ball.count = 0
   
    ball.update = function(player,player_cpu)
        if this.live = true
            select this.state
            case 0
                this.x = 320 - this.Width / 2
                this.y = 240 - this.Height / 2
                this.speedX = 2
                this.speedY = 2
               
                this.count = this.count + 1
                if this.count >= 120
                    this.count = 0
                    this.state = 1
                endif   
            case 1
                this.move()
                this.bounce()
                this.collision_player(player)
                this.collision_player_cpu(player_cpu)
                this.score()
            endsel
        endif
    endfunc
   
    ball.Draw = function()
        if this.live = true
            set  color 200,200,200
            draw rect this.x,this.y,this.Width,this.Height,true
        endif
    endfunc
   
    ball.move = function()
        this.x = this.x + this.speedX
        this.y = this.y + this.speedY
    endfunc
   
    ball.bounce = function()
        if this.x <= 0 or this.x >= 640
            'this.speedX = this.speedX * -1
            play sound sound_over,0.5
            this.state = 0
            wait(1000)
        endif
       
        if this.y <= 0 or this.y >= 480
            this.speedY = this.speedY * -1
            play sound sound_bounce,1
        endif
    endfunc
   
    ball.collision_player = function(player)
        ' Marcus.
        ' Check if they overlap.
        if collision_rect(this.x,this.y,this.Width,this.Height,player.x,player.y,player.Width,player.Height)
            play sound sound_bounce,1
            ' Calculate delta x and delta y, between the center of the ball and the center of the
            ' paddle. Divide the delta x value width the width of the paddle and delta y with the
            ' height of the paddle to normalize them (make comparison valid).
            ' Calcular delta x y delta y, entre el centro de la pelota y el centro de la
            ' remo. Divida el valor delta x ancho el ancho de la paleta y delta y con el
            ' altura de la paleta para normalizarlos (hacer válida la comparación).
            dx = (this.x + this.Width/2 - (player.x + player.Width/2))/player.Width
            dy = (this.y + this.Height/2 - (player.y + player.Height/2))/player.Height
            ' If dx is higher, it means that there's less overlapping along the x-axis. In that
            ' case bounce left or right.
            ' Si dx es mayor, significa que hay menos superposición a lo largo del eje x. En eso
            ' el caso rebota hacia la izquierda o hacia la derecha.
            if |dx| >= |dy|
                ' dx < 0, ball should bounce to the left, and we also move the ball to the left so
                ' that there's no longer any collision.
                ' dx < 0, la pelota debe rebotar hacia la izquierda, y también la movemos hacia la izquierda para que
                ' que ya no hay ninguna colisión.
                if dx < 0
                    this.speedX = -|this.speedX|
                    this.x = player.x - this.Width               
                ' dx > 0, ball should bounce to the right, and move the ball to the right of the
                ' paddle.
                ' dx > 0, la pelota debe rebotar hacia la derecha y moverse hacia la derecha del
                 ' remo.
                else
                    this.speedX = |this.speedX|
                    this.x = player.x + player.Width
                endif
            ' dy is higher, same principle as for dx :)
            ' dy es mayor, el mismo principio que para dx
            else
                if dy < 0
                    this.speedY = -|this.speedY|
                    this.y = player.y - this.Height
                else
                    this.speedY = |this.speedY|
                    this.y = player.y + player.Height
                endif
            endif
        endif
    endfunc
   
    ball.collision_player_cpu = function(player_cpu)
        ' Marcus.
        ' Check if they overlap.
        if collision_rect(this.x,this.y,this.Width,this.Height,player_cpu.x,player_cpu.y,player_cpu.Width,player_cpu.Height)
            'sonido
            play sound sound_bounce,1
            'aumentar velocidad
            this.increase_speed()
           
            dx = (this.x + this.Width/2 - (player_cpu.x + player_cpu.Width/2))/player_cpu.Width
            dy = (this.y + this.Height/2 - (player_cpu.y + player_cpu.Height/2))/player_cpu.Height
           
            if |dx| >= |dy|
                if dx < 0
                    this.speedX = -|this.speedX|
                    this.x = player_cpu.x - this.Width               
                else
                    this.speedX = |this.speedX|
                    this.x = player_cpu.x + player_cpu.Width
                endif
            else
                if dy < 0
                    this.speedY = -|this.speedY|
                    this.y = player_cpu.y - this.Height
                else
                    this.speedY = |this.speedY|
                    this.y = player_cpu.y + player_cpu.Height
                endif
            endif
        endif
    endfunc
   
    ball.score = function()
        if this.x <= 0
            add_score_player_cpu(1)
        endif
       
        if this.x >= 640
            add_score_player(1)
        endif
    endfunc
   
    ball.increase_speed = function()
        'aumentar velocidad al colisionar
        this.speedX = this.speedX + 1
        if this.speedX >= 10
            this.speedX = 10
        endif
    endfunc

    return ball
endfunc

Code:
'miscellaneous

'variables y funciones para manejar los puntos
'para el player---------------------
visible score_player = 0

function set_score_player(number)
    score_player = number
endfunc

function add_score_player(number)
    score_player = score_player + number
endfunc

function get_score_player()
    return score_player
endfunc
'para el player cpu-------------------
visible score_player_cpu = 0

function set_score_player_cpu(number)
    score_player_cpu = number
endfunc

function add_score_player_cpu(number)
    score_player_cpu = score_player_cpu + number
endfunc

function get_score_player_cpu()
    return score_player_cpu
endfunc

'funcion de colision--------------------------------
function collision_rect(x1,y1,w1,h1,x2,y2,w2,h2)
    return x1 + w1 > x2 and x1 < x2 + w2 and
            y1 + h1 > y2 and y1 < y2 + h2
endfunc

'funcion para el sonido------------------------------
function CreateSineSfx(duration, startFreq, endFreq, fadeOut, sampleRate)
    data = []
    a = 0
    da = 2*PI*startFreq/sampleRate
    dda = (2*PI*endFreq/sampleRate - 2*PI*startFreq/sampleRate)/(duration*sampleRate)
    vol = 1
    fadeOut = fadeOut*duration*sampleRate
    fadeOutDelta = 1/(duration*sampleRate - fadeOut)
    for i = 0 to duration*sampleRate - 1
        data[i] = sin(a)*vol
        a = a + da
        da = da + dda
        if i > fadeOut  vol = vol - fadeOutDelta
    next
   
    return createsound(data, data, sampleRate)
endfunc

Print this item

  Puzzle Popper and the OHS library
Posted by: Marcus - 01-27-2024, 12:53 PM - Forum: NaaLaa 7 Code - Replies (10)

Here's a new library (ohs.n7) for online high score lists and a small example game that shows you how to use it.

Look at the library source code for more detailed information about the functions. And don't be alarmed by the warnings in the comments at the top.

If something looks strange or is unclear, don't be afraid to ask!



Attached Files
.zip   PuzzlePopper.zip (Size: 4.88 KB / Downloads: 12)
Print this item

  improve cpu movement in pong
Posted by: aliensoldier - 01-26-2024, 02:10 PM - Forum: NaaLaa 7 Questions - Replies (3)

I have programmed the movement in a very simple way for the player cpu following the ball, I would like some tips to improve the movement and make it seem more intelligent, and make it more fun to play.

I share all the code, the movement is in the player_cpu.move method of player_cpu:

Code:
'pong
include "player.n7"
include "player-cpu.n7"
include "ball.n7"

set window "example pong",640,480,false
set redraw off


'objeto-----------------------------------
player = Player()
ball = Ball()
player_cpu = Player_Cpu()


while not keydown(KEY_ESCAPE,true)
    set color 0,0,0
    cls
   
    'objetos-----------------------------
    player.update()
    player.Draw()
    player_cpu.update(ball)
    player_cpu.Draw()
    ball.update(player,player_cpu)
    ball.Draw()
    'lineas para el fondo------------------
    'draw rect 320,32,2,60,true
    'draw rect 320,120,2,60,true
    'draw rect 320,210,2,60,true
    'draw rect 320,300,2,60,true
    'draw rect 320,390,2,60,true
    'draw line 320,32,320,460
    'draw line 330,32,330,460
     
           
    redraw
    fwait 60
wend

Code:
'player

function Player()
    player = []
    player.Width = 20
    player.Height = 100
    player.x = 32 - player.Width/2
    player.y = 240 - player.Height/2
    player.speed = 5
    player.live = true
   
    player.update = function()
        if this.live = true
            this.move()
        endif
    endfunc
   
    player.Draw = function()
        if this.live = true
            set color 255,0,205
            draw rect this.x,this.y,this.Width,this.Height,true
        endif
    endfunc
   
    player.move = function()
        if keydown(KEY_UP,false) and this.y > 16
            this.y = this.y - this.speed
        elseif keydown(KEY_DOWN,false) and this.y < 370
            this.y = this.y + this.speed
        endif
    endfunc
   
    return player
endfunc


Code:
'player-cpu

function Player_Cpu()
    player_cpu = []
    player_cpu.Width = 20
    player_cpu.Height = 100
    player_cpu.x = 608 - player_cpu.Width/2
    player_cpu.y = 240 - player_cpu.Height/2
    player_cpu.speed = 5
    player_cpu.live = true
    'player_cpu.ball = ball

    player_cpu.update = function(ball)
        if this.live
            this.move(ball)
        endif
    endfunc

    player_cpu.Draw = function()
        if this.live
            set color 255,204,0
            draw rect this.x,this.y,this.Width,this.Height,true
        endif
    endfunc
   
    player_cpu.move = function(ball)
        if this.y > ball.y and this.y > 16
            this.y = this.y - this.speed
        endif
       
        if this.y < ball.y and this.y < 370
            this.y = this.y + this.speed
        endif
    endfunc

    return player_cpu
endfunc

Code:
'ball
include "miscellaneous.n7"

function Ball()
    ball = []
    ball.Width = 16
    ball.Height = 16
    ball.x = 320 - ball.Width / 2
    ball.y = 240 - ball.Height / 2
    ball.speedX = 2
    ball.speedY = 2
    ball.live = true
    'ball.player = player

    ball.update = function(player,player_cpu)
        if this.live = true
            this.move()
            this.bounce()
            this.collision_player(player)
            this.collision_player_cpu(player_cpu)
        endif
    endfunc

    ball.Draw = function()
        if this.live = true
            set  color 200,200,200
            draw rect this.x,this.y,this.Width,this.Height,true
            'draw ellipse this.x,this.y,9,9,true
        endif
    endfunc

    ball.move = function()
        this.x = this.x + this.speedX
        this.y = this.y + this.speedY
    endfunc

    ball.bounce = function()
        if this.x <= 0 or this.x >= 640
            this.speedX = this.speedX * -1
        endif
     
        if this.y <= 0 or this.y >= 480
            this.speedY = this.speedY * -1
        endif
    endfunc

    ball.collision_player = function(player)
        'colision con la x
        if collision_rect(this.x+this.speedX,this.y,this.Width,this.Height,player.x,player.y,player.Width,player.Height)
            this.speedX = this.speedX * -1
        endif
        'colision con la y
        if collision_rect(this.x,this.y+this.speedY,this.Width,this.Height,player.x,player.y,player.Width,player.Height)
            this.speedY = this.speedY * -1
        endif
    endfunc
   
    ball.collision_player_cpu = function(player_cpu)
        'colision con la x
        if collision_rect(this.x+this.speedX,this.y,this.Width,this.Height,player_cpu.x,player_cpu.y,player_cpu.Width,player_cpu.Height)
            this.speedX = this.speedX * -1
        endif
        'colision con la y
        if collision_rect(this.x,this.y+this.speedY,this.Width,this.Height,player_cpu.x,player_cpu.y,player_cpu.Width,player_cpu.Height)
            this.speedY = this.speedY * -1
        endif
    endfunc

    return ball
endfunc

Code:
'miscellaneous

'variables y funciones para manejar los puntos
visible score_player = 0
visible score_player_cpu = 0

function get_score_player()
    return score_player
endfunc

function get_score_player_cpu()
    return score_player_cpu
endfunc

'funcion de colision--------------------------------
function collision_rect(x1,y1,w1,h1,x2,y2,w2,h2)
    return x1 + w1 > x2 and x1 < x2 + w2 and
            y1 + h1 > y2 and y1 < y2 + h2
endfunc

Print this item