|
|
|
app.py
import pyxel
import random
class Jeu:
# initialisation
def __init__(self):
pyxel.init(128, 128, title="Nuit du c0de")
self.vaisseau_x = 60
self.vaisseau_y = 60
self.tirs_list = []
self.enemies_list = []
self.mini_boss_list = []
self.boss_list = []
self.explosion_list = []
self.vies = 4
self.points = [0, 0]
pyxel.load("images.pyxres")
self.scroll_y = 960
pyxel.run(self.update, self.draw)
# vaisseau
def vaisseau_deplacement(self):
if pyxel.btn(pyxel.KEY_RIGHT) and self.vaisseau_x < 120:
self.vaisseau_x += 1.5
if pyxel.btn(pyxel.KEY_LEFT) and self.vaisseau_x > 0:
self.vaisseau_x += -1.5
if pyxel.btn(pyxel.KEY_DOWN) and self.vaisseau_y < 120:
self.vaisseau_y += 1.5
if pyxel.btn(pyxel.KEY_UP) and self.vaisseau_y > 0:
self.vaisseau_y += -1.5
def vaisseau_supression_enemie(self):
for enemie in self.enemies_list:
if (
abs(self.vaisseau_x - enemie[0]) <= 8
and abs(self.vaisseau_y - enemie[1]) <= 8
):
self.enemies_list.remove(enemie)
self.vies -= 1
self.creation_explosion(self.vaisseau_x, self.vaisseau_y)
def vaisseau_supression_mini_boss(self):
for mini_boss in self.mini_boss_list:
if (
abs(self.vaisseau_x - mini_boss[0]) <= 8
and abs(self.vaisseau_y - mini_boss[1]) <= 8
):
self.mini_boss_list.remove(mini_boss)
self.vies -= 1
self.creation_explosion(self.vaisseau_x, self.vaisseau_y)
def vaisseau_supression_boss(self):
for boss in self.boss_list:
if (
abs(self.vaisseau_x - boss[0]) <= 8
and abs(self.vaisseau_y - boss[1]) <= 8
):
self.boss_list.remove(boss)
self.vies -= 2
self.creation_explosion(self.vaisseau_x, self.vaisseau_y)
# tirs
def creation_tirs(self):
if pyxel.btnr(pyxel.KEY_SPACE):
self.tirs_list.append([self.vaisseau_x, self.vaisseau_y - 4])
def deplacement_tires(self):
for tir in self.tirs_list:
tir[1] -= 1
if tir[1] < -8:
self.tirs_list.remove(tir)
# enemie
def creation_enemie(self):
if pyxel.frame_count % 30 == 0:
self.enemies_list.append([random.randint(0, 120), 0])
def deplacement_enemie(self):
for enemie in self.enemies_list:
enemie[1] += 1
if enemie[1] > 128:
self.enemies_list.remove(enemie)
self.points[0] -= random.randint(1, 5)
def enemie_supression(self):
for enemie in self.enemies_list:
for tir in self.tirs_list:
if (
enemie[0] <= tir[0] + 8
and enemie[0] + 8 >= tir[0]
and enemie[1] + 8 >= tir[1]
):
self.enemies_list.remove(enemie)
self.tirs_list.remove(tir)
self.creation_explosion(enemie[0], enemie[1])
self.points[0] += random.randint(1, 5)
# explosion
def creation_explosion(self, x, y):
self.explosion_list.append([x, y, 0])
def explosion_animation(self):
for explosion in self.explosion_list:
explosion[2] += 1
if explosion[2] == 12:
self.explosion_list.remove(explosion)
# mini boss
def creation_mini_boss(self):
if pyxel.frame_count % 300 == 0: # chaque 5 secondes
self.mini_boss_list.append([random.randint(0, 120), 0, 0])
def touche_mini_boss(self):
for mini_boss in self.mini_boss_list:
for tir in self.tirs_list:
if (
mini_boss[0] <= tir[0] + 8
and mini_boss[0] + 8 >= tir[0]
and mini_boss[1] + 8 >= tir[1]
):
self.creation_explosion(mini_boss[0] + 8, mini_boss[1] + 8)
mini_boss[2] += 1
self.tirs_list.remove(tir)
def supression_mini_boss(self):
for mini_boss in self.mini_boss_list:
if mini_boss[2] >= 5:
self.mini_boss_list.remove(mini_boss)
self.points[0] += random.randint(10, 20)
def deplacement_mini_boss(self):
for mini_boss in self.mini_boss_list:
mini_boss[1] += 0.5
if mini_boss[1] >= 128:
self.mini_boss_list.remove(mini_boss)
self.points[0] -= random.randint(10, 20)
# boss
def creation_boss(self):
if pyxel.frame_count % 900 == 0:
self.boss_list.append([random.randint(0, 120), 0, 0])
def touche_boss(self):
for boss in self.boss_list:
for tir in self.tirs_list:
if (
boss[0] <= tir[0] + 8
and boss[0] + 8 >= tir[0]
and boss[1] + 8 >= tir[1]
):
self.creation_explosion(boss[0] + 8, boss[1] + 8)
boss[2] += 1
self.tirs_list.remove(tir)
def supression_boss(self):
for boss in self.boss_list:
if boss[2] >= 10:
self.boss_list.remove(boss)
self.points[0] += 50
def deplacement_boss(self):
for boss in self.boss_list:
boss[1] += 0.3
if boss[1] >= 128:
self.boss_list.remove(boss)
self.vies -= 2
# ajustement ecriture points
def ecriture_points(self):
if self.points[0] >= 1000:
self.points[1] = 7
elif self.points[0] >= 100:
self.points[1] = 3
# le fond
def scroll(self):
if self.scroll_y > 384:
self.scroll_y -= 1
else:
self.scroll_y = 960
# =====================================================
# == UPDATE
# =====================================================
def update(self):
# vaisseau
self.vaisseau_deplacement()
self.vaisseau_supression_mini_boss()
self.vaisseau_supression_enemie()
self.vaisseau_supression_boss()
# enemie
self.creation_enemie()
self.deplacement_enemie()
self.enemie_supression()
# tir
self.creation_tirs()
self.deplacement_tires()
# mini_boss
self.creation_mini_boss()
self.touche_mini_boss()
self.supression_mini_boss()
self.deplacement_mini_boss()
# boss
self.creation_boss()
self.touche_boss()
self.supression_boss()
self.deplacement_boss()
# explosion
self.explosion_animation()
# fond
self.scroll()
# ecriture points
self.ecriture_points()
# =====================================================
# == DRAW
# =====================================================
def draw(self):
pyxel.cls(0)
if self.vies > 0:
pyxel.camera()
pyxel.bltm(0, 0, 0, 192, (self.scroll_y // 4) % 128, 128, 128)
pyxel.text(5, 5, "VIES:" + str(self.vies), 7)
pyxel.text(90 - self.points[1], 5, "POINTS:" + str(self.points[0]), 7)
pyxel.blt(self.vaisseau_x, self.vaisseau_y, 0, 0, 0, 8, 8)
for tir in self.tirs_list:
pyxel.blt(tir[0], tir[1], 0, 8, 0, 8, 8)
for enemie in self.enemies_list:
pyxel.blt(enemie[0], enemie[1], 0, 0, 8, 8, 8)
for mini_boss in self.mini_boss_list:
pyxel.blt(mini_boss[0], mini_boss[1], 0, 8, 24, 8, 8)
for boss in self.boss_list:
pyxel.blt(boss[0], boss[1], 0, 0, 32, 8, 8)
for explosion in self.explosion_list:
pyxel.circb(
explosion[0],
explosion[1],
2 * (explosion[2] // 4),
8 + explosion[2] % 3,
)
else:
pyxel.text(50, 64, "GAME OVER", 7)
Jeu() 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/fb58hgen
File to execute with the public link
PYXEL DOCUMENTATION
|