コード例 #1
0
def main():
    global FPSCLOCK, DISPLAYSURF, BASICFONT, BIGFONT
    pygame.init()
    print "in main"
    FPSCLOCK = pygame.time.Clock()
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    DISPLAYSURF.fill((255,255,255))
    BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
    BIGFONT = pygame.font.Font('freesansbold.ttf', 100)
    pygame.display.set_caption('Cotton Candy')
    initBoardArr()
    renderScreen()
    while True: # game loop
        runGame()
        showTextScreen('Game Over')
コード例 #2
0
ファイル: game.py プロジェクト: Spenca/eduhacks2017
    def __init__(self):
        self.controls = {
            "up": False,
            "down": False,
            "left": False,
            "right": False
        }
        Game.game = self

        pygame.init()
        pygame.mixer.music.load("assets/music/420.wav")
        pygame.mixer.music.play(loops=-1, start=0.0)
        self.clock = pygame.time.Clock()

        self.display = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))

        self.font = pygame.font.Font("assets/fonts/unifont-10.0.06.ttf",
                                     TEXT_HEIGHT)
        self.world = World()
        self.player = Player()

        self.generate_asteroids()
        self.connect_to_server()
コード例 #3
0
def setup():
    pygame.init()
    
    screen = pygame.display.set_mode((500, 500))
    pygame.display.set_caption('Blocky')
    pygame.mouse.set_visible(1)
    
    #Create The Backgound
    bg_col= (0,99,0) #colour of background see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Colors/Color_picker_tool
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill(bg_col)
    
    #set up machinery for writing to background
    font = pygame.font.Font(None, 24)
    text = font.render('Take Blocky on an adventure with wasd', 1, (10, 10, 10))
    textpos = text.get_rect(centerx=background.get_width()/2)
    background.blit(text, textpos)
        
    #create surface for block
    block_size=50
    block_col=(247,243,7)
    global x_pos
    global y_pos
    x_pos=background.get_width()/2 -0.5*block_size
    y_pos=background.get_height()/2 -0.5*block_size
    
    blocksurface = pygame.Surface((block_size,block_size))   
    pygame.draw.rect(blocksurface, (block_col), (0,0,block_size,block_size)) # rect: (x1, y1, width, height)
    
    #paint background and block on screen
    screen.blit(background, (0,0))     # blit background on screen (overwriting all)
    screen.blit(blocksurface, (x_pos,y_pos))
    

    return screen, background, blocksurface
コード例 #4
0
ファイル: maze.py プロジェクト: LeweyM/python-maze
import pyjsdl as pygame
from Grid import Grid
from Solver import Solver


pygame.init()

res = 20
size = width, height = 500, 500
speed = [2, 2]
black = 0, 0, 0

screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()

grid = Grid(width, res, screen)
solver = Solver(grid)

crashed = False


def run():
    global grid, solver, crashed
    screen.fill((0, 0, 0))
    grid.update()
    if grid.finished():
        solver.update()
        solver.show_visited_nodes()

        if solver.finished:
            solver.show_trail()
#buttons
throwball=pygame.image.load('throwballbutton.png')
THROWBALL=pygame.transform.scale(throwball, (300, 50))
nextround=pygame.image.load('nextroundbutton.png')
NEXTROUND=pygame.transform.scale(nextround, (300, 50))

throwball_clicked=pygame.image.load('throwballbutton_clicked.png')
THROWBALL_CLICKED=pygame.transform.scale(throwball_clicked, (300, 50))
nextround_clicked=pygame.image.load('nextroundbutton_clicked.png')
NEXTROUND_CLICKED=pygame.transform.scale(nextround_clicked, (300, 50))

randnums=random.sample(xrange(0,10),10)

#initialize game
pygame.init()

#fonts and text
myfont=pygame.font.Font(None,30)
ballsleft_label="Balls left"
round_label=myfont.render("Round",1,WHITE)
points_label=myfont.render("Points",1,WHITE)
endfont=pygame.font.Font(None, 70)
GAMEOVER=endfont.render("Game Over", True, WHITE)

def createButton(button,x,y,width, height, mousePos):
	clicked=False 
	DISPLAYSURF.blit(button,(x,y))
	click=pygame.mouse.get_pressed()
	if click[0]==1:
		if x+width>mousePos[0]>x and y+height>mousePos[1]>y:
コード例 #6
0
        rowsRect = (199, 48, 18, 19)
        colsRect = (199, 83, 18, 19)
        # the number displayed in the Mines box can be 1-4 digits long, while the others have to be 2, so it gets special treatment
        minesRect = minesText.get_rect()
        minesRect.__setattr__('right', 217)
        minesRect.__setattr__('top', 118)

        screen.blit(rowsText, rowsRect)
        screen.blit(colsText, colsRect)
        screen.blit(minesText, minesRect)

        pg.display.flip()


pg.init()
clock = None
timer = None
bottomBarFont = None
screen = None
Game = None
menu = None


def run():
    global timer, Game, screen, gameOver, menu
    ms = clock.tick_busy_loop(30)  # milliseconds since last tick
    for event in pg.event.get():
        if event.type == pg.MOUSEBUTTONUP:
            x, y = pg.mouse.get_pos()
            row, col = y // Game.TILESIZE, x // Game.TILESIZE
コード例 #7
0
# import pygame;
import pyjsdl as pygame
from settings import Settings;
from background import Background;
import game_functions as gf;
from pygame.sprite import Group, groupcollide
from zombie import Zombie;
from square import Square;
from plant_icon import Plant_Icon;
import time;

pyjsdl.display.setup(run, images)
pygame.init();
game_settings = Settings();
screen = pygame.display.set_mode(game_settings.screen_size);
pygame.display.set_caption("DC PvZ clone");
background = Background(game_settings);
peashooter_icon = Plant_Icon(game_settings,'peashooter-icon.png',1);
gatling_icon = Plant_Icon(game_settings,'gatling-icon.png',2);
sunflower_icon = Plant_Icon(game_settings,'sunflower.png',3);
icons = [peashooter_icon,gatling_icon,sunflower_icon];

# All our groups
zombies = Group();
plants = Group();
squares = Group();
bullets = Group()

# Load up squares with our vars
for i in range(0,5):
	for j in range(0,9):