meteorites.py

Created by schraf

Created on April 27, 2020

1.69 KB

Jeu “météorites” inspiré du jeu Game & Watch “Helmet”.

But du jeu : Traverser le terrain en évitant la pluie de météorites ! Mais attention, la porte du côté droit n’est pas toujours ouverte, il faut attendre que le voyant soit vert ;-)

Le programme a la même base que jeu “fire” pour la NUMWORKS, vous ne devriez donc pas avoir de difficultés à le comprendre.


from kandinsky import *
from time import *
from random import *
from ion import *


RO, VE, BL, NR, BE = (255,0,0), (70,160,70), (255,255,255), (70,70,70), (30,50,120)
MAXVIES, DELAI = 10, 0.2
fr, aff = fill_rect, draw_string
GA, HT = 40, 20

def dep_joueur(j, d):
  aff(" ", GA + 40*j, 174,BL,BE)
  j += d
  aff("P", GA + 40*j, 174,BL,BE)
  sleep(0.1)
  return j

def aff_lettre(txt, l, co = BE):
  p, c = l[0], l[1]
  aff(txt, GA+40*c, HT+30*p, BL, co)
  
def dep_lettre(l):
  aff_lettre(" ", l)
  l[0] += 1
  aff_lettre("*", l)
  return l

def decors():
  fr(0,0,320,220,BE)
  for i in range(100):
    set_pixel(randrange(0,320), randrange(0,320), BL)
  fr(0,200,320,30,VE)
  fr(0,150,30,50,NR)  
  fr(290,150,30,50,NR)  
  
def go():
  decors()
  score, vies = 0, MAXVIES
  t = monotonic()
  j = dep_joueur(0, 0)
  pp = []
  ouvert = False
  while vies >= 0:
    if monotonic() - t > DELAI:
      futur = []
      for l in pp:
        l = dep_lettre(l)
        if l[0] == 6: 
          if j == l[1]:
           txt = "="  
           vies -= 1
           j = dep_joueur(0, 0)
           aff("*"*(MAXVIES - vies), 0, 0, NR, RO)
          else: txt = " "
          aff_lettre(txt, l, VE)
        else: futur.append(l)
      t = monotonic()
      pp = futur
      pp.append([-1, randint(1,5)])
      if random() < 0.1: ouvert = not(ouvert)
      coul = VE if ouvert else RO
      fr(300,140,10,10,coul)
    if keydown(KEY_LEFT) and j > 0:
      j = dep_joueur(j, -1)
    if keydown(KEY_RIGHT) and j < 5:
      j = dep_joueur(j, 1)
    if keydown(KEY_RIGHT) and j == 5 and ouvert:
      score += 1
      aff(str(score), 290, 202, BL, VE)
      j = dep_joueur(j, -5)
  aff("GAME OVER !", 100, 203, RO, NR)

go()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.