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 ghosts = [] goodguys = [] ch = { 'x': width/2, 'y': height/2, 'width': 30, 'height':30 } score = 0 game_over = False def setup(): global ghostImg, crosshairImg, goodGuyImg size(width, height) ghostImg = loadImage( "http://livbeccs.oyosite.com/piskelspritebad.png") crosshairImg = loadImage( "http://sabrinaw.oyosite.com/crosshair.png") goodGuyImg = loadImage( "http://livbeccs.oyosite.com/piskelspritegood.png") for i in range(15): g = { 'x': randint(50, 450), 'y': randint(50, 500), 'width': 60, 'height': 60, 'x_vel': 2, 'y_vel': randint(-3, 3) } ghosts.append(g) for i in range(5): gg = { 'x': randint(50, 450), 'y': randint(50, 500), 'width': 60, 'height': 60, 'x_vel': 2, 'y_vel': randint(-3, 3) } goodguys.append(gg) def draw(): background(150, 0, 80) 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: fill(0, 225, 0) textSize(40) text("You win!", 225, 30) exitp() if game_over: fill(0, 225, 0) 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'] = width - 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'] = width - 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 + 50 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()
shooterGame.py
( around 124 lines python code )
Published By:
livbeccs46
Published on
2017-07-20T17:40:38Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here