supermario.py

Created by alexandre-merle

Created on November 17, 2023

14.2 KB


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

colors=[(0,200,255),(0,)*3,(255,)*3,(255,0,0),(255,230,150),(0,0,255),(0,200,0),(0,255,0),(255,230,0),(0,255,255),(200,200,50)]
bg_color=colors[0]
mario1=[
0,0,0,0,0,0,5,5,5,5,0,0,0,0,0,0,
0,0,0,0,0,5,3,3,3,3,5,0,0,0,0,0,
0,0,0,0,5,3,3,3,3,3,5,0,0,0,0,0,
0,0,0,5,3,3,3,3,5,5,5,5,5,0,0,0,
0,0,5,3,3,3,5,5,5,5,5,5,5,5,0,0,
0,0,5,3,3,5,5,4,4,4,4,4,5,0,0,0,
0,5,3,3,5,5,4,4,2,2,4,2,0,0,0,0,
0,5,5,5,5,5,4,4,2,5,4,5,0,0,0,0,
0,5,4,4,5,5,4,4,2,5,4,5,5,5,0,0,
0,5,4,4,5,5,5,4,4,4,4,4,4,4,5,0,
0,5,5,4,4,5,4,4,5,4,4,4,4,4,5,0,
0,0,5,4,4,4,4,5,5,5,5,4,4,5,5,5,
0,0,5,5,4,4,4,4,4,5,5,5,5,5,0,0,
0,0,5,5,4,4,4,4,4,4,4,5,5,0,0,0,
#0,0,0,0,5,4,4,4,4,4,4,5,0,0,0,0,
0,0,0,5,5,5,4,4,4,4,5,0,0,0,0,0,
0,0,5,3,3,5,5,5,5,5,5,5,0,0,0,0,
0,5,3,3,3,5,5,5,3,3,3,5,5,5,0,0,
5,3,3,3,5,4,4,4,5,3,3,3,5,4,5,0,
5,3,3,5,4,4,4,4,4,5,3,3,5,4,5,0,
5,3,3,5,4,4,4,4,4,5,3,3,5,5,0,0,
5,5,3,3,5,4,4,4,5,3,5,5,3,5,0,0,
0,0,5,5,5,5,5,5,3,3,5,5,3,5,0,0,
0,0,0,5,5,5,5,5,5,5,5,5,5,5,0,0,
0,0,0,5,5,5,5,5,5,5,5,5,5,5,0,0,
0,0,0,0,5,5,5,5,5,5,5,5,5,0,0,0,
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,3,5,
0,5,3,3,5,5,5,5,5,5,5,5,3,3,3,5,
5,5,3,5,5,5,5,5,5,5,5,5,3,3,3,5,
5,3,3,5,5,5,5,5,5,5,5,5,3,3,3,5,
5,3,3,5,5,5,5,5,0,0,0,5,3,3,5,5,
5,3,3,5,5,0,0,0,0,0,0,0,5,5,5,0,
0,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
def draw_1(list,x,y,t):
  x1=x;y1=y
  for i in list:
    if i!=0:fill_rect(x1,y1,t,t,colors[i])
    x1+=t
    if x1>x+(16*t)-t:y1+=t;x1-=16*t
def draw_2(list,x,y,t):
  x+=(16*t)-t
  x1=x;y1=y
  for i in list:
    if i!=0:fill_rect(x1,y1,t,t,colors[i])
    x1-=t
    if x1<x-(16*t)+t:y1+=t;x1+=(16*t)
class plateform:
  def __init__(self):
    self.type="truc"
    self.posx=0
    self.posy=0
    self.long=1
    self.larg=1
  def goto(self,x,y):self.posx=x;self.posy=y
  def buisson(self):self.type="buisson"
  def caissepiece(self):self.type="caissepiece"
  def caisse(self):self.type="caisse"
  def herbe(self):self.type="herbe"
  def boite(self):self.type="boite"
  def draw(self,t):
    if self.type=="buisson":
      fill_rect(self.posx+(5*t),self.posy,11*t,1*t,colors[1])
      fill_rect(self.posx+(3*t),self.posy+(1*t),2*t,1*t,colors[1])
      fill_rect(self.posx+(2*t),self.posy+(2*t),1*t,1*t,colors[1])
      fill_rect(self.posx+(1*t),self.posy+(3*t),1*t,2*t,colors[1])
      fill_rect(self.posx,self.posy+(5*t),1*t,11*t,colors[1])
      fill_rect(self.posx+(5*t),self.posy+(1*t),11*t,1*t,colors[6])
      fill_rect(self.posx+(3*t),self.posy+(2*t),3*t,1*t,colors[6])
      fill_rect(self.posx+(3*t),self.posy+(3*t),1*t,1*t,colors[6])
      fill_rect(self.posx+(2*t),self.posy+(3*t),1*t,3*t,colors[6])
      fill_rect(self.posx+(1*t),self.posy+(5*t),1*t,11*t,colors[6])
      fill_rect(self.posx+(6*t),self.posy+(2*t),10*t,1*t,colors[7])
      fill_rect(self.posx+(4*t),self.posy+(3*t),12*t,1*t,colors[6])
      fill_rect(self.posx+(3*t),self.posy+(4*t),13*t,1*t,colors[7])
      fill_rect(self.posx+(3*t),self.posy+(5*t),13*t,1*t,colors[6])
      for i in range(6,16,2):
        fill_rect(self.posx+(2*t),self.posy+(i*t),14*t,1*t,colors[7])
        fill_rect(self.posx+(2*t),self.posy+((i+1)*t),14*t,1*t,colors[6])
      j=0
      for j in range(16*t,((self.long-1)*(16*t)),16*t):
        fill_rect(self.posx+j,self.posy,16*t,1*t,colors[1])
        fill_rect(self.posx+j,self.posy+(1*t),16*t,1*t,colors[6])
        for i in range(2,16,2):
          fill_rect(self.posx+j,self.posy+(i*t),16*t,1*t,colors[7])
          fill_rect(self.posx+j,self.posy+((i+1)*t),16*t,1*t,colors[6])
      j+=16*t
      fill_rect(self.posx+j,self.posy,11*t,1*t,colors[1])
      fill_rect(self.posx+j+(9*t),self.posy+(1*t),4*t,1*t,colors[1])
      fill_rect(self.posx+j+(11*t),self.posy+(2*t),3*t,1*t,colors[1])
      fill_rect(self.posx+j+(12*t),self.posy+(3*t),3*t,2*t,colors[1])
      fill_rect(self.posx+j+(13*t),self.posy+(5*t),3*t,11*t,colors[1])
      fill_rect(self.posx+j,self.posy+(1*t),9*t,1*t,colors[6])
      fill_rect(self.posx+j+(8*t),self.posy+(2*t),3*t,1*t,colors[6])
      fill_rect(self.posx+j+(10*t),self.posy+(3*t),1*t,1*t,colors[6])
      fill_rect(self.posx+j+(11*t),self.posy+(3*t),1*t,3*t,colors[6])
      fill_rect(self.posx+j+(12*t),self.posy+(5*t),1*t,11*t,colors[6])
      fill_rect(self.posx+j,self.posy+(2*t),8*t,1*t,colors[7])
      fill_rect(self.posx+j,self.posy+(3*t),10*t,1*t,colors[6])
      fill_rect(self.posx+j,self.posy+(4*t),11*t,1*t,colors[7])
      fill_rect(self.posx+j,self.posy+(5*t),11*t,1*t,colors[6])
      for i in range(6,16,2):
        fill_rect(self.posx+j,self.posy+(i*t),12*t,1*t,colors[7])
        fill_rect(self.posx+j,self.posy+((i+1)*t),12*t,1*t,colors[6])
      for k in range(16*t,self.larg*(16*t),16*t):
        j=0
        fill_rect(self.posx+j,self.posy+k,1*t,16*t,colors[1])
        fill_rect(self.posx+j+(1*t),self.posy+k,1*t,16*t,colors[6])
        for i in range(0,16,2):
          fill_rect(self.posx+j+(2*t),self.posy+k+(i*t),14*t,1*t,colors[7])
          fill_rect(self.posx+j+(2*t),self.posy+k+((i+1)*t),14*t,1*t,colors[6])
        for j in range(16*t,(16*t)+((self.long-2)*(16*t)),16*t):
          for i in range(0,16,2):
            fill_rect(self.posx+j,self.posy+k+(i*t),16*t,1*t,colors[7])
            fill_rect(self.posx+j,self.posy+k+((i+1)*t),16*t,1*t,colors[6])
        j+=16*t
        fill_rect(self.posx+j+(13*t),self.posy+k,3*t,16*t,colors[1])
        fill_rect(self.posx+j+(12*t),self.posy+k,1*t,16*t,colors[6])
        for i in range(0,16,2):
          fill_rect(self.posx+j,self.posy+k+(i*t),12*t,1*t,colors[7])
          fill_rect(self.posx+j,self.posy+k+((i+1)*t),12*t,1*t,colors[6])
    if self.type=="caissepiece":
      fill_rect(self.posx,self.posy,1*t,16*t,colors[1])
      fill_rect(self.posx,self.posy,16*t,1*t,colors[1])
      fill_rect(self.posx+(16*t),self.posy+(16*t),-1*t,-16*t,colors[1])
      fill_rect(self.posx+(16*t),self.posy+(16*t),-16*t,-1*t,colors[1])
      fill_rect(self.posx+t,self.posy+t,3*t,4*t,colors[8])
      fill_rect(self.posx+(t*4),self.posy+t,t,4*t,colors[1])
      fill_rect(self.posx+(t*12),self.posy+t,3*t,4*t,colors[8])
      fill_rect(self.posx+(t*11),self.posy+t,t,4*t,colors[1])
      fill_rect(self.posx+(t*4),self.posy+t,t,4*t,colors[1])
      fill_rect(self.posx+(t*8),self.posy+(t*6),t*1,4*t,colors[1])
      fill_rect(self.posx+t,self.posy+(t*5),14*t,t,colors[1])
      fill_rect(self.posx+t,self.posy+(t*6),7*t,4*t,colors[8])
      fill_rect(self.posx+(t*9),self.posy+(t*6),6*t,4*t,colors[8])
      fill_rect(self.posx+t,self.posy+(t*10),14*t,t,colors[1])
      fill_rect(self.posx+(t*4),self.posy+(t*11),t,4*t,colors[1])
      fill_rect(self.posx+(t*12),self.posy+(t*11),3*t,4*t,colors[8])
      fill_rect(self.posx+(t*11),self.posy+(t*11),t,4*t,colors[1])
      fill_rect(self.posx+(t*5),self.posy+t,6*t,4*t,colors[8])
      fill_rect(self.posx+(t*5),self.posy+(t*11),6*t,4*t,colors[8])
      fill_rect(self.posx+t,self.posy+(t*11),3*t,4*t,colors[8])
    if self.type=="caisse":
      fill_rect(self.posx,self.posy+t,1*t,14*t,colors[1])
      fill_rect(self.posx+t,self.posy,14*t,1*t,colors[1])
      fill_rect(self.posx+(16*t),self.posy+(15*t),-1*t,-14*t,colors[1])
      fill_rect(self.posx+(15*t),self.posy+(16*t),-14*t,-1*t,colors[1])
      fill_rect(self.posx+t,self.posy+t,14*t,14*t,colors[9])
      fill_rect(self.posx+(t*2),self.posy+(t*2),t,t,colors[1])
      fill_rect(self.posx+(t*2),self.posy+(t*13),t,t,colors[1])
      fill_rect(self.posx+(13*t),self.posy+(2*t),t,t,colors[1])
      fill_rect(self.posx+(13*t),self.posy+(13*t),t,t,colors[1])  
      fill_rect(self.posx+(5*t),self.posy+(3*t),t*2,t*3,colors[1])
      fill_rect(self.posx+(6*t),self.posy+(2*t),t*4,t*2,colors[1])
      fill_rect(self.posx+(9*t),self.posy+(3*t),t*2,t*4,colors[1])
      fill_rect(self.posx+(8*t),self.posy+(6*t),t*2,t*2,colors[1])  
      fill_rect(self.posx+(7*t),self.posy+(7*t),t*2,t*4,colors[1])
      fill_rect(self.posx+(7*t),self.posy+(12*t),t*2,t*2,colors[1])
    if self.type=="herbe":
      fill_rect(self.posx,self.posy,self.larg*(16*t),self.long*(16*t),colors[6])
      fill_rect(self.posx,self.posy,self.larg*(16*t),t,colors[7])
    if self.type=="boite":
      fill_rect(self.posx,self.posy+t,1*t,14*t,colors[1])
      fill_rect(self.posx+t,self.posy,14*t,1*t,colors[1])
      fill_rect(self.posx+(16*t),self.posy+(15*t),-1*t,-14*t,colors[1])
      fill_rect(self.posx+(15*t),self.posy+(16*t),-14*t,-1*t,colors[1])
      fill_rect(self.posx+t,self.posy+t,14*t,14*t,colors[9])
  def deplace(self,v):self.posx+=v
class feu:
  def __init__(self):
    self.x=0
    self.y=0
    self.vx=0
    self.vy=0
  def draw(self):
    fill_rect(self.x,self.y+2,8,4,(255,180,0))
    fill_rect(self.x+2,self.y,4,8,(255,180,0))
class mario:
  def __init__(self):
    self.x=0
    self.y=0
    self.vx=0
    self.vy=0
    self.move=-1
    self.orient=0
    self.bonus="no"
    self.start=(0,0)
  def draw(self):
    if self.orient==0:
      if self.move==-1:draw_1(mario1,self.x,self.y,2)
      elif self.move==1:draw_1(mario2,self.x,self.y,2)
    elif self.orient==1:
      if self.move==-1:draw_2(mario1,self.x,self.y,2)
      elif self.move==1:draw_2(mario2,self.x,self.y,2)
  def deplace(self,list,f,n):
    self.x+=trunc(self.vx)
    self.y+=trunc(self.vy)
    self.vy=2+self.vy*0.99
    self.vx=self.vx*0.9
    if abs(self.vx)<1:self.vx=0
    a=0
    for i in f:
      if f[a]!=0:
        f[a].x+=trunc(f[a].vx)
        f[a].y+=trunc(f[a].vy)
        f[a].vy=2+f[a].vy
        f[a].vx=f[a].vx
        if f[a].x>320 or f[a].x<0 or f[a].y>222:f[a]=0
      a+=1
    a=0
    for i in list:
      if list[a].type=="buisson" and list[a].posx-16<self.x<list[a].posx+(list[a].long*32)-16 and list[a].posy-64<self.y<list[a].posy-32:
        self.vy=0
        self.y=list[a].posy-60
      if list[a].type=="caisse" and list[a].posx-16<self.x<list[a].posx+16 and list[a].posy-64<self.y<list[a].posy-32:
        self.vy=0
        self.y=list[a].posy-60
      elif list[a].type=="caisse" and list[a].posx-16<self.x<list[a].posx+16 and list[a].posy+16<self.y<list[a].posy+32:
        list[a].boite()
        colors[3]=(255,180,0);colors[5]=(255,0,0);self.bonus="yes"
        self.vy=0.01
      elif list[a].type=="caisse" and list[a].posx-32<self.x<list[a].posx and list[a].posy-58<self.y<list[a].posy+32:
        self.x=list[a].posx-32
        self.vx=0
      elif list[a].type=="caisse" and list[a].posx<self.x<list[a].posx+32 and list[a].posy-58<self.y<list[a].posy+32:
        self.x=list[a].posx+32
        self.vx=0
      if list[a].type=="boite" and list[a].posx-16<self.x<list[a].posx+16 and list[a].posy-64<self.y<list[a].posy-32:
        self.vy=0
        self.y=list[a].posy-60
      elif list[a].type=="boite" and list[a].posx-16<self.x<list[a].posx+16 and list[a].posy+16<self.y<list[a].posy+32:
        self.vy=0.01
        self.y=list[a].posy+32
      elif list[a].type=="boite" and list[a].posx-32<self.x<list[a].posx and list[a].posy-58<self.y<list[a].posy+32:
        self.x=list[a].posx-32
        self.vx=0
      elif list[a].type=="boite" and list[a].posx<self.x<list[a].posx+32 and list[a].posy-58<self.y<list[a].posy+32:
        self.x=list[a].posx+32
        self.vx=0
      if list[a].type=="caissepiece" and list[a].posx-16<self.x<list[a].posx+16 and list[a].posy-64<self.y<list[a].posy-32:
        self.vy=0
        self.y=list[a].posy-60
      elif list[a].type=="caissepiece" and list[a].posx-16<self.x<list[a].posx+16 and list[a].posy+16<self.y<list[a].posy+32:
        self.y=list[a].posy+32
        self.vy=0.01
        list[a].posx=1000
        list[a].posy=1000
      elif list[a].type=="caissepiece" and list[a].posx-32<self.x<list[a].posx and list[a].posy-58<self.y<list[a].posy+32:
        self.x=list[a].posx-32
        self.vx=0
      elif list[a].type=="caissepiece" and list[a].posx<self.x<list[a].posx+32 and list[a].posy-58<self.y<list[a].posy+32:
        self.x=list[a].posx+32
        self.vx=0
      a+=1
    if self.y>150:self.vy=0
    if keydown(KEY_OK)and self.vy==0:self.vy=-16
    elif keydown(KEY_LEFT):self.vx=-10;self.orient=1;self.move-=self.move*2
    elif keydown(KEY_RIGHT):self.vx=10;self.orient=0;self.move-=self.move*2
    elif self.vy==0:self.move=-1;self.vx=0
    if self.vy!=0:self.move=1
    if keydown(KEY_BACKSPACE) and self.bonus=="yes" and n==1:
      b=0
      a=0
      for i in f:
        if i==0:
          f[a]=feu()
          f[a].x=self.x+16
          f[a].y=self.y+32
          f[a].vy=0
          if self.orient==1:f[a].vx=-15
          elif self.orient==0:f[a].vx=15
          b=1
          break
        a+=1
      if b==0:
        n=0
        for i in f:n+=1
        f+=[feu()]
        f[n].x=self.x+16
        f[n].y=self.y+32
        f[n].vy=0
        if self.orient==1:f[n].vx=-15
        elif self.orient==0:f[n].vx=15
f=[]
p=[]
for i in range(0,10):
  p+=[plateform()]
p[0].buisson()
p[0].posx=0
p[0].posy=96
p[0].long=3
p[0].larg=4
p[1].caissepiece()
p[1].posx=200
p[1].posy=96
p[2].caissepiece()
p[2].posx=200
p[2].posy=128
p[3].caisse()
p[3].posx=232
p[3].posy=0
p[4].caissepiece()
p[4].posx=232
p[4].posy=128
p[5].caissepiece()
p[5].posx=264
p[5].posy=128
p[6].caissepiece()
p[6].posx=296
p[6].posy=96
p[7].caissepiece()
p[7].posx=296
p[7].posy=128
#p[8].caissepiece()
#p[8].posx=296
#p[8].posy=64
m=mario()
n=1
while True:
  fill_rect(0,0,320,222,(0,200,255))
  for i in p:
    i.draw(2)
  for i in f:
    if i!=0:
      i.draw()
  m.draw()
  m.deplace(p,f,n)
  #if m.x>280:
  #  for i in p:i.deplace(trunc(-m.vx))
  #  m.x=280
  #  m.x-=trunc(m.vx)
  n+=1
  if n>=4:n=1
  sleep(0.0)

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.