Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * def setup(): print 'DEV NOTES:' print 'arrow keys to control' global Mario, state, camera, keys, anim, lives, MAX_SPEED, GRAVITY, empty, ground, bricks, itembl, emptyb, tile, ene, invis, smallRightRun, smallLeftRun size(256*2,240*2) state = "lives" anim = 200 camera = 96 lives = 3 keys = [] MAX_SPEED = 3#3 GRAVITY = 1.4#1.4 empty = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/smbsprite-sheet-1.png') ground = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/smbsprite-sheet-2.png') bricks = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/smbsprite-sheet-3.png') itembl = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/smbsprite-sheet-4.png') emptyb = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/smbsprite-sheet-5.png') invis = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/smbsprite-sheet-6.png') global pipetl, pipetr, pipel, piper pipetl = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-16.png') pipetr = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-17.png') pipel = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-38.png') piper = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-39.png') global poletop, polemid, stone poletop = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-100.png') polemid = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-103.png') stone = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-78.png') global goomba1, goomba2, goombadie, koopar1, ktr1, koopar2, ktr2, koopal1, ktl1, koopal2, ktl2, shell goomba1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-1.png') goomba2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-2.png') goombadie = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-3.png') koopal1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-4.png') koopal2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-5.png') koopar1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-6.png') koopar2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-7.png') shell = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-8.png') ktl1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-9.png') ktl2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-10.png') ktr1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-11.png') ktr2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/goompa-12.png') global rightIdle, rightRun1, rightRun2, rightRun3, rightTurn, rightJump, dead, leftIdle, leftRun1, leftRun2, leftRun3, leftTurn, leftJump rightIdle = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-7.png') rightRun1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-8.png') rightRun2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-9.png') rightRun3 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-10.png') rightTurn = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-11.png') rightJump = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-12.png') dead = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/dead-mar-1.png') leftIdle = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-6.png') leftRun1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-5.png') leftRun2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-4.png') leftRun3 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-3.png') leftTurn = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-2.png') leftJump = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/mario-1.png') global gameover, deadtimer, livescounter gameover = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/gameob-er-1.png') deadtimer = 120 livescounter = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/lives-counter-1.png') global bigLeftTopJump,bigLeftTopTurn,bigLeftTopRun,bigLeftTopRun,bigLeftTopRun,bigLeftTopCrouch,bigLeftTopIdle,bigRightTopIdle,bigRightTopCrouch,bigRightTopRun,bigRightTopRun,bigRightTopRun,bigRightTopTurn,bigRightTopJump,bigLeftBotJump,bigLeftBotTurn,bigLeftBotRun,bigLeftBotRun,bigLeftBotRun,bigLeftBotCrouch,bigLeftBotIdle,bigRightBotIdle,bigRightBotCrouch,bigRightBotRun,bigRightBotRun,bigRightBotRun,bigRightBotTurn,bigRightBotJump bigLeftTopJump = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-1.png') bigLeftTopTurn = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-2.png') bigLeftTopRun3 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-3.png') bigLeftTopRun2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-4.png') bigLeftTopRun1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-5.png') bigLeftTopCrouch = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-6.png') bigLeftTopIdle = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-7.png') bigRightTopIdle = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-8.png') bigRightTopCrouch = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-9.png') bigRightTopRun1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-10.png') bigRightTopRun2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-11.png') bigRightTopRun3 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-12.png') bigRightTopTurn = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-13.png') bigRightTopJump = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-14.png') bigLeftBotJump = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-15.png') bigLeftBotTurn = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-16.png') bigLeftBotRun3 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-17.png') bigLeftBotRun2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-18.png') bigLeftBotRun1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-19.png') bigLeftBotCrouch = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-20.png') bigLeftBotIdle = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-21.png') bigRightBotIdle = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-22.png') bigRightBotCrouch = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-23.png') bigRightBotRun1 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-24.png') bigRightBotRun2 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-25.png') bigRightBotRun3 = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-26.png') bigRightBotTurn = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-27.png') bigRightBotJump = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/big-mario-28.png') smallRightRun = [rightRun1,rightRun2,rightRun3] smallLeftRun = [leftRun1,leftRun2,leftRun3] global halftopl, halftopr, halfbotl, halfbotr, tobig halftopl = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/cursed-marop-1.png') halftopr = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/cursed-marop-2.png') halfbotl = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/cursed-marop-3.png') halfbotr = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/cursed-marop-4.png') tobig = { 'left':[[bigLeftBotIdle,bigLeftTopIdle],[halfbotl,halftopl],[bigLeftBotIdle,bigLeftTopIdle],[halfbotl,halftopl],[leftIdle,invis],[bigLeftBotIdle,bigLeftTopIdle],[halfbotl,halftopl],[leftIdle,invis],[halfbotl,halftopl],[leftIdle,invis]], 'right':[[bigRightBotIdle,bigRightTopIdle],[halfbotr,halftopr],[bigRightBotIdle,bigRightTopIdle],[halfbotr,halftopr],[rightIdle,invis],[bigRightBotIdle,bigRightTopIdle],[halfbotr,halftopr],[rightIdle,invis],[halfbotr,halftopr],[rightIdle,invis]] } global coin, mushroom, flower, star, life coin = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/Imported-piskel-116.png') mushroom = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/poweru-1.png') flower = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/poweru-2.png') star = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/poweru-3.png') life = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/1up-1.png') global bigmar bigmar = { 'left':{ 'top':{ 'jump':bigLeftTopJump, 'turn':bigLeftTopTurn, 'run':[bigLeftTopRun1,bigLeftTopRun2,bigLeftTopRun3], 'crouch':bigLeftTopCrouch, 'idle':bigLeftTopIdle, }, 'bottom':{ 'jump':bigLeftBotJump, 'turn':bigLeftBotTurn, 'run':[bigLeftBotRun1,bigLeftBotRun2,bigLeftBotRun3], 'crouch':bigLeftBotCrouch, 'idle':bigLeftBotIdle, }, }, 'right':{ 'top':{ 'jump':bigRightTopJump, 'turn':bigRightTopTurn, 'run':[bigRightTopRun1,bigRightTopRun2,bigRightTopRun3], 'crouch':bigRightTopCrouch, 'idle':bigRightTopIdle, }, 'bottom':{ 'jump':bigRightBotJump, 'turn':bigRightBotTurn, 'run':[bigRightBotRun1,bigRightBotRun2,bigRightBotRun3], 'crouch':bigRightBotCrouch, 'idle':bigRightBotIdle, }, }, } tile = { 'g':ground, '?':itembl, 'd':empty, '.':emptyb, 'b':bricks, 'i':invis, 'p':pipetl, 'q':pipetr, '(':pipel, ')':piper, 'j':invis, '9':bricks, '8':bricks, '7':bricks, '6':bricks, '5':bricks, '4':bricks, '3':bricks, '2':bricks, '1':bricks, '0':bricks, 'm':itembl, 's':stone, 'o':poletop, 'l':polemid, '*':bricks, } ene = { 'e':[-.5,0,[[goomba1,invis],[goomba2,invis]],[[goomba1,invis],[goomba2,invis]],goombadie,'goomba',0], 'k':[-.5,0,[[koopal1,ktl1],[koopal2,ktl2]],[[koopar1,ktr1],[koopar2,ktr2]],None,'koopa',0], 'h':[-.5,0,[[goomba1,invis],[goomba2,invis]],[[goomba1,invis],[goomba2,invis]],goombadie,'goomba',8], } Mario = Player(64,192,"small",ground,itembl) class Player: global state def __init__(self,x,y,power,top=None,bottom=0xffff0000,tags={'facing':'right','jumping':False},vx=0,vy=0,animBot=0,animTop=0,iframes=0): self.x = x self.y = y self.power = power self.tags = tags self.vx = vx self.vy = vy self.animBot = animBot self.animTop = animTop self.top = top self.bottom = bottom self.iframes = iframes def collideHorizontal(self): if level[int((self.y+8)/16)][int(self.x/16)+1] in solid: return "right" elif level[int((self.y+8)/16)][int(self.x/16)] in solid: return "left" else: return False def collideBottom(self): if level[int((self.y)/16)+1][int((self.x+1)/16)] in solid or level[int(self.y/16)+1][int((self.x-1)/16)+1] in solid: if level[int((self.y)/16)+1][int((self.x+1)/16)] == 'd' or level[int(self.y/16)+1][int((self.x-1)/16)+1] == 'd': mariodead() return True else: return False def collideTop(self): if self.power == "small": k = 0 else: k = 1 if level[int((self.y-1)/16)-k][int((self.x+8)/16)] in solid+['j'] and self.vy < 0:# or level[int((self.y-1)/16)-k][int((self.x-1)/16)+1] in solid: if level[int((self.y-1)/16)-k][int((self.x+8)/16)] == "?": level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + 'i' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] Entity(int((self.x+8)/16)*16,(int((self.y-1)/16)-k)*16,-4,4,itembl,'empty') elif level[int((self.y-1)/16)-k][int((self.x+8)/16)].isdigit(): Entity(int((self.x+8)/16)*16,(int((self.y-1)/16)-k)*16,-4,4,bricks,level[int((self.y-1)/16)-k][int((self.x+8)/16)],) level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + 'i' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] elif level[int((self.y-1)/16)-k][int((self.x+8)/16)] == 'j': level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + 'i' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] Entity(int((self.x+8)/16)*16,(int((self.y-1)/16)-k)*16,-4,4,itembl,'life') elif level[int((self.y-1)/16)-k][int((self.x+8)/16)] == 'm': level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + 'i' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] Entity(int((self.x+8)/16)*16,(int((self.y-1)/16)-k)*16,-4,4,itembl,'mushroom') elif level[int((self.y-1)/16)-k][int((self.x+8)/16)] == '*': level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + 'i' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] Entity(int((self.x+8)/16)*16,(int((self.y-1)/16)-k)*16,-4,4,itembl,'star') elif level[int((self.y-1)/16)-k][int((self.x+8)/16)] == "b": level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + ' ' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] if self.power == 'small': Entity(int((self.x+8)/16)*16,(int((self.y-1)/16)-k)*16,-4,4,bricks,'bricks') level[int((self.y-1)/16)-k] = level[int((self.y-1)/16)-k][:int((self.x+8)/16)] + 'i' + level[int((self.y-1)/16)-k][int((self.x+8)/16)+1:] else: pass return True else: return False class Entity: instances = [] def __init__(self,x,y,vy,tvy,image,data='',desp=False,vx=0,image2=None,rot=0,vr=0): self.x = x self.y = y self.vy = vy self.vx = vx self.tvy = tvy self.data = data self.image = image self.desp = desp self.image2 = image2 self.rot = rot self.vr = vr Entity.instances.append(self) class Enemy: instances = [] def __init__(self,x,y,vx,vy,imagel,imager,imagedie,enemy,collide=0,timer=30,state=0,anim=0,animrate=0.0625): self.x = x self.y = y self.vx = vx self.vy = vy self.imagel = imagel self.imager = imager self.collide = collide self.imagedie = imagedie self.enemy = enemy self.timer = timer self.state = state self.anim = anim self.animrate = animrate Enemy.instances.append(self) def collideHorizontal(self): if level[int(self.y/16)][int(self.x/16)+1] in solid: return "right" elif level[int(self.y/16)][int(self.x/16)] in solid: return "left" else: return False def collideBottom(self): if level[int((self.y)/16)+1][int((self.x)/16)] in solid or level[int(self.y/16)+1][int((self.x)/16)+1] in solid: if level[int((self.y)/16)+1][int((self.x+1)/16)] == 'd' or level[int(self.y/16)+1][int((self.x-1)/16)+1] == 'd': return 'im dead' return True else: return False class Powerup: instances = [] def __init__(self,x,y,vx,vy,image,power,anim,collide): self.x = x self.y = y self.vx = vx self.vy = vy self.image = image self.power = power self.anim = anim self.collide = collide Powerup.instances.append(self) def collideHorizontal(self): if level[int(self.y/16)][int(self.x/16)+1] in solid: return "right" elif level[int(self.y/16)][int(self.x/16)] in solid: return "left" else: return False def collideBottom(self): if level[int((self.y)/16)+1][int((self.x)/16)] in solid or level[int(self.y/16)+1][int((self.x)/16)+1] in solid: if level[int((self.y)/16)+1][int((self.x+1)/16)] == 'd' or level[int(self.y/16)+1][int((self.x-1)/16)+1] == 'd': return 'im dead' return True else: return False level = [ ' ', ' ', ' o ', ' l ', ' e h l ', ' bbbbbbbb bbb? ? ss l ', ' ? bbb b??b sss l ', ' ssss l ', ' j sssss l ', ' ? bmb?b pq pq bmb 9 b* ? ? ? b bb s s ss s bb?b ssssss l ', ' pq () () ss ss sss ss sssssss l ', ' pq () () () sss sss ssss sss pq pq ssssssss l ', ' e () ()e () eh () eh eh k eh eh eh ssss ssss sssss ssss ()eh eh ()sssssssss s ', 'gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggg', 'gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg gggggggggggggggggggggggggggggggggggggggggggggggggggg', ' d d d d d d ', ' d d d d d d ', ' dddd ddddd dddd ' ] enemies = ['e','k','h'] solid = ['g','?','.','d','b','i','p','q','(',')','9','8','7','6','5','4','3','2','1','0','m','s','*'] def hone(var,target,step): if var < step+target and var > target-step and var != target: var = target elif var > target: var -= step elif var < target: var += step return var def keyPressed(): global keys if keyboard.keyCode not in keys: keys.append(keyboard.keyCode) if keyboard.key == 'g':# Enemy(Mario.x+16,Mario.y,0,0,[[shell,invis],[shell,invis]],[[shell,invis],[shell,invis]],None,'shell',-1) def keyReleased(): global keys if keyboard.keyCode in keys: keys.remove(keyboard.keyCode) def mariodead(): global state state = 'die' def draw(): scale(2,2) global camera, state, anim, Mario, deadtimer background(0xff9290ff) if state == "lives": background(0xff000000) image(livescounter,0,0,256,240) anim -= 1 if anim == 0: state = "play" elif state == "play": translate(-camera+96,0) if RIGHT in keys: if not Mario.tags['jumping']: Mario.tags['facing'] = 'right' Mario.vx += 0.1 if Mario.vx > MAX_SPEED:#5.25 Mario.vx = MAX_SPEED if Mario.vx < -1.0: Mario.vx = -1.0 elif LEFT in keys: if not Mario.tags['jumping']: Mario.tags['facing'] = 'left' Mario.vx -= 0.1 if Mario.vx > 1.0: Mario.vx = 1.0 if Mario.vx < -MAX_SPEED: Mario.vx = -MAX_SPEED else: Mario.vx = hone(Mario.vx,0,0.2) if UP in keys: if Mario.vy == 0 and Mario.collideBottom(): Mario.vy = -9 Mario.y -= 1 Mario.tags['jumping'] = True Mario.animBot = 0 elif Mario.vy < 0: Mario.vy -= 1 if camera < Mario.x: camera = Mario.x if Mario.x < camera-96: Mario.vx = 0 Mario.x = camera-96 Mario.vy += GRAVITY if Mario.vy > 1: Mario.vy -= 1 if Mario.collideTop(): Mario.vy = 0 while Mario.collideTop(): Mario.y += 1 Mario.y += 3 for i in Powerup.instances: if i.anim == 0: i.x += i.vx i.y += i.vy i.vy += 1 if i.collideHorizontal(): i.vx *= -1 else: if i.collideBottom(): if i.collideBottom() == 'im dead': Powerup.instances.remove(i) i.vy = 0 while i.collideBottom(): i.y -= 1 i.y += 1 for j in Entity.instances: if j.x > i.x-16 and j.x < i.x+16 and j.y > i.y-16 and j.y < i.y+16 and j.desp == False: i.vy = -5 else: i.anim -= 1 i.y -= 1 if Mario.x > i.x-16 and Mario.x < i.x+16 and Mario.y > i.y-16 and Mario.y < i.y+16 and i.collide == 0: Powerup.instances.remove(i) if i.power == 'mushroom': state = 'power' Mario.power = 'big' anim = 39 if i.x < camera - 200: Powerup.instances.remove(i) if i.collide > 0: i.collide -= 1 image(i.image,i.x,i.y,16,16) for i in Entity.instances: i.y += i.vy i.x += i.vx i.vy += 1 pushMatrix() translate(i.x+8,i.y+8) imageMode(CENTER) rotate(i.rot) image(i.image,0,0,16,16) if i.image2 != None: image(i.image2,0,-16,16,16) popMatrix() imageMode(CORNER) i.rot += i.vr if i.vy == i.tvy and not i.desp: if i.data == 'empty': level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + '.' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] Entity(i.x,i.y,-5,2,coin) elif i.data == 'bricks': level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + 'b' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] elif i.data.isdigit(): Entity(i.x,i.y,-5,2,coin) if i.data == '0': level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + '.' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] else: level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + str(int(i.data)-1) + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] elif i.data == 'mushroom': level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + '.' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] if Mario.power == 'small': Powerup(i.x,i.y,1,0,mushroom,'mushroom',16,16) else: Entity(i.x,i.y,-8,0,flower,'',True,Mario.vx+2,None,0,0.5) print 'i couldnt implement many powerups sorry :(' elif i.data == 'star': level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + '.' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] Entity(i.x,i.y,-8,0,star,'',True,Mario.vx+2,None,0,0.5) print 'i couldnt implement many powerups sorry :(' elif i.data == 'life': level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + '.' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] Entity(i.x,i.y,-8,0,life,'',True,Mario.vx+2,None,0,0.5) print 'i couldnt implement many powerups sorry :(' Entity.instances.remove(i) if i.desp and i.y > 240: Entity.instances.remove(i) for row in range(len(level)): for col in range(18): try: current = level[row][int(camera/16)+col-6] except: raise 'DEV NOTE: the flagpole crashes the game' if current == ' ': continue if current in enemies: Enemy(camera+((col-6)*16)+ene[current][6],row*16,ene[current][0],ene[current][1],ene[current][2],ene[current][3],ene[current][4],ene[current][5]) level[row] = level[row][:int(camera/16)+col-6] + ' ' + level[row][(int(camera/16)+col-6)+1:] else: image(tile[current],(float(int(camera/16))+col-6)*16,row*16,16,16) for i in Enemy.instances: if i.timer == 30: i.x += i.vx i.y += i.vy i.vy += 1 if i.collideHorizontal(): i.vx *= -1 else: if i.collideBottom(): if i.collideBottom() == 'im dead': Enemy.instances.remove(i) i.vy = 0 while i.collideBottom(): i.y -= 1 i.y += 1 for j in Enemy.instances: if i == j: continue if j.x > i.x-16 and j.x < i.x+16 and j.y > i.y-16 and j.y < i.y+16: if i.enemy == 'shell' and i.vx != 0: Enemy.instances.remove(j) Entity(j.x,j.y,-5,0,j.imager[0][0],None,True,j.vx,j.imager[0][1],PI) if j.enemy == 'shell' and j.vx != 0: Enemy.instances.remove(i) Entity(i.x,i.y,-5,0,i.imager[0][0],None,True,i.vx,i.imager[0][1],PI) else: i.vx *= -1 for j in Entity.instances: if j.x > i.x-16 and j.x < i.x+16 and j.y > i.y-16 and j.y < i.y+16 and j.desp == False: if i.enemy == 'koopa': Enemy(i.x,i.y,i.vx,-5,[[shell,invis],[shell,invis]],[[shell,invis],[shell,invis]],None,'shell',-1) Enemy.instances.remove(i) else: Enemy.instances.remove(i) Entity(i.x,i.y,-5,0,i.imager[0][0],None,True,i.vx,i.imager[0][1],PI) if i.x < camera - 200: Enemy.instances.remove(i) if i.collide > 0: i.collide -= 1 if i.vx < 0: image(i.imagel[int(i.anim)][0],i.x,i.y,16,16) image(i.imagel[int(i.anim)][1],i.x,i.y-16,16,16) else: image(i.imager[int(i.anim)][0],i.x,i.y,16,16) image(i.imager[int(i.anim)][1],i.x,i.y-16,16,16) i.anim += i.animrate if i.anim >= 2: i.anim = 0 if Mario.x > i.x-16 and Mario.x < i.x+16 and Mario.y > i.y-16 and Mario.y < i.y+16: if Mario.vy <= 1 and i.collide == 0: if Mario.power == 'small' and Mario.iframes == 0: state = 'die' Entity(Mario.x,Mario.y,-10,0,dead,None,True) elif Mario.power == 'big' and Mario.iframes == 0: Mario.power = 'small' Mario.iframes = 100 else: if i.vx != 0 and i.collide == 0: Mario.tags['jumping'] = True Mario.vy = -7 #Mario.y = i.y - 17 Mario.y -= 1 i.timer -= 1 else: if i.enemy == 'goomba': image(i.imagedie,i.x,i.y,16,16) if i.timer == 0: Enemy.instances.remove(i) i.timer -= 1 elif i.enemy == 'koopa': Enemy(i.x,i.y,0,0,[[shell,invis],[shell,invis]],[[shell,invis],[shell,invis]],None,'shell',-1) Enemy.instances.remove(i) elif i.enemy == 'shell': image(shell,i.x,i.y,16,16) i.timer = 30 if i.vx == 0: i.collide = 2 if Mario.x <= i.x+8: i.vx = 5 else: i.vx = -5 else: i.collide = -1 i.vx = 0 if Mario.collideBottom() and Mario.vy > -1: Mario.vy = 0 Mario.tags['jumping'] = False while Mario.collideBottom(): Mario.y -= 1 Mario.y += 1 Mario.x += Mario.vx Mario.y += Mario.vy if Mario.iframes: Mario.iframes -= 1 k = Mario.collideHorizontal() if k: Mario.vx = 0 if k == "right": Mario.x = (float(int(Mario.x/16)))*16-0.01 if k == "left": Mario.x = (float(int((Mario.x)/16+1)))*16+0.01 fill(0xffff0000) if Mario.power == "small": if Mario.tags['jumping'] == True: if Mario.tags['facing'] == 'left': Mario.bottom = leftJump else: Mario.bottom = rightJump else: if Mario.vx > 0 and LEFT in keys or Mario.vx < 0 and RIGHT in keys: if Mario.tags['facing'] == 'left': Mario.bottom = leftTurn else: Mario.bottom = rightTurn else: if Mario.vx == 0: Mario.animBot = 0 if Mario.tags['facing'] == 'left': Mario.bottom = leftIdle else: Mario.bottom = rightIdle else: Mario.animBot += float(abs(hone(Mario.vx,0,0.01)))/10 if Mario.animBot >= 3: Mario.animBot %= 3 if Mario.tags['facing'] == 'left': Mario.bottom = smallLeftRun[int(Mario.animBot)] else: Mario.bottom = smallRightRun[int(Mario.animBot)] size = 0 if float(Mario.iframes) / 4.0 == int(Mario.iframes / 4) or float(Mario.iframes) / 4.0 + 1.0 == int(Mario.iframes / 4): image(Mario.bottom,Mario.x,Mario.y,16,16) else: size = 16 if Mario.tags['jumping'] == True: if Mario.tags['facing'] == 'left': Mario.bottom = bigmar['left']['bottom']['jump'] Mario.top = bigmar['left']['top']['jump'] else: Mario.bottom = bigmar['right']['bottom']['jump'] Mario.top = bigmar['right']['top']['jump'] else: if Mario.vx > 0 and LEFT in keys or Mario.vx < 0 and RIGHT in keys: if Mario.tags['facing'] == 'left': Mario.bottom = bigmar['left']['bottom']['turn'] Mario.top = bigmar['left']['top']['turn'] else: Mario.bottom = bigmar['right']['bottom']['turn'] Mario.top = bigmar['right']['top']['turn'] else: if Mario.vx == 0: Mario.animBot = 0 if Mario.tags['facing'] == 'left': Mario.bottom = bigmar['left']['bottom']['idle'] Mario.top = bigmar['left']['top']['idle'] else: Mario.bottom = bigmar['right']['bottom']['idle'] Mario.top = bigmar['right']['top']['idle'] else: Mario.animBot += float(abs(hone(Mario.vx,0,0.01)))/10 Mario.animTop += float(abs(hone(Mario.vx,0,0.01)))/10 if Mario.animBot >= 3: Mario.animBot %= 3 if Mario.animTop >= 3: Mario.animTop %= 3 if Mario.tags['facing'] == 'left': Mario.bottom = bigmar['left']['bottom']['run'][int(Mario.animBot)] Mario.top = bigmar['left']['top']['run'][int(Mario.animTop)] else: Mario.bottom = bigmar['right']['bottom']['run'][int(Mario.animBot)] Mario.top = bigmar['right']['top']['run'][int(Mario.animTop)] if float(Mario.iframes) / 4.0 == int(Mario.iframes / 4) or float(Mario.iframes) / 4.0 + 1.0 == int(Mario.iframes / 4): image(Mario.bottom,Mario.x,Mario.y,16,16) image(Mario.top,Mario.x,Mario.y-16,16,16) elif state == 'die': translate(-camera+96,0) deadtimer -= 1 if deadtimer < 0: state = 'gameover' for row in range(len(level)): for col in range(18): current = level[row][int(camera/16)+col-6] if current == ' ': continue if current not in enemies: image(tile[current],(float(int(camera/16))+col-6)*16,row*16,16,16) for i in Entity.instances: i.y += i.vy i.x += i.vx i.vy += 1 pushMatrix() translate(i.x,i.y) if i.rot != 0: #translate(16,16) rotate(PI) image(i.image,0,0,16,16) if i.image2 != None: image(i.image2,0,-16,16,16) popMatrix() if i.vy == i.tvy and not i.desp: if i.image == itembl: level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + '.' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] elif i.image == bricks: level[int((i.y-1)/16)+1] = level[int((i.y-1)/16)+1][:int((i.x+8)/16)] + 'b' + level[int((i.y-1)/16)+1][int((i.x+8)/16)+1:] Entity.instances.remove(i) if i.desp and i.y > 240: Entity.instances.remove(i) for i in Enemy.instances: if i.timer == 30: if i.vx < 0: image(i.imagel[int(i.anim)][0],i.x,i.y,16,16) image(i.imagel[int(i.anim)][1],i.x,i.y-16,16,16) else: image(i.imager[int(i.anim)][0],i.x,i.y,16,16) image(i.imager[int(i.anim)][1],i.x,i.y-16,16,16) else: if i.enemy == 'goomba': image(i.imagedie,i.x,i.y,16,16) elif i.enemy == 'shell': image(shell,i.x,i.y,16,16) elif state == 'power': translate(-camera+96,0) anim -= 1 if anim < 0: state = 'play' for row in range(len(level)): for col in range(18): current = level[row][int(camera/16)+col-6] if current == ' ': continue if current not in enemies: image(tile[current],(float(int(camera/16))+col-6)*16,row*16,16,16) for i in Entity.instances: pushMatrix() translate(i.x,i.y) if i.rot != 0: #translate(16,16) rotate(PI) image(i.image,0,0,16,16) if i.image2 != None: image(i.image2,0,-16,16,16) popMatrix() for i in Enemy.instances: if i.timer == 30: if i.vx < 0: image(i.imagel[int(i.anim)][0],i.x,i.y,16,16) image(i.imagel[int(i.anim)][1],i.x,i.y-16,16,16) else: image(i.imager[int(i.anim)][0],i.x,i.y,16,16) image(i.imager[int(i.anim)][1],i.x,i.y-16,16,16) else: if i.enemy == 'goomba': image(i.imagedie,i.x,i.y,16,16) elif i.enemy == 'shell': image(shell,i.x,i.y,16,16) if Mario.power == 'big': Mario.bottom = tobig[Mario.tags['facing']][int(anim/4)][0] Mario.top = tobig[Mario.tags['facing']][int(anim/4)][1] image(Mario.bottom,Mario.x,Mario.y,16,16) image(Mario.top,Mario.x,Mario.y-16,16,16) elif state == 'gameover': background(0xff000000) imageMode(CENTER) image(gameover,128,120,70,70) run()
soupmario.py
( around 753 lines python code )
Published By:
luyfru
Published on
2023-09-21T19:12:50Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here