Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Chargement du perso
- Perso_gauche = Image.load("./Image/Personnage/Gauche.png") -- Les images
- Perso_droite = Image.load("./Image/Personnage/Droite.png")
- player = Image.load("./Image/Personnage/Face.png")
- Perso_dos = Image.load("./Image/Personnage/Dos.png")
- maison = Image.load("./Image/Batiment/Maison 1.png")
- background = Image.load("./Image/background/background.png")
- --Mouvement--
- Face_Run = Image.load("./Image/Personnage/Face - Marche.png")
- Face_Run2= Image.load("./Image/Personnage/Face - Marche 2.png")
- Gauche_Run = Image.load("./Image/Personnage/Gauche - Marche.png")
- Gauche_Run2 = Image.load("./Image/Personnage/Gauche - Marche 2.png")
- Droite_Run = Image.load("./Image/Personnage/Droite - Marche.png")
- Droite_Run2 = Image.load("./Image/Personnage/Droite - Marche 2.png")
- Dos_Run = Image.load("./Image/Personnage/Dos - Marche.png")
- Dos_Run2 = Image.load("./Image/Personnage/Dos - Marche 2.png")
- --position de depart
- Player = {x = 0, y = 0}
- playerHeight = 85
- playerWidth = 62
- Player.img = player
- Player.marche = 1
- Maison = {}
- Maison[1] = { x = 175, y = 80, height = 19, width = 16 }
- function MovePlayer()
- oldpad = Controls.read()
- pad = Controls.read()
- if pad:up()then
- statut = "up"
- Player.y = Player.y -2
- Player.marche = Player.marche+1
- Player.img = Perso_dos
- end
- if pad:left() then
- statut = "left"
- Player.x = Player.x -2
- Player.marche = Player.marche+1
- Player.img = Perso_gauche
- end
- if pad:right()then
- statut = "right"
- Player.x = Player.x +2
- Player.marche = Player.marche+1
- Player.img = Perso_droite
- end
- if pad:down()then
- statut = "down"
- Player.y = Player.y +2
- Player.marche = Player.marche+1
- Player.img = player
- end
- end
- function collisionCheck(object)
- 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
- Player.x = oldx
- Player.y = oldy
- end
- end
- function TurnPlayer()
- --Marche Up--
- if statut == "up" then
- if Player.marche>=0 and Player.marche<=5 then Player.img = Dos_Run end
- if Player.marche>=5 and Player.marche<=10 then Player.img = Dos_Run2 end
- if Player.marche>10 then Player.marche= 0 end
- end
- --Marche Down--
- if statut == "down" then
- if Player.marche>=0 and Player.marche<=5 then Player.img = Face_Run end
- if Player.marche>=5 and Player.marche<=10 then Player.img = Face_Run2 end
- if Player.marche>10 then Player.marche= 0 end
- end
- --Marche Left--
- if statut == "left" then
- if Player.marche>=0 and Player.marche<=5 then Player.img = Gauche_Run end
- if Player.marche>=5 and Player.marche<=10 then Player.img = Gauche_Run2 end
- if Player.marche>10 then Player.marche= 0 end
- end
- --Marche Right--
- if statut == "right" then
- if Player.marche>=0 and Player.marche<=5 then Player.img = Droite_Run end
- if Player.marche>=5 and Player.marche<=10 then Player.img = Droite_Run2 end
- if Player.marche>10 then Player.marche= 0 end
- end
- end
- --boucle principale
- while true do
- oldx = Player.x
- oldy = Player.y
- screen:clear()
- MovePlayer()
- collisionCheck(Maison[1])
- screen:blit(0, 0, background)
- for a = 1,1 do
- screen:blit(Maison[a].x,Maison[a].y,maison)
- end
- screen:blit(Player.x,Player.y,Player.img)
- TurnPlayer()
- screen.waitVblankStart()
- screen.flip()
- end
Add Comment
Please, Sign In to add comment