Auteurs: Antoni Marzewski, Lenny Montfort, Simon Ferren, Mathis Vicente
MicroFighters est un jeu platformeur 2D. Il s’agit d’un duel entre 2 joueurs contrôles par un seul clavier. Il consiste de 8 maps, et 30 personnages que les joueurs peuvent choisir avant de commencer la partie. Chacun joueur dispose d’un pistolet et des bombes, et un powerup qui apparaît au milieu de la map toutes les 15 secondes. Le but est de tuer l’adversaire.
Ce jeu a été écrit dans Python a l’aide du module Pygame. Les graphismes du jeu ont été crée a l’aide du site Pixilart. Notre but était de créer un simple jeu auquel on peut jouer n’importe quand avec des amis.
Nous avons choisi: Python car c’est un langage qu’on connesait déjà grâce à la NSI, Pygame car c’est le module de python le plus connu et utilisé dans le cadre des jeux video-python et Pixilart car c’est un site internet donc on pouvait l’utiliser n’importe ou sans téléchargement pour créer des graphismes du style pixel art pour notre jeu.
Pygame est un module cree le 28 Octobre 2000, qui offre des outils indispensables pour créer des jeux. Il permet par exemple de:
-creer une fenetre pygame.display.set_mode((1920, 1024))
-importer des images pygame.image.load(‘ui/menu.png’)
-afficher des images window.blit(image, rect)
-detecter des collisions rect1.colliderect(rect2)
-regulariser la vitesse d’execution du programme clock.tick(60)
-detecter la saisie de l’utilisateur event.key == pygame.K_SPACE
Pixil art est un site internet qui permet de creer et exporter des images style pixel art en format .png, apres cela nous pouvons directement les utiliser dans Pygame!
Voici le code entier de notre jeu, avec des docstring pour vous aider a comprendre si cela vous interesse.
import pygame, sys, random
# Initialisation du module
pygame.init()
#Variable clock qui permet de regulariser la vitesse d'execution du programme
clock = pygame.time.Clock()
#Importation des Images
titleImg = pygame.image.load('ui/title.png')
menuImg = pygame.image.load('ui/menu.png')
selectorLongImg = pygame.image.load('ui/selectorLong.png')
selectorShortImg = pygame.image.load('ui/selectorShort.png')
player1win = pygame.image.load('ui/player1win.png')
player2win = pygame.image.load('ui/player2win.png')
pistolImg = pygame.image.load('weapons/pistol.png')
bulletImg = pygame.image.load('weapons/bullet.png')
bombImg = pygame.image.load('weapons/bomb.png')
explosionImg = pygame.image.load('weapons/explosion.png')
explosionBigImg = pygame.image.load('weapons/explosionBig.png')
characterDefault = pygame.image.load('characters/characterDefault.png')
characterSoldier = pygame.image.load('characters/characterSoldier.png')
characterFernando = pygame.image.load('characters/characterFernando.png')
characterDuck = pygame.image.load('characters/characterDuck.png')
characterAmongus = pygame.image.load('characters/characterAmongus.png')
characterKnight = pygame.image.load('characters/characterKnight.png')
characterWizard = pygame.image.load('characters/characterWizard.png')
characterMario = pygame.image.load('characters/characterMario.png')
characterFrog = pygame.image.load('characters/characterFrog.png')
characterMajora = pygame.image.load('characters/characterMajora.png')
characterElgato = pygame.image.load('characters/characterElgato.png')
characterAstronaut = pygame.image.load('characters/characterAstronaut.png')
characterBatman = pygame.image.load('characters/characterBatman.png')
characterIronman = pygame.image.load('characters/characterIronman.png')
characterMessi = pygame.image.load('characters/characterMessi.png')
characterSpiderman = pygame.image.load('characters/characterSpiderman.png')
characterSpongebob = pygame.image.load('characters/characterSpongebob.png')
characterZombie = pygame.image.load('characters/characterZombie.png')
characterYoru = pygame.image.load('characters/characterYoru.png')
characterKayn = pygame.image.load('characters/characterKayn.png')
characterSkeleton = pygame.image.load('characters/characterSkeleton.png')
characterZac = pygame.image.load('characters/characterZac.png')
characterCartman = pygame.image.load('characters/characterCartman.png')
characterMonkey = pygame.image.load('characters/characterMonkey.png')
characterRiche = pygame.image.load('characters/characterRiche.png')
characterToyalien = pygame.image.load('characters/characterToyalien.png')
characterFarmer = pygame.image.load('characters/characterFarmer.png')
characterKarate = pygame.image.load('characters/characterKarate.png')
characterMarsupilami = pygame.image.load('characters/characterMarsupilami.png')
characterLuffy = pygame.image.load('characters/characterLuffy.png')
characterSpeed = pygame.image.load('characters/characterSpeed.png')
characterAlien = pygame.image.load('characters/characterAlien.png')
characterCreeper = pygame.image.load('characters/characterCreeper.png')
characterSteve = pygame.image.load('characters/characterSteve.png')
characterDeadpool = pygame.image.load('characters/characterDeadpool.png')
characterDucky = pygame.image.load('characters/characterDucky.png')
characterHalo = pygame.image.load('characters/characterHalo.png')
characterNinja = pygame.image.load('characters/characterNinja.png')
characterRonaldo = pygame.image.load('characters/characterRonaldo.png')
characterYoda = pygame.image.load('characters/characterYoda.png')
characterLgbt = pygame.image.load('characters/characterLgbt.png')
characterPingu = pygame.image.load('characters/characterPingu.png')
characterScuttle = pygame.image.load('characters/characterScuttle.png')
characterLich = pygame.image.load('characters/characterLich.png')
characterFinn = pygame.image.load('characters/characterFinn.png')
characterJake = pygame.image.load('characters/characterJake.png')
characterDemon = pygame.image.load('characters/characterDemon.png')
characterFifi = pygame.image.load('characters/characterFifi.png')
characterStickman = pygame.image.load('characters/characterStickman.png')
characterBen = pygame.image.load('characters/characterBen.png')
characterBird = pygame.image.load('characters/characterBird.png')
characterPig = pygame.image.load('characters/characterPig.png')
characterPumpkin = pygame.image.load('characters/characterPumpkin.png')
characterTriangle = pygame.image.load('characters/characterTriangle.png')
characterOrange = pygame.image.load('characters/characterOrange.png')
characterBanana = pygame.image.load('characters/characterBanana.png')
characterSuperman = pygame.image.load('characters/characterSuperman.png')
characterPutin = pygame.image.load('characters/characterPutin.png')
characterTrump = pygame.image.load('characters/characterTrump.png')
characterGlitch = pygame.image.load('characters/characterGlitch.png')
powerupPistol = pygame.image.load('powerups/powerupPistol.png')
powerupBomb = pygame.image.load('powerups/powerupBomb.png')
powerupSpeed = pygame.image.load('powerups/powerupSpeed.png')
powerupHealth = pygame.image.load('powerups/powerupHealth.png')
#Parametres de la Fenetre
windowW, windowH = 1920, 1024
window = pygame.display.set_mode((windowW, windowH), pygame.FULLSCREEN)
pygame.display.set_caption("MicroFighters")
pygame.display.set_icon(pygame.image.load('ui/logo.png'))
#Surface temporaire sur lequel le jeu est affiche, cette surface est apres aggrandie a la taille de la fenetre
#cela permet d'aggrandir les pixels 4 fois
unscaledWindow = pygame.Surface((480, 256))
# Les mapes, 30 sur 16 blocs de 16x16 pixels, en tout 480 sur 240 pixels et donc la resolution de le fenetre temporaire
mapJungle = \
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '3', '3', '3', '3', '3', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '3', '3', '3', '3', '3', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '1', '1', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2'],
['1', '1', '1', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '1', '1', '1'],
['1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '1', '1', '2', '2', '2', '2', '2', '2', '2', '1', '1', '1', '1', '1', '1', '1']]
mapIceberg = \
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2'],
['1', '1', '2', '0', '0', '0', '0', '2', '2', '2', '2', '2', '2', '2', '0', '0', '2', '2', '2', '2', '2', '2', '2', '0', '0', '0', '0', '2', '1', '1'],
['1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1'],
['1', '1', '1', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '1', '1', '1'],
['1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1'],
['1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1'],
['1', '1', '3', '3', '3', '0', '0', '0', '0', '0', '2', '2', '2', '0', '0', '0', '0', '2', '2', '2', '0', '0', '0', '0', '0', '3', '3', '3', '1', '1'],
['1', '3', '0', '0', '0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0', '0', '0', '3', '1'],
['3', '0', '0', '0', '0', '0', '3', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '3', '0', '0', '0', '0', '0', '3'],
['3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3'],
['3', '0', '0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0', '0', '3'],
['2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2']]
mapDesert =\
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0'],
['0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0'],
['2', '2', '2', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '2', '2', '2'],
['1', '1', '1', '0', '0', '0', '2', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '2', '0', '0', '0', '1', '1', '1'],
['1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1'],
['1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1'],
['1', '1', '1', '2', '0', '0', '0', '0', '0', '0', '3', '0', '3', '0', '0', '0', '0', '3', '0', '3', '0', '0', '0', '0', '0', '0', '2', '1', '1', '1'],
['1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '3', '3', '3', '0', '0', '0', '0', '3', '3', '3', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1'],
['1', '1', '1', '1', '0', '0', '0', '0', '3', '0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0', '3', '0', '0', '0', '0', '1', '1', '1', '1'],
['1', '1', '1', '1', '2', '0', '0', '0', '3', '3', '3', '0', '0', '0', '2', '2', '0', '0', '0', '3', '3', '3', '0', '0', '0', '2', '1', '1', '1', '1'],
['1', '1', '1', '1', '1', '0', '0', '0', '0', '0', '3', '0', '0', '2', '1', '1', '2', '0', '0', '3', '0', '0', '0', '0', '0', '1', '1', '1', '1', '1'],
['1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '1', '1', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '1', '1', '1', '1', '1']]
mapOcean =\
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '4', '0', '0', '0', '4', '0', '0', '0', '0', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '4', '0', '0', '0', '4', '0', '0', '0'],
['0', '0', '0', '4', '4', '0', '4', '4', '0', '0', '0', '0', '2', '1', '1', '1', '1', '2', '0', '0', '0', '0', '4', '4', '0', '4', '4', '0', '0', '0'],
['0', '0', '0', '0', '4', '4', '4', '0', '0', '0', '0', '0', 'T', 'T', 'T', 'T', 'T', 'T', '0', '0', '0', '0', '0', '4', '4', '4', '0', '0', '0', '0'],
['0', '4', '0', '0', '4', '0', '0', '0', '0', '0', '0', '0', 'T', 'T', 'T', 'T', 'T', 'T', '0', '0', '0', '0', '0', '0', '0', '4', '0', '0', '4', '0'],
['0', '4', '0', '4', '4', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '4', '4', '0', '4', '0'],
['0', '4', '4', '4', '0', '0', '0', '4', '0', '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '0', '0', '0', '4', '0', '0', '0', '4', '4', '4', '0'],
['0', '0', '4', '0', '0', '0', '0', '4', '4', '0', '2', '1', '1', '1', '1', '1', '1', '1', '1', '2', '0', '4', '4', '0', '0', '0', '0', '4', '0', '0'],
['0', '0', '4', '0', '0', '0', '0', '0', '4', '2', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '4', '0', '0', '0', '0', '0', '4', '0', '0'],
['3', '3', '3', '3', '3', '3', '3', '3', '2', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '3', '3', '3', '3', '3', '3', '3', '3']]
mapParadise =\
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '5', '0', '0', '0', '2', '2', '2', '2', '2', '27', '0', '0', '5', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '5', '0', '0', '0', '4', '0', '0', '0', '0', '1', '1', '1', '1', '0', '0', '0', '4', '0', '0', '0', '5', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '4', '0', '0', '0', '4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4', '0', '0', '0', '4', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '3', '0', '0', '0', '3', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '3', '0', '0', '0', '3', '0', '0', '0', '0', '0'],
['5', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '5'],
['4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4'],
['4', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '4'],
['1', '2', '2', '0', '0', '0', '0', '0', '0', '0', '5', '0', '0', '0', '0', '0', '0', '0', '0', '5', '0', '0', '0', '0', '0', '0', '0', '2', '2', '1'],
['1', '1', '1', '2', '0', '0', '0', '5', '0', '0', '3', '0', '0', '5', '0', '0', '5', '0', '0', '3', '0', '0', '5', '0', '0', '0', '2', '1', '1', '1'],
['1', '1', '1', '1', '0', '0', '0', '4', '0', '0', '0', '0', '0', '4', '0', '0', '4', '0', '0', '0', '0', '0', '4', '0', '0', '0', '1', '1', '1', '1']]
mapBloodbath =\
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2'],
['1', '1', '0', '0', '2', '2', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '2', '2', '0', '0', '1', '1'],
['0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '0', '0'],
['0', '0', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '1', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0']]
mapMinecraft =\
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '6', '6', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '6', 'T', 'T', '6', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '0', 'T', 'T', 'T', 'T', 'T', 'T', '0', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4', '0'],
['0', '4', '4', '4', '0', '0', '0', '0', '0', '0', '0', '6', 'T', 'T', 'T', 'T', 'T', 'T', '6', '0', '0', '0', '0', '0', '0', '0', '4', '4', '4', '0'],
['4', '4', '4', '4', '4', '0', '0', '0', '0', '0', '6', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', '6', '0', '0', '0', '0', '0', '4', '4', '4', '4', '4'],
['4', '4', '4', '4', '4', '0', '0', '0', '0', '6', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '6', '0', '0', '0', '0', '4', '4', '4', '4', '4'],
['0', '0', '3', '0', '0', '0', '0', '0', '0', '0', '5', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', '5', '0', '0', '0', '0', '0', '0', '0', '3', '0', '0'],
['0', '0', '3', '0', '0', '4', '4', '0', '0', '0', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', '0', '0', '0', '4', '4', '0', '0', '3', '0', '0'],
['0', '0', '3', '0', '0', '4', '4', '0', '0', '0', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', 'T', '0', '0', '0', '4', '4', '0', '0', '3', '0', '0'],
['2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2'],
['1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1']]
mapMoon =\
[['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'T', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', 'T', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '2', '2', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '2', '2', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '0', '0', '0', '0', '0', '0', '0', '0', '2', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0', '0', '0', '0', '2', '1', '2', '2', '0', '0', '0', '0', '2', '2', '1', '2', 'T', '0', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', 'T', '0', '0', '2', '2', '1', '1', '1', '1', '2', '2', '2', '2', '1', '1', '1', '1', '2', '2', '0', '0', '0', '0', '0', '0', '0'],
['0', '0', '0', '2', '2', '2', '2', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2', '2', '0', 'T', '0'],
['2', '2', '2', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', '2', '2']]
currentMap = mapJungle #Map par defaut
#Creation des variables "block actuel/block choisi"
currentTile1, currentTile2, currentTile3, currentTile4, currentTile5, currentTileT, currentBackground = None,None,None,None,None,None, None
#Variables des boucles de generation, cela evite de par exemple scanner et generer la map a chaque iteration de la boucle du jeu
jumpHeight = -3.4
tileSize = 16
generatedTiles = []
launched = False
gameGenerated = False
menuGenerated = False
# Variables des images des joueurs
player1Img = pygame.image.load('characters/characterDefault.png')
player2Img = pygame.image.load('characters/characterDefault.png')
#Variavles du saisi
player1Right, player1Left, player1Jumping, player1Shooting, player1Throwing = False, False, False, False, False
player2Right, player2Left, player2Jumping, player2Shooting, player2Throwing = False, False, False, False, False
# Definition des groupes d'objets
bulletGroup = pygame.sprite.Group()
bombGroup = pygame.sprite.Group()
explosionGroup = pygame.sprite.Group()
#Selecteurs par defaut (rectangles bleus qui indiquent quel map/personnage a ete choisi)
selectors = [(selectorLongImg, (46, 22)), (selectorShortImg, (38, 66)), (selectorShortImg, (38, 132))]
# Classes, elles permettent de decrire les comportements des objets qui seront initialise plusieurs fois, par exemple les
# balles, chaque balle doit avoir a peu pres les memes proprietes et comportements, tout cela est decrit dans la classe "7Bullet".
#Classe Joueur
class Player(pygame.sprite.Sprite):
# Methode d'initialisation du joueur
# Arguments: coordonees de l'initialisation, image du joueur, blocs de la map, gravite de la map
def __init__(self, spawncords, img, tilerectlist, gravity):
self.rect = pygame.Rect(spawncords[0], spawncords[1], 16, 16)
self.image = img
self.pistol = pistolImg
self.momentumY = 0
self.tilerectlist = tilerectlist
self.pistolCooldown = 0
self.pistolSpeed = 10
self.bombCooldown = 0
self.bombSpeed = 100
self.flip = True
self.health = 16
self.gravity = gravity
self.speed = 2
self.bombType = 'small'
# Methode de deplacement du joueur
# Arguments: variables de saisie
def update(self, right, left, jumping, shooting, throwing):
dx = 0 #Delta X, le changement de la coordonee x pour cette iteration
dy = 0 #Delta Y, le changement de la coordonee Y pour cette iteration
if right: #Si le joueur doit de deplacer vers la droite
dx += self.speed #Delta X += la vitesse du joueur
self.flip = True #Joueur retourne = Vrai
if left:
dx += -self.speed
self.flip = False
dy += self.momentumY #Delta Y += l'elan du joueur
self.momentumY += self.gravity #Elan += gravite
if self.momentumY > 4: #Limite de l'elan, le joueur ne peut pas accelerer a l'infini
self.momentumY = 4
self.rect, collisions = collide(self.rect, dx, dy, self.tilerectlist) #Test de collisions
if collisions['bottom']:
self.momentumY = 1
if collisions['bottom'] and jumping:
self.momentumY = -3.4
elif collisions['top']:
self.momentumY = 0.5
# Limites de la map
if self.rect.x <= -1:
self.rect.x = 0
elif self.rect.x >= 465:
self.rect.x = 464
if self.rect.y > 256:
self.health = 0
if shooting and self.pistolCooldown == 0: #Si le joueur veut tirer et peut tirer
bullet = Bullet(self.rect.x,self.rect.y, self.flip) #Initialisation d'une une balle
bulletGroup.add(bullet)
self.pistolCooldown = self.pistolSpeed
elif throwing and self.bombCooldown == 0: #Si le joueur jete une bombe et peut jeter une bombe
bomb = Bomb(self.rect.x, self.rect.y, self.flip, self.gravity, self.tilerectlist, self.speed, self.bombType) #Initialisation d'une une bombe
bombGroup.add(bomb)
self.bombCooldown = self.bombSpeed
# Decompte des cooldowns
if self.pistolCooldown != 0:
self.pistolCooldown -= 1
if self.bombCooldown != 0:
self.bombCooldown -= 1
if self.rect.colliderect(powerup.rect): #Si le joueur touche un powerup
if powerup.type == powerupPistol:
self.pistolSpeed = 5
if powerup.type == powerupBomb:
self.bombSpeed = 50
self.bombType = 'big'
if powerup.type == powerupSpeed:
self.speed = 3
if powerup.type == powerupHealth:
self.health = 16
powerup.rect.x = -64
# Methode d'affichage
def draw(self):
if self.flip:
unscaledWindow.blit(pygame.transform.flip(self.image, True, False), self.rect)
unscaledWindow.blit(pygame.transform.flip(self.pistol, True, False), (self.rect.x + 15, self.rect.y))
else:
unscaledWindow.blit(self.image, self.rect)
unscaledWindow.blit(self.pistol, (self.rect.x - 15, self.rect.y))
pygame.draw.rect(unscaledWindow, (255-player1.health*15, player1.health*15, 0), (player1.rect.x, player1.rect.y - 3, player1.health, 2))
pygame.draw.rect(unscaledWindow, (255-player2.health*15, player2.health*15, 0), (player2.rect.x, player2.rect.y - 3, player2.health, 2))
class Bullet(pygame.sprite.Sprite):
def __init__(self, x, y, flip):
pygame.sprite.Sprite.__init__(self)
self.speed = 6
self.image = bulletImg
self.rect = (self.image.get_rect())
self.rect.y = y+8
self.flip = flip
if flip:
self.rect.x = x+14
else:
self.rect.x = x-2
def update(self, rectlist):
if self.flip:
self.rect.x += self.speed
else:
self.rect.x -= self.speed
if self.rect.x < 0 or self.rect.x > 480:
self.kill()
if self.rect.collidelist(rectlist) >= 0:
self.kill()
if self.rect.colliderect(player1.rect):
player1.health -= 1
if player1.health < 0:
player1.health = 0
self.kill()
if self.rect.colliderect(player2.rect):
player2.health -= 1
if player2.health < 0:
player2.health = 0
self.kill()
class Bomb(pygame.sprite.Sprite):
def __init__(self, x, y, flip, gravity, tilerectlist, speed, type):
pygame.sprite.Sprite.__init__(self)
self.momentumY = -3
self.speed = speed
self.image = bombImg
self.rect = self.image.get_rect()
self.rect.y = y
self.flip = flip
self.gravity = gravity
self.tilerectlist = tilerectlist
self.type = type
if flip:
self.rect.x = x+16
else:
self.rect.x = x-7
def update(self, rectlist):
dx = 0
dy = 0
if self.flip:
dx += self.speed
else:
dx -= self.speed
dy += self.momentumY
self.momentumY += self.gravity
if self.momentumY > 8:
self.momentumY = 8
self.rect.x += dx
self.rect.y += dy
if self.rect.x < 0 or self.rect.x > 473 or self.rect.collidelist(rectlist) >= 0 or self.rect.colliderect(player1.rect) or self.rect.colliderect(player2.rect):
explosion = Explosion(self.rect.x, self.rect.y, self.type)
explosionGroup.add(explosion)
self.kill()
class Explosion(pygame.sprite.Sprite):
def __init__(self, x, y, type):
super().__init__()
self.size = type
if self.size == 'small':
self.rect = pygame.Rect(x-13,y-11, 32, 32)
self.image = explosionImg
if self.size == 'big':
self.rect = pygame.Rect(x - 28, y - 27, 64, 64)
self.image = explosionBigImg
self.timer = 20
self.doneDamage = False
def update(self):
if not self.doneDamage:
if self.rect.colliderect(player1.rect):
player1.health -= 4
if player1.health < 0:
player1.health = 0
if self.rect.colliderect(player2.rect):
player2.health -= 4
if player2.health < 0:
player2.health = 0
self.doneDamage = True
self.timer -= 1
if self.timer == 0:
self.kill()
class Powerup(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.rect = pygame.Rect(232, 64, 16, 16)
types = [powerupPistol, powerupBomb, powerupSpeed, powerupHealth]
self.type = self.image = types[random.randint(0,3)]
player1.pistolSpeed = 10
player1.bombSpeed = 100
player1.speed = 2
player1.bombType = 'small'
player2.pistolSpeed = 10
player2.bombSpeed = 100
player2.speed = 2
player2.bombType = 'small'
def draw(self):
unscaledWindow.blit(self.image, self.rect)
def hitTest(rect, tilerectlist): #Test des blocks en contact avec un objet
hitList = []
for tilerect in tilerectlist:
if rect.colliderect(tilerect):
hitList.append(tilerect)
return hitList
def collide(rect, dx, dy, tilerectlist): #Test de collisions
collisions = {'top':False, 'bottom':False,'right':False,'left':False,}
rect.x += dx
hitList = hitTest(rect, tilerectlist)
for tileRect in hitList:
if dx > 0:
rect.right = tileRect.left
collisions['right'] = True
elif dx < 0:
rect.left = tileRect.right
collisions['left'] = True
rect.y += dy
hitList = hitTest(rect, tilerectlist)
for tileRect in hitList:
if dy > 0:
rect.bottom = tileRect.top
collisions['bottom'] = True
elif dy < 0:
rect.top = tileRect.bottom
collisions['top'] = True
return rect, collisions
def menu():
global currentMap, currentTile1, currentTile2, currentTile3, currentTile4, currentTile5, currentTile6, currentTileT, currentBackground,\
player1Img, player2Img, player1Spawn, player2Spawn, menuGenerated, gameGenerated, selectors
inMenu = True
menuGenerated = False
while inMenu:
if not menuGenerated:
unscaledWindow.blit(menuImg, (0, 0))
#Definition des boutons
buttonQuit = pygame.Rect(470, 0, 10, 10)
buttonStart = pygame.Rect(377, 233, 100, 20)
mapButtons = []
for i in range(4):
mapButtons.append(pygame.Rect(46 + i * 102, 22, 100, 20))
for i in range(4):
mapButtons.append(pygame.Rect(46 + i * 102, 44, 100, 20))
maps = [mapJungle, mapIceberg, mapDesert, mapOcean, mapParadise, mapBloodbath, mapMinecraft, mapMoon]
player1Buttons = []
player2Buttons = []
for i in range(20):
player1Buttons.append(pygame.Rect(38 + i * 22, 66, 20, 20))
for i in range(20):
player1Buttons.append(pygame.Rect(38 + i * 22, 88, 20, 20))
for i in range(20):
player1Buttons.append(pygame.Rect(38 + i * 22, 110, 20, 20))
for i in range(20):
player2Buttons.append(pygame.Rect(38 + i * 22, 132, 20, 20))
for i in range(20):
player2Buttons.append(pygame.Rect(38 + i * 22, 154, 20, 20))
for i in range(20):
player2Buttons.append(pygame.Rect(38 + i * 22, 176, 20, 20))
characters = [characterDefault, characterSoldier, characterFernando, characterDuck, characterAmongus, \
characterKnight, characterWizard, characterMario, characterFrog, characterMajora, \
characterElgato, characterAstronaut, characterBatman, characterIronman, characterMessi, \
characterSpiderman, characterSpongebob, characterZombie, characterYoru, \
characterKayn, characterSkeleton, characterZac, characterCartman, characterMonkey, \
characterRiche, characterToyalien, characterFarmer, characterKarate, characterMarsupilami, \
characterLuffy, characterSpeed, characterAlien, characterCreeper, characterSteve, characterDeadpool, \
characterDucky, characterHalo, characterNinja, characterRonaldo, characterYoda, characterLgbt, \
characterPingu, characterScuttle, characterLich, characterFinn, characterJake, characterDemon, \
characterFifi, characterStickman, characterBen, characterBird, characterPig, characterPumpkin, \
characterTriangle, characterOrange, characterBanana, characterSuperman, characterPutin, characterTrump, \
characterGlitch]
menuGenerated = True
click = False #Variable click
mx, my = pygame.mouse.get_pos() #Variables position souris
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_KP_ENTER:
inMenu = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
click = True
#Logique des boutons
if buttonQuit.collidepoint((mx/4, my/4)) and click:
pygame.quit()
sys.exit()
if buttonStart.collidepoint((mx/4, my/4)) and click:
inMenu = False
for i in range(8):
if mapButtons[i].collidepoint((mx/4,my/4)) and click:
currentMap = maps[i]
selectors[0] = ((selectorLongImg, (mapButtons[i].x, mapButtons[i].y)))
for i in range(60):
if player1Buttons[i].collidepoint((mx/4,my/4)) and click:
player1Img = characters[i]
selectors[1] = (selectorShortImg, (player1Buttons[i].x, player1Buttons[i].y))
for i in range(60):
if player2Buttons[i].collidepoint((mx/4,my/4)) and click:
player2Img = characters[i]
selectors[2] = (selectorShortImg, (player2Buttons[i].x, player2Buttons[i].y))
#Definition des variables des images des blocks correspondant a la map choisie
if currentMap == maps[0]:
currentTile3 = pygame.image.load('maps/jungle/jungleWood.png')
currentTile2 = pygame.image.load('maps/jungle/jungleGrass.png')
currentTile1 = pygame.image.load('maps/jungle/jungleGround.png')
currentBackground = pygame.image.load('maps/jungle/jungleBackground.png')
player1Spawn = (448,192)
player2Spawn = (16,192)
elif currentMap == maps[1]:
currentTile3 = pygame.image.load('maps/iceberg/icebergBlock.png')
currentTile2 = pygame.image.load('maps/iceberg/icebergGrass.png')
currentTile1 = pygame.image.load('maps/iceberg/icebergGround.png')
currentBackground = pygame.image.load('maps/iceberg/icebergBackground.png')
player1Spawn = (448, 224)
player2Spawn = (16, 224)
elif currentMap == maps[2]:
currentTile3 = pygame.image.load('maps/desert/desertCactus.png')
currentTile2 = pygame.image.load('maps/desert/desertSand.png')
currentTile1 = pygame.image.load('maps/desert/desertGround.png')
currentBackground = pygame.image.load('maps/desert/desertBackground.png')
player1Spawn = (464, 80)
player2Spawn = (0, 80)
elif currentMap == maps[3]:
currentTileT = pygame.image.load('maps/ocean/oceanGroundT.png')
currentTile4 = pygame.image.load('maps/ocean/oceanCoral.png')
currentTile3 = pygame.image.load('maps/ocean/oceanSand.png')
currentTile2 = pygame.image.load('maps/ocean/oceanGroundTop.png')
currentTile1 = pygame.image.load('maps/ocean/oceanGround.png')
currentBackground = pygame.image.load('maps/ocean/oceanBackground.png')
player1Spawn = (464, 80)
player2Spawn = (0, 80)
elif currentMap == maps[4]:
currentTile5 = pygame.image.load('maps/paradise/paradiseColumnTop.png')
currentTile4 = pygame.image.load('maps/paradise/paradiseColumn.png')
currentTile3 = pygame.image.load('maps/paradise/paradiseColumnBottom.png')
currentTile2 = pygame.image.load('maps/paradise/paradiseCloudTop.png')
currentTile1 = pygame.image.load('maps/paradise/paradiseCloud.png')
currentBackground = pygame.image.load('maps/paradise/paradiseBackground.png')
player1Spawn = (464, 144)
player2Spawn = (0, 144)
elif currentMap == maps[5]:
currentTile4 = pygame.image.load('maps/bloodbath/bloodbathBloodTop.png')
currentTile3 = pygame.image.load('maps/bloodbath/bloodbathBlood.png')
currentTile2 = pygame.image.load('maps/bloodbath/bloodbathGroundTop.png')
currentTile1 = pygame.image.load('maps/bloodbath/bloodbathGround.png')
currentBackground = pygame.image.load('maps/bloodbath/bloodbathBackground.png')
player1Spawn = (464, 64)
player2Spawn = (0, 64)
elif currentMap == maps[6]:
currentTileT = pygame.image.load('maps/minecraft/minecraftPlanksT.png')
currentTile6 = pygame.image.load('maps/minecraft/minecraftCobble.png')
currentTile5 = pygame.image.load('maps/minecraft/minecraftPlanks.png')
currentTile4 = pygame.image.load('maps/minecraft/minecraftLeaves.png')
currentTile3 = pygame.image.load('maps/minecraft/minecraftWood.png')
currentTile2 = pygame.image.load('maps/minecraft/minecraftGroundTop.png')
currentTile1 = pygame.image.load('maps/minecraft/minecraftGround.png')
currentBackground = pygame.image.load('maps/minecraft/minecraftBackground.png')
player1Spawn = (464, 128)
player2Spawn = (0, 128)
elif currentMap == maps[7]:
currentTileT = pygame.image.load('maps/moon/moonCrater.png')
currentTile2 = pygame.image.load('maps/moon/moonGroundTop.png')
currentTile1 = pygame.image.load('maps/moon/moonGround.png')
currentBackground = pygame.image.load('maps/moon/moonBackground.png')
player1Spawn = (464, 224)
player2Spawn = (0, 224)
gameGenerated = False
#Affichage
unscaledWindow.blit(menuImg, (0, 0))
unscaledWindow.blit(selectors[0][0], selectors[0][1])
unscaledWindow.blit(selectors[1][0], selectors[1][1])
unscaledWindow.blit(selectors[2][0], selectors[2][1])
window.blit(pygame.transform.scale(unscaledWindow, (windowW, windowH)), (0, 0))
pygame.display.update()
clock.tick(60)
# Boucle du Jeu
def game():
global player1Img, player1Right, player1Left, player1Jumping, player1Shooting, player1Flip, player1Throwing, player1, \
player2Img, player2Right, player2Left, player2Jumping, player2Shooting, player2Flip, player2Throwing, player2, \
generatedTiles, gameGenerated, menuGenerated, powerup
inGame = True
while inGame:
unscaledWindow.blit(currentBackground, (0, 0))
#Generation de la mape
if not gameGenerated: #Si mape non generee
player1Right, player1Left, player1Jumping, player1Shooting, player1Throwing = False, False, False, False, False #Reset des variables du saisie
player2Right, player2Left, player2Jumping, player2Shooting, player2Throwing = False, False, False, False, False
#Changement de la gravite selon la map
if currentMap == mapMoon or currentMap == mapOcean:
gravity = 0.075
else:
gravity = 0.15
#Reset des objets
bulletGroup.empty()
bombGroup.empty()
explosionGroup.empty()
#Reset des blocs
tileRects = []
generatedTiles = []
#Generation de la map, ces deux boucles scannent la liste de la map et genere les blocs selon les valeurs dans la liste
rowIndex = 0
for row in currentMap:
tileIndex = 0
for tile in row:
if tile == '1':
generatedTiles.append([currentTile1, (tileIndex * 16, rowIndex * 16)])
elif tile == '2':
generatedTiles.append([currentTile2, (tileIndex * 16, rowIndex * 16)])
elif tile == '3':
generatedTiles.append([currentTile3, (tileIndex * 16, rowIndex * 16)])
elif tile == '4':
generatedTiles.append([currentTile4, (tileIndex * 16, rowIndex * 16)])
elif tile == '5':
generatedTiles.append([currentTile5, (tileIndex * 16, rowIndex * 16)])
elif tile == '6':
generatedTiles.append([currentTile6, (tileIndex * 16, rowIndex * 16)])
elif tile == 'T':
generatedTiles.append([currentTileT, (tileIndex * 16, rowIndex * 16)])
if tile != '0' and tile != 'T':
tileRects.append(pygame.Rect(tileIndex * tileSize, rowIndex * tileSize, tileSize, tileSize))
tileIndex += 1
rowIndex += 1
#Initialisation de joueurs
player1 = Player(player1Spawn, player1Img, tileRects, gravity)
player2 = Player(player2Spawn, player2Img, tileRects, gravity)
powerup = Powerup()
powerupCooldown = 0
gameGenerated = True
#Generation du powerup
if powerupCooldown == 1000:
powerup = Powerup()
powerupCooldown = 0
powerupCooldown +=1
###Affichage###
for i in range(len(generatedTiles)): #Affiche les blocs generes
unscaledWindow.blit(generatedTiles[i][0], generatedTiles[i][1])
#Affiche les barres d'hp des joueurs
if player1.health <= 0:
player1.rect.x = -64
player1.rect.y = 256
unscaledWindow.blit(player2win, (140, 0))
unscaledWindow.blit(player2.image, (184,12))
unscaledWindow.blit(player2.image, (280, 12))
elif player2.health <= 0:
player2.rect.x = -64
player2.rect.y = 256
unscaledWindow.blit(player1win, (140, 0))
unscaledWindow.blit(player1.image, (184, 12))
unscaledWindow.blit(player1.image, (280, 12))
bulletGroup.draw(unscaledWindow)
bombGroup.draw(unscaledWindow)
powerup.draw()
explosionGroup.draw(unscaledWindow)
player1.draw()
player2.draw()
#Affiche la fenetre temporaire sur la vraie
window.blit(pygame.transform.scale(unscaledWindow, (windowW, windowH)), (0, 0))
#Mise a jour des objets
player1.update(player1Right, player1Left, player1Jumping, player1Shooting, player1Throwing)
player2.update(player2Right, player2Left, player2Jumping, player2Shooting, player2Throwing)
bulletGroup.update(tileRects)
bombGroup.update(tileRects)
explosionGroup.update()
# Boucle des evenements
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
player1Jumping = True
if event.key == pygame.K_RIGHT:
player1Right = True
if event.key == pygame.K_LEFT:
player1Left = True
if event.key == pygame.K_RCTRL:
player1Shooting = True
if event.key == pygame.K_DOWN:
player1Throwing = True
if event.key == pygame.K_e:
player2Jumping = True
if event.key == pygame.K_f:
player2Right = True
if event.key == pygame.K_s:
player2Left = True
if event.key == pygame.K_SPACE:
player2Shooting = True
if event.key == pygame.K_d:
player2Throwing = True
if event.key == pygame.K_ESCAPE:
inGame = False
if event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
player1Right = False
if event.key == pygame.K_LEFT:
player1Left = False
if event.key == pygame.K_UP:
player1Jumping = False
if event.key == pygame.K_RCTRL:
player1Shooting = False
if event.key == pygame.K_DOWN:
player1Throwing = False
if event.key == pygame.K_e:
player2Jumping = False
if event.key == pygame.K_f:
player2Right = False
if event.key == pygame.K_s:
player2Left = False
if event.key == pygame.K_SPACE:
player2Shooting = False
if event.key == pygame.K_d:
player2Throwing = False
# Mise a jour de l'ecran
pygame.display.update()
#Regulation du temps d'iteration
clock.tick(60)
def title():
global launched
launched = False
while not launched:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
launched = True
unscaledWindow.blit(titleImg, (0,0))
window.blit(pygame.transform.scale(unscaledWindow, (windowW, windowH)), (0, 0))
pygame.display.update()
while True:
title()
menu()
game()