pvz_old.py

Created by antarctus

Created on November 05, 2021

7.39 KB

Un jeu” Plante vs Zombi” ou des zombis multicolores s’attaquent à ton champ. Utilises les flèches pour sélectionner un endroit ou planter quelque chose puis choisi entre deux plantes avec les boutons OnOff et Home !


Vous pouvez me contacter sur Discord à l’aide de ce lien https://discord.gg/wNtEFdQgWD.
N’hésitez pas à venir, vous pourriez découvrir des choses intéressantes…


Vous pouvez utilisez CE shop alternatif pour trouver bien plus de programmes et de jeux !!!


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


class Zombie():
  def __init__(self,speed=5,line=0,level=1):
    self.speed=speed  #Pixel per seconds
    self.line=line
    self.path=270+randint(-20,20)
    self.last_path_time=monotonic()
    self.eyes=[[randint(0,5),randint(0,5)],[randint(0,5),randint(0,5)]]
    self.level=level*(level<7)+(8*(not(level<7)))


  def move(self):
    global end
    m=monotonic()
    walk=self.speed*(m-self.last_path_time)
    walk/=1+(-1<int(self.path/50)<5 and map[self.line][int(self.path/50)]==3)

    self.path-=walk
    self.last_path_time=m

    if self.path<0:
      end=self.line

    for i in range(len(tirs)-1,-1,-1):
      if (self.path-20)<tirs[i][2]<(self.path+30):
        if tirs[i][1]==self.line:

          fill_rect(tirs[i][2]+[0,0,10,10][tirs[i][0]],tirs[i][1]*50+[10,10,23,10][tirs[i][0]],[23,23,7,7][tirs[i][0]],[23,23,7,7][tirs[i][0]],backGround)

          if tirs[i][0]==0:
            tirs.append([1,tirs[i][1],tirs[i][2]])

          del tirs[i]
          self.level-=1

  def draw(self):
    coordx=int(self.path)
    draw_instruction=[
(0,15,50,10,(180,80 ,0)),
(12,5,10,40,(180,80 ,0)),
(28,5,10,40,(180,80 ,0)),
(10,0,30,30,zombColor[self.level]),
(12,5,10,10,(240,)*3),
(28,5,10,10,(240,)*3),
(12+self.eyes[0][0],5+self.eyes[0][1],5,5,(10,)*3),
(27+self.eyes[1][0],5+self.eyes[1][1],5,5,(10,)*3)
]
    for i in draw_instruction[:4]:
      fill_rect(coordx+i[0],self.line*50+i[1],i[2],i[3],backGround)

    self.move()
    if self.level<=0:
      return

    coordx=int(self.path)

    for i in draw_instruction:
      fill_rect(coordx+i[0],self.line*50+i[1],i[2],i[3],i[4])

#    for i in [0,1]:
#      fill_rect(coordx+[12,28][i],self.line*50+5,10,10,(240,)*3)
#      fill_rect(coordx+[12,27][i]+self.eyes[i][0],self.line*50+5+self.eyes[i][1],5,5,(10,)*3)

#    fill_rect(coordx+12,self.line*50+5,10,10,(240,)*3)
#    fill_rect(coordx+28,self.line*50+5,10,10,(240,)*3)

#    fill_rect(coordx+12+self.eyes[0][0],self.line*50+5+self.eyes[0][1],5,5,(10,)*3)
#    fill_rect(coordx+27+self.eyes[1][0],self.line*50+5+self.eyes[1][1],5,5,(10,)*3)

map=[
[0,0,0,0,0],
[0,0,0,0,0],
[1,0,0,0,0],
[0,0,0,0,0],
]
select=[0,0]

backGround=(0,)*3
zombie=[]
tirs=[]
vague=1.0

first=monotonic()+11
last_spawn=first

last_move=first

flower=3
last_flower_maj=first

last_fire_maj=first

last_tir_maj=first

end=None
#first-=620

zombColor=[(),(0,200,0),(0,255,255),(0,0,255),(255,0,255),(255,0,0),(255,255,0),(255,255,255),backGround]

def tirs_maj():
  global tirs,last_fire_maj,last_small_fire_maj

  m=monotonic()
  if m>=(last_fire_maj+7):
    for i in range(4):
      for j in range(5):
        if (map[i][j] in (4,5,6)):
          tirs.append([{4:1,5:3,6:0}[map[i][j]],i,35+j*50])
    last_fire_maj+=7

  if (m+1)>(last_fire_maj+4)>m:
    for i in range(4):
      for j in range(5):
        if map[i][j]==5:
          tirs.append([2,i,35+j*50])
    last_fire_maj-=1

def flower_maj():
  global flower,last_flower_maj
  m=monotonic()
  for i in map:
    for j in i:
      if j in (1,2):
        if (random()*[5,2][j-1])<(m-last_flower_maj):
          flower+=1
  last_flower_maj=m

def spawn():
  global zombie,last_spawn,vague
  m=monotonic()
  vague=(m-first)/10+1
  level=int(vague)

  if (m-last_spawn)>=10:
    for i in range(level%6+1+((level-48)>0)*(level-48)):
      zombie.append(
      Zombie(int(randint(level,10*level)**0.5),
      randint(0,3),level//6+1))
    last_spawn+=10

def move_all_tir():
  global last_tir_maj,tirs
  m=monotonic()
  for i in range(len(tirs)-1,-1,-1):
    tirs[i][2]+=int((m-last_tir_maj)*50)
    if tirs[i][2]>320:
      del tirs[i]
  last_tir_maj=m

def draw_flower(id,x,y,width=1,height=1):

  flower_draw_instruction=[
[(0,0,50,50,backGround)],
[(20,15,10,30,(0,160,0)),(15,10,20,20,(250,180,0)),(10,35,30,5,(0,200,0))],
[(20,15,10,30,(0,160,0)),(15,10,20,20,(250,180,0)),(10,35,30,5,(0,200,0)),(5,32,10,10,(255,220,0)),(35,32,10,10,(255,220,0))],
[(10,10,30,30,(0,160,0)),(5,15,20,5,(10,)*3),(25,22,20,5,(10,)*3),(5,30,20,5,(10,)*3)],
[(20,15,10,30,(0,160,0)),(5,5,40,30,(0,230,0)),(35,10,5,20,(0,160,0)),(10,10,15,15,(255,)*3),(14,11,10,10,(10,)*3)],
[(20,15,10,30,(0,160,0)),(5,5,40,30,(0,230,0)),(35,10,5,7,(0,160,0)),(35,23,5,7,(0,160,0)),(10,10,15,15,(255,)*3),(14,11,10,10,(10,)*3)],
[(20,15,10,30,(0,160,0)),(5,5,40,30,(220,0,0)),(35,10,5,20,(255,0,0)),(10,10,15,15,(255,)*3),(14,11,10,10,(10,)*3)],
]
  for i in flower_draw_instruction[id]:
    fill_rect(x+int(width*i[0]),y+int(height*i[1]),int(width*i[2]),int(height*i[3]),i[4])


def draw_all():
  for i in range(len(zombie)-1,-1,-1):
    zombie[i].draw()
    if zombie[i].level<=0:
      zombie[i].move()
      del zombie[i]

  for i in range(len(tirs)-1,-1,-1):  
    fill_rect(tirs[i][2]+[0,0,10,10][tirs[i][0]],tirs[i][1]*50+[10,10,23,10][tirs[i][0]],[20,20,7,7][tirs[i][0]],[20,20,7,7][tirs[i][0]],backGround)

  for y in range(4):
    for x in range(5):
      if map[y][x]==0:
        continue
      draw_flower(map[y][x],x*50,y*50)

  move_all_tir()

  for i in range(len(tirs)-1,-1,-1):  
    fill_rect(tirs[i][2]+[0,0,10,10][tirs[i][0]],tirs[i][1]*50+[10,10,23,10][tirs[i][0]],[20,20,7,7][tirs[i][0]],[20,20,7,7][tirs[i][0]],[(240,0,0),(0,240,0),(0,240,0),(0,240,0)][tirs[i][0]])

  flower_maj()

  fill_rect(0,200,320,22,(51,)*3)

  draw_string(str(flower),10,205,(250,180,0),(51,)*3)
  fill_rect(40,208,10,10,(250,180,0))

  draw_string(str(int(vague)),80,205,(255,)*3,(51,)*3)
  fill_rect(100,205,120,14,(0,)*3)
  fill_rect(102,207,int(116*(vague-int(vague))),10,(120,)*3)

  if map[select[1]][select[0]] in (0,1,4):

    for i in [0,1]:
      draw_string("^",[230,280][i],202,[(250,180,0),(51,)*3][i],(51,)*3)
      draw_flower(
      [[1,2,0,0,5,0,0],
      [4,3,0,0,6,0,0]][i][map[select[1]][select[0]]],
      [250,300][i],200,0.4,0.4)

#    draw_string("^",230,202,(250,180,0),(51,)*3)
#    draw_flower([1,2,0,0,5,0,0][map[select[1]][select[0]]],250,200,0.4,0.4)

#    draw_string("^",280,202,(10,)*3,(51,)*3)
#    draw_flower([4,3,0,0,6,0,0][map[select[1]][select[0]]],300,200,0.4,0.4)


def move():
  global select,last_move,map,flower
  if not last_move+0.2<monotonic():
    return
  last_move+=0.2

  x,y=0,0

  for i in range(4):
    if keydown(i):
      x+=[-1,0,0,1][i]
      y+=[0,-1,1,0][i]
  fill_rect(50*select[0]+5,50*select[1]+5,40,40,backGround)
  select[0]=(x+select[0])%5
  select[1]=(y+select[1])%4

  fill_rect(50*select[0]+5,50*select[1]+5,40,40,(102,)*3)

  if keydown(KEY_HOME) or keydown(KEY_ONOFF):
    ex_flower_id=map[select[1]][select[0]]
    cost=[5,15,0,0,15,0,0][ex_flower_id]
    if flower<cost:
      return
    flower-=cost
    map[select[1]][select[0]]=[4-3*keydown(KEY_HOME),3-keydown(KEY_HOME),2,3,6-keydown(KEY_HOME),5,6][ex_flower_id]

  if map[select[1]][select[0]]!=0 and keydown(KEY_OK):
    flower+=2
    map[select[1]][select[0]]=[0,0,1,1,0,4,4][map[select[1]][select[0]]]
    draw_flower(map[select[1]][select[0]],select[0]*50,select[1]*50)

instruction=[
("Appuyer sur:",80,20),
("Home" ,100,40,(255,)*3,(250,180,0)),
("OnOff",100,60,(255,)*3,(0,)*3),
("Pour ameliorer.",80,80),
("Pour supprimer=>Ok",80,120),
(">La premiere amelioration\n    coute 5 petales.",20,150),
("La seconde en coutera 15!",20,190)
]
for i in instruction:
  draw_string(*i)
  sleep(1)

sleep(4)

fill_rect(0,0,320,222,backGround)

while True:
  move()
  draw_all()
  tirs_maj()
  spawn()
  if end!=None:
    break
  sleep(0.05)


draw_string("<= Perdu! Et ce a la vague "+str(int(vague)),10,50*end,(255,)*3,backGround)

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 cookies policy.