-- IrDA sample
red = Color.new(255, 0, 0)
white = Color.new(255, 255, 255)
timeout = 10
x = 240
y = 260
shoot = false
shoot1 = false
shoot2 = false
alien = true
ax = 2
ay = 30
while true do
	screen:clear()
	screen:print(x,y,"X",white)
	if alien == true then
		ax = ax + 2
		screen:print(ax,ay,"==>",white)
		if (bullety==ay and (bulletx>(ax-20) and bulletx<(ax+20))) then
			screen:print(100,100,"HIT",white)
			System.sleep(1000)
		end
	end
	hpad = Hprm.read()
	pad = Controls.read()
	if pad:start() then
		dofile("./System/system2.lua")
	end
	if (hpad=="FWD") then
		x = x + 4
		if x>=470 then
			x = 470
		end
	end
	if (hpad=="BACK") then
		x = x - 4
		if x<=1 then
			x = 1
		end
	end
	if (hpad=="PLAY") and not (oldhpad=="PLAY") then
		if shoot2==false and shoot1==true then
			shoot2 = true
			bulletx2 = x - 5
			bullety2 = y
		end
		if shoot1==false and shoot==true then
			shoot1 = true
			bulletx1 = x - 5
			bullety1 = y
		end
		if shoot==false then
			shoot = true
			bulletx = x - 5
			bullety = y
		end
	end
	if shoot==true then
		bullety = bullety - 2
		if bullety<=0 then
			shoot = false
		end
		screen:print(bulletx,bullety,"!!!",red)
	end
	if shoot1==true then
		bullety1 = bullety1 - 2
		if bullety1<=0 then
			shoot1 = false
		end
		screen:print(bulletx1,bullety1,"!!!",red)
	end
	if shoot2==true then
		bullety2 = bullety2 - 2
		if bullety2<=0 then
			shoot2 = false
		end
		screen:print(bulletx2,bullety2,"!!!",red)
	end
	screen.flip()
	oldhpad = hpad
end
