planeur_bombe.py

Created by florian-allard

Created on March 14, 2021

1.67 KB

Un petit jeu inspiré de BombRun sur Casio. Le planeur doit raser la ville avant de pouvoir atterrir. Un appui sur EXE ou OK permet de lâcher une bombe pour raser un immeuble. Attention au timing ! Si le planeur heurte un immeuble, c’est perdu !
Version couleur du 14/03/2021. La version initiale est disponible ici.


from random import randint
from kandinsky import get_pixel,draw_string,fill_rect
from ion import *
from time import sleep

while 1:
  nb_immeubles = 32
  draw_string("EXE pour lancer une partie",30,100,(160,0,255))
  while keydown(KEY_EXE) or keydown(KEY_OK):True
  while not (keydown(KEY_EXE) or keydown(KEY_OK)):True
  fill_rect(0,0,319,221,'white')
  for a in range(nb_immeubles):
    c = randint(1,12)
    for b in range(c+1):
      draw_string("œ",10*a,207-14*c+14*b,((200-30*c)%255,(40+35*c)%255,(210-40*c)%255))#((255-30*c)%255,(30+30*c)%255,(70+70*c)%255)#((255-50*c)%255,(120+40*c)%256,30+20*c)

  x = 0
  y = 10
  drop = False

  while y < 10+14*14 and nb_immeubles > 0:
    x += 10
    if x > 310:
      x = 0
      y += 14
    if (x < 310 and get_pixel(x+15,y+7) != (248,252,248)) or (x == 310 and get_pixel(0+5,y+14+7) != (248,252,248)):
      draw_string("C'est perdu, ça a touché !",30,80,"red")
      break
    draw_string(">",x,y-1,'green')
    k = 0
    for k in range(15):
      if (keydown(KEY_EXE) or keydown(KEY_OK)) and not drop:
        bx = x
        by = y
        drop = True
      sleep(0.01)
    if drop:
      draw_string(" ",bx,by)
      by += 14
      if by < 210 and get_pixel(bx+5,by+7) != (248,252,248): #s'il y a un immeuble
        for etage in range(by,210,14): #alors on l'efface
          draw_string(" ",bx,etage)
        nb_immeubles -= 1
        drop = False
      elif by < 210: #sinon la bombe descend
        draw_string("°",bx-1,by,'red')
      else:
        drop = False
    #draw_string(str(nb_immeubles),150,2)
    if y > 10+13*14 or nb_immeubles == 0:
      draw_string("C'est gagné, bravo !!",55,80)
    draw_string(" ",x,y-1)