Exemple #1
0
 def __init__(self, screen, color, fps):
     self.fps = fps
     self.end = False
     self.screen = screen
     self.color = color
     self.info = Surface((1024, 50))
     self.info.fill(color)
     self.ground = load('Resources\images\Sprites\Tiles\\0.png')
     self.pause_bg = load('Resources\images\\bg.png')
     self.pause = load('Resources\images\pause.png')
     self.pause.set_colorkey((179, 179, 179))
     self.bomb_info = load('Resources\images\\bomb.png')
     self.life_info = load('Resources\images\life.png')
     self.power_info = load('Resources\images\power.png')
     self.main_menu = load('Resources\images\Buttons\Main menu.png')
     self.continue_btn = load('Resources\images\Buttons\Continue.png')
     self.pause_text = load('Resources\images\Buttons\Pause.png')
     self.bomb = load('Resources\images\\bomb.png')
     self.lvl = 1
     self.scores = 0
     self.start = 0
     self.lives = 3
     self.max_bombs = 1
     self.strength = 1
     set_visible(False)
     self.load_level()
     self.result = 0
     self.play()
     set_visible(True)
     set_repeat()
Exemple #2
0
 def __init__(self):
     pygame.init()
     set_repeat(20)
     self._keys_down = set([])
     self._keys_up = set([])
     self._user_events = {}
     self._clock = Clock()
    def __init__(self):
        if hasattr(EventManager, "_singleton"): return
        key.set_repeat(DELAY, RATE)
        event.set_allowed(None)
        event.set_allowed([KEYDOWN, JOYBUTTONDOWN, JOYAXISMOTION,
                           JOYBUTTONUP, PLAYER])

        for i in range(joystick.get_count()):
            joystick.Joystick(i).init()

        # Information for joystick repeat.
        self._last_press = [None, None]
        self._last_press_start = [0, 0]
        self._last_press_times = [0, 0]

        # Maps key values to player numbers.
        self.players = { K_w: 0, K_a: 0, K_s: 0, K_d: 0, K_q: 0, K_e: 0,
                         K_i: 1, K_j: 1, K_k: 1, K_l: 1, K_u: 1, K_o: 1,
                         K_LEFT: 0, K_RIGHT: 0, K_UP: 0, K_DOWN: 0,
                         K_SPACE: 0, K_KP_ENTER: 0, K_RETURN: 0, K_2: 1,
                         K_1: 0, K_BACKSPACE: 1 }

        # Maps key values to internal event keys.
        self.events = { K_w: UP, K_a: LEFT, K_s: DOWN, K_d: RIGHT,
                        K_q: ROT_CC, K_e: ROT_CW,
                        K_i: UP, K_j: LEFT, K_k: DOWN, K_l: RIGHT,
                        K_u: ROT_CC, K_o: ROT_CW,
                        K_LEFT: LEFT, K_RIGHT: RIGHT, K_UP: UP, K_DOWN: DOWN,
                        K_SPACE: ROT_CC, K_KP_ENTER: CONFIRM,
                        K_RETURN: CONFIRM, K_2: CONFIRM,
                        K_BACKSPACE: CONFIRM, K_1: CONFIRM }

        Singleton.__init__(self)
Exemple #4
0
def init():
    """base.init () -> None

    Initializes the globally used variables and objects.

    Initializes the globally used variables and objects for the widgets
    package such as a global style and the pygame engine
    """
    global GlobalStyle
    global DoubleClickRate

    GlobalStyle = Style()
    DoubleClickRate = 250

    pygameinit()
    key.set_repeat(500, 30)
Exemple #5
0
def init ():
    """base.init () -> None

    Initializes the globally used variables and objects.

    Initializes the globally used variables and objects for the widgets
    package such as a global style and the pygame engine
    """
    global GlobalStyle
    global DoubleClickRate
    
    GlobalStyle = Style ()
    DoubleClickRate = 250

    pygameinit ()
    key.set_repeat (500, 30)
Exemple #6
0
    def __init__(self):
        self.game = None
        
        pygame.init()

        key.set_repeat(100, 100)

        self.zoom = DisplayOptions('FreeMono.ttf', False, 16, 18)
        
        self.definefont()

        self.makescreen((1400,800))

        display.set_caption(_(u'Hex Grid'))

        self.child = None
        self.done = False
Exemple #7
0
 def game_pause(self):
     set_visible(True)
     set_repeat(0, 0)
     self.screen.blit(self.pause_bg, (0, 0))
     is_paused = True
     start_pause = get_ticks()
     self.hero.ismoved = False
     n = 0
     while is_paused:
         for event in get():
             if event.type == QUIT:
                 exit()
             elif event.type == KEYDOWN:
                 if event.key == K_ESCAPE:
                     n = 0
                     is_paused = False
                 elif event.key == K_UP:
                     n = 0
                 elif event.key == K_DOWN:
                     n = 1
                 elif event.key == 13:
                     is_paused = False
             elif event.type == MOUSEMOTION or event.type == MOUSEBUTTONDOWN and event.button == 1:
                 [x, y] = event.pos
                 if 405 <= x <= 620 and 360 <= y <= 408:
                     n = 0
                     is_paused = event.type == MOUSEMOTION
                 elif 380 <= x <= 650 and 440 <= y <= 486:
                     n = 1
                     is_paused = event.type == MOUSEMOTION
         if not is_paused:
             if n == 1:
                 self.end = True
         self.screen.blit(self.pause, (310, 240))
         self.screen.blit(self.pause_text, (345, 255))
         self.screen.blit(self.continue_btn, (405, 360))
         self.screen.blit(self.main_menu, (380, 440))
         self.screen.blit(self.bomb, (360 - n * 25, 365 + n * 80))
         update()
     set_repeat(1, 1)
     set_visible(False)
     pause_time = get_ticks() - start_pause
     self.hero.update(self.screen, Group(), pause_time)
     self.start = self.start + pause_time
Exemple #8
0
def physics(handle):
    """
    """
    window = display.set_mode(windowSize)
    display.set_caption('Test')
    screen = display.get_surface()
    key.set_repeat(10, 1)
    reportInterval = 10
    reportCounter = 0

    distanceMatrix = matrix(handle)
    particles = map(lambda x: point(), range(distanceMatrix.numberOfParticles))

    while True:
        inp = input(event.get())
        if inp != None:
            for particle in particles:
                particle.impulse(impulseResolution * 0.01 * inp)

        for i in range(distanceMatrix.numberOfParticles):
            for j in range(distanceMatrix.numberOfParticles):
                if i != j:
                    direction = 1
                    temp = torusPosition(particles[i].position,
                                         particles[j].position)
                    if (dist(particles[i].position, temp) <
                            distanceMatrix.distance(i, j)):
                        direction = -1
                    particles[j].impulse(
                        direction * impulseResolution *
                        (particles[i].position - temp) * abs(
                            dist(particles[i].position, temp) -
                            distanceMatrix.distance(i, j)))
                #if

        for particle in particles:
            render(screen, particle)

        if not reportCounter % reportInterval:
            sys.stdout.write(
                "%f\r" % sum(map(lambda x: sum(abs(x.velocity)), particles)))
            sys.stdout.flush()
        #if
        reportCounter += 1
    def play_game(self):
        """ detects pressing the keyboard's arrows,
            calculates new coordinates of MacGyver and moves him
        """
        # movement when an arrow is held down
        key.set_repeat(FAST[0], FAST[1])

        # this loop continues while game_result == 0
        while self.game_result == 0:
            # browses the list of all the events received
            for evt in event.get():

                if evt.type == QUIT:  # if an event is "QUIT"
                    pygame.quit()  # deactivates the Pygame library
                    exit()  # stop the game

                if evt.type == KEYDOWN:
                    self.test_destination_after_keydown(evt.key)

            self.display_maze_game()
Exemple #10
0
    def __init__(self):
        init()
        font.init()
        display.set_caption(TITLE)
        key.set_repeat()

        self.playing = False

        self.screen = display.set_mode((WIDTH, HEIGHT))

        self.clock = time.Clock()
        self.dt = self.clock.tick(FPS) / 1000

        self.labels = list()
        self.infos = list()

        self.all_sprites = Group()

        self.adventure = Home(self)

        self.camera = Camera(self.adventure.map.width, self.adventure.map.height)
        self.score = Score("Renato")

        self.game_over = False
Exemple #11
0
But_path.place((5, 5))
# FIN pathfinding
# FIN
'''
#---------------------Some variables--------------------#
mylaby = laby(5, 5)
mylaby.generate_laby()
perso = Perso(mylaby) 
    
perso_time = 0

liste_b1 = Fonction.liste_bip(WW, WH)
liste_b2 = Fonction.fill_liste_b2(liste_b1)

display.flip()
key.set_repeat(50, 55)
# FIN


if joystick.get_count() > 0:
    Joy = joystick.Joystick(0)
    Joy.init()


while True:
    time.Clock().tick(30)
    Window.fill(const.Porange)    

    for event in handle_widgets():
        if event.type == QUIT:
            quit()
Exemple #12
0
#!/usr/bin/python2
RELEASE = False

from math import pi, cos, sin, hypot
from datetime import datetime
import random, os, sys, json

import pygame
from pygame import draw, display, image, key, font, transform, mouse

pygame.init()
#mouse.set_visible(False)
key.set_repeat(10, 75)

try:
    import android
except ImportError:
    android = None

import particles

if RELEASE:
    modes = display.list_modes()
    VWIDTH, VHEIGHT = modes[0]
else:
    VWIDTH, VHEIGHT = 1080, 960

FPS = 60
TURNS = 10

color_schemes = ["blue", "red", "green", "yellow"]
Exemple #13
0
def main(difficulty):
    #---------------------Pygame init--------------------#

    myfont = font.SysFont("monospace", 15)
    #Création de la fenêtre
    WW, WH = 640, 480
    Window = display.set_mode((WW, WH))

    #icone = image.load("Bipo.png")
    #icone.set_colorkey(const.pink)
    #display.set_icon(icone)
    # FIN

    if difficulty == 0:
        time_limit = 40
    elif difficulty == 1:
        time_limit = 30
    elif difficulty == 2:
        time_limit = 20

    #---------------------Some variables--------------------#
    mylaby = laby(5, 5)
    mylaby.generate_laby()
    perso = Perso(mylaby)

    perso_time = 0
    display.flip()
    key.set_repeat(50, 55)
    # FIN

    first_time = time.time()

    while True:
        current_time = time.time()
        Window.fill(const.Porange)

        time_play = int(current_time - first_time)
        label = myfont.render(str(time_limit - time_play), 1, (0, 0, 0))
        Window.blit(label, (200, 0))

        if time_play >= time_limit:
            return -1

        for event in handle_widgets():
            if event.type == QUIT:
                quit()
                exit()

        pygame.time.wait(50)
        keys = key.get_pressed()
        if keys:
            if keys[K_UP]:
                if not perso.che_jaune:
                    perso.move(const.up)
            if keys[K_DOWN]:
                if not perso.che_jaune:
                    perso.move(const.down)
            if keys[K_LEFT]:
                if not perso.che_jaune:
                    perso.move(const.left)
            if keys[K_RIGHT]:
                if not perso.che_jaune:
                    perso.move(const.right)

        perso.show(Window)
        render_widgets()
        display.flip()

        if perso.x == perso.laby.w - 1 and perso.y == perso.laby.h - 1:
            return 0
Exemple #14
0
	def __init__(self, window):
		key.set_repeat(300, 1000/60)
		self.window = window
		window.autoupdate = False
		window.font = assets.font
Exemple #15
0
def main(difficulty):
    #---------------------Pygame init--------------------#
    init()

    myfont = font.SysFont("monospace", 15)
    #Création de la fenêtre
    WW, WH = 640, 480
    Window = display.set_mode((WW, WH))

    #icone = image.load("Bipo.png")
    #icone.set_colorkey(const.pink)
    #display.set_icon(icone)
    display.set_caption("Bipo Maze")
    # FIN

    if difficulty == 1:
        taille = 10
    elif difficulty == 2:
        taille = 11
    elif difficulty == 3:
        taille = 12


    #---------------------Some variables--------------------#
    mylaby = laby(taille, taille)
    mylaby.generate_laby()
    perso = Perso(mylaby) 
        
    perso_time = 0
    display.flip()
    key.set_repeat(50, 55)
    # FIN


    while True:
        time.Clock().tick(30)
        Window.fill(const.Porange)

        time_play = time.get_ticks()/1000
        label = myfont.render(str(time_play), 1, (0,0,0))
        Window.blit(label, (200, 0))

        for event in handle_widgets():
            if event.type == QUIT:
                quit()
                exit()
            
        keys = key.get_pressed()
        if keys:
            if keys[K_UP]:
                if not perso.che_jaune:
                    perso.move(const.up)
            if keys[K_DOWN]:
                if not perso.che_jaune:
                    perso.move(const.down)
            if keys[K_LEFT]:
                if not perso.che_jaune:
                    perso.move(const.left)
            if keys[K_RIGHT]:
                if not perso.che_jaune:
                    perso.move(const.right)
                   

        perso.show(Window)
        render_widgets()
        display.flip()
        
        if perso.x == perso.laby.w - 1 and perso.y == perso.laby.h - 1:
            quit()
            exit()
Exemple #16
0
import pygame, model
from pygame import key, event

key.set_repeat(20)


def obrabotka_sobitiy():
    # ОБРАБОТКА СОБЫТИЙ
    spisok_sobitiy = event.get()

    for sobitie in spisok_sobitiy:
        if sobitie.type == pygame.KEYDOWN:
            if sobitie.key == pygame.K_a:
                model.plat.x -= 10
            if sobitie.key == pygame.K_d:
                model.plat.x += 10
        if sobitie.type == pygame.QUIT:
            exit()
        if sobitie.type == pygame.MOUSEMOTION:
            pos_x = sobitie.pos[0]
            model.plat.centerx = pos_x
Exemple #17
0
from pygame import image, init, key, transform, font, display, \
    event, time

from maze import *

init()

window = pygame.display.get_surface()
pos_x = (NBR_SPRITE, SPRITE_SIZE)
pos_y = (NBR_SPRITE, SPRITE_SIZE)
HOME = image.load("images/acceuil.png")
BACKGROUND = image.load("images/fond.jpg")

key.set_repeat()
main_loop = True
while main_loop:
    window.blit(transform.scale(HOME, (800, 800)), (0, 0))
    # print text on the screen
    FONT = font.Font(None, 50)
    TEXT_HOME = FONT.render("Press Enter to continue or ECHAP to quit", True, (200, 200, 200))
    window.blit(TEXT_HOME, (50, 400))
    # refersh the screen
    display.flip()
    run_home = True
    run_game = True
    # run_home loop
    while run_home:
        time.Clock().tick(30)
        for e in event.get():
            if e.type == QUIT or e.type == KEYDOWN and e.key == K_ESCAPE:
                main_loop = False
Exemple #18
0
#!/usr/bin/python2
RELEASE = False

from math import pi, cos, sin, hypot
from datetime import datetime
import random, os, sys, json

import pygame
from pygame import draw, display, image, key, font, transform, mouse

pygame.init()
#mouse.set_visible(False)
key.set_repeat(10, 75)

try:
    import android
except ImportError:
    android = None

import particles

if RELEASE:
    modes = display.list_modes()
    VWIDTH, VHEIGHT = modes[0]
else:
    VWIDTH, VHEIGHT = 1080, 960

FPS = 60
TURNS = 10

color_schemes = ["blue", "red", "green", "yellow"]
Exemple #19
0
 def play(self):
     set_repeat(1, 1)
     timer = Clock()
     while not self.end:
         for event in get():
             if event.type == QUIT:
                 exit()
             if event.type == KEYDOWN:
                 k = event.key
                 if k == K_ESCAPE:
                     self.game_pause()
                 if k == K_DOWN:
                     self.hero.rotate(0)
                     self.hero.ismoved = True
                 if k == K_UP:
                     self.hero.rotate(1)
                     self.hero.ismoved = True
                 if k == K_RIGHT:
                     self.hero.rotate(2)
                     self.hero.ismoved = True
                 if k == K_LEFT:
                     self.hero.rotate(3)
                     self.hero.ismoved = True
                 if k == K_SPACE:
                     self.hero.place_bomb(self.sprites_and_bombs)
             elif event.type == KEYUP and event.key != 32:
                 self.hero.ismoved = False
         for m in self.mobs:
             m.strategy()
         self.screen.fill(self.color)
         self.grass.update(self.screen)
         self.bonuses.update(self.screen)
         self.sprites.update(self.screen)
         self.hero.update(self.screen, self.sprites)
         self.mobs.update(self.screen, self.sprites_and_bombs)
         self.show_info()
         update()
         killed = False
         clock = get_ticks()
         for ex in self.hero.explosions:
             if clock + 780 < ex.clear_time:
                 for m in self.mobs:
                     if collide_rect(m, ex):
                         self.scores += 15
                         m.kill()
                 if collide_rect(self.hero, ex):
                     killed = True
         if killed or self.hero.collide(self.mobs):
             self.death()
             if self.end:
                 break
         else:
             for bon in self.bonuses:
                 if bon.visible() and collide_rect(self.hero, bon):
                     if bon.type == 4:
                         self.lives += 1
                     elif bon.type == 5:
                         self.max_bombs += 1
                         self.hero.max_bombs += 1
                     elif bon.type == 6:
                         self.strength += 1
                         self.hero.strength += 1
                     bon.remove(self.bonuses)
                     self.scores += 10
         if len(self.mobs) == 0:
             self.lvl += 1
             self.scores += 20
             self.load_level()
         timer.tick(self.fps)
Exemple #20
0
FF = font.Font("Purisa.otf", 14)
small_FF = font.Font("Purisa.otf", 10)

width_lines = 3
radius = 7
t = 0
w = 4
l1 = 100.0
l2 = 300.0
h = 200
v = 250
v_for_red_point = 250
h_for_red_point = 200
done = True
razgon = False
key.set_repeat(500, 10)
while done:
    for e in event.get():
        if e.type == QUIT:
            done = False
        if e.type == KEYDOWN:
            if e.key == K_UP:
                if l1 > radius*2-1:
                    l1 -= 1
            if e.key == K_DOWN:
                if l1 < 175:
                    l1 += 1
            if e.key == K_LEFT:
                if l2 > radius*2-1:
                    l2 -= 1
            if e.key == K_RIGHT: