infinite_run.py

Created by fixem

Created on May 12, 2025

4.74 KB

Jeu de plateforme en 2D avec défilement infini vers la gauche. Plateforme générée aléatoirement de sorte à être toujours accessible.


from kandinsky import*
from random import*
from time import*
from ion import*
def play(hm,dm):
  light=(255,)*3
  dark=(0,)*3
  if dm:
    light,dark=dark,light
  maxp=0
  ready=0
  while 1:
    j=0
    fill_rect(0,0,320,222,light)
    pl=[(320,0,150)]
    x,y=0,150
    for i in range(7):
      if hm:
        pl.append((randint(20,30),pl[-1][0]+pl[-1][1]+randint(30,50),randint(120,160)))
      else:
        pl.append((randint(20,60),pl[-1][0]+pl[-1][1]+randint(20,60),randint(120,180)))
    for i in pl:
      fill_rect(x+i[1],i[2],i[0],i[0],dark)
    cy=120
    p=0
    jumping=False
    if hm:
      col=[255,0,255]
    else:
      col=[0,255,255]
    opt=1
    draw_string("Infinite Run",100,40,dark,light)
    while 1-keydown(4) and 1-keydown(1):
      if col[2]>70 and opt==1:col[2]-=1
      else:
        col[2]+=1
        if col[2]<255:opt=0
        else:opt=1
      draw_string("Press [OK] to start",65,165,col,dark);sleep(.004)
    draw_string(" "*19,65,100,light,light)
    draw_string(" "*12,100,40,light,light)
    l=monotonic()
    while 1:
      txt="Easy Mode"
      c1=(0,255,0)
      c2=(0,255,255)
      if hm:
        txt="Hard Mode"
        c1=(255,0,0)
        c2=(255,0,255)
        c=(0,)*3
      if keydown(42):
        hm=1
      if keydown(48):
        hm=0
      if monotonic()-l>=1:
        l=monotonic()
      elif monotonic()-l>=0.5:
        c=c1
      else:
         c=c2
      draw_string(txt,220,15,c,light)
      draw_string(str(int(p)),0,0,(250,125,125),light)
      draw_string(str(int(maxp)),0,20,(125,125,250),light)
      if cy==0 or cy==202:
        draw_string("Game Over",50,50,dark,light)
        onj=monotonic()
        while 1-keydown(52):
          if monotonic()-onj>=1:
            break
          continue
        ready=0
        break
      fill_rect(50,cy,20,20,(0,255,255))
      if (keydown(1) or keydown(4)) and get_pixel(50,cy+20)==dark or get_pixel(69,cy+20)==dark:
        jumping=True 
      if not keydown(4) and not keydown(1) or j==70:
        j=0
        jumping=False
      if jumping:
        j+=1
        fill_rect(50,cy+18,20,2,light)
        cy-=2
        fill_rect(50,cy,20,1,(0,255,255))
      if get_pixel(50,cy+20)==light and get_pixel(69,cy+20)==light:
        fill_rect(50,cy,20,1,light)
        cy+=1
        fill_rect(50,cy+19,20,1,(0,255,255))
        if p>maxp:maxp=p
      if get_pixel(70,cy)!=dark and get_pixel(70,cy+19)!=dark:
        for i in pl:
          fill_rect(x+i[1]+i[0],i[2],1,i[0],light)
        x-=1
        for i in pl:
          fill_rect(x+i[1],i[2],1,i[0],dark)
          if x+i[1]+i[0]<0:
            p+=1
            pl.remove(i)
            if hm:
              pl.append((randint(20,30),pl[-1][0]+pl[-1][1]+randint(20,30),randint(120,160)))
            else:
              pl.append((randint(20,100),pl[-1][0]+pl[-1][1]+randint(20,60),randint(120,180)))
      else:
        while cy!=202:
          sleep(0.002)
          fill_rect(50,cy,20,20,light)
          cy+=1
          fill_rect(50,cy,20,20,(0,255,255))

def menu(hm):
  chargement=0
  fill_rect(0,0,320,222,(0,)*3)
  fill_rect(55,145,210,40,(255,)*3)
  fill_rect(60,150,200,30,(0,)*3)
  l1=monotonic()
  while 1:
    fill_rect(60+int(chargement),150,1,30,(255,0,0))
    draw_string(str(int(chargement/2)),60,155,(255,)*3,(255,0,0))
    if chargement>=200:
      if hm:
        col=[255,0,255]
      else:
        col=[0,255,255]
      opt=1
      while 1-keydown(4) and 1-keydown(1):
        if col[2]>70 and opt==1:col[2]-=1
        else:
          col[2]+=1
          if col[2]<255:opt=0
          else:opt=1
        draw_string("Press [OK] to start",65,200,col,(0,)*3);sleep(.004)
      break
    if monotonic()-l1>=2:
      l1=monotonic()
      fill_rect(110,91,100,20,(0,)*3)
    elif monotonic()-l1>=1.5:
      draw_string("LOADING...",110,91,(255,)*3,(0,)*3)
    elif monotonic()-l1>=1:
      draw_string("LOADING..",115,91,(255,)*3,(0,)*3)
    elif monotonic()-l1>=0.5:
      draw_string("LOADING.",120,91,(255,)*3,(0,)*3)
    else:
      draw_string("LOADING",125,91,(255,)*3,(0,)*3)
    chargement+=0.1

"""
--All the text on triple quote can be removed--
 
 This game was created by FIXEM,
 Project finish on may the 6th of 2025.

Rules:
  - By clicking on "OK", jump and try to
    stay alive.
  - The platforms are randomly generated,
    but all jumps can be done.
Tips:
  - You can also use key UP to jump.
  - All jumps are possible but you can have
    to skip some platforms for it.
  - You can change the difficulty in game
    by clicking on "1"(hard) or on "0"
    (easy).
  - You can also change the theme by
    modifying the variable "Dark Mode" on 
    1(dark mode) or 0(light mode).
"""

HardMode=1# 1=Hard Mode, 0=Easy Mode
DarkMode=1# 1=Dark Mode, 0=Light Mode
#menu(HardMode)# "Loading" (can be removed)
play(HardMode,DarkMode)# GameLoop

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.