Guest User

Untitled

a guest
Oct 21st, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | None | 0 0
  1. -- Chargement du perso
  2. Perso_gauche = Image.load("./Image/Personnage/Gauche.png") -- Les images
  3. Perso_droite = Image.load("./Image/Personnage/Droite.png")
  4. player = Image.load("./Image/Personnage/Face.png")
  5. Perso_dos = Image.load("./Image/Personnage/Dos.png")
  6. maison = Image.load("./Image/Batiment/Maison 1.png")
  7. background = Image.load("./Image/background/background.png")
  8.  
  9. --Mouvement--
  10.  
  11. Face_Run = Image.load("./Image/Personnage/Face - Marche.png")
  12. Face_Run2= Image.load("./Image/Personnage/Face - Marche 2.png")
  13. Gauche_Run = Image.load("./Image/Personnage/Gauche - Marche.png")
  14. Gauche_Run2 = Image.load("./Image/Personnage/Gauche - Marche 2.png")
  15. Droite_Run = Image.load("./Image/Personnage/Droite - Marche.png")
  16. Droite_Run2 = Image.load("./Image/Personnage/Droite - Marche 2.png")
  17. Dos_Run = Image.load("./Image/Personnage/Dos - Marche.png")
  18. Dos_Run2 = Image.load("./Image/Personnage/Dos - Marche 2.png")
  19.  
  20. --position de depart
  21.  
  22. Player = {x = 0, y = 0}
  23. playerHeight = 85
  24. playerWidth = 62
  25. Player.img = player
  26. Player.marche = 1
  27.  
  28. Maison = {}
  29. Maison[1] = { x = 175, y = 80, height = 19, width = 16 }
  30.  
  31. function MovePlayer()
  32.  
  33. oldpad = Controls.read()
  34. pad = Controls.read()
  35.  
  36.  
  37.     if pad:up()then
  38.         statut = "up"
  39.         Player.y = Player.y -2
  40.         Player.marche = Player.marche+1
  41.         Player.img = Perso_dos
  42.     end
  43.  
  44.     if pad:left() then
  45.         statut = "left"
  46.         Player.x = Player.x -2
  47.         Player.marche = Player.marche+1
  48.         Player.img = Perso_gauche
  49.     end
  50.  
  51.     if pad:right()then
  52.         statut = "right"
  53.         Player.x = Player.x +2
  54.         Player.marche = Player.marche+1
  55.         Player.img = Perso_droite
  56.     end
  57.  
  58.     if pad:down()then
  59.         statut = "down"
  60.         Player.y = Player.y +2
  61.         Player.marche = Player.marche+1
  62.         Player.img = player
  63.     end
  64. end
  65.  
  66. function collisionCheck(object)
  67.     if (Player.x - playerWidth < object.x) and (Player.x > object.x - object.width) and (Player.y - playerHeight < object.y) and (Player.y > object.y - object.height) then
  68.     Player.x = oldx
  69.     Player.y = oldy
  70.     end
  71. end
  72.  
  73. function TurnPlayer()
  74.  
  75. --Marche Up--
  76.     if statut == "up" then
  77.     if Player.marche>=0 and Player.marche<=5 then Player.img = Dos_Run end
  78.     if Player.marche>=5 and Player.marche<=10 then Player.img = Dos_Run2 end
  79.     if Player.marche>10 then Player.marche= 0 end
  80.     end
  81. --Marche Down--
  82.     if statut == "down" then
  83.     if Player.marche>=0 and Player.marche<=5 then Player.img = Face_Run end
  84.     if Player.marche>=5 and Player.marche<=10 then Player.img = Face_Run2 end
  85.     if Player.marche>10 then Player.marche= 0 end
  86.     end
  87. --Marche Left--
  88.     if statut == "left" then
  89.     if Player.marche>=0 and Player.marche<=5 then Player.img = Gauche_Run end
  90.     if Player.marche>=5 and Player.marche<=10 then Player.img = Gauche_Run2 end
  91.     if Player.marche>10 then Player.marche= 0 end
  92.     end
  93. --Marche Right--
  94.     if statut == "right" then
  95.     if Player.marche>=0 and Player.marche<=5 then Player.img = Droite_Run end
  96.     if Player.marche>=5 and Player.marche<=10 then Player.img = Droite_Run2 end
  97.     if Player.marche>10 then Player.marche= 0 end
  98.     end
  99.  
  100. end
  101.  
  102. --boucle principale
  103.  
  104. while true do
  105.     oldx = Player.x
  106.     oldy = Player.y
  107.     screen:clear()
  108.     MovePlayer()
  109.     collisionCheck(Maison[1])
  110.     screen:blit(0, 0, background)
  111.     for a = 1,1 do
  112.         screen:blit(Maison[a].x,Maison[a].y,maison)
  113.     end
  114.     screen:blit(Player.x,Player.y,Player.img)
  115.  
  116.     TurnPlayer()
  117.  
  118.  
  119. screen.waitVblankStart()
  120. screen.flip()
  121. end
Add Comment
Please, Sign In to add comment