Compare commits
3 Commits
82bebe3eeb
...
f889faa472
| Author | SHA1 | Date | |
|---|---|---|---|
| f889faa472 | |||
| 743fd2b8cc | |||
| 841f4f66f3 |
12
ascii.cpp
12
ascii.cpp
@@ -42,6 +42,7 @@ SDL_Texture *mini_bak = NULL;
|
|||||||
SDL_AudioDeviceID mini_audio_device;
|
SDL_AudioDeviceID mini_audio_device;
|
||||||
Uint32 *pixels;
|
Uint32 *pixels;
|
||||||
int pitch;
|
int pitch;
|
||||||
|
Uint32 counter=0;
|
||||||
|
|
||||||
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
uint32_t palette[16] = { 0x00000000, 0x000000AA, 0x0000AA00, 0x0000AAAA, 0x00AA0000, 0x00AA00AA, 0x00AA5500, 0x00AAAAAA,
|
||||||
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
0x00555555, 0x005555FF, 0x0055FF55, 0x0055FFFF, 0x00FF5555, 0x00FF55FF, 0x00FFFF55, 0x00FFFFFF };
|
||||||
@@ -63,6 +64,7 @@ const char* get_filename() {
|
|||||||
|
|
||||||
void reinit() {
|
void reinit() {
|
||||||
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
|
if (mini_bak != NULL) SDL_DestroyTexture(mini_bak);
|
||||||
|
counter=0;
|
||||||
switch (current_mode) {
|
switch (current_mode) {
|
||||||
case 0:
|
case 0:
|
||||||
screen_width = 80;
|
screen_width = 80;
|
||||||
@@ -305,6 +307,7 @@ int main(int argc,char*argv[]) {
|
|||||||
SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect);
|
SDL_RenderCopy(mini_ren, mini_bak, NULL, &rect);
|
||||||
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
//SDL_RenderCopy(mini_ren, mini_bak, NULL, NULL);
|
||||||
SDL_RenderPresent(mini_ren);
|
SDL_RenderPresent(mini_ren);
|
||||||
|
counter++;
|
||||||
}
|
}
|
||||||
lua_quit();
|
lua_quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
@@ -672,4 +675,11 @@ const char* fromclipboard() {
|
|||||||
SDL_free((void*)text);
|
SDL_free((void*)text);
|
||||||
|
|
||||||
return str_tmp;
|
return str_tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t cnt() {
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
void rst() {
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
|||||||
5
ascii.h
5
ascii.h
@@ -204,4 +204,7 @@ void fileout(const char* str, uint16_t addr, uint16_t size);
|
|||||||
void filein(const char* str, uint16_t addr, uint16_t size);
|
void filein(const char* str, uint16_t addr, uint16_t size);
|
||||||
|
|
||||||
void toclipboard(const char* str);
|
void toclipboard(const char* str);
|
||||||
const char* fromclipboard();
|
const char* fromclipboard();
|
||||||
|
|
||||||
|
uint32_t cnt();
|
||||||
|
void rst();
|
||||||
|
|||||||
@@ -6,116 +6,179 @@ WALL = 7
|
|||||||
|
|
||||||
function init()
|
function init()
|
||||||
mode(2)
|
mode(2)
|
||||||
level=1
|
setchar(127,0xee,0xee,0xee,0x00,0xbb,0xbb,0xbb,0x00)
|
||||||
player={}
|
setchar(16,0xff,0xc3,0xa5,0x99,0x99,0xa5,0xc3,0xff)
|
||||||
init_level()
|
menu.init()
|
||||||
end
|
end
|
||||||
|
|
||||||
function init_level()
|
-- ====================================================================================================
|
||||||
update=update_level
|
-- MENU (game state)
|
||||||
load_from_string("####|# .#|# ###|#*@ #|# $ #|# ###|####")
|
-- ====================================================================================================
|
||||||
end
|
menu={
|
||||||
|
init = function()
|
||||||
|
rst()
|
||||||
|
update=menu.update
|
||||||
|
end,
|
||||||
|
|
||||||
function load_from_string(str)
|
update = function()
|
||||||
map={}
|
color(15,0) cls()
|
||||||
local pos=0
|
ink(1) print("\x20\x20\x20\x87\x81\x87\x85\x85\x85\x87\x85\x87\x85\x87\x85\x87\x84\x20\x20\x20",0,2)
|
||||||
local y,x=1,1
|
ink(9) print("\x20\x20\x20\x83\x85\x85\x85\x8D\x81\x85\x85\x87\x84\x8D\x85\x85\x85\x20\x20\x20",0,3)
|
||||||
local maxx=0
|
ink(11) print("\x20\x20\x20\x83\x81\x83\x81\x81\x81\x83\x81\x83\x81\x81\x81\x81\x81\x20\x20\x20",0,4)
|
||||||
map[y] = {}
|
ink(15*flr((cnt()%60)/30)) print("PRESS SPACE TO PLAY",1,9)
|
||||||
while pos<#str do
|
|
||||||
local chr = ascii(str,pos)
|
if btnp(KEY_SPACE) then
|
||||||
if chr == 35 then map[y][x] = WALL end
|
level.start()
|
||||||
if chr == 64 then player.x,player.y=x,y map[y][x] = FLOOR end
|
game.init()
|
||||||
if chr == 43 then player.x,player.y=x,y map[y][x] = GOAL end
|
|
||||||
if chr == 36 then map[y][x] = BOX end
|
|
||||||
if chr == 42 then map[y][x] = GOAL+BOX end
|
|
||||||
if chr == 46 then map[y][x] = GOAL end
|
|
||||||
if chr == 32 then map[y][x] = FLOOR end
|
|
||||||
if chr == 124 then
|
|
||||||
y=y+1
|
|
||||||
map[y] = {}
|
|
||||||
if maxx < x then maxx=x end
|
|
||||||
x=0
|
|
||||||
end
|
end
|
||||||
pos=pos+1
|
|
||||||
x=x+1
|
|
||||||
end
|
end
|
||||||
ox = flr((20-maxx)/2)
|
}
|
||||||
oy = flr((15-y)/2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function update_level()
|
-- ====================================================================================================
|
||||||
border(0)
|
-- GAME (game state)
|
||||||
color(1,0)
|
-- ====================================================================================================
|
||||||
cls()
|
game={
|
||||||
for y=1,#map do
|
init = function()
|
||||||
for x=1,#map[y] do
|
update=game.update
|
||||||
if map[y][x] == WALL then color(4,15) print("\127",ox+x-1,oy+y-1)
|
level.load()
|
||||||
elseif map[y][x]&BOX == BOX then color(0,6) print("\016",ox+x-1,oy+y-1)
|
end,
|
||||||
elseif map[y][x] == GOAL then color(4,0) print("\144",ox+x-1,oy+y-1)
|
|
||||||
|
update = function()
|
||||||
|
border(0)
|
||||||
|
color(1,0)
|
||||||
|
cls()
|
||||||
|
level.draw()
|
||||||
|
|
||||||
|
if btnp(KEY_UP) then level.try_move(0,-1)
|
||||||
|
elseif btnp(KEY_DOWN) then level.try_move(0,1)
|
||||||
|
elseif btnp(KEY_LEFT) then level.try_move(-1,0)
|
||||||
|
elseif btnp(KEY_RIGHT) then level.try_move(1,0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
-- ====================================================================================================
|
||||||
|
-- LOADING (game state)
|
||||||
|
-- ====================================================================================================
|
||||||
|
loading = {
|
||||||
|
init = function()
|
||||||
|
border(15)
|
||||||
|
update=loading.update
|
||||||
|
rst()
|
||||||
|
end,
|
||||||
|
|
||||||
|
update = function()
|
||||||
|
color(15,0)
|
||||||
|
cls()
|
||||||
|
print("LEVEL "..num_level,6,5)
|
||||||
|
print("GOOD JOB!",5,8)
|
||||||
|
if (cnt()%60)<15 then print("\248",9,10)
|
||||||
|
elseif (cnt()%60)<30 then print("\250",9,10)
|
||||||
|
elseif (cnt()%60)<45 then print("\248",9,10)
|
||||||
|
else print("\251",9,10) end
|
||||||
|
if cnt()==120 then
|
||||||
|
level.next()
|
||||||
|
game.init()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- ====================================================================================================
|
||||||
|
-- LEVEL
|
||||||
|
-- ====================================================================================================
|
||||||
|
levels= {
|
||||||
|
"####|# .#|# ###|#*@ #|# $ #|# ###|####",
|
||||||
|
"######|# #|# #@ #|# $* #|# .* #|# #|######",
|
||||||
|
" ####|### ####|# $ #|# # #$ #|# . .#@ #|#########",
|
||||||
|
"########|# #|# .**$@#|# #|##### #| ####",
|
||||||
|
" #######| # #| # .$. #|## $@$ #|# .$. #|# #|########",
|
||||||
|
"###### #####|# ### #|# $$ #@#|# $ #... #|# ########|#####",
|
||||||
|
"#######|# .$. #|# $.$ #|# .$. #|# $.$ #|# @ #|#######",
|
||||||
|
"#####|#. ##|#@$$ #|## #| ## #| ##.#| ###"
|
||||||
|
}
|
||||||
|
|
||||||
|
level = {
|
||||||
|
start = function() num_level=1 end,
|
||||||
|
next = function() num_level=num_level+1 end,
|
||||||
|
|
||||||
|
load = function()
|
||||||
|
local str = levels[num_level]
|
||||||
|
player={}
|
||||||
|
map={}
|
||||||
|
local pos=0
|
||||||
|
local y,x=1,1
|
||||||
|
local maxx=0
|
||||||
|
map[y] = {}
|
||||||
|
while pos<#str do
|
||||||
|
local chr = ascii(str,pos)
|
||||||
|
if chr == 35 then map[y][x] = WALL end
|
||||||
|
if chr == 64 then player.x,player.y=x,y map[y][x] = FLOOR end
|
||||||
|
if chr == 43 then player.x,player.y=x,y map[y][x] = GOAL end
|
||||||
|
if chr == 36 then map[y][x] = BOX end
|
||||||
|
if chr == 42 then map[y][x] = GOAL+BOX end
|
||||||
|
if chr == 46 then map[y][x] = GOAL end
|
||||||
|
if chr == 32 then map[y][x] = FLOOR end
|
||||||
|
if chr == 124 then
|
||||||
|
y=y+1
|
||||||
|
map[y] = {}
|
||||||
|
if maxx < x then maxx=x end
|
||||||
|
x=0
|
||||||
|
end
|
||||||
|
pos=pos+1
|
||||||
|
x=x+1
|
||||||
|
end
|
||||||
|
ox = flr((20-maxx)/2)
|
||||||
|
oy = flr((15-y)/2)
|
||||||
|
end,
|
||||||
|
|
||||||
|
draw = function()
|
||||||
|
for y=1,#map do
|
||||||
|
for x=1,#map[y] do
|
||||||
|
if map[y][x] == WALL then color(4,0) print("\127",ox+x-1,oy+y-1)
|
||||||
|
elseif map[y][x] == BOX then color(8,7) print("\016",ox+x-1,oy+y-1)
|
||||||
|
elseif map[y][x] == BOX+GOAL then color(3,11) print("\016",ox+x-1,oy+y-1)
|
||||||
|
elseif map[y][x] == GOAL then color(3,0) print("\144",ox+x-1,oy+y-1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
color(15,0) print("\248",ox+player.x-1,oy+player.y-1)
|
||||||
color(15,0) print("\248",ox+player.x-1,oy+player.y-1)
|
end,
|
||||||
|
|
||||||
if btnp(KEY_UP) then try_move(0,-1)
|
try_move = function(x,y)
|
||||||
elseif btnp(KEY_DOWN) then try_move(0,1)
|
if level.is_empty(x,y) then
|
||||||
elseif btnp(KEY_LEFT) then try_move(-1,0)
|
level.move_player(x,y)
|
||||||
elseif btnp(KEY_RIGHT) then try_move(1,0)
|
elseif level.is_box(x,y) and level.is_empty(x*2,y*2) then
|
||||||
end
|
level.move_box(x,y)
|
||||||
end
|
|
||||||
|
|
||||||
function try_move(x,y)
|
|
||||||
if is_empty(x,y) then
|
|
||||||
move_player(x,y)
|
|
||||||
elseif is_box(x,y) and is_empty(x*2,y*2) then
|
|
||||||
move_box(x,y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function is_empty(x,y)
|
|
||||||
return map[player.y+y][player.x+x] < 2
|
|
||||||
end
|
|
||||||
|
|
||||||
function is_box(x,y)
|
|
||||||
return map[player.y+y][player.x+x] < 4
|
|
||||||
end
|
|
||||||
|
|
||||||
function move_player(x,y)
|
|
||||||
player.x=player.x+x
|
|
||||||
player.y=player.y+y
|
|
||||||
end
|
|
||||||
|
|
||||||
function move_box(x,y)
|
|
||||||
map[player.y+y*2][player.x+x*2] = map[player.y+y*2][player.x+x*2] + BOX
|
|
||||||
map[player.y+y][player.x+x] = map[player.y+y][player.x+x] - BOX
|
|
||||||
move_player(x,y)
|
|
||||||
check_finished()
|
|
||||||
end
|
|
||||||
|
|
||||||
function check_finished()
|
|
||||||
for y=1,#map do
|
|
||||||
for x=1,#map[y] do
|
|
||||||
if map[y][x] == GOAL then return end
|
|
||||||
end
|
end
|
||||||
end
|
end,
|
||||||
init_goodjob()
|
|
||||||
end
|
|
||||||
|
|
||||||
function init_goodjob()
|
is_empty = function(x,y)
|
||||||
border(15)
|
return map[player.y+y][player.x+x] < 2
|
||||||
update=update_goodjob
|
end,
|
||||||
wait=120
|
|
||||||
end
|
is_box = function(x,y)
|
||||||
|
return map[player.y+y][player.x+x] < 4
|
||||||
function update_goodjob()
|
end,
|
||||||
color(15,0)
|
|
||||||
cls()
|
move_player = function(x,y)
|
||||||
print("LEVEL "..level,6,6)
|
player.x=player.x+x
|
||||||
print("GOOD JOB!",4,8)
|
player.y=player.y+y
|
||||||
wait=wait-1
|
end,
|
||||||
if wait==0 then
|
|
||||||
level=level+1
|
move_box = function(x,y)
|
||||||
init_level()
|
map[player.y+y*2][player.x+x*2] = map[player.y+y*2][player.x+x*2] + BOX
|
||||||
|
map[player.y+y][player.x+x] = map[player.y+y][player.x+x] - BOX
|
||||||
|
level.move_player(x,y)
|
||||||
|
level.check_finished()
|
||||||
|
end,
|
||||||
|
|
||||||
|
check_finished = function()
|
||||||
|
for y=1,#map do
|
||||||
|
for x=1,#map[y] do
|
||||||
|
if map[y][x] == GOAL then return end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
loading.init()
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
|
|||||||
13
lua.cpp
13
lua.cpp
@@ -392,6 +392,16 @@ extern "C" {
|
|||||||
lua_pushstring(L, fromclipboard());
|
lua_pushstring(L, fromclipboard());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cpp_cnt(lua_State *L) {
|
||||||
|
lua_pushinteger(L, cnt());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cpp_rst(lua_State *L) {
|
||||||
|
rst();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STATE_STOPPED 0
|
#define STATE_STOPPED 0
|
||||||
@@ -485,6 +495,9 @@ void lua_init(const char* filename, const bool start_playing) {
|
|||||||
lua_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard");
|
lua_pushcfunction(L,cpp_toclipboard); lua_setglobal(L, "toclipboard");
|
||||||
lua_pushcfunction(L,cpp_fromclipboard); lua_setglobal(L, "fromclipboard");
|
lua_pushcfunction(L,cpp_fromclipboard); lua_setglobal(L, "fromclipboard");
|
||||||
|
|
||||||
|
lua_pushcfunction(L,cpp_cnt); lua_setglobal(L, "cnt");
|
||||||
|
lua_pushcfunction(L,cpp_rst); lua_setglobal(L, "rst");
|
||||||
|
|
||||||
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
lua_pushinteger(L, 0); lua_setglobal(L, "KEY_UNKNOWN");
|
||||||
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
lua_pushinteger(L, 4); lua_setglobal(L, "KEY_A");
|
||||||
lua_pushinteger(L, 5); lua_setglobal(L, "KEY_B");
|
lua_pushinteger(L, 5); lua_setglobal(L, "KEY_B");
|
||||||
|
|||||||
65
tools/fontedit.lua
Normal file
65
tools/fontedit.lua
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
function init()
|
||||||
|
mode(1)
|
||||||
|
sel = 127
|
||||||
|
end
|
||||||
|
|
||||||
|
clicked=false
|
||||||
|
mx,my=0,0
|
||||||
|
function update()
|
||||||
|
color(0,7)
|
||||||
|
cls()
|
||||||
|
|
||||||
|
color(8,0)
|
||||||
|
for y=0,15 do
|
||||||
|
for x=0,15 do
|
||||||
|
print(chr(x+y*16),x+1,y+1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
poke(1200+((sel%16)+1+(flr(sel/16)+1)*40),15)
|
||||||
|
|
||||||
|
drawchar(sel,19,1)
|
||||||
|
|
||||||
|
if mousebutton(1) then
|
||||||
|
if mousex()>=1 and mousey()>=1 and mousex()<=16 and mousey()<=16 then
|
||||||
|
sel = mousex()-1+(mousey()-1)*16
|
||||||
|
elseif mousex()>=19 and mousey()>=1 and mousex()<=26 and mousey()<=8 then
|
||||||
|
if not clicked or mousex()~=mx or mousey()~=my then
|
||||||
|
clicked,mx,my=true,mousex(),mousey()
|
||||||
|
local pos = 2560+sel*8+(mousey()-1)
|
||||||
|
local bit = 1 << (7-(mousex()-19))
|
||||||
|
local value = peek(pos)
|
||||||
|
poke(pos, value ~ bit)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
clicked = false
|
||||||
|
end
|
||||||
|
|
||||||
|
if btnp(KEY_S) then
|
||||||
|
local pos = 2560+sel*8
|
||||||
|
local string = "setchar("..sel..","..peek(pos)..","..peek(pos+1)..","..peek(pos+2)..","..peek(pos+3)..","..peek(pos+4)..","..peek(pos+5)..","..peek(pos+6)..","..peek(pos+7)..")"
|
||||||
|
toclipboard(string)
|
||||||
|
end
|
||||||
|
|
||||||
|
ink(4)
|
||||||
|
print("\143",mousex(), mousey())
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawchar(char,x,y)
|
||||||
|
color(15,0)
|
||||||
|
local pos = 2560+char*8
|
||||||
|
for i=1,8 do
|
||||||
|
local val = peek(pos)
|
||||||
|
print(" ",x,y)
|
||||||
|
if val&1==1 then print("\143",x+7,y) end
|
||||||
|
if val&2==2 then print("\143",x+6,y) end
|
||||||
|
if val&4==4 then print("\143",x+5,y) end
|
||||||
|
if val&8==8 then print("\143",x+4,y) end
|
||||||
|
if val&16==16 then print("\143",x+3,y) end
|
||||||
|
if val&32==32 then print("\143",x+2,y) end
|
||||||
|
if val&64==64 then print("\143",x+1,y) end
|
||||||
|
if val&128==128 then print("\143",x,y) end
|
||||||
|
y=y+1
|
||||||
|
pos=pos+1
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
ind = 22
|
|
||||||
function init()
|
function init()
|
||||||
mode(2)
|
mode(2)
|
||||||
map = {}
|
map = {}
|
||||||
@@ -7,7 +6,6 @@ function init()
|
|||||||
map[i] = 32
|
map[i] = 32
|
||||||
col[i] = 0x0f
|
col[i] = 0x0f
|
||||||
end
|
end
|
||||||
map[ind] = 65
|
|
||||||
sel_col = 0x0f
|
sel_col = 0x0f
|
||||||
sel_chr = 65
|
sel_chr = 65
|
||||||
end
|
end
|
||||||
@@ -76,10 +74,17 @@ function draw_map()
|
|||||||
map[mx+my*20] = sel_chr
|
map[mx+my*20] = sel_chr
|
||||||
col[mx+my*20] = sel_col
|
col[mx+my*20] = sel_col
|
||||||
end
|
end
|
||||||
|
if mousebutton(3) then
|
||||||
|
col[mx+my*20] = sel_col
|
||||||
|
end
|
||||||
if btn(KEY_SPACE) then
|
if btn(KEY_SPACE) then
|
||||||
sel_chr = peek(mx+my*20)
|
sel_chr = peek(mx+my*20)
|
||||||
sel_col = peek(300+mx+my*20)
|
sel_col = peek(300+mx+my*20)
|
||||||
end
|
end
|
||||||
|
if btnp(KEY_UP) then for i=20,299 do map[i-20]=map[i]col[i-20]=col[i] end end
|
||||||
|
if btnp(KEY_DOWN) then for i=279,0,-1 do map[i+20]=map[i]col[i+20]=col[i] end end
|
||||||
|
if btnp(KEY_LEFT) then for i=0,298 do map[i]=map[i+1]col[i]=col[i+1] end end
|
||||||
|
if btnp(KEY_RIGHT) then for i=299,1,-1 do map[i]=map[i-1]col[i]=col[i-1] end end
|
||||||
|
|
||||||
blink = blink - 1
|
blink = blink - 1
|
||||||
if blink < 30 then
|
if blink < 30 then
|
||||||
@@ -88,4 +93,15 @@ function draw_map()
|
|||||||
local c = peek(300+(mx+my*20))
|
local c = peek(300+(mx+my*20))
|
||||||
poke(300+(mx+my*20), c~0xff)
|
poke(300+(mx+my*20), c~0xff)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if btn(KEY_S) then
|
||||||
|
fileout("map.bin", 0, 600);
|
||||||
|
elseif btn(KEY_L) then
|
||||||
|
filein("map.bin", 0, 600);
|
||||||
|
for i=0,299 do
|
||||||
|
map[i] = peek(i)
|
||||||
|
col[i] = peek(300+i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -85,6 +85,11 @@ function draw_map()
|
|||||||
sel_col = peek(1200+mx+my*40)
|
sel_col = peek(1200+mx+my*40)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if btnp(KEY_UP) then for i=40,1199 do map[i-40]=map[i]col[i-40]=col[i] end end
|
||||||
|
if btnp(KEY_DOWN) then for i=1159,0,-1 do map[i+40]=map[i]col[i+40]=col[i] end end
|
||||||
|
if btnp(KEY_LEFT) then for i=0,1198 do map[i]=map[i+1]col[i]=col[i+1] end end
|
||||||
|
if btnp(KEY_RIGHT) then for i=1199,1,-1 do map[i]=map[i-1]col[i]=col[i-1] end end
|
||||||
|
|
||||||
blink = blink - 1
|
blink = blink - 1
|
||||||
if blink < 30 then
|
if blink < 30 then
|
||||||
if blink==0 then blink = 60 end
|
if blink==0 then blink = 60 end
|
||||||
|
|||||||
84
tools/spritedit.lua
Normal file
84
tools/spritedit.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
function init()
|
||||||
|
ink_color = 15
|
||||||
|
paper_color = 0
|
||||||
|
setchar(0,0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff)
|
||||||
|
sprite={0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03}
|
||||||
|
end
|
||||||
|
|
||||||
|
function update()
|
||||||
|
color(15,1)
|
||||||
|
cls()
|
||||||
|
color(ink_color,paper_color)
|
||||||
|
drawbigspr(sprite,1,1)
|
||||||
|
drawspr(sprite,65)
|
||||||
|
print("AB",18,1) print("CD",18,2)
|
||||||
|
|
||||||
|
for i=0,15 do
|
||||||
|
color(0,i)
|
||||||
|
poke(721+i,0) poke(1921+i,i<<4)
|
||||||
|
poke(761+i,0) poke(1961+i,i<<4)
|
||||||
|
end
|
||||||
|
|
||||||
|
poke(1921+ink_color, peek(1921+ink_color)+4)
|
||||||
|
poke(1961+paper_color, peek(1961+paper_color)+4)
|
||||||
|
|
||||||
|
if mousebutton(1) and mousex()>=1 and mousey()>=18 and mousex()<=16 and mousey()<=19 then
|
||||||
|
if mousey()==18 then
|
||||||
|
ink_color = mousex()-1
|
||||||
|
else
|
||||||
|
paper_color = mousex()-1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
handlesprmouse()
|
||||||
|
end
|
||||||
|
|
||||||
|
mousepressed = false
|
||||||
|
mousepos = {x=-1,y=-1}
|
||||||
|
function handlesprmouse()
|
||||||
|
local mx,my=mousex(),mousey()
|
||||||
|
if mx>=1 and my>=1 and mx<=16 and my<=16 then
|
||||||
|
if mousebutton(1) then
|
||||||
|
if (not mousepressed or (mousepos.x ~= mx or mousepos.y ~= my)) then
|
||||||
|
mousepressed = true mousepos.x = mx mousepos.y = my
|
||||||
|
local quadrant = flr((mx-1)/8)+flr((my-1)/8)*2
|
||||||
|
local x=(mx-1)%8
|
||||||
|
local y=(my-1)%8
|
||||||
|
local val = sprite[quadrant*8+y+1]
|
||||||
|
val = val ~ (1<<(7-x))
|
||||||
|
sprite[quadrant*8+y+1] = val
|
||||||
|
end
|
||||||
|
else
|
||||||
|
mousepressed = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawbigspr(spr,x,y)
|
||||||
|
drawbigsprchr(spr,0,x,y)
|
||||||
|
drawbigsprchr(spr,1,x+8,y)
|
||||||
|
drawbigsprchr(spr,2,x,y+8)
|
||||||
|
drawbigsprchr(spr,3,x+8,y+8)
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawbigsprchr(spr,chr,x,y)
|
||||||
|
local pos = 1+chr*8
|
||||||
|
for i=1,8 do
|
||||||
|
local val = spr[pos]
|
||||||
|
print(" ",x,y)
|
||||||
|
if val&1==1 then print("\143",x+7,y) end
|
||||||
|
if val&2==2 then print("\143",x+6,y) end
|
||||||
|
if val&4==4 then print("\143",x+5,y) end
|
||||||
|
if val&8==8 then print("\143",x+4,y) end
|
||||||
|
if val&16==16 then print("\143",x+3,y) end
|
||||||
|
if val&32==32 then print("\143",x+2,y) end
|
||||||
|
if val&64==64 then print("\143",x+1,y) end
|
||||||
|
if val&128==128 then print("\143",x,y) end
|
||||||
|
y=y+1
|
||||||
|
pos=pos+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function drawspr(spr,chr)
|
||||||
|
for i=0,31 do poke(i+2560+chr*8,spr[i+1]) end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user