#🔒 Python/Pyxel
15 messages · Page 1 of 1 (latest)
@peak barn
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
hello could someone finish my code so that there is:
-> personal sprites
-> beautiful map
-> collect objects of at least 2 types
-> set a counter of objects collected
-> put an enemy that changes place from time to time
-> if hit by an enemy -> loss of HP
-> add a PV recharge in the form of an object
-> if PV is 0 then end of game
-> display an image when game ends
->move the enemy automatically every 5 seconds
-> move the enemy towards the character
-> set a timer
add multiple enemies
I have already started but when I execute the code I cannot move my sprites using the directional arrows
I also made my sprites (drawings) this is what I want to display but some sprites are not displayed
import pyxel
from random import randint
largeur_fenetre = 128
hauteur_fenetre = 128
pyxel.init(largeur_fenetre, hauteur_fenetre, title="Monjeu")
pyxel.load("res.pyxres")
pv = 20
time = 60
fin = 0
sprite_x = 50
sprite_y = 50
taille_sprite = 8
objets = 0
x_v = 5 # monstre vert
y_v2 = 25
x_b = 10 # monstre bleu
y_b2 = 65
x_p = 50 # potion de vie
y_p2 = 40
x_d = 15 # diamant
y_d2 = 10
x_pi = 75 # pièce d'or
y_pi2 = 85
x_t = 45 # tête de mort
y_t2 = 25
def deplacement_sprite(x, y):
taille_sprite = 8
v = 2
if pyxel.btn(pyxel.KEY_RIGHT):
if x < largeur_fenetre - taille_sprite:
if pyxel.pget(x + v + taille_sprite, y + taille_sprite) not in (4, 6) and pyxel.pget(x + v + taille_sprite, y) not in (4, 6):
x += v
if pyxel.btn(pyxel.KEY_UP):
if y > 0:
if pyxel.pget(x + taille_sprite, y - v) not in (4, 6) and pyxel.pget(x, y - v) not in (4, 6):
y -= v
if pyxel.btn(pyxel.KEY_DOWN):
if y < hauteur_fenetre - taille_sprite:
if pyxel.pget(x + taille_sprite, y + v + taille_sprite - 2) not in (4, 6) and pyxel.pget(x, y + v + taille_sprite - 4) not in (4, 6):
y += v
if pyxel.btn(pyxel.KEY_LEFT):
if x > 0:
if pyxel.pget(x - v, y + taille_sprite) not in (4, 6) and pyxel.pget(x - v, y) not in (4, 6):
x -= v
return x, y
def collision(x, y, x_e, y_e):
x = x + taille_sprite / 2
y = y + taille_sprite / 2
if ((x - x_e) ** 2 + (y - y_e) ** 2) <= (taille_sprite ** 2 / 2):
return True
else:
return False
def draw(): #modif les coordonées
pyxel.cls(12)
pyxel.bltm(0, 0, 0, 0, 0, largeur_fenetre, hauteur_fenetre) # Afficher la carte de tuiles
pyxel.blt(sprite_x, sprite_y, 0, 0, 0, taille_sprite, taille_sprite, 0) # Prsng
pyxel.blt(x_v, y_v2, 0, 8, 0, taille_sprite, taille_sprite, 0) # Monstre vert
pyxel.blt(x_b, y_b2, 0, 16, 0, taille_sprite, taille_sprite, 0) # Monstre bleu
pyxel.blt(x_p, y_p2, 0, 24, 0, taille_sprite, taille_sprite, 0) # Potion de vie
pyxel.blt(x_d, y_d2, 0, 32, 0, taille_sprite, taille_sprite, 0) # Diamant
pyxel.blt(x_pi, y_pi2, 0, 40, 0, taille_sprite, taille_sprite, 0) # Pièce d'or
pyxel.blt(x_t, y_t2, 0, 48, 0, taille_sprite, taille_sprite, 0) # Tête de mort
def update():
global sprite_x, sprite_y, pv, fin, time, x_v, y_v2, x_p, y_p2, x_pi, y_pi2, x_d, y_d2, x_b, y_b2
sprite_x, sprite_y = deplacement_sprite(sprite_x, sprite_y)
# Gestion des collisions
toucher_v = collision(sprite_x, sprite_y, x_v, y_v2)
toucher_p = collision(sprite_x, sprite_y, x_p, y_p2)
toucher_pi = collision(sprite_x, sprite_y, x_pi, y_pi2)
toucher_d = collision(sprite_x, sprite_y, x_d, y_d2)
toucher_b = collision(sprite_x, sprite_y, x_b, y_b2)
if toucher_v:
pv -= 1
if toucher_p:
pv += 1
if toucher_pi or toucher_d:
objets += 1
if toucher_b:
pv -= 1
if pv <= 0:
fin_jeu()
if time <= 0:
fin_jeu()
if pyxel.frame_count % 60 == 0:
time -= 1
if pyxel.frame_count % 300 == 0:
deplacement_ennemi()
pyxel.text(5, 2, "temps :" + str(time), 0)
pyxel.text(40, 2, "pv :" + str(pv), 0)
def deplacement_ennemi():
global x_v, y_v2, x_b, y_b2, x_t, y_t2
x_v += randint(-1, 1)
y_v2 += randint(-1, 1)
x_b += randint(-1, 1)
y_b2 += randint(-1, 1)
x_t += randint(-1, 1)
y_t2 += randint(-1, 1)
def fin_jeu():
global fin
fin = 1
pyxel.run(update, draw)
my sprits:
Nobody here is going to write your code for you.
We will help if you have specific questions, sure.
please follow this when asking questions
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.