Quote: "@ Latch, ran your tank game code. Pity you didn't get it finished, it looked really good. "
Thanks! I've decided to finish up the tank code - mainly to get my head into coding again a bit, and also to try and throw this thread a bit of a lifline.
Anyway, it's not as "finished" as it could be. I had ideas for animations, exploding tanks, maybe sound, scores, etc.; but what I'm submitting here is very true to the game I played on paper.
Basically, there are ten tanks on each side of a sheet of paper folded in half. Each player marks a dot on their side of the battle field. They fold the paper end to end and color the back of the sheet where they had placed their dot. This transfers a carbon copy of sorts of the dot onto the enemy's battle field. This duplicate is where you have fired. If it's within the drawing of an enemy tank, then you have hit it.
This version is very open. I've only included the mechanics: the drawing of the tanks, the placement of the dots, the folding of the page, and the transfer of the dots. To play it, simply move the pencil around on the virtual paper. LEFT CLICK on either side of the battle field of where you want to fire. You can guage the middle of the page by locating a faint fold line down the center of the screen - this should help in gauging where to attack. If you fire from the RED side, your dot will be red. If you fire from the blue side, your dot will be blue. Again, this is almost exactly how the game works and looks on paper so you can make the rules for how you want to play and what is considered a legal hit.
The code is meant for use with DBC 1.20 . 1.13 and earlier may have lighting and texturing differences.
remstart
==============================================================
= Title : Tank Battle paper 'n' pencil game
= Author : latch
= Date : 05/05/2011
= Update : 08/27/2011, 09/07/2011
= Version: .03
==============================================================
Comments
Simulate the paper and pencil game I know as
tank battle where attacks are made from either
side of a folded sheet of paper by folding the paper
half and matching up colored in dots.
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 60
hide mouse
rem =============================================================
rem = MAIN
rem =============================================================
_main:
gosub _init
gosub _set_tank_positions
gosub _screen_to_planes
gosub _make_pencil
position camera 0,0,0
rem background to black
color backdrop 0
do
gosub _move_pencil
gosub _check_for_click
sync
loop
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_init:
rem setup tanks
`identify tank images
bluetank=1
yellowtank=2
paperdot=3
paperbmp=1
tankbmp=2
pencilmarkbmp=3
pencilmarkimg=4
rem create a bitmap that will be used to capture pencil mark images
create bitmap pencilmarkbmp,screen width(),screen height()
rem draw tanks and save them to an image
create bitmap tankbmp,100,100
rem blue tank
cls 0
ink 128,0
rem set data counter to beginning of tank data
restore _tank_data
read totdata
rem dimension an array to store the tank data for later use
rem and a displacement array for explosions later on
dim tdata(totdata,1)
dim displace#(totdata,3)
for c=1 to totdata
read x,y
tdata(c,0)=x : tdata(c,1)=y
dot x,y
next c
get image bluetank,0,0,64,32,1
sync
rem red tank
cls 0
ink rgb(255,0,0),0
rem set data counter to beginning of tank data
restore _tank_data
read totdata
for c=1 to totdata
read x,y
dot 63-x,y
next c
get image yellowtank,0,0,64,32,1
sync
rem cleanup
delete bitmap tankbmp
rem note paper texture
gosub _note_paper_texture
return
`================================================================
_set_tank_positions:
randomize timer()
rem array to store all tanks screen positions
rem 1-10 are blue, 1-20 are yellow
dim tankpos(20,1)
rem position blue tanks on the right side of the screen
sw=screen width()
sh=screen height()
create bitmap tankbmp,sw,sh
hsw=sw/2
hsh=sh/2
rem copy note_paper_background
copy bitmap paperbmp,tankbmp
rem blue tanks
for t=1 to 10
_randpos:
redo=0
x=rnd(hsw)+hsw
if x > (sw-65) then x=sw-65
y=rnd(sh)
if y > (sh-34) then y=sh-34
rem make sure the tanks don't overlap
for t2=1 to t
if t2 ! t
dist#=sqrt((tankpos(t2,0)-x)^2 + (tankpos(t2,1)-y)^2)
if dist# < 100
redo=1
exit
endif
endif
next t2
if redo then goto _randpos
tankpos(t,0)=x : tankpos(t,1)=y
paste image bluetank,x,y,1
next t
rem yellow tanks
for t=11 to 20
_randpos2:
redo=0
x=rnd(hsw)
if x > (hsw-65) then x=hsw-65
y=rnd(sh)
if y > (sh-34) then y=sh-34
rem make sure the tanks don't overlap
for t2=11 to t
if t2 ! t
dist#=sqrt((tankpos(t2,0)-x)^2 + (tankpos(t2,1)-y)^2)
if dist# < 100
redo=1
exit
endif
endif
next t2
if redo then goto _randpos2
tankpos(t,0)=x : tankpos(t,1)=y
paste image yellowtank,x,y,1
next t
return
`================================================================
_screen_to_planes:
rem copy the screen to planes so we can simulate folding
set current bitmap tankbmp
rem calculate z for plane size and distance so the textures
rem are equal to the screen size
fov#=180*((3.14/2.905)/3.14)
`fov#=62
zdist#=hsh/tan(fov#/2.0)
wdtoht#=sw/(sh+0.0)
y#=tan(fov#/2.0)
x#=wdtoht#*y#
rem get images
leftside=1000
get image leftside,0,0,hsw,sh
sync
rightside=1001
get image rightside,hsw,0,sw,sh
sync
rem create halves of screen (planes)
make object plain leftside,hsw,sh
offset limb leftside,0,hsw/-2.0,0,0
make mesh from object leftside,leftside
delete object leftside
make object leftside,leftside,leftside
delete mesh leftside
position object leftside,0-y#,y#,zdist#
set object leftside,1,0,0
ghost object on leftside
sync
make object plain rightside,hsw,sh
offset limb rightside,0,hsw/2.0,0,0
make mesh from object rightside,rightside
delete object rightside
make object rightside,rightside,rightside
delete mesh rightside
position object rightside,0-y#,y#,zdist#
set object rightside,1,0,0
ghost object on rightside
sync
return
`================================================================
_note_paper_texture:
rem create paper bitmap
create bitmap paperbmp,screen width(),screen height()
rem clear screen white
cls rgb(255,255,255)
rem make a fold in the middle of the paper
oldx=screen width()/2
for y=0 to screen height()
c=rnd(35)+220
ink rgb(c,c,c),0
x=(screen width()/2)+(rnd(2)-1)
y=y+rnd(4)
line oldx,oldy,x,y
oldx=x
oldy=y
next y
rem create blue stripes
ink rgb(192,192,255),0
for x=96 to screen width() step 24
line x,0,x,screen height()
next x
rem create double red line margin
ink rgb(255,192,192),0
line 0,screen height()-96,screen width(),screen height()-96
line 0,screen height()-92,screen width(),screen height()-92
rem create black spots for binder rings
ink 0,0
for r=0 to 15
circle 15,15,r
circle 16,15,r
next r
get image paperdot,0,0,32,32
sync
ink rgb(255,255,255),0
box 0,0,34,34
paste image paperdot,(screen width()/2)-16,screen height()-48
paste image paperdot,64,screen height()-48
paste image paperdot,screen width()-80,screen height()-48
set current bitmap 0
sync
return
`================================================================
_check_for_click:
rem see if the mouse was left clicked on the left or right
rem side of the screen and a fold is not taking place
if (mouseclick()&1)
mx=mousex()
my=mousey()
if mx > hsw
rem the mouse was left clicked on the right side
rem draw the shoot point
gosub _draw_shot_spot
rem start folding
ang=0
while ang < 180
inc ang
yrotate object rightside,ang
rem get pencil out of scene ; oldx,oldy,oldz defined in _draw_shot_spot
position object pencil,oldx#,oldy#,oldz#-(5*ang)
sync
endwhile
rem so the page should be folded. Now transfer the dot
mirror sprite pencilmarkimg
set current bitmap tankbmp
paste sprite pencilmarkimg,(hsw-(mx-hsw))-6,my-7
sync
delete sprite pencilmarkimg
delete image leftside
get image leftside,0,0,hsw,sh
sync
texture object leftside,leftside
ang=180
while ang > 0
dec ang
yrotate object rightside,ang
rem bring pencil back in scene ; oldx,oldy,oldz defined in _draw_shot_spot
position object pencil,oldx#,oldy#,oldz#-(5*ang)
sync
endwhile
position object pencil,oldx#,oldy#,oldz#
else
rem the fold has taken place on the left side
rem draw shoot point
gosub _draw_shot_spot
rem start folding
ang=360
while ang > 180
dec ang
yrotate object leftside,ang
rem get pencil out of scene ; oldx,oldy,oldz defined in _draw_shot_spot
position object pencil,oldx#,oldy#,oldz#-(5*(360-ang))
sync
endwhile
rem so the page should be folded. Now transfer the dot
mirror sprite pencilmarkimg
set current bitmap tankbmp
paste sprite pencilmarkimg,(hsw+(hsw-mx))-6,my-7
sync
delete sprite pencilmarkimg
delete image rightside
get image rightside,hsw,0,sw,sh
sync
texture object rightside,rightside
ang=180
while ang < 360
inc ang
yrotate object leftside,ang
rem bring pencil back in scene ; oldx,oldy,oldz defined in _draw_shot_spot
position object pencil,oldx#,oldy#,oldz#-(5*(360-ang))
sync
endwhile
position object pencil,oldx#,oldy#,oldz#
endif
endif
return
`================================================================
_make_pencil:
rem make a pencil graphic
pencil=5000
size#=25
make_pencil(pencil,size#,pencil)
xrotate object pencil,230
position object pencil,0,0,zdist#-100
set object ambient pencil,rgb(80,80,80)
set object specular pencil,rgb(64,64,64),50
return
`================================================================
_move_pencil:
penx#=object position x(pencil)
peny#=object position y(pencil)
penz#=object position z(pencil)
mmx=mousemovex()
mmy=mousemovey()
penx#=penx#+mmx
peny#=peny#-mmy
position object pencil,penx#,peny#,penz#
if object screen x(pencil) > sw or object screen x(pencil) < 0
penx#=penx#-mmx
endif
if object screen y(pencil) > sh or object screen y(pencil) < 0
peny#=peny#+mmy
endif
position object pencil,penx#,peny#,penz#
position mouse object screen x(pencil),object screen y(pencil)
rem turn pencil for fun
yrotate object pencil,wrapvalue(object angle y(pencil)+1)
return
`================================================================
_draw_shot_spot:
rem draw the spot from which to launch an attack
set current bitmap pencilmarkbmp
rem current positions of pencil and mouse
x1=mousex()
y1=mousey()
oldx#=object position x(pencil)
oldy#=object position y(pencil)
oldz#=object position z(pencil)
rem change pencil ink depending on who shoots
if x1 > hsw
`blue
ink 128,0
else
`red
ink rgb(255,0,0),0
endif
for n=0 to 0
for ang=0 to 359 step 4
r=rnd(8)
x2=r*cos(ang)+x1
y2=r*sin(ang)+y1
line x1,y1,x2,y2
rem move pencil as if scribbling
position object pencil,oldx#+(r*cos(ang)),oldy#-(r*sin(ang)),oldz#
rem make sure scribbled image is within bitmap limits
x3=x1-8 : if x3 < 0 then x3=0
x4=x1+8 : if x4 > sw-1 then x4=sw-1
y3=y1-8 : if y3 < 0 then y3=0
y4=y1+8 : if y4 > sh-1 then y4=sh-1
get image pencilmarkimg,x3,y3,x4,y4
sync : rem sync helpful for keeping image current and delay for visuals
sprite pencilmarkimg,x1-8,y1-8,pencilmarkimg
next ang
next n
rem pasting the pencil mark directly to the tank+paper bitmap
position object pencil,oldx#,oldy#,oldz#
set current bitmap tankbmp
paste image pencilmarkimg,x1-8,y1-8,1
rem retexture the folding paper planes
`right side
if x1 > hsw
delete image rightside
get image rightside,hsw,0,sw,sh
sync
texture object rightside,rightside
else
delete image leftside
get image leftside,0,0,hsw,sh
sync
texture object leftside,leftside
endif
hide sprite pencilmarkimg
return
`================================================================
rem =============================================================
rem = FUNCTIONS
rem =============================================================
function make_pencil(obj,size#,startimg)
rem pencil textures
bmp=1
while bitmap exist(bmp)
inc bmp
endwhile
create bitmap bmp,64,64
rem eraser
img1=startimg
while image exist(img1)
inc img1
endwhile
ink RGB(255,128,128),0
box 0,0,63,63
get image img1,0,0,64,64
cls 0
rem shaft
img2=img1+1
while image exist(img2)
inc img2
endwhile
ink RGB(244,209,11),rgb(0,0,100)
box 0,0,63,63
set text font "system",1
set text opaque
set text size 16
sync
text 0,10,"2"
get image img2,0,0,64,64
cls 0
rem point
img3=img2+1
while image exist(img3)
inc img3
endwhile
ink RGB(254,227,200),0
box 0,0,63,63
ink RGB(128,128,128),0
box 0,0,63,25
get image img3,0,0,64,64
delete bitmap bmp
tip=obj
eraser=obj+1
shaft=obj+2
make object cylinder shaft,size#
scale object shaft,100,400,100
make mesh from object shaft,shaft
delete object shaft
make object cylinder eraser,size#
make mesh from object eraser,eraser
delete object eraser
make object cone tip,size#
rotate limb tip,0,180,0,0
make mesh from object tip,tip
delete object tip
make object tip,tip,0
offset limb tip,0,0,size#/2.0,0
make mesh from object tip,tip
delete object tip
rem build pencil from meshes
make object tip,tip,img3
add limb tip,1,shaft
texture limb tip,1,img2
offset limb tip,1,0,size#*3,0
add limb tip,2,eraser
texture limb tip,2,img1
offset limb tip,2,0,size#*5.5,0
scroll limb texture tip,0,0,.42
endfunction tip
rem =============================================================
rem = DATA STATEMENTS
rem =============================================================
_tank_data:
rem the data is based on the layout of a 64x32 grid. Each pair of numbers
rem is an x y coordinate of where there is color on the grid. This will
rem draw the outline of a tank. If there is no color, the pixel doesn't
rem have to be represented. the first number is the count of pairs
data 228
data 0,9, 0,10, 0,11, 1,7, 1,8, 1,12, 2,7, 2,12, 3,7, 3,12, 4,7, 4,12, 5,7, 5,12, 6,7, 6,12
data 7,7, 7,12, 8,7, 8,12, 9,7, 9,12, 10,7, 10,12, 11,7, 11,12, 12,7, 12,12, 13,7, 13,12, 14,7, 14,12
data 15,7, 15,12, 16,8, 16,11, 17,8, 17,11, 17,18, 17,19, 18,8, 18,11, 18,17, 18,19, 19,8, 19,11, 19,16, 19,19
data 19,20, 19,21, 19,22, 19,23, 20,8, 20,11, 20,15, 20,24, 21,8, 21,11, 21,15, 21,25, 22,8, 22,11, 22,14, 22,26
data 23,8, 23,11, 23,14, 23,27, 23,28, 24,8, 24,11, 24,12, 24,13, 24,26, 24,29, 25,8, 25,11, 25,25, 25,30, 26,8
data 26,11, 26,25, 26,31, 27,7, 27,11, 27,25, 27,28, 27,31, 28,7, 28,11, 28,25, 28,31, 29,7, 29,11, 29,25, 29,31
data 30,6, 30,7, 30,10, 30,11, 30,25, 30,31, 31,5, 31,25, 31,31, 32,5, 32,25, 32,31, 33,4, 33,25, 33,31, 34,3
data 34,25, 34,31, 35,3, 35,25, 35,28, 35,31, 36,3, 36,25, 36,31, 37,3, 37,25, 37,31, 38,3, 38,25, 38,31, 39,2
data 39,3, 39,25, 39,31, 40,1, 40,25, 40,31, 41,1, 41,25, 41,31, 42,0, 42,1, 42,25, 42,31, 43,1, 43,25, 43,31
data 44,2, 44,3, 44,11, 44,25, 44,31, 45,3, 45,11, 45,25, 45,28, 45,31, 46,3, 46,11, 46,25, 46,31, 47,3, 47,11
data 47,25, 47,31, 48,3, 48,11, 48,25, 48,31, 49,3, 49,11, 49,25, 49,31, 50,3, 50,11, 50,25, 50,31, 51,3, 51,11
data 51,25, 51,31, 52,4, 52,5, 52,11, 52,25, 52,31, 53,5, 53,11, 53,25, 53,31, 54,6, 54,7, 54,8, 54,9, 54,10
data 54,11, 54,25, 54,28, 54,31, 55,11, 55,25, 55,31, 56,11, 56,25, 56,30, 57,11, 57,25, 57,29, 58,11, 58,25, 58,28
data 59,11, 59,25, 59,27, 60,11, 60,26, 61,11, 61,17, 61,18, 61,19, 61,20, 61,21, 61,22, 61,23, 61,24, 61,25, 62,12
data 62,15, 62,16, 63,13, 63,14
Enjoy your day.