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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 31
» Latest member: nartex
» Forum threads: 111
» Forum posts: 894

Full Statistics

Online Users
There are currently 19 online users.
» 2 Member(s) | 14 Guest(s)
Bing, Facebook, Google, luwal, Marcus

Latest Threads
That 3d thing
Forum: NaaLaa 7 Code
Last Post: Marcus
11 hours ago
» Replies: 47
» Views: 2,380
"A Game Jam is Coming Up"
Forum: Programming
Last Post: johnno56
05-28-2024, 12:34 PM
» Replies: 7
» Views: 241
return movement
Forum: NaaLaa 7 Questions
Last Post: kevin
05-22-2024, 04:28 PM
» Replies: 9
» Views: 375
Happy Birthday
Forum: Everything else
Last Post: aliensoldier
05-19-2024, 09:09 PM
» Replies: 4
» Views: 138
Enchanted Forest
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
05-16-2024, 02:16 PM
» Replies: 8
» Views: 425
Scrolling
Forum: NaaLaa 7 Questions
Last Post: johnno56
05-15-2024, 06:25 PM
» Replies: 3
» Views: 238
Devil's Triangle (The Gam...
Forum: NaaLaa 7 Code
Last Post: 1micha.elok
05-15-2024, 10:51 AM
» Replies: 1
» Views: 217
S3D : the devil's triangl...
Forum: NaaLaa 7 Questions
Last Post: 1micha.elok
05-08-2024, 07:26 AM
» Replies: 9
» Views: 763
Just for the Star Wars fa...
Forum: Everything else
Last Post: johnno56
05-05-2024, 10:40 PM
» Replies: 7
» Views: 597
Convex hull, quick algori...
Forum: NaaLaa 7 Code
Last Post: johnno56
05-04-2024, 07:23 PM
» Replies: 7
» Views: 673

 
  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: 11)
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

  problems with collisions in pong
Posted by: aliensoldier - 01-24-2024, 06:59 PM - Forum: NaaLaa 7 Questions - Replies (7)

I'm trying to create the pong game and I'm having problems when the ball collides with the top and bottom of the moving player, the ball doesn't bounce, it just goes into the player's graph.

This happens when the player is moving, standing still it does not happen, the problem is in the ball.collision_player method of the ball.

I show all the code I have for now:

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()
player_cpu = Player_Cpu()
ball = Ball()

while not keydown(KEY_ESCAPE,true)
    set color 0,0,0
    cls
   
    'objetos-----------------------------
    player.update()
    player.Draw()
    player_cpu.update()
    player_cpu.Draw()
    ball.update()
    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
visible player = []

function 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

function get_player()
    return player
endfunc

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

visible ball = get_ball()
visible player_cpu = []
function 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()
    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
 
    return player_cpu
endfunc
function get_player_cpu()
    return player_cpu
endfunc


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

visible player = get_player()
visible player_cpu = get_player_cpu()
visible ball = []

function 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.update = function()
        if this.live = true
            this.move()
            this.bounce()
            this.collision_player()
        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()
        '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

    return ball
endfunc

function get_ball()
    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

  Bombsweeper
Posted by: johnno56 - 01-23-2024, 07:12 PM - Forum: NaaLaa 7 Questions - Replies (11)

I know... I know... not your favourite game (in any version lol...)... As I have never played it before, would you be so kind, as to provide instructions etc... I do not know the significance of the "numbered" squares... Thank you.

J

Print this item

  N7 version 24.01.23 released
Posted by: Marcus - 01-23-2024, 06:00 PM - Forum: Announcements - Replies (3)

Sorry about posting another update so shortly after the last one, but it's an important update ... for myself.

https://naalaa.com/n7/N7_240123.zip

2024-01-23

  • Added the 'download' function
  • Added the game Denaalaafender to examples/other

I want to write a library for online leaderboards (there was such a library for N6, but I'm not sure if it's still working), so I really need the 'download' function, which you can use to retrieve data from php scripts and such.

This is the download.n7 example from the examples/help folder. It downloads the n7 changelog in three different ways.

Code:
' download.n7
' -----------

' You can use 'download(url, filename)' to download something from the internet to a destination
' file. The function returns true on success or false on failure. Depending on where you've put
' your N7 directory, this example might fail.
if download("https://naalaa.com/n7/CHANGELOG.txt", "my_file.txt")
    pln "Downloaded to file successfully!"
    pln
else
    pln "Download to file failed!"
    pln
endif
wait 1000

' If you know that the url will produce pure text, you can use 'download(url, TYPE_STRING)' to
' get the result as a string. If the download fails, an unset variable is returned.
aString = download("https://naalaa.com/n7/CHANGELOG.txt", TYPE_STRING)
if typeof(aString) ' TYPE_UNSET is 0, so we can just write this instead of 'if typeof(aString) = TYPE_STRING'
    pln "Downloaded to string successfully!"
    pln
    wait 1000
    ' Print the string.
    pln aString
    pln
else
    pln "Download to string failed!"
endif
wait 1000

' If you, for some reason, want the downloaded data as an array of bytes, you can use 'download(url,
' TYPE_TABLE)'. If the download fails, an unset variable is returned.
anArray = download("https://naalaa.com/n7/CHANGELOG.txt", TYPE_TABLE)
if typeof(anArray)
    pln "Downloaded to byte array successfully!"
    pln
    wait 1000
    ' Just print the first line of text (we know it's text this time)
    i = 0
    ' Use 'chr' to convert the ASCII values (bytes) to characters.
    while anArray[i] <> 10
        write chr(anArray[i])
        i = i + 1
    wend
    pln
else
    pln "Download to byte array failed!"
endif
pln

system "pause"

Print this item

  The maximum size of a multidimensional array
Posted by: Zuzikofon - 01-22-2024, 11:06 AM - Forum: NaaLaa 7 Questions - Replies (3)

Hello.

A great programming language, very well thought out - the quintessence of what you need. Congratulations.

Question - what is the maximum size of array ?
Can it be enlarged?
In a one-dimensional array I managed to get to 1 million.
Below are sample data that I want to convert. I will write a CSV to array parser. However, there are e.g. 30 million rows of this data.
How to do it?

20210103 170000;3.724250;3.724550;3.724250;3.724250;0
20210103 170500;3.723850;3.725150;3.723650;3.724160;0
20210103 170600;3.724160;3.724160;3.723850;3.723850;0
20210103 170700;3.724250;3.724460;3.724250;3.724460;0
20210103 170800;3.724450;3.724450;3.722350;3.722350;0
20210103 170900;3.722150;3.723950;3.722150;3.723950;0
20210103 171000;3.724750;3.724750;3.724750;3.724750;0
20210103 171100;3.722850;3.723160;3.722560;3.723160;0
20210103 171200;3.723050;3.724250;3.723050;3.724250;0
20210103 171500;3.724150;3.724250;3.723250;3.723250;0
20210103 171900;3.723260;3.723450;3.722450;3.722460;0
20210103 172000;3.722950;3.723350;3.720850;3.723350;0
20210103 172100;3.724250;3.724250;3.724250;3.724250;0
20210103 172200;3.724260;3.724260;3.724150;3.724150;0

Print this item

  NGUI examples
Posted by: Marcus - 01-21-2024, 03:15 PM - Forum: NaaLaa 7 Code - Replies (8)

I must have planned to write some examples for the widget library ngui, for I found a couple in a folder. I've attached the ones I found and I'll try to write some more - there are many widgets to cover.

buttons.n7 is probably a good start.

It can take some seconds to compile a program that includes ngui.n7, because it contains thousands of lines of code (I should put the "larger" widgets in separate files).



Attached Files
.n7   buttons.n7 (Size: 5.4 KB / Downloads: 5)
.n7   checkboxes_and_radiobuttons.n7 (Size: 7.47 KB / Downloads: 6)
.n7   combobox_and_listbox.n7 (Size: 4.92 KB / Downloads: 6)
.n7   menus.n7 (Size: 3.31 KB / Downloads: 5)
.n7   sliders.n7 (Size: 3.45 KB / Downloads: 1)
Print this item

  Sound effects experimentation
Posted by: kevin - 01-20-2024, 05:12 PM - Forum: NaaLaa 7 Code - Replies (7)

I love the new sound effects in the latest N7 version. I am working on this program to let me see the effects of changing the various parameters that you need to use when creating the sound effects.

You need to click the mouse when inside the blue buttons to change the paramenters, and click the red button to play the new sound. 

I've only incorporated one of the new functions so far, and spent little time on aesthetics, as you can see.

I'll leave this now until tomorrow, and see whether I can think of any changes that I can make, before moving on to the other 2 functions. In the meantime, I would love to hear any suggestions for improvements that you may have?

All the best - Kevin.


Code:
visible screen_w = 1024,screen_h = 768
'Open a window
set window "Sound FX",screen_w,screen_h,1
'enable double buffering
set redraw off


sampleRate = 12000
duration = 0.25
startFreq = 500
endFreq = 100
fadeOut = 0.75




############  to calculate FPS  ##########################
visible framecount,lasttime = 999,fps,frametime = 0,starttime = 0,endtime = 0
##########################################################
##############################################################################################
#######################################   GAME LOOP  #########################################
##############################################################################################
do
###  for FPS calc #########
framecount = framecount + 1
starttime = clock()
###########################
'clear the screen
set color 255,255,255
cls
set color 0,0,0

set caret 110,30
set justification center
write "CreateSquareSfx"
'-----------------------------------------------------------------
play_sound = false
if mousebutton(0)
    if mousey() > 60 and mousey() < 110
        if mousex() > 20 and mousex() < 220
            play_sound = true
            laserShotSnd = CreateSquareSfx(duration, startFreq, endFreq, fadeOut, sampleRate)
            play sound laserShotSnd
        endif   
    endif
endif
if play_sound = true
    set color 0,0,0
else
    set color 255,0,0
endif
draw rect 20,60,200,50,1
set caret 120,75
set color 255,255,255
write "PLAY SOUND"
set color 0,0,0
set caret 120,130

write "DURATION 0.1 - 2.0"
set caret 90,180
write "DURATION = "
set caret 160,180;write duration
set color 128,128,226
draw rect 20,150,200,25,1
set color 0,0,0
draw rect 20 + duration * 200/2,150,2,25
if mousebutton(0)
    if mousey() > 150 and mousey() < 175
        if mousex() > 20 + duration * 200/2 and mousex() < 220
            duration = duration + 0.05
        elseif mousex() > 20 and mousex() < 20 + duration * 200/2
            duration = duration - 0.05
        endif
    endif
endif

'-------------------------------------------------

set caret 120,230

write "startFreq 0 - 1000"
set caret 90,280
write "startFreq = "
set caret 160,280;write startFreq
set color 128,128,226
draw rect 20,250,200,25,1
set color 0,0,0
draw rect 20 + startFreq * 200/1000,250,2,25
if mousebutton(0)
    if mousey() > 250 and mousey() < 275
        if mousex() > 20 + startFreq * 200/1000 and mousex() < 220
            startFreq = startFreq + 10
        elseif mousex() > 20 and mousex() < 20 + startFreq * 200/1000
            startFreq = startFreq - 10
        endif
    endif
endif

'-----------------------------------------------------------------

'-------------------------------------------------

set caret 120,330

write "endFreq 0 - 1000"
set caret 90,380
write "endFreq = "
set caret 160,380;write endFreq
set color 128,128,226
draw rect 20,350,200,25,1
set color 0,0,0
draw rect 20 + endFreq * 200/1000,350,2,25
if mousebutton(0)
    if mousey() > 350 and mousey() < 375
        if mousex() > 20 + endFreq * 200/1000 and mousex() < 220
            endFreq = endFreq + 10
        elseif mousex() > 20 and mousex() < 20 + endFreq * 200/1000
            endFreq = endFreq - 10
        endif
    endif
endif

'-----------------------------------------------------------------

'-------------------------------------------------

set caret 120,430

write "fadeOut 0 - 1"
set caret 90,480
write "fadeOut = "
set caret 160,480;write fadeOut
set color 128,128,226
draw rect 20,450,200,25,1
set color 0,0,0
draw rect 20 + fadeOut * 200/1,450,2,25
if mousebutton(0)
    if mousey() > 450 and mousey() < 475
        if mousex() > 20 + fadeOut * 200/1 and mousex() < 220
            fadeOut = fadeOut + 0.005
        elseif mousex() > 20 and mousex() < 20 + fadeOut * 200/1
            fadeOut = fadeOut - 0.005
        endif
    endif
endif

'-----------------------------------------------------------------

'-------------------------------------------------

set caret 120,530

write "sampleRate 8000 - 22050"
set caret 90,580
write "sampleRate = "
set caret 160,580;write sampleRate
set color 128,128,226
draw rect 20,550,200,25,1
set color 0,0,0
draw rect 20 + (sampleRate - 8000) * 200/14050,550,2,25
if mousebutton(0)
    if mousey() > 550 and mousey() < 575
        if mousex() > 20 + (sampleRate - 8000) * 200/14050 and mousex() < 220
            sampleRate = min(22050,sampleRate + 200 )
        elseif mousex() > 20 and mousex() < 20 + (sampleRate - 8000) * 200/14050
            sampleRate = max(8000,sampleRate - 200 )
        endif
    endif
endif

'-----------------------------------------------------------------

set color 226,226,226
draw rect 20,630,200,25,1
set color 0,0,0
draw rect 20,630,200,25
set caret 120,635
write "RESTORE DEFAULTS"

if mousebutton(0)
    if mousey() > 630 and mousey() < 655
        if mousex() > 20  and mousex() < 220
            sampleRate = 12000
            duration = 0.25
            startFreq = 500
            endFreq = 100
            fadeOut = 0.75
           
        endif
    endif
endif





set caret 120,680
write "CreateSquareSfx(" + duration + ", " + startFreq + ", ";wln
write  endFreq+", " +fadeOut+", " +sampleRate + ")"

set caret screen_w/2,screen_h - 110
write "mouse = " + mousex() + " / " + mousey();wln
write "FPS = " + str(fps);wln

'copy back buffer to the screen
redraw
'cap FPS to 60
fwait 60

#######  FPS calc  ############################
endtime = clock()
frametime = frametime + endtime - starttime
if frametime > 1000 # 1 second
    fps = framecount
    framecount = 0
    frametime = 0
endif
################################################


until keydown(KEY_ESCAPE)

#########################################################################################
#################################  FUNCTIONS  ###########################################
#########################################################################################
' CreateSquareSfx
' ---------------
' Same as CreateSineSfx but using a square wave.
function CreateSquareSfx(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
        ' No, using sin here is stupid.
        sa = sin(a)
        if sa < 0  sa = -1
        elseif sa > 0 sa = 1
        data[i] = sa*vol
        a = a + da
        da = da + dda
        if i > fadeOut  vol = vol - fadeOutDelta
    next
    ' 'createsound(leftData, rightData, sampleRate)' creates a new sound and returns a sound id.
    ' 'leftData' is an array with data for the left channel and 'rightData' is for the right
    ' channel. The values in the arays should be in the range [-1..1]. 'sampleRate' is the number
    ' of samples per second, So if you want to create a sound that lasts for three seconds with a
    ' sample rate of 11025, the data arrays should contain 33075 (11025*3) elements each.
    '   You can also use 'create sound sound_id, leftData, rightData, sampleRate' if you want to
    ' use your own sound id.
    return createsound(data, data, sampleRate)
endfunc

Print this item