Space Invaders 8: Nothing to see here
This one is mostly for the record, if it goes as planned. I’m just going to import some more bitmaps. I recommend against reading this.
Here’s the program I used to create the existing invader bitmaps, modified just a bit from Dave1707’s original gift to me.
displayMode(STANDARD)
function setup()
parameter.integer("sc",1,15,5)
inv1={0x00,0x00,0x39,0x79,0x7A,0x6E,0xEC,0xFA,0xFA,0xEC,0x6E,0x7A,0x79,0x39}
inv2={0x00,0x00,0x00,0x78,0x1D,0xBE,0x6C,0x3C,0x3C,0x3C,0x6C,0xBE,0x1D,0x78}
inv3={0x00,0x00,0x00,0x00,0x19,0x3A,0x6D,0xFA,0xFA,0x6D,0x3A,0x19,0x00,0x00}
play={0x00,0x0F,0x1F,0x1F,0x1F,0x1F,0x7F,0xFF,0x7F,0x1F,0x1F,0x1F,0x1F,0x0F}
inv12={0x00,0x00,0x38,0x7A,0x7F,0x6D,0xEC,0xFA,0xFA,0xEC,0x6D,0x7F,0x7A,0x38,0x00,0x00}
inv22={0x00,0x00,0x00,0x0E,0x18,0xBE,0x6D,0x3D,0x3C,0x3D,0x6D,0xBE,0x18,0x0E,0x00,0x00}
inv32={0x00,0x00,0x00,0x00,0x1A,0x3D,0x68,0xFC,0xFC,0x68,0x3D,0x1A,0x00,0x00,0x00,0x00}
playx1={0x00,0x04,0x01,0x13,0x03,0x07,0xB3,0x0F,0x2F,0x03,0x2F,0x49,0x04,0x03,0x00,0x01}
playx2={0x40,0x08,0x05,0xA3,0x0A,0x03,0x5B,0x0F,0x27,0x27,0x0B,0x4B,0x40,0x84,0x11,0x48}
inv1map=image(16,8)
inv2map=image(16,8)
inv3map=image(16,8)
playmap=image(16,8)
inv12map=image(16,8)
inv22map=image(16,8)
inv32map=image(16,8)
playx1map=image(16,8)
playx2map=image(16,8)
bitMap(inv1,inv1map)
bitMap(inv2,inv2map)
bitMap(inv3,inv3map)
bitMap(play,playmap)
bitMap(inv12,inv12map)
bitMap(inv22,inv22map)
bitMap(inv32,inv32map)
bitMap(playx1,playx1map)
bitMap(playx2,playx2map)
-- save the imagessprite(asset.documents.Dropbox.milkyway,20,20)
saveImage(asset.documents.Dropbox .. "inv11", inv1map)
saveImage(asset.documents.Dropbox .. "inv21", inv2map)
saveImage(asset.documents.Dropbox .. "inv31", inv3map)
saveImage(asset.documents.Dropbox .. "play", playmap)
saveImage(asset.documents.Dropbox .. "inv12", inv12map)
saveImage(asset.documents.Dropbox .. "inv22", inv22map)
saveImage(asset.documents.Dropbox .. "inv32", inv32map)
saveImage(asset.documents.Dropbox .. "playx1", playx1map)
saveImage(asset.documents.Dropbox .. "playx2", playx2map)
end
function bitMap(hexString,img)
for a=1,#hexString do
for z=0,7 do
if (hexString[a]>>z)&1==1 then
img:set(a,z+1,255,255,255,255)
end
end
end
end
function draw()
background(0)
noSmooth()
fontSize(30)
fill(255)
text("Scale "..sc,WIDTH/2,HEIGHT-100)
scale(sc,sc)
sprite(inv1map,WIDTH/2/sc,HEIGHT*.7/sc)
sprite(inv12map, WIDTH/2/sc + 3*sc, HEIGHT*.7/sc)
sprite(inv2map,WIDTH/2/sc,HEIGHT*.5/sc)
sprite(inv22map, WIDTH/2/sc + 3*sc, HEIGHT*.5/sc)
sprite(inv3map,WIDTH/2/sc,HEIGHT*.3/sc)
sprite(inv32map, WIDTH/2/sc + 3*sc, HEIGHT*.3/sc)
sprite(playmap,WIDTH/2/sc,HEIGHT*.1/sc)
sprite(playx1map, WIDTH/2/sc + 3*sc, HEIGHT*.1/sc)
sprite(playx2map, WIDTH/2/sc + 6*sc, HEIGHT*.1/sc)
end
This code gives us the invader bitmaps, six of them (three invader types times two positions), and the player cannon plus two explosions for it,
The remaining bitmaps include the missiles, which are what I really want, plus the player shot explosion, alien explosion, alien shot explosion, the shield, and the saucer. There’s also a couple of bitmaps of the alien pulling an upside down Y that is used in the attract screen. I’m not planning to do that part of this game, but I suppose I might as well drag it in.
My basic plan is to duplicate Dave’s program, rip out the calls that build what we have now, and replace with what it takes to build the new stuff. I’ll pull the definitions out of the source code into Sublime, edit them there into Lua format, and paste them across into the program. Should be tedious but I’m hoping for no trouble.
I’m expecting no big learnings here, so this article is just to be sure I have a fairly complete record.
Here goes.
- regex replace ; …….. with nothing to remove comments
- regex replace ^….: with nothing, remove addresses
- manually roll three lines into one for shots
- regex ([[:xdigit:]])([[:xdigit:]]) into 0x\1\2,
- regex ^.*0x into {
- regex ,$ into }
- regex comma space into comma
- replace spaces in comment names with underbar to get legit names
- replace { with ={
- duplicate and number names squig1 2 3 4 etc
Then inline the creations thusly:
player_shot
={0x0F}
map_player_shot = image(1,8)
bitMap(player_shot, map_player_shot)
saveImage(asset.documents.Dropbox .. "player_shot", map_player_shot)
The saveImage
is hard to edit, pull out a function named save:
function save(name, map)
saveImage(asset.documents.Dropbox .. name, map)
end
Used:
player_shot
={0x0F}
map_player_shot = image(1,8)
bitMap(player_shot, map_player_shot)
save("player_shot", map_player_shot)
Now it’s just tedium to do them all, though perhaps we can shorten the effort with another function. Let’s try it. We do want to save the map because we’re displaying our results in draw. I’ll just try typing something in:
function makeBitmap(bits, cols, rows, name)
local img = image(cols,rows)
bitMap(bits, img)
save(name, img)
end
Used like this:
player_shot_exploding
={0x99,0x3C,0x7E,0x3D,0xBC,0x3E,0x7C,0x99}
map_player_shot_expl = makeBitmap(player_shot_exploding, 8,8, "player shot exploding")
Trying it … forgot to return the result:
function makeBitmap(bits, cols, rows, name)
local img = image(cols,rows)
bitMap(bits, img)
save(name, img)
return img
end
Plugging the two new bitmaps into draw, I get this:
However, looking into the assets folder “Dropbox”, I don’t see my new maps. Pressing the sync button seems to have done the trick. I don’t understand what that did, but now I’m displaying the bitmaps, not from internal memory but from the dropbox. That means I don’t need to save the bitmaps:
player_shot_exploding
={0x99,0x3C,0x7E,0x3D,0xBC,0x3E,0x7C,0x99}
makeBitmap(player_shot_exploding, 8,8, "player shot exploding")
So now to do the next one …
Alien_Exploding
={0x00,0x08,0x49,0x22,0x14,0x81,0x42,0x00,0x42,0x81,0x14,0x22,0x49,0x08,0x00,0x00}
makeBitmap(Alien_Exploding, 16,8, "alien_exploding")
That works and draws correctly after syncing the dropbox, whatever that means. Maybe it just means to refresh the cached copy in Codea? I’ll ask on the forum. Anyway, we’re good to do the rest.
The rest all go in nicely, with the exception of the shield, which looks decidedly odd:
I seem to recall the comment on the shield was odd as well. Here’s one such:
0221: 01 02 16 LD BC,$1602 ; 22 rows, 2 bytes/row (for 1 shield pattern)
That makes me think the bitmap there is supposed to be 22 by 16. Let’s see if Dave’s program can deal with that.
It can, but the result isn’t better. I’ll have to do a little decoding of the code to figure this out, I guess. For now, we certainly have all the data and we have saved it to the folder.
I’m calling that done. And there is a small lesson:
Summing Up
Maybe even a lesson and a half. The half was to remember to edit the data on my Mac, in Sublime, where I could regex-replace the stuff to get it into Codea’s format. That saved ages of tedious typing. Since I knew I could copy-paste between machines, that was an easy decision to make.
But then, in two easy steps, I simplified what needed to be typed to do the saves down from three lines to one. And I even then took advantage of the save to display from Codea’s Dropbox, instead of from the maps as the original program had done, which gives confidence that the data is actually saved.
All in all, a decent morning. I still recommend that you not bother to read this.
Postscript
The difficulty with the shield appears to me to be that the rows are reversed, with the row that should be on the bottom on top and vice versa. I’ll see if I can hack the bitMap
function to fix that. And I do mean hack.
I came up with this:
shield
= {0xFF,0x0F,0xFF,0x1F,0xFF,0x3F,0xFF,0x7F,
0xFF,0xFF,0xFC,0xFF,0xF8,0xFF,0xF0,0xFF,
0xF0,0xFF,0xF0,0xFF,0xF0,0xFF,0xF0,0xFF,
0xF0,0xFF,0xF0,0xFF,0xF8,0xFF,0xFC,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0x3F,
0xFF,0x1F,0xFF,0x0F}
makeBitmap2(shield, 22,16, "shield")
function makeBitmap2(bits, cols, rows, name)
local img = image(cols,rows)
bitMap2Row(bits, img)
save(name, img)
end
function bitMap2Row(hexString,img)
local col = 0
for str = 1, #hexString, 2 do
col = col + 1
b1 = hexString[str] -- bottom
b2 = hexString[str+1] -- top
for z = 0,7 do
if (b1>>z)&1==1 then -- set bottom
img:set(col,z+1, 255,255,255,255)
end
if (b2>>z)&1==1 then -- set top
img:set(col,z+9,255,255,255,255)
end
end
end
end
This was grotesque hackery and it results in this final pic:
The Code
displayMode(STANDARD)
function setup()
parameter.integer("sc",1,15,5)
--[[
alien_upside_down_Y_1
={0x00,0x03,0x04,0x78,0x14,0x13,0x08,0x1A,0x3D,0x68,0xFC,0xFC,0x68,0x3D,0x1A,0x00}
alien_upside_down_Y_2
={0x00,0x00,0x01,0xB8,0x98,0xA0,0x1B,0x10,0xFF,0x00,0xA0,0x1B,0x00,0x00,0x00,0x00}
Splash_shooting_C
={0x00,0x10,0x00,0x0E,0x05,0x00,0x00,0x00,0x00,0x00,0x07,0xD0,0x1C,0xC8,0x9B,0x03}
Alien_Y2
={0x00,0x00,0x03,0x04,0x78,0x14,0x0B,0x19,0x3A,0x6D,0xFA,0xFA,0x6D,0x3A,0x19,0x00}
]]--
player_shot
={0x0F}
map_player_shot = image(1,8)
bitMap(player_shot, map_player_shot)
save("player_shot", map_player_shot)
player_shot_exploding
={0x99,0x3C,0x7E,0x3D,0xBC,0x3E,0x7C,0x99}
makeBitmap(player_shot_exploding, 8,8, "player_shot_exploding")
Alien_Exploding
={0x00,0x08,0x49,0x22,0x14,0x81,0x42,0x00,0x42,0x81,0x14,0x22,0x49,0x08,0x00,0x00}
makeBitmap(Alien_Exploding, 16,8, "alien_exploding")
squig1
={0x44,0xAA,0x10}
makeBitmap(squig1, 3,8, "squig1")
squig2
={0x88,0x54,0x22}
makeBitmap(squig2, 3,8, "squig2")
squig3
={0x10,0xAA,0x44}
makeBitmap(squig3, 3,8, "squig3")
squig4
={0x22,0x54,0x88}
makeBitmap(squig4, 3,8, "squig4")
alien_shot_exploding
={0x4A,0x15,0xBE,0x3F,0x5E,0x25}
makeBitmap(alien_shot_exploding, 6,8, "alien_shot_exploding")
plunger_shot_1
={0x04,0xFC,0x04}
makeBitmap(plunger_shot_1, 3,8, "plunger1")
plunger_shot_2
={0x10,0xFC,0x10}
makeBitmap(plunger_shot_2, 3,8, "plunger2")
plunger_shot_3
={0x20,0xFC,0x20}
makeBitmap(plunger_shot_3, 3,8, "plunger3")
plunger_shot_4
={0x80,0xFC,0x80}
makeBitmap(plunger_shot_4, 3,8, "plunger4")
rolling_shot_1
={0x00,0xFE,0x00}
makeBitmap(rolling_shot_1, 3,8, "rolling1")
rolling_shot_2
={0x24,0xFE,0x12}
makeBitmap(rolling_shot_2, 3,8, "rolling2")
rolling_shot_3
={0x00,0xFE,0x00}
makeBitmap(rolling_shot_3, 3,8, "rolling3")
rolling_shot_4
={0x48,0xFE,0x90}
makeBitmap(rolling_shot_4, 3,8, "rolling4")
shield
= {0xFF,0x0F,0xFF,0x1F,0xFF,0x3F,0xFF,0x7F,
0xFF,0xFF,0xFC,0xFF,0xF8,0xFF,0xF0,0xFF,
0xF0,0xFF,0xF0,0xFF,0xF0,0xFF,0xF0,0xFF,
0xF0,0xFF,0xF0,0xFF,0xF8,0xFF,0xFC,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0x3F,
0xFF,0x1F,0xFF,0x0F}
makeBitmap2(shield, 22,16, "shield")
Saucer
={0x00,0x00,0x00,0x00,0x04,0x0C,0x1E,0x37,0x3E,0x7C,0x74,0x7E,0x7E,0x74,0x7C,0x3E,0x37,0x1E,0x0C,0x04,0x00,0x00,0x00,0x00}
makeBitmap(Saucer, 24,8, "saucer")
saucer_exploding
={0x00,0x22,0x00,0xA5,0x40,0x08,0x98,0x3D,0xB6,0x3C,0x36,0x1D,0x10,0x48,0x62,0xB6,0x1D,0x98,0x08,0x42,0x90,0x08,0x00,0x00}
makeBitmap(saucer_exploding, 24,8, "saucer_exploding")
--[[
alien_with_Y
={0x60,0x10,0x0F,0x10,0x60,0x30,0x18,0x1A,0x3D,0x68,0xFC,0xFC,0x68,0x3D,0x1A,0x00}
makeBitmap(alien_with_Y, 16,8, "alien_y")
]]--
end
function bitMap(hexString,img)
for a=1,#hexString do
for z=0,7 do
if (hexString[a]>>z)&1==1 then
img:set(a,z+1,255,255,255,255)
end
end
end
end
function bitMap2Row(hexString,img)
local col = 0
for str = 1, #hexString, 2 do
col = col + 1
b1 = hexString[str] -- bottom
b2 = hexString[str+1] -- top
for z = 0,7 do
if (b1>>z)&1==1 then -- set bottom
img:set(col,z+1, 255,255,255,255)
end
if (b2>>z)&1==1 then -- set top
img:set(col,z+9,255,255,255,255)
end
end
end
end
function draw()
background(0)
noSmooth()
fontSize(30)
fill(255)
text("Scale "..sc,WIDTH/2,HEIGHT-100)
local y
scale(sc,sc)
sprite(asset.documents.Dropbox.player_shot,WIDTH/2/sc,HEIGHT*.8/sc)
sprite(asset.documents.Dropbox.player_shot_exploding,WIDTH/2/sc + 3*sc,HEIGHT*.8/sc)
sprite(asset.documents.Dropbox.alien_exploding,WIDTH/2/sc,HEIGHT*.7/sc)
sprite(asset.documents.Dropbox.alien_shot_exploding,WIDTH/2/sc + 3*sc,HEIGHT*.7/sc)
y = 0.6
sprite(asset.documents.Dropbox.plunger1,WIDTH/2/sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.plunger2,WIDTH/2/sc + 3*sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.plunger3,WIDTH/2/sc + 6*sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.plunger4,WIDTH/2/sc + 9*sc,HEIGHT*y/sc)
y = 0.5
sprite(asset.documents.Dropbox.rolling1,WIDTH/2/sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.rolling2,WIDTH/2/sc + 3*sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.rolling3,WIDTH/2/sc + 6*sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.rolling4,WIDTH/2/sc + 9*sc,HEIGHT*y/sc)
y = 0.4
sprite(asset.documents.Dropbox.squig1,WIDTH/2/sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.squig2,WIDTH/2/sc + 3*sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.squig3,WIDTH/2/sc + 6*sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.squig4,WIDTH/2/sc + 9*sc,HEIGHT*y/sc)
y = 0.3
sprite(asset.documents.Dropbox.saucer,WIDTH/2/sc,HEIGHT*y/sc)
sprite(asset.documents.Dropbox.saucer_exploding,WIDTH/2/sc + 6*sc,HEIGHT*y/sc)
y = 0.1
sprite(asset.documents.Dropbox.shield,WIDTH/2/sc,HEIGHT*y/sc)
end
function save(name, map)
saveImage(asset.documents.Dropbox .. name, map)
end
function makeBitmap(bits, cols, rows, name)
local img = image(cols,rows)
bitMap(bits, img)
save(name, img)
end
function makeBitmap2(bits, cols, rows, name)
local img = image(cols,rows)
bitMap2Row(bits, img)
save(name, img)
end