-- IrDA sample
red = Color.new(255, 0, 0)
white = Color.new(255, 255, 255)
timeout = 10
x = 240
y = 260
ai = Image.load("./system/1.jpg")
aispeed = 0.5
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 + aispeed
		if ax>=470 then
			ax = 2
		end
		screen:blit(ax,ay,ai,false)
		if (bullety==ay and (bulletx>(ax-30) and bulletx<(ax+15))) then
				ax = 2
		end
		if (bullety1==ay and (bulletx1>(ax-30) and bulletx1<(ax+15))) then
				ax = 2
		end
		if (bullety2==ay and (bulletx2>(ax-30) and bulletx2<(ax+30))) then
				ax = 2
		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 pad:up() then
		aispeed = aispeed + 0.05
	end
	if pad:down() then
		aispeed = aispeed - 0.05
	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
