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 * from random import randint width = 550 height = 600 score = 0 goodguys = [] game_over = False ghosts = [] ch = { 'x': width/2, 'y': height/2, 'width':30, 'height':30 } def setup(): global ghostImg, crosshairImg, goodguyImg size(width, height) ghostImg = loadImage ( "http://dragon.oyosite.com/vulture.png") crosshairImg = loadImage( "https://thumbs.dreamstime.com/z/golden-crosshair-icon-d-illustration-48213546.jpg") goodguyImg = loadImage( "http://dragon.oyosite.com/captain_america.png") for i in range(30): g={ 'x':randint(50,450), 'y':randint(50 ,500), 'width': 60, 'height':60, 'x_vel':3, 'y_vel': randint(-3, 3) } ghosts.append(g) for i in range(20): g={ 'x':randint(50,450), 'y':randint(50 ,500), 'width': 60, 'height':60, 'x_vel':3, 'y_vel': randint(-3, 3) } goodguys.append(g) def draw(): background(255 , 0, 0) moveGhosts() for g in ghosts: image(ghostImg, g['x'], g['y'],g['width'],g['height']) for g in goodguys: image(goodguyImg, g['x'], g['y'],g['width'],g['height']) #draw crosshair image(crosshairImg, ch['x'], ch['y'], ch['width'], ch['height']) fill(255 , 255,255) textSize(20) text("Score:" + str(score), 10, 30) if len(ghosts) == 0: textSize(40) text("You win!" , 225, 300) exitp() if game_over: textSize(40) text("You lose!" , 225, 300) exitp() def moveGhosts(): for g in ghosts: g['x'] = g['x'] + g['x_vel'] g['y'] = g['y'] + g['y_vel'] if g['x'] + g['width'] >= width: g['x'] = width - g['width'] g['x_vel'] = -g['x_vel'] elif g['x'] <= 0: g['x'] = 0 g['x_vel'] = -g['x_vel'] if g['y'] + g['height'] >= height: g['y'] = height - g['height'] g['y_vel'] = -g['y_vel'] elif g['y'] <= 0: g['y'] = 0 g['y_vel'] = -g['y_vel'] for g in goodguys: g['x'] = g['x'] + g['x_vel'] g['y'] = g['y'] + g['y_vel'] if g['x'] + g['width'] >= width: g['x'] = width - g['width'] g['x_vel'] = -g['x_vel'] elif g['x'] <= 0: g['x'] = 0 g['x_vel'] = -g['x_vel'] if g['y'] + g['height'] >= height: g['y'] = height - g['height'] g['y_vel'] = -g['y_vel'] elif g['y'] <= 0: g['y'] = 0 g['y_vel'] = -g['y_vel'] def mouseMoved(): mx = mouse.x my = mouse.y ch['x'] = mx - ch['width']/2 ch['y'] = my - ch['height']/2 def mouseClicked(): global score, game_over mx = mouse.x my = mouse.y ghostToRemove = None for i in range(len(ghosts)): g = ghosts[i] if(mx >= g['x'] and mx <= g['x'] + g['width'] and my >= g['y'] and my <= g['y'] + g['height']): ghostToRemove = i break if ghostToRemove is not None: del ghosts[ghostToRemove] score = score + 100 for g in goodguys: if(mx >= g['x'] and mx <= g['x'] + g['width'] and my >= g['y'] and my <= g['y'] + g['height']): game_over = True break run()
shooter.py
( around 120 lines python code )
Published By:
ryu8
Published on
2017-07-20T16:33:48Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here