Author Topic: A simple old-school demo  (Read 8416 times)

Tomaaz

  • Guest
A simple old-school demo
« on: November 13, 2012, 09:39:33 AM »
I did it for fun. :) It reminds me about all that stuff I did on C-64 long ago:
Code: [Select]
function stars()
for k = 1, 200, 2 do
dot(stars1[k], stars1[k + 1])
end
for k = 1, 40, 2 do
fillbox(stars2[k], stars2[k + 1], stars2[k] + 1, stars2[k + 1] + 1)
end
for k = 1, 200, 2 do
if stars1[k] < 798 then
stars1[k] = stars1[k] + 1
else
stars1[k] = 1
end
end
for k = 1, 40, 2 do
if stars2[k] < 798 then
stars2[k] = stars2[k] + 3
else
stars2[k] = 1
end
end
end

function animation()
zx = zx + 3
zy = zy + 3
a = zx / 99
b = zy / 99
alphachannel(164)
for x = -1,1 do
  for y = -1,1 do
    for z = -1,1 do
      y2 = y
      x2 = x * math.cos(a) - y2 * math.sin(a)
      y3 = x * math.sin(a) + y2 * math.cos(a)
      y2 = y3
      y3 = y2 * math.cos(b) - z * math.sin(b)
      z2 = y2 * math.sin(b) + z * math.cos(b)
      sx = x2 * (z2 + 2)
      sy = y3 * (z2 + 2)
      picture2 = zoomimage(picture, (z2 + 2) / 4, (z2 + 2) / 4)
      putimage(sx * 40 + 360, sy * 40 + 200, picture2)
      freeimage(picture2)
    end
  end
end
alphachannel(255)
end

function scroll()
colour(kol, kol, kol)
kol = kol + stan
if kol >= 255 or kol < 10 then
stan = -stan
end
for k = 1, 98 do
drawtext((k * 8) + licz, 500, tekst[pocz + k])
end
licz = licz - 1
if licz < 0 then
pocz = pocz + 1
licz = 8
end
if pocz > table.maxn(tekst) then
pocz = 1
end
end

openwindow(800, 519, 0, "Simple demo")
setframetimer(50)
backcolour(0, 0, 0)
picture = loadimage("1.png")
colourkey(0, 0, 0)

stars1 = {}
stars2 = {}
tekst = {}
tekst2 = "                                                                                                   Hi everybody! This is a simple demo made with EGSL - a very nice interpreter for making retro games. EGSL is based on Lua, an easy to learn scripting language that is often used in game industry. If you are interested in making simple 2d games or graphic demos, EGSL is something for you. For more information, please visit http://egsl.retrogamecoding.org/. To exit, press 'Esc'. Code: Tomaaz."

a, b, zx, zy, x, y, z, y2, x2, y3, x3, z2, sx, sy = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
pocz = 1
licz = 8
kol = 10
stan = 5

for k = 1, string.len(tekst2) do
tekst[k] = string.sub(tekst2, k, k)
end

for k = 1, 200, 2 do
stars1[k] = math.random(1, 799)
stars1[k + 1] = math.random(20, 470)
end

for k = 1, 40, 2 do
stars2[k] = math.random(1, 799)
stars2[k + 1] = math.random(20, 470)
end

muz = loadmusic("1.mp3")
playmusic(muz, 99, 0)
repeat
klawisz = getkey()
clearscreen()
colour(255, 255, 255)
stars()
animation()
scroll()
colour(128, 128, 0)
fillbox(0, 0, 799, 19)
fillbox(0, 471, 799, 490)
fillbox(0, 515, 799, 518)
colour(0, 0, 0)
fillbox (5, 499, 20, 514)
fillbox (779, 499, 799, 514)
sync()
until klawisz == 27

EDIT: Fixed some mistakes. The .zip file has been updated as well.
EDIT 2: Removed download link. To download, please have a look on this post.
« Last Edit: December 01, 2012, 01:26:09 AM by Tomaaz »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: A simple old-school demo
« Reply #1 on: November 13, 2012, 02:51:57 PM »
This looks really good, but I found one minor mistake (maybe because of bad docu):
Code: [Select]
muz = loadmusic("1.mp3")
playmusic(muz, 99, loop)
loop is an integer value which means 0= play forever, 1 = play once, etc. So correct this should be:
Code: [Select]
muz = loadmusic("1.mp3")
playmusic(muz, 99, 0)

Another "interesting" thing is that the music does not play at all on my Mageia Linux with EGSL.  ???

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #2 on: November 13, 2012, 06:16:13 PM »
loop is an integer value which means 0= play forever, 1 = play once, etc.

Oh, yes. I was going to ask you about it. I tried 1, true and loop and, because it worked exactly the same way every single time, just left it with loop. Thanx for explanation!

Another "interesting" thing is that the music does not play at all on my Mageia Linux with EGSL.  ???

On Linux Mint 9 LXDE I don't have any problems with EGSL, but yes - something getting sound to work properly under it is painful. :(

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #3 on: November 13, 2012, 07:51:46 PM »
There is another strange thing with sound, this time on Windows. When I run the script from Geany or EGSL-IDE it works properly. When I double click on it, it works with no sound. ???

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: A simple old-school demo
« Reply #4 on: November 13, 2012, 08:45:08 PM »
Hm, something weird is happening here, too: no music on Windows. (Have you smpeg.dll in the path of the executable or in system? This is needed for mp3 files.) Well, I have smpeg.dll but still no mp3 support ...  ???

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #5 on: November 13, 2012, 09:06:02 PM »
It works with sound on my Windows, but only when I run the script from Geany or EGSL-IDE. When I run it by double-clicking (the action for files with .lua extension is set to run them with EGSL) the program works, but with no sound. When I try to make an executable the process is completed, but the executable doesn't work and I get a message about some dlls missing. ??? It's been long time since I made an executable with EGSL on Windows, but I don't remember having any problems with it. Strange...  ???
« Last Edit: November 13, 2012, 09:09:00 PM by Tomaaz »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: A simple old-school demo
« Reply #6 on: November 13, 2012, 10:05:12 PM »
That's because the DLLs must be in the directory where the executable is.

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #7 on: November 13, 2012, 10:50:44 PM »
Not necessarily. You can copy them to System32 and SysWOW64 folders and run executables without dlls placed in the same folder (of course if you're going to give your program to someone else it's a good idea to put all required dlls together with the executable). I was sure I did it some time ago, but they were missing. I copied them now and everything works fine but sometimes there is a sound and sometimes there is not. I have no idea why. Doesn't matter if the executable was created and/or run with administrator's rights or not. The same with double-clicking .lua script. Sometimes the music simply plays and sometimes not. The same when all dlls and the executable are in one folder. It looks like there is a problem with smpeg.dll or something wrong with this .mp3 file? Any ideas?

EDIT: It also happens when I run the script from Geany or EGSL-IDE. I thought it wasn't like that but it was only coincidence.
« Last Edit: November 13, 2012, 10:53:52 PM by Tomaaz »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: A simple old-school demo
« Reply #8 on: November 14, 2012, 09:16:44 AM »
Don't know why this is. I updated the smpeg.dll but have the same issue: no mp3 music. This evening I might try it with an ogg music file to see what happens.

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #9 on: November 14, 2012, 10:41:54 PM »
I have good news. :) It looks like there is something wrong with that mp3 file. I converted it to ogg and wav and the demo worked without problems with both formats. So, I tried to use different mp3 file and everything was fine this time. Try this updated version. Sorry for confusing you, but I have no idea what's wrong with that file. It plays correctly on all my music players... ???

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: A simple old-school demo
« Reply #10 on: November 15, 2012, 07:57:03 AM »
Hm, yes that's weird. I also converted it to ogg (with Audacity) and then it plays fine.

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #11 on: December 01, 2012, 01:04:45 AM »
loop is an integer value which means 0= play forever, 1 = play once, etc. So correct this should be:
Code: [Select]
muz = loadmusic("1.mp3")
playmusic(muz, 99, 0)

I just tried a shorter piece of music and on my Linux 0 = play once. Also, there is a difference between the same music in mp3 format and ogg format. Looping is much smoother with ogg file. I wonder if it's just my machine or generally ogg files are better choice. All files are attached. You just need to change line 112 to play mp3 instead of ogg.
« Last Edit: December 01, 2012, 01:12:24 AM by Tomaaz »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: A simple old-school demo
« Reply #12 on: December 01, 2012, 08:24:14 AM »
Hehe, yes that was wrong. To play forever the value is -1::)

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #13 on: December 01, 2012, 03:29:11 PM »
Yes, with -1 it works like it should. :) Did you try to run it with both audio formats? Was there any difference?

Tomaaz

  • Guest
Re: A simple old-school demo
« Reply #14 on: December 08, 2012, 02:27:57 AM »
I've translated the demo to FreePascal/egslengine. The source code is slightly bigger. This example is not as much faster than Lua version as in case of Mandelbrot animation (I should rather say "can't be" - when sync() is replaced with redraw()). There is no that much difference in speed of execution between Lua and FreePascal when EGSL functions are often or constantly called, but with heavy calculations (like in Mandelbrot animation) FreePascal is significantly faster.

Code: [Select]
program Demo;
uses egslengine;

var
x, y, z, k, pocz, licz, kol, stan : integer;
a, b, zx, zy, y2, x2, y3, z2, sx, sy, stan2, stan3, przes, przes2 : real;
stars1 : array[1..200] of integer;
stars2 : array[1..40] of integer;
tekst : array[1..500] of char;
muz, picture, picture2 : pointer;
tekst2 : string;

procedure animation();
begin
zx := zx + 3;
zy := zy + 3;
a := zx / 99;
b := zy / 99;
alphachannel(164);
for x := -1 to 1 do
begin
for y := -1 to 1 do
begin
for z := -1 to 1 do
begin
y2 := y;
x2 := x * cos(a) - y2 * sin(a);
y3 := x * sin(a) + y2 * cos(a);
y2 := y3;
y3 := y2 * cos(b) - z * sin(b);
z2 := y2 * sin(b) + z * cos(b);
sx := x2 * (z2 + 2);
sy := y3 * (z2 + 2);
picture2 := zoomimage(picture, (z2 + 2) / 4, (z2 + 2) / 4);
putimage(int(sx * 40 + przes), int(sy * 40 + przes2), picture2);
freeimage(picture2);
przes := przes + stan2;
przes2 := przes2 + stan3;
if (przes = 150) or (przes = 550) then
stan2 := -stan2;     
if (przes2 = 160) or (przes2 = 260) then
stan3 := -stan3;
end;
end;
end;
alphachannel(255)
end;

procedure scroll();
begin
colour(kol, kol, kol);
kol := kol + stan;
if (kol >= 255) or (kol < 10) then
begin
stan := -stan;
end;
for k := 1 to 98 do
begin
drawtext((k * 8) + licz, 500, tekst[pocz + k])
end;
licz := licz - 1;
if (licz < 0) then
begin
pocz := pocz + 1;
licz := 8;
end;
if (pocz > 100 + length(tekst2)) then
begin
pocz := 1;
end;
end;

procedure stars();
begin
k := 1;
while (k <= 200) do
begin
dot(stars1[k], stars1[k + 1]);
k := k + 2;
end;

k := 1;
while (k <= 40) do
begin
fillbox(stars2[k], stars2[k + 1], stars2[k] + 1, stars2[k + 1] + 1);
k := k + 2;
end;

k := 1;
while (k <= 200) do
begin
if (stars1[k] < 798) then
stars1[k] := stars1[k] + 1
else
stars1[k] := 1;
k := k + 2;
end;

k := 1;
while (k <= 40) do
begin
if (stars2[k] < 798) then
stars2[k] := stars2[k] + 3
else
stars2[k] := 1;
k := k + 2;
end;
end;

begin
x := 0;
y := 0;
k := 0;
a := 0;
b := 0;
zx := 0;
zy := 0;
z := 0;
x2 := 0;
y2 := 0;
y3 := 0;
y3 := 0;
z2 := 0;
sx := 0;
sy := 0;
pocz := 1;
licz := 8;
kol := 10;
stan := 5;
stan2 := 0.125/2;
stan3 := 0.125/4;
przes := 500;
przes2 := 250;
tekst2 := 'Hi everybody! This is a simple demo made with FreePascal and egslengine - a very nice engine for making 2D games. It is free, open-source and multiplatform. For more information, please visit http://egsl.retrogamecoding.org/. To exit, press "Esc". Code: Tomaaz.';

for k := 1 to 100 do
begin
tekst[k] := ' ';
end;

for k := 1 to length(tekst2) do
begin
tekst[k + 100] := tekst2[k];
end;

for k := 1 to 100 do
begin
tekst[k + 100 + length(tekst2)] := ' ';
end;

k := 1;
while (k <= 200) do
begin
stars1[k] := random(799) + 1;
stars1[k + 1] := random(450) + 20;
k := k + 2;
end;

k := 1;
while (k <= 40) do
begin
stars2[k] := random(799) + 1;
stars2[k + 1] := random(450) + 20;
k := k + 2;
end;

openwindow(800, 519, 0, 'Simple demo');
setframetimer(50);
backcolour(0, 0, 0);
muz := loadmusic('1.ogg');
picture := loadimage('1.png');
colourkey(0, 0, 0);
playmusic(muz, 99, -1);
repeat
clearscreen();
colour(255, 255, 255);
stars();
animation();
scroll();
colour(int((255 - kol) / 4 + 64), int((255 - kol) / 4 + 64), 0);
fillbox(0, 0, 799, 19);
fillbox(0, 515, 799, 518);
fillbox(0, 471, 799, 490);
colour(0, 0, 0);
fillbox (5, 499, 20, 514);
fillbox (779, 499, 799, 514);
sync();
until (getkey() = 27);
end.

Source code, Windows executable and all required files are attached.