REM Virus Attack
REM CR 2007
 
cls
sync on
autocam off
hide mouse
 
enemies_exist=5
data_exist=20
num_enemies=100
num_data=200
lightening_tex=10
laser_tex=41
download=0
powerup_countdown=rnd(50)+100
reverse=1
 
rem dimension arrays
dim enemy_angle(100)
dim enemy_distance(100)
dim enemy_speed(100)
dim enemy_dead(100)
dim data_angle(200)
dim data_distance(200)
dim data_speed(200)
dim data_dead(200)
dim firewall(360)
 
rem draw textures
create bitmap 1,32,32
set current bitmap 1
cls rgb(0,0,255)
get image 1,0,0,16,16
cls rgb(255,0,0)
get image 2,0,0,16,16
cls rgb(0,0,255)
get image 3,0,0,16,16
cls rgb(0,0,0)
ink rgb(100,100,100),0
line 0,0,0,31
line 0,0,31,0
line 0,31,31,31
line 31,0,31,31
get image 5,0,0,32,32
 
rem setup firewall texture
create bitmap 2,256,256
for a=1 to 360
	firewall(a)=255
next a
 
rem setup lightening textures
gosub lightening:
 
rem setup powerup textures
gosub powerup_texture:
 
position camera 0,-200,400
point camera 0,0,0
 
rem create plain mesh
make object plain 1,30,100
zrotate object 1,180
make mesh from object 1,1
delete object 1
make object plain 1,30,700
zrotate object 1,180
make mesh from object 2,1
delete object 1
make object plain 1,120,40
xrotate object 1,180
make mesh from object 3,1
delete object 1
 
rem make player object
make object triangle 1,0,15,0,10,-15,0,-10,-15,0
position object 1,0,0,0
yrotate object 1,180
texture object 1,1
 
rem make player limbs
add limb 1,1,1
add limb 1,2,2
offset limb 1,1,0,55,0
offset limb 1,2,0,350,0
ghost object on 1
hide limb 1,1
 
rem make virus object
for a=1 to 100
	make object triangle a+1,0,6,0,4,-4,0,-2,-4,0
	yrotate object a+1,180
	texture object a+1,2
	enemy_distance(a)=2000
	enemy_angle(a)=rnd(359)
	x=enemy_distance(a)*sin(enemy_angle(a))
	y=enemy_distance(a)*cos(enemy_angle(a))
	position object a+1,x,y,0
	zrotate object a+1,wrapvalue(180+enemy_angle(a))
next a
 
for a=1 to enemies_exist
	enemy_distance(a)=rnd(500)+200
next a
 
rem make data object
for a=1 to 200
	make object triangle a+1+num_enemies,0,4,0,4,-4,0,-2,-4,0
	yrotate object a+1+num_enemies,180
	texture object a+1+num_enemies,3
	data_distance(a)=rnd(1000)+100
	data_angle(a)=rnd(359)
next a
 
rem make firewall object
make object plain num_enemies+num_data+3,256,256
position object num_enemies+num_data+3,0,0,0
xrotate object num_enemies+num_data+3,180
ghost object on num_enemies+num_data+3
 
rem make grid object
make object plain num_enemies+num_data+4,2000,2000
position object num_enemies+num_data+4,0,0,-100
ghost object on num_enemies+num_data+4
texture object num_enemies+num_data+4,5
scale object texture num_enemies+num_data+4,32,32
 
rem make download bar object
make object plain num_enemies+num_data+5,500,25
position object num_enemies+num_data+5,250-(download*5),300,0
texture object num_enemies+num_data+5,1
ghost object on num_enemies+num_data+5
scale object num_enemies+num_data+5,1+download,100,100
 
rem make powerup object
make object sphere num_enemies+num_data+6,10
position object num_enemies+num_data+6,2000,0,0
ghost object on num_enemies+num_data+6
 
rem make powerup limbs
add limb num_enemies+num_data+6,1,3
offset limb num_enemies+num_data+6,1,0,10,0
 
rem make level up sign
make object plain num_enemies+num_data+7,300,300
position object num_enemies+num_data+7,0,100,0
create bitmap 4,128,128
ghost object on num_enemies+num_data+7
 
color backdrop rgb(0,0,0)
 
file_size=40
gosub levelup:
 
do
 
	rem show/hide level up sign
	dec levelup_countdown
	if levelup_countdown>0 then show object num_enemies+num_data+7 else hide object num_enemies+num_data+7
 
	rem get mouse status
	mc=mouseclick()
	mmx=mousemovex()*reverse
 
	rem colour backdrop
	red#=virus_collected*2
	color backdrop rgb(red#,0,0)
	if virus_collected>40
		set current bitmap 4
		cls
		ink rgb(255,255,255),0
		center text 64,0,"Game Over"
		center text 64,20,"Virus levels fatal"
		center text 64,40,"Level "+str$(level)
		wait 5
		mirror bitmap 4
		get image 70,0,0,128,128
		texture object num_enemies+num_data+7,70
		show object num_enemies+num_data+7
		color backdrop rgb(0,0,0)
		sync
		suspend for key
		end
	endif
 
	rem update progress bar
	download=((100*data_collected)-(100*data_killed))/file_size
	if download<1 then download=1
	if download>99
		gosub levelup:
	endif
	position object num_enemies+num_data+5,250-(download*2.5),300,0
	scale object num_enemies+num_data+5,1+download,100,100
 
	rem rotate player with mouse
	inc player_angle,mmx
	zrotate object 1,wrapvalue(player_angle)
 
	rem position enemy
	for a=1 to enemies_exist
		if enemy_distance(a)=110 and firewall(enemy_angle(a))>0
			for b=-5 to 5
				firewall(wrapvalue(enemy_angle(a)+b))=firewall(wrapvalue(enemy_angle(a)+b))-1
			next b
		else
			if enemy_dead(a)=0 then enemy_distance(a)=enemy_distance(a)-1
		endif		
 
		rem is enemy dead and decaying??
		if enemy_dead(a)>0
			scale object a+1,100-enemy_dead(a)*5,100-enemy_dead(a)*5,100
			enemy_dead(a)=enemy_dead(a)+1
		endif
		if enemy_dead(a)>17
			enemy_distance(a)=rnd(500)+400
			enemy_angle=rnd(359)
			enemy_dead(a)=0
			scale object a+1,100,100,100
		endif
 
		if enemy_distance(a)<=0
			enemy_distance(a)=rnd(1000)+1000
			enemy_angle=rnd(359)
			inc virus_collected
		endif
		x=enemy_distance(a)*sin(enemy_angle(a))
		y=enemy_distance(a)*cos(enemy_angle(a))
		position object a+1,x,y,0
		zrotate object a+1,wrapvalue(180+enemy_angle(a))
	next a
 
	rem position data
	for a=1 to data_exist
		rem is data dead and decaying??
		if data_dead(a)>0
			scale object a+1+num_enemies,100-data_dead(a)*5,100-data_dead(a)*5,100
			data_dead(a)=data_dead(a)+1
		endif
		if data_dead(a)>17
			data_distance(a)=rnd(1000)+1000
			data_angle=rnd(359)
			data_dead(a)=0
			scale object a+1+num_enemies,100,100,100
		endif
 
		data_distance(a)=data_distance(a)-1
		if data_distance(a)<=0
			data_distance(a)=rnd(1000)+1000
			data_angle=rnd(359)
			inc data_collected
		endif
		x=data_distance(a)*sin(data_angle(a))
		y=data_distance(a)*cos(data_angle(a))
		position object a+1+num_enemies,x,y,0
		zrotate object a+1+num_enemies,wrapvalue(180+data_angle(a))
	next a
 
	rem create / move powerups
	if powerup=0
		dec powerup_countdown
		if powerup_countdown=0
			powerup=rnd(3)+1
			powerup_speed=rnd(2)+1
			powerup_rotate=rnd(4)-2
			powerup_angle=rnd(359)+1
			powerup_distance=rnd(1000)+500
			if powerup=1
				texture object num_enemies+num_data+6,2
			else
				texture object num_enemies+num_data+6,1
			endif
			texture limb num_enemies+num_data+6,1,60+powerup
		endif
	else
		dec powerup_distance, powerup_speed
		powerup_angle=wrapvalue(powerup_angle+powerup_rotate)
		x=powerup_distance*sin(powerup_angle)
		y=powerup_distance*cos(powerup_angle)
		position object num_enemies+num_data+6,x,y,0
		if powerup_distance<1 then gosub powerup_effect:
	endif
 
	rem draw firewall
	set current bitmap 2
	ink rgb(100,100,255),0
	for a=1 to 500
		firewall_ang=rnd(359)+1
		if firewall(firewall_ang)>rnd(255)
			radius=100+rnd((8*firewall(firewall_ang))/255)
			x=radius*sin(firewall_ang)
			y=radius*cos(firewall_ang)
			dot x+128,y+128
		endif
	next a
	blur bitmap 2,2
	get image 4,0,0,256,256
	texture object num_enemies+num_data+3,4
 
	rem register mouse clicks
 
	rem fire regenerator
	if mc=2
		if limb visible(1,1)=0 then show limb 1,1
		inc lightening_tex
		if lightening_tex>40 then lightening_tex=10
		texture limb 1,1,lightening_tex
		for b=-4 to 4
			firewall(wrapvalue(player_angle+b))=firewall(wrapvalue(player_angle+b))+5
		next b
	else
		if limb visible(1,1)=1 then hide limb 1,1
	endif
 
	rem fire laser 
	if mc=1
		if limb visible(1,2)=0 then show limb 1,2
		inc laser_tex
		if laser_tex>60 then laser_tex=41
		texture limb 1,2,laser_tex
		for a=1 to num_enemies
			for b=-1 to 1
				if enemy_angle(a)=wrapvalue(b+player_angle) and enemy_dead(a)=0 and enemy_distance(a)<500
					enemy_dead(a)=1
					inc virus_killed
				endif
			next b
		next a
		for a=1 to num_data
			for b=-1 to 1
				if data_angle(a)=wrapvalue(b+player_angle) and data_dead(a)=0 and data_distance(a)<500
					data_dead(a)=1
					if object in screen(a+1+num_enemies)=1 and data_distance(a)<400 then inc data_killed
				endif
			next b
		next a
		if powerup>0
			for b=-2 to 2
				if powerup_angle=wrapvalue(b+player_angle)
					powerup=0
					powerup_countdown=rnd(100)
					position object num_enemies+num_data+6,2000,0,0
				endif
			next b
		endif
	else
		if limb visible(1,2)=1 then hide limb 1,2
	endif
 
 
sync
 
loop
 
 
lightening:
size=1
blur=2
spread=5
 
num=100
dim x(num)
dim y(num)
 
rem set initial positions of particles
for a=1 to num
	x(num)=32*size
	y(num)=rnd(32*size)
next a
 
rem create bitmap where the image will be drawn
create bitmap 3,64*size,64*size
 
rem get images
for img=-50 to 40
	set current bitmap 3
	rem move, draw electric particles
	for a=1 to num
		y(num)=y(num)+1
		x(num)=x(num)+rnd(spread*2)-spread
		if y(num)>size*64
			x(num)=32*size
			y(num)=0
		endif
		rem draw the particle
		ink rgb(100,100,200+rnd(55)),0
		dot x(num),y(num)
	next a
 
	rem blur bitmap
	if blur>0 then blur bitmap 3,blur
 
	rem get the image
	if img>=10 then get image img,0,0,64*size,64*size
next img
 
rem draw laser images
spread=0
num=50
for img=-30 to 60
	set current bitmap 3
	rem move, draw electric particles
	for a=1 to num
		y(num)=y(num)+1
		x(num)=x(num)+rnd(spread*2)-spread
		if y(num)>size*64
			x(num)=32*size
			y(num)=0
		endif
		rem draw the particle
		ink rgb(255,200,200),0
		dot x(num),y(num)
	next a
 
	rem blur bitmap
	if blur>0 then blur bitmap 3,blur
 
	rem get the image
	if img>40 then get image img,0,0,64*size,64*size
next img
undim x(num)
undim y(num)
delete bitmap 3
return
 
powerup_texture:
create bitmap 3,128,32
ink rgb(255,255,255),0
set current bitmap 3
restore
for a=61 to 64
	read name$
	cls rgb(0,0,0)
	center text 64,0,name$
	wait 100
	mirror bitmap 3
	flip bitmap 3
	get image a,0,0,128,32
next a 
delete bitmap 3
return
 
rem powerup names
data "data bomb", "reverse", "regenerate", "virus wipe"
 
powerup_effect:
 
select powerup
	case 1
		for a=0 to 360
			firewall(wrapvalue(a))=rnd(100)
		next a
	endcase
	case 2
		reverse=reverse*-1
	endcase
	case 3
		for a=0 to 360
			firewall(wrapvalue(a))=255
		next a
	endcase
	case 4
		for a=1 to enemies_exist
			enemy_dead(a)=1
		next a
	endcase
endselect
 
 
rem reset powerup
powerup=0
powerup_countdown=rnd(100)
position object num_enemies+num_data+6,2000,0,0
return
 
levelup:
		rem set variables for next level
		levelup_countdown=100
		inc level
		inc file_size,level*12
		inc enemies_exist,4
		inc data_exist,5
		if enemies_exist>num_enemies then enemies_exist=num_enemies
		if data_exist>num_data then data_exist=num_data
		data_collected=0
		data_killed=0
		virus_collected=0
		rem kill all viruses
		if level>1
			for a=1 to enemies_exist
				enemy_dead(a)=1
			next a
		endif
		set current bitmap 4
		cls
		ink rgb(255,255,255),0
		center text 64,0,"Downloading..."
		center text 64,20,"File size "+str$(file_size*10)+"kB"
		wait 5
		mirror bitmap 4
		get image 70,0,0,128,128
		texture object num_enemies+num_data+7,70
return