yahoum

Membres
  • Compteur de contenus

    1
  • Inscription

  • Dernière visite

yahoum's Achievements

Débutant

Débutant (1/7)

0

Réputation sur la communauté

  1. yahoum

    Topic Général Sur Le Lua

    Salut, moi aussi j'ai commencé mon petit jeu en Lua (Jeu très simple ) Voilà le code: --------------------Données de Jeu--------------------------------------Les couleurs------------------gold=Color.new(224,171,73)black=Color.new(0,0,0)red=Color.new(255,0,0)whtie=Color.new(255,255,255) ----------------Les images----------------background = Image.load("images/fond.png")pompiste_down = Image.load("images/pompiste_down.png")pompiste_up = Image.load("images/pompiste_up.png")pompiste_left = Image.load("images/pompiste_left.png")pompiste_right = Image.load("images/pompiste_right.png")auto = Image.load("images/voiture.png")----------------Les balles----------------bullet = Image.createEmpty(4,4)bullet:clear(gold)---------------Le joueur---------------player = pompiste_rightplayer2 = pompiste_leftplayerHeight = 45playerWidth = 30----------------Les Blocks----------------block = Image.createEmpty(32,32)block:clear(black)------------------Les Voitures------------------auto = auto---------------Variables---------------oldpad = Controls.read()currentBullet = 0direction = "right"----------------------------------Position de départ du joueur----------------------------------Player = {}Player[1] = { x = 30, y = 100 }Player[2] = { x = 415, y = 100 }------------------------------------------Zone de départ des balles (Joueur 1)------------------------------------------BulletInfo = {}for a = 1,5 doBulletInfo[a] = { pic = bullet , firing = false, direction = "right", x = Player[1].x + 30, y = Player[1].y + 22,5 }end------------------------------------------Zone de départ des balles (Joueur 2)------------------------------------------BulletInfo = {}for b = 1,5 doBulletInfo[b] = { pic = bullet , firing = false, direction = "right", x = Player[2].x + 30, y = Player[2].y + 22,5 }end-------------------------Position des Blocks-------------------------Block = {}Block[1] = { x = 160, y = 120, height = block:height(), width = block:width() }Block[2] = { x = 240, y = 120, height = block:height(), width = block:width() }Block[3] = { x = 200, y = 120, height = block:height(), width = block:width() }---------------------------Position des voitures---------------------------Voiture = {}Voiture[1] = { x = 160, y = 7, height = auto:height(), width = auto:width() }Voiture[2] = { x = 160, y = 215, height = auto:height(), width = auto:width() }---------------Fonctions---------------------------------------Balles du Joueur 1------------------------function bulletSetup()if currentBullet < 5 thencurrentBullet = currentBullet + 1elsecurrentBullet = 1endif direction == "left" then BulletInfo[currentBullet].x = Player[1].x + 10BulletInfo[currentBullet].y = Player[1].y + 22,5endif direction == "right" then BulletInfo[currentBullet].x = Player[1].x + 20 BulletInfo[currentBullet].y = Player[1].y + 22,5 endif direction == "up" then BulletInfo[currentBullet].x = Player[1].x + 15 BulletInfo[currentBullet].y = Player[1].y endif direction == "down" then BulletInfo[currentBullet].x = Player[1].x + 15BulletInfo[currentBullet].y = Player[1].y + 45 endBulletInfo[currentBullet].direction = directionBulletInfo[currentBullet].firing = trueendfunction bulletFire()for i = 1,5 doif BulletInfo[i].firing == true thenif BulletInfo[i].direction == "right" then BulletInfo[i].x = BulletInfo[i].x + 10 endif BulletInfo[i].direction == "left" then BulletInfo[i].x = BulletInfo[i].x - 10 endif BulletInfo[i].direction == "up" then BulletInfo[i].y = BulletInfo[i].y - 10 endif BulletInfo[i].direction == "down" then BulletInfo[i].y = BulletInfo[i].y + 10 endscreen:blit(BulletInfo[i].x,BulletInfo[i].y,BulletInfo[i].pic)endif BulletInfo[i].x < 0 or BulletInfo[i].x > 480 or BulletInfo[i].y < 0 or BulletInfo[i].y > 272 then BulletInfo[i].firing = false endendend------------------------Balles du Joueur 2------------------------function bulletSetup2()--Increase the current bullet by one, or reset it to 1if currentBullet < 5 thencurrentBullet = currentBullet + 1elsecurrentBullet = 1endif direction == "left2" then BulletInfo[currentBullet].x = Player[2].x + 10BulletInfo[currentBullet].y = Player[2].y + 22,5endif direction == "right2" then BulletInfo[currentBullet].x = Player[2].x + 20 BulletInfo[currentBullet].y = Player[2].y + 22,5 endif direction == "up2" then BulletInfo[currentBullet].x = Player[2].x + 15 BulletInfo[currentBullet].y = Player[2].y endif direction == "down2" then BulletInfo[currentBullet].x = Player[2].x + 15BulletInfo[currentBullet].y = Player[2].y + 45 endBulletInfo[currentBullet].direction = directionBulletInfo[currentBullet].firing = trueendfunction bulletFire2()for i = 1,5 doif BulletInfo[i].firing == true thenif BulletInfo[i].direction == "right2" then BulletInfo[i].x = BulletInfo[i].x + 10 endif BulletInfo[i].direction == "left2" then BulletInfo[i].x = BulletInfo[i].x - 10 endif BulletInfo[i].direction == "up2" then BulletInfo[i].y = BulletInfo[i].y - 10 endif BulletInfo[i].direction == "down2" then BulletInfo[i].y = BulletInfo[i].y + 10 endscreen:blit(BulletInfo[i].x,BulletInfo[i].y,BulletInfo[i].pic)endif BulletInfo[i].x < 0 or BulletInfo[i].x > 480 or BulletInfo[i].y < 0 or BulletInfo[i].y > 272 then BulletInfo[i].firing = false endendend----------------Collisions----------------function collisionCheck(object)if (Player[1].x + playerWidth > object.x) and (Player[1].x < object.x + object.width) and (Player[1].y + playerHeight > object.y) and (Player[1].y < object.y + object.height) thenPlayer[1].x = oldxPlayer[1].y = oldyend end---------------------------Mouvement du Joueur 1---------------------------function movePlayer()pad = Controls.read()if pad:left() thenplayer = pompiste_left Player[1].x = Player[1].x - 1 direction = "left"endif pad:right() thenplayer = pompiste_right Player[1].x = Player[1].x + 1 direction = "right"endif pad:up() thenplayer = pompiste_up Player[1].y = Player[1].y - 1 direction = "up"endif pad:down() thenplayer = pompiste_down Player[1].y = Player[1].y + 1 direction = "down"endend---------------------------Mouvement du Joueur 2---------------------------function movePlayer2()pad = Controls.read()if pad:square() thenplayer2 = pompiste_left Player[2].x = Player[2].x - 1 direction = "left2"endif pad:circle() thenplayer2 = pompiste_right Player[2].x = Player[2].x + 1 direction = "right2"endif pad:triangle() thenplayer2 = pompiste_up Player[2].y = Player[2].y - 1 direction = "up2"endif pad:cross() thenplayer2 = pompiste_down Player[2].y = Player[2].y + 1 direction = "down2"endend-----------------------Boucle principale-----------------------while true dopad = Controls.read()oldx = Player[1].xoldy = Player[1].yscreen:clear()screen:blit(0,0,background)for a = 1,3 doscreen:blit(Block[a].x,Block[a].y,block)endfor b = 1,2 doscreen:blit(Voiture[b].x,Voiture[b].y,auto)endscreen:blit(Player[1].x,Player[1].y,player)screen:blit(Player[2].x,Player[2].y,player2)if pad:l() and oldpad:l() ~= pad:l() thenbulletSetup()endif pad:r() and oldpad:r() ~= pad:r() thenbulletSetup2()endmovePlayer()movePlayer2()collisionCheck(Block[1])collisionCheck(Block[2])collisionCheck(Block[3])collisionCheck(Voiture[1])collisionCheck(Voiture[2])bulletFire()bulletFire2()screen.waitVblankStart()screen.flip()oldpad = padend Maintenant, je voudrais bloquer les joueurs au bord de l'écran (Avant ça marchais, depuis que j'ai ajouté les balles ça marche plus...), bloquer les balles lorsqu'elles croisent un obstacle (Lorsqu'elle rentre dans les voitures ou dans les joueurs par exemple) et rajouter une barre de vie aux joueurs, qui diminue lorsqu'ils se font toucher par une balle et quand ils n'en ont plus ils meurrent. Je voudrais aussi mettre un système de point, chaque fois qu'un joueur tue l'autre, +1