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 * import random def setup(): global letter, flip, rotation, direction, rsymbol, ccsymbol, hsymbol, vsymbol, nosymbol, letterb, letterp, letterq, letterd, keyb, keyp, keyq, keyd, keysmooth, keybcool, keypcool, keyqcool, keydcool, point, time, start, red, menu size(500,500) letter = random.choice(['b','p','q','d']) flip = random.choice(['None','Horizontal','Vertical']) rotation = random.choice([0,0,0,0,0,0,0,0,180,180,180,180,180,180,60,120,-60,-120]) direction = random.choice(['clockwise','clockwise','clockwise','counterclockwise','counterclockwise']) keyb = 400 keyp = 400 keyq = 400 keyd = 400 point = 0 keybcool = 13 keypcool = 13 keyqcool = 13 keydcool = 13 time = 899 start = 4 red = 0 menu = 0 keysmooth = [400,450,440,430,425,420,415,410,407,405,403,402,401,400] rsymbol = loadImage('https://i.ibb.co/yV3S6Sh/Untitled-drawing-5-removebg-preview.png') ccsymbol = loadImage('https://i.ibb.co/dbkyXRp/image-5.png') hsymbol = loadImage('https://i.ibb.co/xF1npK8/image-6.png') vsymbol = loadImage('https://i.ibb.co/qkx9k67/Untitled-drawing-6.png') nosymbol = loadImage('https://oyohub.s3.amazonaws.com/spriteeditor/projects/59ff7bf1ca292c38749df130/bpqdgamesymb-4.png') letterp = loadImage('https://i.ibb.co/sPSTGxq/Untitled-drawing-3.png') letterd = loadImage('https://i.ibb.co/YDJm6s9/Untitled-drawing-1.png') letterq = loadImage('https://i.ibb.co/zrbmDSK/Untitled-drawing-2.png') letterb = loadImage('https://i.ibb.co/tcJc2Sn/Untitled-drawing.png') def keyPressed(): global keybcool, keypcool, keyqcool, keydcool, menu, start if keyboard.key == 'b': keybcool = 1 if start != 4: if letter == 'b': addPoint() else: loseLife() if keyboard.key == 'p': keypcool = 1 if start != 4: if letter == 'p': addPoint() else: loseLife() if keyboard.key == 'q': keyqcool = 1 if start != 4: if letter == 'q': addPoint() else: loseLife() if keyboard.key == 'd': keydcool = 1 if start != 4: if letter == 'd': addPoint() else: loseLife() if start == 4: if keyboard.key == 'b': menu -= 1 if keyboard.key == 'd': menu += 1 if menu == -1: start = 3 if menu == 5: menu = 4 def addPoint(): global point, letter, flip, rotation, time, direction letter = random.choice(['b','p','q','d']) flip = random.choice(['None','Horizontal','Vertical']) rotation = random.choice([0,0,0,0,0,0,0,0,180,180,180,180,180,180,60,120,-60,-120]) direction = random.choice(['clockwise','clockwise','clockwise','counterclockwise','counterclockwise']) point += 1 time = 479 if point < 7: time += (7-point)*60 if point > 14: if point < 20: time += (14-point)*30 else: time -= 180 def loseLife(): global point, letter, flip, rotation, time, start, red, direction letter = random.choice(['b','p','q','d']) flip = random.choice(['None','Horizontal','Vertical']) rotation = random.choice([0,0,0,0,0,0,0,0,180,180,180,180,180,180,60,120,-60,-120]) direction = random.choice(['clockwise','clockwise','clockwise','counterclockwise','counterclockwise']) start -= 1 time = 479 if point < 7: time += (7-point)*60 if point > 14: if point < 20: time += (14-point)*30 else: time -= 180 red = 255 def flipLetter(): if flip == 'Horizontal': if letter == 'b': return 'd' if letter == 'd': return 'b' if letter == 'q': return 'p' if letter == 'p': return 'q' elif flip == 'Vertical': if letter == 'b': return 'p' if letter == 'p': return 'b' if letter == 'q': return 'd' if letter == 'd': return 'q' else: return letter def checkFlip(): if flip == 'Horizontal': return hsymbol elif flip == 'Vertical': return vsymbol else: return nosymbol def checkLetter(a): if a == 'b': return letterb elif a == 'p': return letterp elif a == 'q': return letterq elif a == 'd': return letterd def draw(): global keybcool, keypcool, keyqcool, keydcool, time, red, menu background(200) fill(100) rectMode(CENTER,CENTER) textAlign(CENTER,CENTER) imageMode(CENTER,CENTER) rect(250,175,450,300) fill(70) rect(250,375,450,100) fill(20) rect(250,100,120,120) rect(100,100,120,120) rect(400,100,120,120) rect(250,250,120,120) rect(400,250,120,120) rect(100,250,120,120) if start < 4: time -= 1 pushMatrix() translate(250,100) if direction == 'clockwise': rotate(radians(rotation)) else: rotate(radians(rotation*-1)) image(checkLetter(flipLetter()),0,0,100,100) popMatrix() textSize(30) fill(red,275-red,20) if direction == 'clockwise': image(rsymbol,100,250,100,100) else: image(ccsymbol,100,250,100,100) text(rotation,100,250) text('Points',250,225) text('Time',100,75) text('Lives',400,75) textSize(50) text(point,250,275) text(time/60,100,125) text(start,400,125) image(checkFlip(),400,250,90,90) if start == 4: if menu == 0: fill(red,275-red,20) textSize(30) text('bpqd',250,60) text('game',250,100) textSize(70) text('+',250,135) textSize(35) text('b: play',100,250) text('d: how',400,235) text('to play',400,265) if menu == 1: textSize(25) fill(red,275-red,20) text('Objective:',100,100) text('Identify',250,85) text('the letter',250,115) textSize(20) text('Before time',400,85) text('runs out',400,115) textSize(35) text('b: back',100,250) text('d: next',400,235) text('page',400,265) if menu == 2: textSize(25) fill(red,275-red,20) text('Objective:',100,100) textSize(20) text('You must find',250,85) text('out what the',250,115) text('letter is',400,70) text('after rotation',400,100) text('and flipping',400,130) textSize(35) text('b: back',100,250) text('d: next',400,235) text('page',400,265) if menu == 3: image(rsymbol,250,225,50,50) fill(red,275-red,20) textSize(15) text('0',250,225) textSize(20) text('This symbol',250,275) textSize(25) text('Rotation:',100,100) textSize(20) text('The number',250,55) text('in the symbol',250,85) text('tells how',250,115) text('much',250,145) text('the letter',400,85) text('is rotated',400,115) textSize(35) text('b: back',100,250) text('d: next',400,235) text('page',400,265) if menu == 4: image(hsymbol,220,225,50,50) image(vsymbol,280,225,50,50) fill(red,275-red,20) textSize(20) text('These',250,275) textSize(25) text('Flipping:',100,100) textSize(20) text('The symbol',250,55) text('says if the',250,85) text('letter is',250,115) text('flipped',250,145) text('and in',400,85) text('what way',400,115) textSize(35) text('b: back',100,250) keyb = keysmooth[keybcool] if keybcool > 0: keybcool += 1 if keybcool > 13: keybcool = 13 keyp = keysmooth[keypcool] if keypcool > 0: keypcool += 1 if keypcool > 13: keypcool = 13 keyq = keysmooth[keyqcool] if keyqcool > 0: keyqcool += 1 if keyqcool > 13: keyqcool = 13 keyd = keysmooth[keydcool] if keydcool > 0: keydcool += 1 if keydcool > 13: keydcool = 13 if time < 2: loseLife() if red > 20: red -= 5 if start < 1: background(200) fill(100) rectMode(CENTER,CENTER) textAlign(CENTER,CENTER) imageMode(CENTER,CENTER) rect(250,175,450,300) fill(70) rect(250,375,450,100) fill(20) rect(250,100,120,120) rect(100,100,120,120) rect(400,100,120,120) rect(250,250,120,120) rect(400,250,120,120) rect(100,250,120,120) fill(20,255,20) textSize(30) text('Game',250,85) text('Over',250,115) text('Points',250,225) textSize(50) text(point,250,275) exitp() #keys fill(20) rect(100,400,30,100) rect(200,400,30,100) rect(300,400,30,100) rect(400,400,30,100) fill(150) rect(100,keyb,60,100) rect(200,keyp,60,100) rect(300,keyq,60,100) rect(400,keyd,60,100) fill(100) rect(100,keyb+60,60,20) rect(200,keyp+60,60,20) rect(300,keyq+60,60,20) rect(400,keyd+60,60,20) fill(20) textSize(60) text('b',100,keyb) text('p',200,keyp) text('q',300,keyq) text('d',400,keyd) run()
bpqdgameplus.py
( around 328 lines python code )
Published By:
luyfru
Published on
2024-06-06T23:49:20Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here