a few months ago i was checking out this website
http://www.davebollinger.com/works/pixelspaceships/
and decided to try to adapt his ideas into my own dbp code.
it worked!
this program generates an endless (~4 million) array of pixel spaceships,
which could be used as sprites for retro games or whatever.
i made it so you could change the color and size of a particular spaceship,
and even fully commented and spaced, that's 300 lines.
here's the uncompressed code:
` this work is based on a method created by Dave Bollinger (apparently)
` http://www.davebollinger.com/works/pixelspaceships/
` all the code is mine, but it is based on his descriptions.
set display mode 1024,768,32
sync on
sync rate 0
sync
set window on
set window position 0,0
randomize timer()
ink rgb(255,222,128),0
set text font "lucida console"
set text size 14
Dim Col(9) as DWORD
dim ship(13,13)
` MIRRORING: 1,12 ; 2,11 ; 3,10 ; 4,9 ; 5,8 ; 6,7
dim Temp(13,13)
` this is the TEMPLATE for ship building, and should be LOADED and STORED.
Global Size
Global Ysize
col(0)=0
col(1)=rgb(33,33,33)
col(2)=rgb(77,77,77)
col(3)=rgb(111,111,111)
col(4)=rgb(155,155,155)
col(5)=rgb(200,200,200)
col(6)=rgb(255,255,255)
Initialize_Ship_Template()
size=8
Ysize=12
Do
Generate_Ship()
draw_ship()
manipulate_Ship()
loop
END
Function Initialize_Ship_Template()
Restore Ship_Square_CASE_Data
for y=1 to 12
for x=1 to 6
read C
Temp(x,y)=c
next x
next y
Endfunction
Function Generate_Ship()
CLS
SOLID=rnd(1)
for x=1 to 12
for y=1 to 12
ship(x,y)=0
next y
next x
Restore Ship_Square_CASE_Data
for y=1 to 12
for x=1 to 6
C = Temp(x,y)
SELECT C
Case 0 : ` - always BLACK, NOT part of the spaceship.
ship(x,y)=0
endcase
Case 1 : ` - the ALWAYS SOLID bit (which should really be allowed to be either WHITE or DARK GREY
if SOLID=1
ship(x,y)=2
else
ship(x,y)=6
endif
endcase
Case 2 : ` - BODY
` this is the body. 50% chance of being ON, or BLACK (totally off)
if rnd(1)=0
ship(x,y)=3
else
ship(x,y)=0
endif
endcase
Case 3 : ` - COCKPIT
if rnd(1)=0 : ` 50% on or off. if it's ON, the color is the OPPOSITE of the "always on" color. if it's OFF, its BLACK.
if SOLID=0
ship(x,y)=4
else
ship(x,y)=5
endif
else
ship(x,y)=0
endif
endcase
Case 4 : ` - nothing here.
endcase
Case 5 : ` - allowed to be SKIN.
` SKIN is done LAST , and EVERY 'ON' PART creates SKIN. done elsewhere.
endcase
ENDSELECT
`DRAW_SHIP()
next x
next y
` NOW, generate the "SKIN"
` SKIN applies ONLY to EMPTY BLACK squares.
` it will be MUCH EASIER AND FASTER to look at EMPTY BLACK SQUARES
` and find if they get turned on, than to look at turner-on'ers.
for y=1 to 12
for x=1 to 12
if ship(x,y)=0
if ship(x-1,y)>1 or ship(x+1,y)>1 or ship(x,y-1)>1 or ship(x,y+1)>1
if TEMP(x,y)>0
` IF this square is black, and an adjacent square is ON, and it's not beyond the outer skin
ship(x,y)=1
endif
endif
endif
next x
next y
` NOW, MIRROR the ship.
` 1,12 ; 2,11 ; 3,10 ; 4,9 ; 5,8 ; 6,7
for y=1 to 12
for x=1 to 6
z=13-x
ship(z,y)=ship(x,y)
next x
next y
DRAW_SHIP()
sync
Endfunction
Function DRAW_SHIP()
cls
for y=1 to 12
for x=1 to 12
box x*size,y*Ysize,x*size+size,y*Ysize+Ysize,col(ship(x,y)),col(ship(x,y)),col(ship(x,y)),col(ship(x,y))
box x*size,y*Ysize+350,x*size+size,y*Ysize+Ysize+350,col(ship(x,y)),col(ship(x,y)),col(ship(x,y)),col(ship(x,y))
next x
next y
Endfunction
Ship_Square_CASE_Data:
data 0,0,0,0,5,5
data 0,0,0,5,2,2
data 0,0,0,5,2,1
data 0,0,5,2,2,1
data 0,0,5,2,2,1
data 0,5,2,2,2,1
data 5,2,2,2,3,3
data 5,2,2,2,3,3
data 5,2,2,2,3,3
data 5,2,2,2,2,1
data 0,5,5,2,2,2
data 0,0,0,5,5,5
Function manipulate_Ship()
do
cls
draw_ship()
box 300,300,600,600,rgb(255,0,0),rgb(0,0,0),rgb(0,255,0),rgb(0,0,255)
box 600,300,900,600,rgb(255,0,255),rgb(255,255,0),rgb(255,128,0),rgb(255,255,255)
box 300,600,900,800,rgb(0,0,0),rgb(0,0,0),rgb(255,255,255),rgb(255,255,255)
text 300,0,"0 - BLACK - Non-ship squares"
text 300,20,"1 - Outer Skin" : box 500,20,700,30,col(1),col(1),col(1),col(1)
text 300,40,"2 - Always Solid (50%)" : box 500,40,700,50,col(2),col(2),col(2),col(2)
text 300,60,"3 - BODY" : box 500,60,700,70,col(3),col(3),col(3),col(3)
text 300,80,"4 - cockpit" : box 500,80,700,90,Col(4),Col(4),Col(4),Col(4)
text 300,100,"5 - cockpit (50%)" : box 500,100,700,110,Col(5),Col(5),Col(5),Col(5)
text 300,120,"6 - Always solid (50%)" : box 500,120,700,130,Col(6),Col(6),Col(6),Col(6)
text 300,160,"put the mouse over a color. press corresponding number to select that color "
TEXT 300,180, " PRESS +/- to change WIDTH ("+STR$(SIZE)+"), or >/< to change HEIGHT ("+STR$(YSIZE)+")"
text 300,240," PRESS SPACE BAR TO GENERATE A NEW SHIP "
text 000,730,"check out this web site :"
text 000,750," http://www.davebollinger.com/works/pixelspaceships/"
a=val(inkey$())
if a>0 and a<7
col(a)=point(mousex(),mousey())
endif
if keystate(12) and size>2
dec size : wait 150
endif
if keystate(13) and size<20
inc size : wait 150
endif
if keystate(51) and Ysize>2
dec Ysize : wait 150
endif
if keystate(52) and Ysize<28
inc Ysize : wait 150
endif
sync
IF SPACEKEY() THEN wait 250 : EXIT
loop
Endfunction
attached is a compiled version. no media required.
some improvements you could make:
-it wouldn't be hard to add a "save image" function, to get these sprites.
-using the mouse to turn a square off or on manually (and even to assign it to one of the 7 'color classes')
-maybe someone could actually include something like this in a game where players can design their own ships for each game.