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.
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)
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.
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.
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.
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
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()
'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
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
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.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