Compare commits

4 Commits

14 changed files with 90 additions and 20 deletions

3
.gitignore vendored
View File

@@ -3,3 +3,6 @@ ascii
.vscode/*
*.dll
wiki/*
scr_min.c
tests.lua
fake_editor.lua

View File

@@ -189,7 +189,7 @@ int main(int argc,char*argv[]) {
while(!exit) {
if (should_reset) {
should_reset = false;
setmode(1);
mode(1);
reinit();
lua_init(lua_filename);
lua_call_init();
@@ -229,9 +229,12 @@ int main(int argc,char*argv[]) {
}
}
keys = SDL_GetKeyboardState(NULL);
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
mouse_x = (mouse_x-40) / (640/screen_width);
mouse_y = (mouse_y-40) / (480/screen_height);
int mx, my;
mouse_buttons = SDL_GetMouseState(&mx, &my);
if (mx>=40 && my>=40 && mx<680 && my<520) {
mouse_x = (mx-40) / (640/screen_width);
mouse_y = (my-40) / (480/screen_height);
}
if (lua_is_playing()) {
lua_call_update();
@@ -629,8 +632,8 @@ void play(const char* str) {
audio_state = AUDIO_PLAY;
}
void setmode(const uint8_t mode) {
current_mode = mode;
void mode(const uint8_t val) {
current_mode = val;
reinit();
cls();
}

View File

@@ -197,7 +197,7 @@ void sound(float freq, uint32_t len);
void nosound();
void play(const char* str);
void setmode(const uint8_t mode);
void mode(const uint8_t val);
void load(const char* str);
void fileout(const char* str, uint16_t addr, uint16_t size);

View File

@@ -1,5 +1,5 @@
function init()
setmode(1)
mode(1)
reset()
end

View File

@@ -1,5 +1,5 @@
function init()
setmode(1)
mode(1)
mountains = {}
local val = 2

53
demos/matrix.lua Normal file
View File

@@ -0,0 +1,53 @@
--[[
===============================
MATRIX CODE DEMO
by JailDoctor
===============================
--]]
function init()
mode(1) -- fiquem el mode multicolor de 40x30 caracters
color(0,0) -- tinta i fondo a negre
cls() -- borrem pantalla
-- La tabla 'col' conté, per a cada columna de la pantalla: la coordenada 'y' actual, la llargaria 's' i la espera 'w'
col = {}
for i=0,39 do
col[i] = {
y=rnd(30), -- la coordenada y valdrà entre 0 i 29, ningún misteri...
s=rnd(5)+2, -- la 's' valdrà entre 2 i 6. S'usarà tant per a definir la llargaria de la estela com per a especificar la velocitat
w=1 -- 'w' es un contador de espera: Fiquem 'w' a un valor, i a cada cicle se resta 1. Quan arribe a 0 updatem la columna i se reseteja 'w' al valor anterior.
}
end
-- Omplim la tabla 'ma' amb els caracters que volem usar
ma = {}
for i=176,191 do ma[1+#ma] = i end
for i=97,122 do ma[1+#ma] = i end
-- Omplim la pantalla de caracters aleatoris (dins de la selecció que havem deixa a la tabla 'ma').
-- No es veuen perque havem ficat el color de tinta i fondo a negre.
for i=0,1199 do poke(i,ma[rnd(#ma)+1]) end
end
function update()
for i=0,39 do
col[i].w=col[i].w-1
if col[i].w == 0 then
col[i].w = col[i].s
col[i].y=col[i].y+1
if (col[i].y >= 30) then col[i].y = 0 end
local pos = 1200+i+col[i].y*40
poke(pos,15) pos=dec(pos)
poke(pos,14) pos=dec(pos)
for i=0,col[i].s do poke(pos,10) pos=dec(pos) end
for i=0,col[i].s do poke(pos,2) pos=dec(pos) end
for i=0,max(1,col[i].s-3) do poke(pos,8) pos=dec(pos) end
poke(pos,0)
end
end
end
-- Aquesta funció resta 40 a la adreça (per a pujar una linea). Si detecta que se'n va fora per dalt (menys de 1200), suma 1200 per a que aparega per baix
function dec(value) return value-40 < 1200 and value+1160 or value-40 end

View File

@@ -1,5 +1,5 @@
function init()
setmode(1)
mode(1)
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
"\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" }

View File

@@ -111,7 +111,7 @@ void print(int x, int y, const char* text, Uint8 color) {
--]]
function init()
setmode(1)
mode(1)
current_piece = starting[rnd(7)+1]
next_piece = starting[rnd(7)+1]

View File

@@ -348,9 +348,9 @@ extern "C" {
return 0;
}
static int cpp_setmode(lua_State *L) {
static int cpp_mode(lua_State *L) {
int val = luaL_checkinteger(L, 1);
setmode(mid(0,val,3));
mode(mid(0,val,3));
return 0;
}
@@ -407,7 +407,7 @@ bool lua_is_playing() {
return lua_state == STATE_PLAYING;
}
const char boot[] = "function init()setmode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.5.4',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end";
const char boot[] = "function init()mode(1)cls()play('o5l0v5cegv4cegv3cegv2cegv1ceg')memcpy(360,4608,240)memcpy(1560,4848,240)ink(1)print('G A M E',8,16)ink(4)print('S Y S T E M',20,16)ink(7)print('mini',9,8)ink(8)print('v0.5.4',34,29)w=0 end function update()w=w+1 if w>90 then cls()load()end end";
void lua_init(const char* filename, const bool start_playing) {
if (lua_state != STATE_STOPPED) lua_quit();
@@ -476,7 +476,7 @@ void lua_init(const char* filename, const bool start_playing) {
lua_pushcfunction(L,cpp_sound); lua_setglobal(L, "sound");
lua_pushcfunction(L,cpp_nosound); lua_setglobal(L, "nosound");
lua_pushcfunction(L,cpp_play); lua_setglobal(L, "play");
lua_pushcfunction(L,cpp_setmode); lua_setglobal(L, "setmode");
lua_pushcfunction(L,cpp_mode); lua_setglobal(L, "mode");
lua_pushcfunction(L,cpp_load); lua_setglobal(L, "load");
lua_pushcfunction(L,cpp_log); lua_setglobal(L, "log");

View File

@@ -79,7 +79,7 @@ uint8_t get_char(uint8_t key) {
}
void init_terminal() {
setmode(0);
mode(0);
cls();
}
@@ -270,7 +270,7 @@ void refresh_code_editor() {
}
void init_code_editor() {
setmode(3);
mode(3);
code.clear();
load_code();
refresh_code_editor();

View File

@@ -1,6 +1,6 @@
ind = 22
function init()
setmode(2)
mode(2)
map = {}
col = {}
for i=0,299 do

View File

@@ -1,5 +1,5 @@
function init()
setmode(1)
mode(1)
setchar(94, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
piano = { "_____", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^", "_____",
"\143\143\143\154\154", " ", "\143\143\143\154\154", " ", "\143\143\143\154\154", "^^^^^" }

View File

@@ -1,6 +1,6 @@
ind = 22
function init()
setmode(1)
mode(1)
map = {}
col = {}
for i=0,1199 do

11
tweetcarts/matrix.lua Normal file
View File

@@ -0,0 +1,11 @@
q=1200
h={}for i=0,q do poke(i,rnd(99))end
function t(a)poke(q+p,a)p=(p-40)%q end
function update()srand(1)for i=0,39 do
h[i]=(h[i] or rnd(30))+(1/(rnd(5)+2))p=i+(flr(h[i])%30)*40
t(15)t(14)
for j=0,5 do t(10)end
for j=0,5 do t(2)end
t(8)t(0)
end
end