REM **************************
REM * DBC Challenge, Targets *
REM **************************
 
set display mode 640,480,32
create bitmap 1,640,480
sync on
sync rate 80
randomize timer
 
gosub Innitialize
 
State$ = ""
 
do
 
	if State$ = "" then gosub MainMenu
	if State$ = "StartNewGame" then gosub StartNewGame
	if State$ = "Game" then gosub Game
	if State$ = "GameMenu" then gosub GameMenu
	if State$ = "GameWin" then gosub GameWin
	if State$ = "GameOver" then gosub GameOver
	ink rgb(255,255,255),0
	text 0,0,"FPS: "+str$(screen fps())
	`text 0,20,"Time: "+str$(TimeLine)
	copy bitmap 1,0
	sync
	cls
loop
 
Innitialize:
	gosub LoadConstants
	gosub LoadGlobals
	gosub LoadArrays
	gosub LoadMemblocks
	gosub LoadImages
	gosub LoadData
return
 
	LoadConstants:
		`Ashingda - Memblock Constants
		MEM_BUFFER1 = 1
		MEM_BUFFER2 = 2
		MEM_IMAGE_BUFFER16x16 = 3
		MEM_IMAGE_TILE_BUFFER32x32 = 4
		MEM_COLLISION = 5
		`Ashingda - Image Constants
		IMG_PLAYER = 1001
		IMG_ENEMY = 1002
		IMG_BOSS = 1003
		IMG_SHOT_PLAYER = 1011
		IMG_SHOT_ENEMY = 1012
		IMG_BOMB_PLAYER = 1013
 
		IMG_SHOT_POWERUP = 1014
		IMG_BOMB_POWERUP = 1015
 
		IMG_TILE_WATER = 2001
		`Ashingda - Array Constants
		MAX_PROJECTILE_ID = 100
		MAX_ENEMY = 25
		MAX_POWERUP = 2
		`Ashingda - Weapon Constants
		WEP_SHOT_PLAYER = 0
		WEP_SHOT_ENEMY = 1
		WEP_BOMB_PLAYER = 2
		`Ashingda - PowerUp Constants
		POW_SHOT = 1
		POW_BOMB = 2
	return
 
	LoadGlobals:
		`Ashingda - Setup Global Mouse variables
		dim mx(0)
		dim my(0)
		dim mc(0)
		dim click(0)
	return
 
	LoadArrays:
		`Ashingda - Custome Image Data Arrays
		dim PaletteColor(9)
		dim Data$(4)
		`Ashingda - All Projectiles Array
		dim ProjectileID(MAX_PROJECTILE_ID)
		dim ProjectileImage(MAX_PROJECTILE_ID)
		dim ProjectileType(MAX_PROJECTILE_ID)
		dim ProjectileFlag(MAX_PROJECTILE_ID)
		dim ProjectileDirectionX#(MAX_PROJECTILE_ID)
		dim ProjectileDirectionY#(MAX_PROJECTILE_ID)
		dim ProjectileX#(MAX_PROJECTILE_ID)
		dim ProjectileY#(MAX_PROJECTILE_ID)
		`Ashingda - Waypoint or AI Arrays
		dim WayPointX(10,3)
		dim WayPointY(10,3)
		dim Map(20,2)
		`Ashingda - Enemy Arrays
		dim EnemyID(MAX_ENEMY)
		dim EnemyAI(MAX_ENEMY)
		dim EnemyDelay(MAX_ENEMY)
		dim EnemyX#(MAX_ENEMY)
		dim EnemyY#(MAX_ENEMY)
		dim EnemyMoveX#(MAX_ENEMY)
		dim EnemyMoveY#(MAX_ENEMY)
		dim EnemyTravel(MAX_ENEMY)
		`Ashingda - Exlposion Effect Arrays
		dim ExplosionID(100)
		dim ExplosionX(100)
		dim ExplosionY(100)
		dim ExplosionS(100)
		dim ExplosionSpeed(100)
		`Ashingda - PowerUp Arrays
		dim PowerUpID(MAX_POWERUP)
		dim PowerUpType(MAX_POWERUP)
		dim PowerUpImage(MAX_POWERUP)
		dim PowerUpX#(MAX_POWERUP)
		dim PowerUpY#(MAX_POWERUP)
		dim PowerUpDrX#(MAX_POWERUP)
		dim PowerUpDrY#(MAX_POWERUP)
	return
 
	LoadMemblocks:
		`Ashingda - Memblock used for Tile creation.
		make memblock MEM_IMAGE_BUFFER16x16,12+(16+16*16)*4
		write memblock dword MEM_IMAGE_BUFFER16x16,0,16
		write memblock dword MEM_IMAGE_BUFFER16x16,4,16
		write memblock dword MEM_IMAGE_BUFFER16x16,8,32
		`Ashingda - Memblock used for Tile creation.
		make memblock MEM_IMAGE_TILE_BUFFER32x32,12+(32+32*32)*4
		write memblock dword MEM_IMAGE_TILE_BUFFER32x32,0,32
		write memblock dword MEM_IMAGE_TILE_BUFFER32x32,4,32
		write memblock dword MEM_IMAGE_TILE_BUFFER32x32,8,32
	return
 
	LoadImages:
		`Ashingda - Water Tile Creation 32x32 pixel image
		for lpy = 0 to 31
		for lpx = 0 to 31
			pos = 12+(lpx+lpy*32)*4
			`Ashingda - Setting up the random water colors
			b = rnd(50)+205
			g = rnd(50)+100
			r = g
			`Ashingda - Writing to Memblock
			write memblock byte MEM_IMAGE_TILE_BUFFER32x32,pos,b
			write memblock byte MEM_IMAGE_TILE_BUFFER32x32,pos+1,g
			write memblock byte MEM_IMAGE_TILE_BUFFER32x32,pos+2,r
		next lpx
		next lpy
		`Ashingda - Creating the Image from the Memblock
		make image from memblock IMG_TILE_WATER,MEM_IMAGE_TILE_BUFFER32x32
 
		`Ashingda - Player Image Creation
		Data$(0) = "0,16711680,65280,255,16776960,65535,16711935,10197760,16777215,657930,"
		Data$(1) = "0000000000000000000000000000000000000000000000000000000990000000"
		Data$(2) = "0000009889000000000000935900000000000095390000000000009849000000"
		Data$(3) = "0090098488900900091998884889919009498884888894900985888848885890"
		Data$(4) = "9858587487858589958589944998585995589091190985599999000990009999"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_PLAYER,MEM_IMAGE_BUFFER16x16)
		`Ashingda - Sizing the Image to 200%
		SizeImage(IMG_PLAYER,200)
 
		`Ashingda - Enemy Image Creation
		Data$(1) = "0000099999900000000098181189000000009811818900000000099819900000"
		Data$(2) = "0000009189000000000000981900000000999991899999000988889819888890"
		Data$(3) = "9811119189111189981111981911118909888891898888900099999819999900"
		Data$(4) = "0000009539000000000000935900000000000098890000000000000990000000"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_ENEMY,MEM_IMAGE_BUFFER16x16)
		`Ashingda - Sizing the Image to 200%
		SizeImage(IMG_ENEMY,200)
 
		`Ashingda - BOSS Image Creation
		Data$(1) = "0999999999999990092222685622229009666668566666900099999999999900"
		Data$(2) = "0000009859000000000000985900000000000968569000009999996856999990"
		Data$(3) = "9222226856222229926262685626262996666695596666690969991991999690"
		Data$(4) = "0919095665909190009009611690090000000916619000000000009999000000"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_BOSS,MEM_IMAGE_BUFFER16x16)
		`Ashingda - Sizing the Image to 400%
		SizeImage(IMG_BOSS,400)
 
		`Ashingda - Player Shot Image Creation
		Data$(1) = "0099900000000000094449000000000004444400000000000444440000000000"
		Data$(2) = "0444440000000000094449000000000009444900000000000044400000000000"
		Data$(3) = "0094900000000000000400000000000000949000000000000004000000000000"
		Data$(4) = "0009000000000000000400000000000000090000000000000004000000000000"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_SHOT_PLAYER,MEM_IMAGE_BUFFER16x16)
 
		`Ashingda - Enemy Shot Image Creation
		Data$(1) = "0000000000000000000000000000000000000000000000000000000000000000"
		Data$(2) = "0000000000000000000000000000000000099900000000000095559000000000"
		Data$(3) = "0095559000000000009555900000000000099900000000000000000000000000"
		Data$(4) = "0000000000000000000000000000000000000000000000000000000000000000"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_SHOT_ENEMY,MEM_IMAGE_BUFFER16x16)
 
		`Ashingda - Player Bomb Image Creation
		Data$(1) = "0009000000000000009190000000000000999000000000000098900000000000"
		Data$(2) = "0098900000000000009890000000000009989900000000009598959000000000"
		Data$(3) = "9596959000000000999999900000000000000000000000000000000000000000"
		Data$(4) = "0000000000000000000000000000000000000000000000000000000000000000"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_BOMB_PLAYER,MEM_IMAGE_BUFFER16x16)
		`Ashingda - Sizing the Image to 200%
		SizeImage(IMG_BOMB_PLAYER,200)
 
		`Ashingda - SHOT PowerUp Image Creation
		Data$(1) = "0000009999900000000000988890000000000099999000000000094414490000"
		Data$(2) = "0000094111490000000009441449000000000099999000000000009888900000"
		Data$(3) = "0000009999900000000000000000000000000000000000008000808888088880"
		Data$(4) = "8000808000080008800080888808888080808080000800008808808888080000"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_SHOT_POWERUP,MEM_IMAGE_BUFFER16x16)
 
		`Ashingda - BOMB PowerUp Image Creation
		Data$(1) = "0000000090000000000000091900000000000009990000000000000989000000"
		Data$(2) = "0000000989000000000000098900000000000099899000000000095989590000"
		Data$(3) = "0000095969590000000009999999000000000000000000008800080080080880"
		Data$(4) = "8080808088880808880080808008088080808080800808088800080080080880"
		`Ashingda - Create the Image using the Data$()
		CreateImage(IMG_BOMB_POWERUP,MEM_IMAGE_BUFFER16x16)
	return
 
	LoadData:
		`Ashingda - Loads the AI data
		Data$(0) = "205,1,214,347,81,254,338,0,351,359,463,247,82,163,189,98,"
		Data$(1) = "461,95,82,282,271,179,463,166,234,3,239,162,84,475,272,0,"
		Data$(2) = "278,296,276,478,305,2,313,198,461,478,82,3,300,177,462,"
		Data$(3) = "479,263,4,115,112,416,113,"
		Data$(4) = ""
		LoadAI()
		`Ashingda - Loads the Map data
		Data$(0) = "123340340005340008567567567004840840840000123123457680605040900"
		LoadMap()
	return
 
MainMenu:
	Gosub HandleKeys
	`Ashingda - Blue Box
	ink rgb(150,200,255),0
	box 50,50,640-50,480-50
	`Ashingda - Green Box
	ink rgb(150,255,200),0
	box 280,150,640-80,480-80
	`Ashingda - Red Box
	ink rgb(255,220,220),0
	box 140,200,640-300,480-120
	`Ashingda - Drawing the Tile
	set text size 50
	ink 0,0
	text 70-1,50-1,"Ashingda's Entry"
	ink rgb(255,255,255),0
	text 70,50,"Ashingda's Entry"
	set text size 30
	ink 0,0
	text 70-1,150-1,"1945 Clone"
	ink rgb(255,255,255),0
	text 70,150,"1945 Clone"
	set text size 10
	`Ashingda - StartGame Menu
	if Menu("Start Game",400,300)
		if click(0) = 0
			State$ = "StartNewGame"
		endif
	endif
	`Ashingda - Exit Game Menu
	if Menu("Exit Game",400,330)
		if click(0) = 0
			end
		endif
	endif
return
 
	StartNewGame:
		`Ashingda - Reseting all the Variables for new game
		PlayerX# = 80 + 11*16
		PlayerY# = 480-32
		PlayerSpeed# = 2
		State$ = "Game"
		StartTime = timer()
		TimeLine = (timer()-StartTime)/2000
		OldTime = -1
		Score = 0
		Health = 10
		GameWin = 0
		GameLoose = 0
		Bombs = 5
		PlayerWep = 1
		hide mouse
		`Ashingda - Clear the Arrays
		for lp = 0 to MAX_PROJECTILE_ID
			ProjectileID(lp) = 0
		next lp
		for lp = 0 to MAX_POWERUP
			PowerUpID(lp) = 0
		next lp
		for lp = 0 to MAX_ENEMY
			EnemyID(lp) = 0
		next lp
	return
 
Game:
	gosub HandleKeys
	gosub HandleBackGround
	gosub HandlePlayer
	gosub HandleEnemy
	gosub HandleProjectile
	gosub HandlePowerUp
	gosub HandleDisplay
return
 
	HandleKeys:
		mx(0) = mousex()
		my(0) = mousey()
		mc(0) = mouseclick()
		if mc(0) = 0
			click(0) = 0
		endif
		if returnkey()
			State$ = "GameMenu"
			show mouse
		endif
	return
 
	HandleBackGround:
		`Ashingda - This variable is used to offset the Water Tiles
		if ScrollWaterY < 0
			ScrollWaterY = ScrollWaterY + 1
		  else
			ScrollWaterY = -32
		endif
	return
 
	HandlePlayer:
		`Ashingda - Flags the GameOver if Health drops to zero
		if Health < 1 then State$ = "GameOver"
		`Ashingda - Arrow Keys
		if leftkey() then PlayerX# = PlayerX# - PlayerSpeed#
		if rightkey() then PlayerX# = PlayerX# + PlayerSpeed#
		if upkey() then PlayerY# = PlayerY# - PlayerSpeed#
		if downkey() then PlayerY# = PlayerY# + PlayerSpeed#
		`Ashingda - Out of Bounce Check
		if PlayerX# < 96 then PlayerX# = 96
		if PlayerX# > 416 then PlayerX# = 416
		if PlayerY# < 16 then PlayerY# = 16
		if PlayerY# > 464 then PlayerY# = 464
		`Ashingda - Key "1" for SHOT
		if keystate(2)
			if PlayerShotDeley = 0
				`Ashingda - Creating the Shot
				PlayerShotDeley = 12
				LoopID = MAX_PROJECTILE_ID
				Image = IMG_SHOT_PLAYER
				Type = WEP_SHOT_PLAYER
				Flag = 0
				DirX# = 0
				DirY# = -6
				X# = PlayerX#
				Y# = PlayerY#
				gosub PlayerWeapon
			endif
		endif
		`Ashingda - Key "2" for BOMB
		if keystate(3)
			if PlayerBombDeley = 0 and Bombs > 0
				Bombs = Bombs - 1
				`Ashingda - Creating the Bomb
				PlayerBombDeley = 32
				LoopID = MAX_PROJECTILE_ID
				Image = IMG_BOMB_PLAYER
				Type = WEP_BOMB_PLAYER
				Flag = 0
				DirX# = 0
				DirY# = -6
				X# = PlayerX#
				Y# = PlayerY#
				CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
			endif
		endif
		`Ashingda - Decrease Delay
		if PlayerShotDeley > 0 then PlayerShotDeley = PlayerShotDeley - 1
		if PlayerBombDeley > 0 then PlayerBombDeley = PlayerBombDeley - 1
	return
 
		PlayerWeapon:
			b# = .25
			if PlayerWep = 1
				CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
			endif
			if PlayerWep = 2
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-3,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+3,Y#)
			endif
			if PlayerWep = 3
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-8,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+8,Y#)
			endif
			if PlayerWep = 4
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-10,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-2,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+2,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+10,Y#)
			endif
			if PlayerWep = 5
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-16,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-8,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+8,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+16,Y#)
			endif
			if PlayerWep = 6
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-18,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-10,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-2,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+2,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+10,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+18,Y#)
			endif
			if PlayerWep => 7
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-24,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-16,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#-b#,DirY#,X#-8,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+8,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+16,Y#)
				CreateProjectile(LoopID,Image,Type,Flag,DirX#+b#,DirY#,X#+24,Y#)
			endif
		return
 
	HandleEnemy:
		gosub EnemySpawn
		gosub EnemyControl
	return
 
		EnemySpawn:
			`Ashingda - Increase the Time counter
			if TimeLine < 20
				TimeLine = (timer()-StartTime)/2000
			endif
			`Ashingda - If the time is updated
			if TimeLine <> OldTime
				for lp = 0 to 2
					AI = Map(TimeLine,lp)
					if AI > 0
						CreateEnemy(AI,MAX_ENEMY)
					endif
				next lp
			endif
			`Ashingda - Record the old time
			OldTime = TimeLine
		return
 
		EnemyControl:
			for lp = 0 to 25
				if EnemyID(lp) > 0
					`Ashingda - Move the Enemy
					EnemyX#(lp) = EnemyX#(lp) + EnemyMoveX#(lp) 
					EnemyY#(lp) = EnemyY#(lp) + EnemyMoveY#(lp)
					DX = WayPointX(EnemyAI(lp),EnemyTravel(lp)+1)
					DY = WayPointY(EnemyAI(lp),EnemyTravel(lp)+1)
					if EnemyTravel(lp) = 2
						DX = WayPointX(EnemyAI(lp),0)
						DY = WayPointY(EnemyAI(lp),0)
					endif
					`Ashingda - Distance Check
					diffX = DX-EnemyX#(lp)
					diffY = DY-EnemyY#(lp)
					Distance = sqrt(diffX*diffX + diffY*diffY)
					`Ashingda - Switch to Next Node
					if Distance < 1
						EnemyTravel(lp) = EnemyTravel(lp) + 1
						if EnemyTravel(lp) < 2 or EnemyAI(lp) = 9
							if EnemyTravel(lp) > 2 then EnemyTravel(lp) = 0
							EnemyX#(lp) = WayPointX(EnemyAI(lp),EnemyTravel(lp))
							EnemyY#(lp) = WayPointY(EnemyAI(lp),EnemyTravel(lp))
							`Ashingda - Find the difference
							DiffX# = WayPointX(EnemyAI(lp),EnemyTravel(lp)+1) - EnemyX#(lp)
							DiffY# = WayPointY(EnemyAI(lp),EnemyTravel(lp)+1) - EnemyY#(lp)
							if EnemyTravel(lp) = 2
								DiffX# = WayPointX(EnemyAI(lp),0) - EnemyX#(lp)
								DiffY# = WayPointY(EnemyAI(lp),0) - EnemyY#(lp)
							endif
							`Ashingda - Find the Positive value
							CheckDiffX# = abs(DiffX#)
							CheckDiffY# = abs(DiffY#)
							`Ashingda - Setting up the Move variable
							if CheckDiffX# > CheckDiffY#
								EnemyMoveX#(lp) = DiffX#/CheckDiffX#
								EnemyMoveY#(lp) = DiffY#/CheckDiffX#
							  else
								EnemyMoveX#(lp) = DiffX#/CheckDiffY#
								EnemyMoveY#(lp) = DiffY#/CheckDiffY#
							endif
						  else
							EnemyID(lp) = 0
						endif
					endif
					`Ashingda - Enemy Shooting
					if EnemyDelay(lp) = 0
						`Ashingda - Creating the Shot
						if EnemyAI(lp) = 9
							EnemyDelay(lp) = 32+rnd(16)
						  else
							EnemyDelay(lp) = 32+rnd((130/PlayerWep))
						endif
						LoopID = MAX_PROJECTILE_ID
						Image = IMG_SHOT_ENEMY
						Type = WEP_SHOT_ENEMY
						Flag = 1
						if EnemyAI(lp) = 9
							Gun1 = -1
							Gun2 = 1
							ShotSpeed# = 1
						  else
							Gun1 = 0
							Gun2 = 0
							ShotSpeed# = 1.5
						endif
						for lpGun = Gun1 to Gun2
							`Ashingda - Targeted Shots
							DiffX# = (PlayerX#) - EnemyX#(lp) + lpGun*32
							DiffY# = PlayerY# - EnemyY#(lp)
							`Ashingda - Randomized Straight shot
							if lpGun <> 0
								if lpGun = -1 then DiffX# = (EnemyX#(lp)-rnd(200)) - EnemyX#(lp)
								if lpGun = 1 then DiffX# = (EnemyX#(lp)+rnd(200)) - EnemyX#(lp)
								DiffY# = 480.0 - EnemyY#(lp)
							endif
							`Ashingda - Find the Positive value
							CheckDiffX# = abs(DiffX#)
							CheckDiffY# = abs(DiffY#)
							`Ashingda - Setting up the Move variable
							if CheckDiffX# > CheckDiffY#
								DirX# = DiffX#/CheckDiffX#
								DirY# = DiffY#/CheckDiffX#
							  else
								DirX# = DiffX#/CheckDiffY#
								DirY# = DiffY#/CheckDiffY#
							endif
							DirX# = DirX#*ShotSpeed#
							DirY# = DirY#*ShotSpeed#
							X# = EnemyX#(lp) + lpGun*32
							Y# = EnemyY#(lp)
							CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
						next lpGun
					endif
					`Ashingda - Decrease Delay
					if EnemyDelay(lp) > 0 then EnemyDelay(lp) = EnemyDelay(lp) - 1
				endif
			next lp
		return
 
	HandleProjectile:
		for lp = 0 to MAX_PROJECTILE_ID
			if ProjectileID(lp) > 0
				`Ashingda - Moving the projectile
				ProjectileX#(lp) = ProjectileX#(lp) + ProjectileDirectionX#(lp)
				ProjectileY#(lp) = ProjectileY#(lp) + ProjectileDirectionY#(lp)
				`Ashingda - Checks if Weapon is SHOTs
				if ProjectileType(lp) = WEP_SHOT_PLAYER or ProjectileType(lp) = WEP_SHOT_ENEMY
					`Ashingda - Collision Check SHOT
					if ProjectileFlag(lp) = 0 
						`Ashingda - Player Projectile Hitting Enemy
						for lpE = 0 to MAX_ENEMY
							`Ashingda - If Enemy is Active
							if EnemyID(lpE) > 0
								`Ashingda - Seting up Values for Collision Check
								cx = ProjectileX#(lp)
								cy = ProjectileY#(lp)
								if EnemyAI(lpE) < 0 then Size = 32 else Size = 64
								x1 = EnemyX#(lpE)-Size/2
								y1 = EnemyY#(lpE)-Size/2
								x2 = x1+Size
								y2 = y1+Size
								`Ashingda - Checking Collision Area
								if CollisionCheckArea(cx,cy,x1,y1,x2,y2)
									X = cx - x1
									Y = cy - y1
									if EnemyAI(lpE) < 0 then IMG = IMG_ENEMY else IMG = IMG_BOSS
									`Ashingda - Checking Pixels for Collision
									if MemBlockCollision(MEM_COLLISION,IMG,X,Y)
										x = ProjectileX#(lp)
										y = ProjectileY#(lp)
										ExplosionSize = 18
										CreateExplosion(x,y,ExplosionSize,1)
										EnemyID(lpE) = EnemyID(lpE) - 9
										Score = Score + 1
										if EnemyID(lpE) < 1
											RndShot = rnd(50)
											if RndShot = 50
												Type = POW_BOMB
												Image = IMG_BOMB_POWERUP
												CreatePowerUp(MAX_POWERUP,Type,Image,X,Y)
											endif
											if RndShot < 30/PlayerWep
												Type = POW_SHOT
												Image = IMG_SHOT_POWERUP
												CreatePowerUp(MAX_POWERUP,Type,Image,X,Y)
											endif
											Score = Score + 10
											if EnemyAI(lpE) = 9
												Score = Score + 2000
												State$ = "GameWin"
												show mouse
											endif
										endif
										ProjectileID(lp) = 0
										lpE = MAX_ENEMY
									endif
								endif
							endif
						next lpE
					  else
						`Ashingda - Enemy Projectile Hiting Player
						cx = ProjectileX#(lp)
						cy = ProjectileY#(lp)
						x1 = PlayerX#-16
						y1 = PlayerY#-16
						x2 = x1+32
						y2 = y1+32
						`Ashingda - Checking Collision Area
						if CollisionCheckArea(cx,cy,x1,y1,x2,y2)
							X = cx - x1
							Y = cy - y1
							IMG = IMG_PLAYER
							`Ashingda - Checking Pixels for Collision
							if MemBlockCollision(MEM_COLLISION,IMG,X,Y)
								x = ProjectileX#(lp)
								y = ProjectileY#(lp)
								ExplosionSize = 18
								CreateExplosion(x,y,ExplosionSize,1)
								ProjectileID(lp) = 0
								Health = Health - 1
							endif
						endif
					endif
				endif
				`Ashingda - Checks if Weapon is BOMBs
				if ProjectileType(lp) = WEP_BOMB_PLAYER
					if ProjectileID(lp) > 1
						ProjectileID(lp) = ProjectileID(lp) - 1
					  else
						`Ashingda - Explodes BOOM!
						ProjectileID(lp) = 0
						ExplosionSize = 64*2
						x = ProjectileX#(lp)
						y = ProjectileY#(lp)
						CreateExplosion(x,y,ExplosionSize,10)
						`Ashingda - CollisionCheck for Bomb Killing Enemy
						for lpE = 0 to MAX_ENEMY
							if EnemyID(lpE) > 0
								DiffX = x - EnemyX#(lpE)
								DiffY = y - EnemyY#(lpE)
								distance = sqrt(DiffX*DiffX+DiffY*DiffY)
								if distance < ExplosionSize
									EnemyID(lpE) = EnemyID(lpE) - 200
									Score = Score + 1
									if EnemyID(lpE) < 1
										RndShot = rnd(50)
										if RndShot = 50
											Type = POW_BOMB
											Image = IMG_BOMB_POWERUP
											CreatePowerUp(MAX_POWERUP,Type,Image,X,Y)
										endif
										if RndShot < 30/PlayerWep
											Type = POW_SHOT
											Image = IMG_SHOT_POWERUP
											CreatePowerUp(MAX_POWERUP,Type,Image,X,Y)
										endif
										Score = Score + 10
										if EnemyAI(lpE) = 9
											Score = Score + 2000
											State$ = "GameWin"
											show mouse
										endif
									endif
									x2 = EnemyX#(lpE)
									y2 = EnemyY#(lpE)
									ExplosionSize2 = 18
									CreateExplosion(x2,y2,ExplosionSize2,1)
								endif
							endif
						next lpE
						`Ashingda - CollisionCheck Removing Enemy Shots
						for lpP = 0 to MAX_PROJECTILE_ID
							if ProjectileID(lpP) > 0
								if ProjectileFlag(lpP) > 0
									DiffX = x - ProjectileX#(lpP)
									DiffY = y - ProjectileY#(lpP)
									distance = sqrt(DiffX*DiffX+DiffY*DiffY)
									if distance < ExplosionSize
										ProjectileID(lpP) = 0
										x2 = ProjectileX#(lpP)
										y2 = ProjectileY#(lpP)
										ExplosionSize2 = 9
										CreateExplosion(x2,y2,ExplosionSize2,1)
									endif
								endif
							endif
						next lpE
					endif
				endif
				`Ashingda - Free Projectile if it's off the screen
				if ProjectileY#(lp) < -32 or ProjectileY#(lp) > 500
					ProjectileID(lp) = 0
				endif
			endif
		next lp
	return
 
	HandlePowerUp:
		for lp = 0 to MAX_POWERUP
			if PowerUpID(lp) > 0
				`Ashingda - Move the PowerUps
				if PowerUpDrY#(lp) < 0 then PowerUpSlow = 2 else PowerUpSlow = 1
				PowerUpX#(lp) = PowerUpX#(lp) + PowerUpDrX#(lp)
				PowerUpY#(lp) = PowerUpY#(lp) + PowerUpDrY#(lp)/PowerUpSlow
					if PowerUpX#(lp) < 96 or PowerUpX#(lp) > 416
					PowerUpDrX#(lp) = PowerUpDrX#(lp) * -1
					PowerUpX#(lp) = PowerUpX#(lp) + PowerUpDrX#(lp)
				endif
				if PowerUpY#(lp) < 16 or PowerUpY#(lp) > 480-16
					PowerUpDrY#(lp) = PowerUpDrY#(lp) * -1
					if PowerUpDrY#(lp) < 0 then PowerUpSlow = 2 else PowerUpSlow = 1
					PowerUpY#(lp) = PowerUpY#(lp) + PowerUpDrY#(lp)/PowerUpSlow
				endif
				`Ashingda - Checks for collision with the Player
				DiffX = PowerUpX#(lp) - PlayerX#
				DiffY = PowerUpY#(lp) - PlayerY#
				distance = sqrt(DiffX*DiffX+DiffY*DiffY)
				if distance < 16
					PowerUpID(lp) = 0
					Score = Score + 10
					if PowerUpType(lp) = POW_SHOT
						if PlayerWep < 7 then PlayerWep = PlayerWep + 1
					endif
					if PowerUpType(lp) = POW_BOMB
						Bombs = Bombs + 1
					endif
				endif
			endif
		next lp
	return
 
	HandleDisplay:
		gosub DisplayWaterTile
		gosub DisplayProjectile
		gosub DisplayPowerUp
		gosub DisplayEnemy
		gosub DisplayPlayer
		gosub DisplayExplosion
		gosub DisplayGUI
	return
 
		DisplayWaterTile:
			`Ashingda - Draws the Water Tiles
			WaterTileX = 80
			for lpy = 0 to 15
			for lpx = 0 to 11
				paste image IMG_TILE_WATER,lpx*32+WaterTileX,lpy*32+ScrollWaterY
			next lpx
			next lpy
		return
 
		DisplayProjectile:
			`Ashingda - Draws the Projectile Images
			for lp = 0 to MAX_PROJECTILE_ID
				if ProjectileID(lp) > 0
					IMG = ProjectileImage(lp)
					X = ProjectileX#(lp)
					Y = ProjectileY#(lp)
					if IMG = IMG_SHOT_PLAYER then paste image IMG,X-4,Y,1
					if IMG = IMG_SHOT_ENEMY then paste image IMG,X-4,Y-10,1
					if IMG = IMG_BOMB_PLAYER then paste image IMG,X-8,Y,1
				endif
			next lp
		return
 
		DisplayPowerUp:
			for lp = 0 to MAX_POWERUP
				if PowerUpID(lp) > 0
					x = PowerUpX#(lp)
					y = PowerUpY#(lp)
					img = PowerUpImage(lp)
					paste image Img,x-8,y-8,1
				endif
			next lp
		return
 
		DisplayEnemy:
			for lp = 0 to MAX_ENEMY
				if EnemyID(lp) > 0
					x# = EnemyX#(lp)
					y# = EnemyY#(lp)
					if EnemyAI(lp) < 9
						paste image IMG_ENEMY,x#-16,y#-16,1
					  else
						paste image IMG_BOSS,x#-32,y#-32,1
					endif
				endif
			next lp
		return
 
		DisplayPlayer:
			`Ashingda - Draws the Player Image
			paste image IMG_PLAYER,PlayerX#-16,PlayerY#-16,1
		return
 
		DisplayExplosion:
			for lp = 0 to 100
				if ExplosionID(lp) > 0
					ExplosionID(lp) = ExplosionID(lp) + ExplosionSpeed(lp)
					if ExplosionID(lp) => ExplosionS(lp) then ExplosionID(lp) = 0
					x = ExplosionX(lp)
					y = ExplosionY(lp)
					ink rgb(255,200,150),0
					circle x,y,ExplosionID(lp)
					circle x,y,ExplosionID(lp)/1.5
				endif
			next lp
		return
 
		DisplayGUI:
			`Ashingda - Black side borders
			ink 0,0
			box 0,0,WaterTileX-1,479
			box WaterTileX+11*32,0,639,479
			`Ashingda - Display the Score
			ink rgb(255,255,255),0
			text 450,50,"Score: "+str$(Score)
			`Ashingda - Display the Health
			text 450,110,"Health: "+str$(Health)
			ink rgb(255,255,255),0
			box 449,129,551,141
			ink rgb(255,0,0),0
			box 450,130,450+Health*10,140
			`Ashingda - Display the amount of Bombs
			ink rgb(255,255,255),0
			text 450,180,"Weapon: "+str$(PlayerWep)
			text 450,200,"Bombs: "+str$(Bombs)
 
			x = 500
			y = 280
 
			text x,y-32,"CONTROLS"
			text x,y,"Arrow Keys:"
			text x,y+16*1," Move"
			text x,y+16*3,"Enter Key:"
			text x,y+16*4," Menu"
			text x,y+16*6,"1: Shoot"
			text x,y+16*7,"2: Bomb"
		return
 
GameMenu:
	gosub HandleKeys
	gosub HandleBackGround
	gosub DisplayWaterTile
	gosub DisplayGUI
	`Ashingda - Box
	ink rgb(255,255,255),0
	box 165,80,330,260
	ink 0,0
	box 175,90,320,250
	`Ashingda - Text
	ink rgb(255,255,255),0
	if menu("Resume Game",185+20,170-45)
		State$ = "Game"
		hide mouse
		click(0) = 1
	endif
	if menu("Return to Main Menu",185,200-45)
		State$ = ""
		click(0) = 1
	endif
	if menu("Exit Game",185+30,230-45)
		end
	endif
return
 
GameWin:
	show mouse
	gosub HandleKeys
	gosub HandleBackGround
	gosub DisplayWaterTile
	gosub DisplayGUI
	`Ashingda - Box
	ink rgb(255,255,255),0
	box 165,80,330,260
	ink 0,0
	box 175,90,320,250
	`Ashingda - Text
	ink rgb(255,255,255),0
	center text 245,100,"YOU WIN!"
	center text 245,120,"Score:"+str$(Score)
	if menu("Return to Main Menu",185,200)
		State$ = ""
		click(0) = 1
	endif
return
 
GameOver:
	show mouse
	gosub HandleKeys
	gosub HandleBackGround
	gosub DisplayWaterTile
	gosub DisplayGUI
	`Ashingda - Box
	ink rgb(255,255,255),0
	box 165,80,330,260
	ink 0,0
	box 175,90,320,250
	`Ashingda - Text
	ink rgb(255,255,255),0
	center text 245,100,"GAME OVER!"
	center text 245,120,"Score:"+str$(Score)
	if menu("Return to Main Menu",185,200)
		State$ = ""
		click(0) = 1
	endif
return
 
REM *************************Functions******************************
 
Function Menu(s$,x1,y1)
	x2 = x1 + text width(s$)
	y2 = y1 + text height(s$)
	ink rgb(255,255,0),0
	box x1,y1,x2+6,y2+6
	ink rgb(0,0,255),0
	box x1+2,y1+2,x2+4,y2+4
	ink rgb(255,255,255),0
	text x1+4,y1+4,s$
	if mx(0)>x1 and mx(0)<x2+6 and my(0)>y1 and my(0)<y2+6 and mc(0) = 1
		ReturnValue = 1
	  else
		ReturnValue = 0
	endif
EndFunction ReturnValue
 
Function CreateImage(IMG,MEM_BUFFER)
	`Ashingda - Setting up the PaletteColor of this Image
	Counter = 0
	for lp = 1 to len(Data$(0))
		StringInput$ = mid$(Data$(0),lp)
		if StringInput$ = ","
			PaletteColor(Counter) = val(StringSave$)
			StringSave$ = ""
			Counter = Counter + 1
		  else
			StringSave$ = StringSave$ + StringInput$
		endif
	next lp
	`Ashingda - Setting up the Image
	CounterX = 0
	CounterY = 0
	for lpy = 1 to 4
	for lpx = 1 to len(Data$(lpy))
		`Ashingda - Input from the Data$()
		ValInput = val(mid$(Data$(lpy),lpx))
		`Ashingda - Positon of Memblock
		pos = 12+(CounterX+CounterY*16)*4
		`Ashingda - Writing to Memblock
		write memblock dword MEM_BUFFER,pos,PaletteColor(ValInput)
		`Ashingda - Increasing the X,Y counters
		CounterX = CounterX + 1
		if CounterX > 15
			CounterY = CounterY + 1
			CounterX = 0
		endif
	next lpx
	next lpy
	`Ashingda - Creating the Image from the Memblock
	make image from memblock IMG,MEM_BUFFER
EndFunction
 
Function SizeImage(Img,Size)
	`Ashingda - Creating Memblock(1) from the Image
	make memblock from image 1,Img
	wd1 = memblock dword(1,0)
	ht1 = memblock dword(1,4)
	dp = memblock dword(1,8)
	`Ashingda - Setting up the variables
	Size# = 100.0/Size
	wd2 = wd1/Size#
	ht2 = ht1/Size#
	`Ashingda - ReCreate the Memblock(2)
	if memblock exist(2) then delete memblock 2
	make memblock 2,(wd2+(ht2*wd2))*4
	write memblock dword 2,0,wd2
	write memblock dword 2,4,ht2
	write memblock dword 2,8,dp
	`Ashingda - Starting the data Transfer
	for y2 = 0 to ht2-1
	for x2 = 0 to wd2-1
		x1 = x2*Size#
		y1 = y2*Size#
		`Ashingda - Reading from Memblock(1)
		pos = 12 + (x1+(y1*wd1))*4
		b = memblock byte(1,pos+0)
		g = memblock byte(1,pos+1)
		r = memblock byte(1,pos+2)
		a = memblock byte(1,pos+3)
		`Ashingda - Writing to Memblock(2)
		pos = 12 + (x2+(y2*wd2))*4
		write memblock byte 2,pos+0,b
		write memblock byte 2,pos+1,g
		write memblock byte 2,pos+2,r
		write memblock byte 2,pos+3,a
	next x2
	next y2
	`Ashingda - Creating the Image from Memblock(2)
	make image from memblock Img,2
EndFunction
 
 
Function CreateProjectile(LoopID,Image,Type,Flag,DirX#,DirY#,X#,Y#)
	for lp = 0 to LoopID
		`Ashingda - Checks if the ID is (zero) free to use
		if ProjectileID(lp) < 1
			`Ashingda - Setting the Projectile data
			ProjectileID(lp) = 30
			ProjectileImage(lp) = Image
			ProjectileType(lp) = Type
			ProjectileFlag(lp) = Flag
			ProjectileDirectionX#(lp) = DirX#
			ProjectileDirectionY#(lp) = DirY#
			ProjectileX#(lp) = X#
			ProjectileY#(lp) = Y#
			`Ashingda - Exiting the loop
			lp = LoopID
		endif
	next lp
EndFunction
 
Function LoadAI()
	CountAI = 1
	Count = 0
	NodeCount = 0
	StringSave$ = ""
	for lpy = 0 to 4
	for lpx = 1 to len(Data$(lpy))
			StringInput$ = mid$(Data$(lpy),lpx)
			if StringInput$ = ","
				if Count = 0
					WayPointX(CountAI,NodeCount) = val(StringSave$)
					Count = 1
				  else
					WayPointY(CountAI,NodeCount) = val(StringSave$)
					Count = 0
					if NodeCount < 2
						NodeCount = NodeCount + 1
					  else
						NodeCount = 0
						CountAI = CountAI + 1
					endif
				endif
				StringSave$ = ""
			  else
				StringSave$ = StringSave$ + StringInput$
			endif
	next lpx
	next lpy
EndFunction
 
Function LoadMap()
	Count = 1
	for lpy = 0 to 20
		map(lpy,0) = val(mid$(Data$(0),Count+0))
		map(lpy,1) = val(mid$(Data$(0),Count+1))
		map(lpy,2) = val(mid$(Data$(0),Count+2))
		Count = Count + 3
	next lpy
EndFunction
 
Function CreateEnemy(AI,MAX_ENEMY)
	`Ashingda - Search for a free ID
	for lp = 0 to MAX_ENEMY
		if EnemyID(lp) < 1
			`Ashingda - Activate Enemy
			EnemyID(lp) = 50
			EnemyAI(lp) = AI
			if EnemyAI(lp) = 9 then EnemyID(lp) = 10000
			EnemyDelay(lp) = 50+rnd(30)
			EnemyTravel(lp) = 0
			EnemyX#(lp) = WayPointX(EnemyAI(lp),0)
			EnemyY#(lp) = WayPointY(EnemyAI(lp),0)
			`Ashingda - Find the difference
			DiffX# = WayPointX(EnemyAI(lp),EnemyTravel(lp)+1) - EnemyX#(lp)
			DiffY# = WayPointY(EnemyAI(lp),EnemyTravel(lp)+1) - EnemyY#(lp)
			`Ashingda - Find the Positive value
			CheckDiffX# = abs(DiffX#)
			CheckDiffY# = abs(DiffY#)
			`Ashingda - Setting up the Move variable
			if CheckDiffX# > CheckDiffY#
				EnemyMoveX#(lp) = DiffX#/CheckDiffX#
				EnemyMoveY#(lp) = DiffY#/CheckDiffX#
			  else
				EnemyMoveX#(lp) = DiffX#/CheckDiffY#
				EnemyMoveY#(lp) = DiffY#/CheckDiffY#
			endif
			`Ashingda - Exit the Loop
			lp = MAX_ENEMY
		endif
	next lp
EndFunction
 
Function CreateExplosion(X,Y,S,Speed)
	For lp = 0 to 100
		if ExplosionID(lp) = 0
			ExplosionID(lp) = 1
			ExplosionX(lp) = X
			ExplosionY(lp) = Y
			ExplosionS(lp) = S
			ExplosionSpeed(lp) = Speed
			lp = 100
		endif
	next lp
EndFunction
 
 
Function CollisionCheckArea(cx,cy,x1,y1,x2,y2)
	if cx => x1 and cx < x2 and cy => y1 and cy < y2
		ReturnValue = 1
	  else
		ReturnValue = 0
	endif
EndFunction ReturnValue
 
Function MemBlockCollision(MEM_COLLISION,IMG,x,y)
	`Ashingda - Creating the Memblock
	make memblock from image MEM_COLLISION,IMG
	wd = Memblock dword(MEM_COLLISION,0)
	ht = Memblock dword(MEM_COLLISION,4)
	`Ashingda - Setting the Position
	pos = 12+(x+y*wd)*4
	`Ashingda - Black out the Alpha channel
	write memblock byte MEM_COLLISION,pos+3,0
	`Ashingda - Checking the pixel color, if Black then no Collision
	if memblock Dword(MEM_COLLISION,pos) > 0
		ReturnValue = 1
	  else
		ReturnValue = 0
	endif
EndFunction ReturnValue
 
Function CreatePowerUp(MAX_POWERUP,Type,Image,X,Y)
	for lp = 0 to MAX_POWERUP
		if PowerUpID(lp) < 1
			`Ashingda - Activating the PowerUp
			PowerUpID(lp) = 150
			PowerUPType(lp) = Type
			PowerUPImage(lp) = Image
			PowerUpX#(lp) = X
			PowerUpY#(lp) = Y
			PointX = 80+rnd(11*32)
			PointY = 240+rnd(240)
			`Ashingda - Find the difference
			DiffX# = PointX - X
			DiffY# = PointY - Y
			`Ashingda - Find the Positive value
			CheckDiffX# = abs(DiffX#)
			CheckDiffY# = abs(DiffY#)
			`Ashingda - Setting up the Move variable
			if CheckDiffX# > CheckDiffY#
				PowerUpDrX#(lp) = DiffX#/CheckDiffX#
				PowerUpDrY#(lp) = DiffY#/CheckDiffX#
			  else
				PowerUpDrX#(lp) = DiffX#/CheckDiffY#
				PowerUpDrY#(lp) = DiffY#/CheckDiffY#
			endif
			lp = MAX_POWERUP
		endif
	next lp
EndFunction