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 math import random p = { 'x':200, 'y':200, 'z':0, 'vx':0, 'vy':0, 'c':0, 'p':-1, 'tx':200, 'ty':200, 'b':0, 'r':0, } b = { 's':0, } keys = [] def setup(): size(400,400,P3D) background(220) frameRate(30) for i in range(120): b['x' + str(i)] = 0 b['y' + str(i)] = 1000 b['z' + str(i)] = -400 def bird(): box(30) def keyPressed(): global keys if keyboard.keyCode not in keys: keys.append(keyboard.keyCode) def keyReleased(): global keys keys.remove(keyboard.keyCode) def collision(): for i in range(120): if math.fabs(p['x'] - b['x' + str(i)]) < 25 and math.fabs(p['y'] - b['y' + str(i)]) < 25 and math.fabs(p['z'] - b['z' + str(i)]) < 25: textSize(50) fill(100,0,0) background(200,100,100) text('GAME OVER', 30, 200) textSize(30) text('score:' + str(p['p']), 30, 250) for i in range(120): b['y' + str(i)] += 1000 p['y'] += 0 exitp() def score(): if math.fabs(p['tx'] - p['x']) < 25 and math.fabs(p['ty'] - p['y']) < 25: p['p'] += 1 p['b'] = 55 if random.randint(1,2) == 1: p['tx'] = random.randint(p['x'] + 100, p['x'] + 300) else: p['tx'] = random.randint(p['x'] + 100, p['x'] + 300) - 400 if random.randint(1,2) == 1: p['ty'] = random.randint(p['y'] + 100, p['y'] + 300) else: p['ty'] = random.randint(p['y'] + 100, p['y'] + 300) - 400 def draw(): if UP in keys: p['vy'] += -2 if DOWN in keys: p['vy'] += 2 if LEFT in keys: p['vx'] += -2 if RIGHT in keys: p['vx'] += 2 background(120 + p['b'],120 + p['b'], 120) if p['b'] > 0: p['b'] -= 5 score() text('x:' + str(p['x']) + ' target:' + str(p['tx']), 10, 10) text('y:' + str(p['y']) + ' target:' + str(p['ty']), 10, 30) text('points:' + str(p['p']), 10, 50) collision() fill(20*(math.fabs(p['vx']) + math.fabs(p['vy'])),0,0) camera(p['x'], p['y'], p['z']+200, p['x'], p['y'], p['z'], 0, 1, 0) pushMatrix() translate(p['x'], p['y'], p['z']) box(20) p['x'] += p['vx'] p['y'] += p['vy'] if p['vx'] > 0: p['vx'] -= 1 if p['vx'] < 0: p['vx'] += 1 if p['vy'] > 0: p['vy'] -= 1 if p['vy'] < 0: p['vy'] += 1 if p['vx'] < -12 or p['vx'] > 12: p['vx'] *= -1 if p['vy'] < -12 or p['vy'] > 12: p['vy'] *= -1 popMatrix() beginShape() vertex(p['x'],p['y'],0) vertex(p['tx'],p['ty'],0) endShape() pushMatrix() translate(p['tx'],p['ty'],0) noFill() stroke(255,255,0) tint(0.5) rotateY(p['r']) sphere(20) p['r'] += 1 if p['r'] > 359: p['r'] = 0 popMatrix() stroke(0) fill(200) if p['c'] == 0: b['x' + str(b['s'])] = random.randint(-300,300) + p['x'] b['y' + str(b['s'])] = random.randint(-300,300) + p['y'] b['z' + str(b['s'])] = -400 p['c'] = 1 b['s'] += 1 if b['s'] > 119: b['s'] = 0 p['c'] -= 1 for i in range(120): pushMatrix() translate(b['x' + str(i)],b['y' + str(i)],b['z' + str(i)],) bird() popMatrix() b['z' + str(i)] += 7 run()
flying2.py
( around 132 lines python code )
Published By:
luyfru
Published on
2023-09-21T19:09:44Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here