rouge = Color.new(255,0,0)
bleu = Color.new(0,0,255)
green=Color.new(0,255,0)
white = Color.new(255,255,255)


bullet = Image.createEmpty(4,4)
bullet:clear(green)

player = Image.load("ms0:/PSP/GAME/Wario Ware PSP/jeu/minijeu/mu/images/fusil.png")


terrain = Image.load("ms0:/PSP/GAME/Wario Ware PSP/jeu/minijeu/mu/images/terrain.png")
vic =  Image.load("ms0:/PSP/GAME/Wario Ware PSP/jeu/minijeu/mu/images/canard.png")

Mp3.load("mu/sons/pouf.mp3")

oldpad = Controls.read()
currentBullet = 0
direction = "right"

Player = {}
Player[1] = { x = 30, y = 100 }

BulletInfo = {}
for a = 1,5 do
BulletInfo[a] = { pic = bullet , firing = false, direction = "right", x = Player[1].x + 32,
y = Player[1].y + 16 }
end

function bulletSetup()
--Increase the current bullet by one, or reset it to 1
if currentBullet < 5 then
currentBullet = currentBullet + 1
else
currentBullet = 1
end
if direction == "left" then
BulletInfo[currentBullet].x = Player[1].x
BulletInfo[currentBullet].y = Player[1].y + 16
end
if direction == "right" then
BulletInfo[currentBullet].x = Player[1].x + 32
BulletInfo[currentBullet].y = Player[1].y + 16
end
if direction == "up" then
BulletInfo[currentBullet].x = Player[1].x + 16
BulletInfo[currentBullet].y = Player[1].y
end
if direction == "down" then
BulletInfo[currentBullet].x = Player[1].x + 16
BulletInfo[currentBullet].y = Player[1].y + 32
end
 
BulletInfo[currentBullet].direction = direction
BulletInfo[currentBullet].firing = true
end

function bulletFire()
for i = 1,5 do
if BulletInfo[i].firing == true then
if BulletInfo[i].direction == "right" then BulletInfo[i].x = BulletInfo[i].x + 10 end
if BulletInfo[i].direction == "left" then BulletInfo[i].x = BulletInfo[i].x - 10 end
if BulletInfo[i].direction == "up" then BulletInfo[i].y = BulletInfo[i].y - 10 end
if BulletInfo[i].direction == "down" then BulletInfo[i].y = BulletInfo[i].y + 10 end
screen:blit(BulletInfo[i].x,BulletInfo[i].y,BulletInfo[i].pic)
end
if BulletInfo[i].x < 0 or BulletInfo[i].x > 480 or BulletInfo[i].y < 0 or BulletInfo[i].y > 272 then BulletInfo[i].firing = false end
end
end

function movePlayer()
pad = Controls.read()
if pad:left() then
Player[1].x = Player[1].x - 3
direction = "left"
end
if pad:right() then
Player[1].x = Player[1].x + 3
direction = "right"
end
if pad:up() then
Player[1].y = Player[1].y - 3
direction = "up"
end
if pad:down() then
Player[1].y = Player[1].y + 3
direction = "down"
end
end

while true do
      screen:clear()
	  pad = Controls.read()
	  if pad:triangle() then
	  System.message("O pour tirer sur les cannard ",0)
	  end
	  
	  screen:blit(0,0,terrain)
	 screen:blit(Player[1].x, Player[1].y, player)
	  
	  if hasard == 1 then
	  screen:blit(10,50,vic)
	  elseif hasard == 2 then
	  screen:blit(1234,201,vic)
	  end
	  
	  if pad:circle() and not oldpad:circle() then
      hasard = math.random(1,2)
      end
	  
	  if pad:circle() then
	  Mp3.play()
	  end
	  
 
if pad:circle()  then
bulletSetup()
end

screen:print(10,10,"Bullet 1: ".. tostring(BulletInfo[1].firing),green)
screen:print(10,20,"Bullet 2: "..tostring(BulletInfo[2].firing),green)
screen:print(10,30,"Bullet 3: "..tostring(BulletInfo[3].firing),green)
screen:print(10,40,"Bullet 4: "..tostring(BulletInfo[4].firing),green)
screen:print(10,50,"Bullet 5: "..tostring(BulletInfo[5].firing),green)
screen:print(10,60,"Direction: "..direction,green)
movePlayer()
 
bulletFire()

if pad:l() and pad:r() then
	  dofile ("ms0:/PSP/GAME/Wario Ware PSP/jeu/menu.lua")
	  end
 
screen.waitVblankStart()
screen.flip()
oldpad = pad
end 