|
app2.py
import pyxel
import random
pyxel.init(255, 112, title="bataille", fps=90)
pyxel.load("2.pyxres")
pyxel.load("realreal.pyxres")
def bouge_perso():
global perso_x, perso_y
if pyxel.btn(pyxel.KEY_RIGHT):
if (perso_x < 255) :
perso_x = perso_x + 1
if (perso_x == 241) :
perso_x = perso_x - 1
if pyxel.btn(pyxel.KEY_LEFT):
if (perso_x > 0) :
perso_x = perso_x - 1
if pyxel.btn(pyxel.KEY_DOWN):
if (perso_y < 112) :
perso_y = perso_y + 1
if (perso_y == 97):
perso_y = perso_y - 1
if pyxel.btn(pyxel.KEY_UP):
if (perso_y > 54) :
perso_y = perso_y - 1
if pyxel.btnr(pyxel.KEY_SPACE):
liste_tirs.append([perso_x + 16, perso_y + 8])
print(liste_tirs)
def affiche_perso():
if pyxel.btn(pyxel.KEY_RIGHT):
pyxel.blt(perso_x,perso_y,0,0,16,16,16,2)
elif pyxel.btn(pyxel.KEY_LEFT):
pyxel.blt(perso_x,perso_y,0,0,16,-16,16,2)
else:
pyxel.blt(perso_x,perso_y,0,0,16,16,16,2)
def affiche_tir():
for tir in liste_tirs:
pyxel.rect(tir[0], tir[1], 4, 1, 10)
def bouge_tir(tir):
for tir in liste_tirs:
if tir[0]==255:
liste_tirs.remove(tir)
else:
tir[0] = tir[0]+1
tir[1] = tir[1]
def update_ennemis():
global liste_ennemis, vie
if pyxel.frame_count%360==0:
liste_ennemis.append([random.randint(176,239),random.randint(64,96), 64])
for ennemi in liste_ennemis:
if pyxel.frame_count%60==0:
ennemi[0]+=random.randint(-4,-2)
if ennemi[2]==64:
ennemi[2]=80
elif ennemi[2]==80:
ennemi[2]=64
if ennemi[0]<=0:
liste_ennemis.remove(ennemi)
if ennemi[0]<=40:
vie=0
if ennemi[0]perso_x-16 and ennemi[1]perso_y-16:
liste_ennemis.remove(ennemi)
vie-=1
def draw_ennemis():
for ennemi in liste_ennemis:
pyxel.blt(ennemi[0],ennemi[1],0,ennemi[2],16,-16,16,2)
def barredevie():
if vie == 3:
pyxel.blt(7,7,0,112,48,15,15,2)
pyxel.blt(19,7,0,112,48,15,15,2)
pyxel.blt(31,7,0,112,48,15,15,2)
elif vie == 2:
pyxel.blt(7,7,0,112,48,15,15,2)
pyxel.blt(19,7,0,112,48,15,15,2)
pyxel.blt(31,7,0,96,48,15,15,2)
else:
pyxel.blt(7,7,0,112,48,15,15,2)
pyxel.blt(19,7,0,96,48,15,15,2)
pyxel.blt(31,7,0,96,48,15,15,2)
def draw():
pyxel.cls(0)
pyxel.blt(0,0,1,0,0,255,112)
affiche_perso()
draw_ennemis()
barredevie()
if vie<=0:
pyxel.cls(0)
pyxel.text(115,56, "GAME OVER", 8)
affiche_tir()
def update():
affiche_perso()
bouge_perso()
update_ennemis()
perso_x = 16
perso_y = 80
liste_ennemis=[]
vie=3
pyxel.run(update, draw)
PACKAGES
If your project uses packages, list them bellow (names separated by commas). Packages that can be added are only packages built in Pyodide. Example: numpy,pandas Create an account to manage your projects and publish them on the playground.
Layout
Packages
If your project uses packages, list them bellow (names separated by commas). Packages that can be added are only packages built in Pyodide.
Example: numpy,pandas Project Name
Documentation
LICENSE
Choose a license:
Public link
Share this link so people can discover your project / game.
Public link: www.pyxelstudio.net/hd64srzt
File to execute with the public link
PYXEL DOCUMENTATION
|