Example #1
0
    def run(self):
        x = static_bg()
        bricks(x)
        pad = paddle(x)
        bal = ball(x)
        static_bg.print_grid(x)
        chec = True
        while x._lives > 0:

            while (chec):
                chec = pad.imove(x, bal)
                static_bg.print_grid(x)

            pad.move(x)
            over = ball.move(bal, x, pad)
            for i in bal._power:
                powerup.move(i, x, pad, bal)
                powerup.end(i, x, pad, bal)
            static_bg.print_grid(x)
            pad.move(x)
            if over == False:
                x._lives -= 1
                over = True
                pad = paddle(x)
                bal = ball(x)
                chec = True
            time.sleep(0.1)
Example #2
0
    def __init__(self):
        # create the main window
        self.gameSize = sf.Vector2(600, 600)
        self.window = sf.RenderWindow(sf.VideoMode(600, 600), "Pyng")
        self.playerPaddle = playerPaddle(self.gameSize)
        self.computerPaddle = computerPaddle(self.gameSize)
        self.ball = ball(self.gameSize)
        self.paddleSpeed = 400
        self.computerScore = score(25, self.gameSize.y / 3)
        self.playerScore = score(25, 2 * self.gameSize.y / 3)

        try:
            # load a sprite to display
            texture = sf.Texture.from_file("Images/pyngLogo.png")
            self.sprite = sf.Sprite(texture)

            # load music to play
            self.music = sf.Music.from_file("Sounds/ambience_rain_outside.wav")
            self.music.loop = True

        except IOError: exit(1)

        # play the music
        self.music.play()
        self.clock = sf.Clock()
        self.clock.restart()
Example #3
0
    def update(self):
        self.check()
        state = self.updateState()
        reward = 0.0

        if self.termination:
            reward = -1000.0
            if self.lastState is not None:
                self.qlearning.learn(self.lastState, self.lastAction, reward,
                                     state)
            self.lastState = None
            # restart game
            self.ball = ball()
            self.paddle = paddle('qlearning')
            self.termination = False
            return
        if self.hit:
            self.hit = False
            reward = 1000.0
        if self.lastState is not None:
            self.qlearning.learn(self.lastState, self.lastAction, reward,
                                 state)

        state = self.updateState()
        action = self.qlearning.chooseAction(state)
        # action = self.qlearning.chooseActionRandom()
        self.lastState = state
        self.lastAction = action
        self.paddle.update(action)
        self.ball.update()
 def ajout(self):
     if self.nb < 5:
         #selectionne des coordonnée aleatoires pour la balle
         x = randint(taille, hauteur - taille)
         y = randint(taille, largeur - taille)
         #selection d'une couleur aleatoire
         col = choice(color)
         #creation de la balle
         name = self.canvas.create_oval(x,
                                        y,
                                        x + taille,
                                        y + taille,
                                        fill=col)
         ball(name, x, y, col)
         #actualiser l'affichage
         affichage.nb += 1
         self.nb_ball["text"] = ("nombre de balle: {}".format(self.nb))
Example #5
0
File: tool2.py Project: ej0cl6/ciao
def startGame(number):
	global canvas
	global im
	global balls
	global openBall
	global exiting
	global comments
	global isComment
	global commentIndex
	global commentNum
	tkObj = Tk()
	canvas = Canvas(tkObj, width = 1200, height = 400)
	canvas.pack()
	background = ImageTk.PhotoImage(master = canvas,file="../resource/background.jpg")
	canvas.create_image(600,100,image=background)
	x0 = 10
	dx = 2
	image = []
	im = []
	balls = []
	openBall = False
	exiting = False
	isComment = False
	comments = []
	count = 0
	for i in range(number):
		image.append(Image.open("../resource/ball"+str(i)+".png"))
		image[i] = image[i].resize((100,100),Image.BICUBIC)
		im.append(ImageTk.PhotoImage(image[i],master = canvas))
	for i in range(3) :
		image.append(Image.open("../resource/comment"+str(i)+".png"))
		im.append(ImageTk.PhotoImage(image[i+number],master = canvas))
	while True:
		if openBall == True :
			x0 = 10
			y0 = (400/number)*index+50
			balls.append(ball(canvas.create_image(x0,y0,image=im[index])))
			openBall = False
		if isComment == True :
			isComment = False
			y0 = (400/number)*commentIndex+50
			comments.append(comment(canvas.create_image(1000,y0,image=im[number+commentNum])))
		if exiting == True :
			count+=1
		if count == 300 :
			tkObj.destroy()
		goBalls()
		checkComment()
		checkBall()
	tkObj.mainloop()
Example #6
0
def main():
	import os
	from time import sleep
	from random import randint
	plr=player()
	while True:
		fl=0
		plr.checkdeath()
		plr.initpos()
		brd=board()
		don=donkey()
		b1=[ball(don)]
		brd.printboard(plr,don,b1)
		while True:
			plr.checkqueen()
			fl=plr.checkdonkey(don,fl)
			if fl==1:
				break
			fl=plr.checkball(b1,fl)
			if fl==1:
				break
			if randint(0,randint(3,6))==1:
				b1+=[ball(don)]
			plr=player.checkfall(plr,brd,don,b1)
			mv=getchar()
			if mv==' ':
				plr=plr.jump(brd,don,b1)
			else:
				plr=plr.getdir(mv)
				plr=plr.move(plr,brd,0,mv)
			for i in b1:
				i=i.move(brd)
			don=don.move(brd)
			brd.printboard(plr,don,b1)
		if fl==1:
			continue	
Example #7
0
    def __init__(self, strRGB_i, pos_ply1, pos_ply2, reset=0, play=1):

        # Inputs.
        self.strRGB_i = strRGB_i
        self.pos_ply1 = pos_ply1
        self.pos_ply2 = pos_ply2
        self.reset = reset
        self.play = play

        # Outputs.
        self.sound = Signal(2)
        self.channel = Signal(2)
        self.strRGB_o = [
            Signal(11),
            Signal(11),
            Signal(),
            Signal(),
            Signal(),
            Signal(),
            Signal(),
            Signal()
        ]

        # Submodules.
        # Create two vertical players with control signals.
        # We chain the streams RGB.
        self.mod_p0 = player(self.strRGB_i,
                             self.pos_ply1,
                             offset=screen.posX_left)
        self.mod_p1 = player(self.mod_p0.strRGB_o,
                             self.pos_ply2,
                             offset=screen.posX_right)

        # Created dynamic module for game.
        # TODO: 'Reset' and 'Play' Signals.
        self.mod_d0 = dynamicGame(self.reset, self.play, self.pos_ply1,
                                  self.pos_ply2)

        # Create module that draw ball in (x_ball, y_ball) position on a stream RGB.
        self.mod_p2 = ball(self.mod_p1.strRGB_o, self.mod_d0.x_ball,
                           self.mod_d0.y_ball)

        # Create a scoreboard for players goals.
        # TODO: Create behaviour for 'reset' score signal.
        self.mod_p3 = scoreboard(self.mod_p2.strRGB_o, 0,
                                 self.mod_d0.goal_ply1, self.mod_d0.goal_ply2)
Example #8
0
 def __init__(self):
     self.ball = ball()
     self.paddle = paddle('qlearning')
     self.qlearning = qlearning(epsilon=EPSILON, alpha=ALPHA, gamma=GAMMA)
     self.state = (self.ball.x, self.ball.y, self.ball.v_x, self.ball.v_y,
                   self.paddle.y)
     self.lastState = None
     self.lastAction = None
     self.success = 0
     self.score = 0
     self.lose = 0
     self.hit = False
     self.scores = []
     self.round = 0
     self.termination = False
     self.finish = False
     self.x = [0]
     self.y = [0]
Example #9
0
blok4 = block(400, 360)
blok5 = block(380, 360)
blok6 = block(360, 360)
blok7 = block(400, 340)
blok8 = block(380, 340)
blok9 = block(360, 340)
#add blocks to list of blocks
blocks.extend((blok, blok2, blok3, blok4, blok5, blok6, blok7, blok8, blok9))
while (True):
    #for first iteration, set up game screen
    if begin:
        surface.fill(white)
        pygame.draw.line(surface, black, [0, 400], [500, 400], 1)
        for contents in blocks:
            contents.draw(surface)
        ba = ball(20, 392)
        ba.draw(surface)
        score = text("Score: " + str(points))
        score.draw(surface)
        begin = False
    surface.fill(white)
    pygame.draw.line(surface, black, [0, 400], [500, 400], 1)
    #loop through blocks list and draw them
    for contents in blocks:
        contents.draw(surface)
    for event in pygame.event.get():
        if (event.type
                == pygame.QUIT) or (event.type == pygame.KEYDOWN
                                    and event.__dict__['key'] == pygame.K_q):
            pygame.quit()
            exit()
Example #10
0
    def elaborate(self, platform: Platform) -> Module:
        m = Module()
        
        # Generated VGA stream in a 'sync' domain (16Mhz).
        mod_0 = pxClkGen (16, 50, 'px')         # Use PLL for 50Mhz from 16Mhz and use 'px' domain.
        m.domains.px = mod_0.domain             # Update 'px' domain clock from new module 'mod_0'.
        clk_pin = ClockSignal('sync')           # Get the signal system clock 'sync'.
        m.d.comb += mod_0.clk_pin.eq(clk_pin)   # Assign 'clk_pin' to PLL module 'mod_0'.
        
        # Created new 'frm' domain with 'endframe' clock (72 frames per second).
        clk_frm = Signal()
        m.domains += ClockDomain('frm')
        clk_frm = ClockSignal('frm')

        # Update a counter each 'clk_frm' for dynamic clock.
        counter = Signal(25)
        m.d.frm += counter.eq (counter+1)

        # Created new 'dyn' domain with dynamic clock for an animation objects.
        # Each 2^6 = 64 frames in counter.
        clk_dyn = Signal()
        m.domains += ClockDomain('dyn') 
        clk_dyn = ClockSignal('dyn')
        m.d.comb += clk_dyn.eq (counter[6])

        # Create new module for VGA synchronisms signals.
        mod_1 = syncVGAGen ()

        # We improvise a combinational module to generate the new frame clock.
        m.d.comb += clk_frm.eq ((mod_1.x == 0) & (mod_1.y == 0))

        # Create new module with tennis court in a stream RGB.
        mod_2 = court (mod_1.strVGA)

        # Create two vertical players with control buttons.
        ply1_up   = Signal()
        ply1_down = Signal()
        ply2_up   = Signal()
        ply2_down = Signal()
        ctl_1 = ctlButtons (ply1_up, ply1_down, ply2_up, ply2_down)
        mod_3 = player (mod_2.strRGB_o, ctl_1.pos_ply1, offset= screen.offset_player)
        mod_4 = player (mod_3.strRGB_o, ctl_1.pos_ply2, offset= screen.width-screen.offset_player-screen.width_player)

        # Created dynamic module for game.
        din_1 = dynamicGame (0, 1, ctl_1.pos_ply1, ctl_1.pos_ply2)

        # Create new module with ball in (x,y) position in a stream RGB.
        mod_5 = ball (mod_4.strRGB_o, din_1.x_ball, din_1.y_ball)

        # Create module with sound card.
        snd_1 = soundCard (din_1.sound, din_1.channel)

        # Create a scoreboard for player's goals.
        mod_6 = scoreboard (mod_5.strRGB_o, 0, din_1.goal_ply1, din_1.goal_ply2)

        # Add all submodules.
        m.submodules += [mod_0, mod_1, mod_2, mod_3, mod_4, mod_5, mod_6, din_1, ctl_1, snd_1]

        # Conected signals with externals pins.
        # VGA signals.
        strRGB_o = mod_6.strRGB_o
        m.d.comb += platform.request ("pin_13").o.eq(strRGB_o[st.VS])
        m.d.comb += platform.request ("pin_12").o.eq(strRGB_o[st.HS])
        m.d.comb += platform.request ("pin_11").o.eq(strRGB_o[st.R])
        m.d.comb += platform.request ("pin_10").o.eq(strRGB_o[st.G])
        m.d.comb += platform.request ( "pin_9").o.eq(strRGB_o[st.B])

        # Test LED
        m.d.comb += platform.request("pin_14").o.eq(counter[16])

        # Audio signals.
        m.d.comb += platform.request ("pin_19").o.eq(snd_1.left_ch)
        m.d.comb += platform.request ("pin_20").o.eq(snd_1.right_ch)

        # Control signals.
        m.d.comb += ply1_up.eq   (platform.request ("pin_21"))
        m.d.comb += ply1_down.eq (platform.request ("pin_22"))
        m.d.comb += ply2_up.eq   (platform.request ("pin_23"))
        m.d.comb += ply2_down.eq (platform.request ("pin_24"))

        return m
Example #11
0
 def __init__(self):
     self.ball = ball(0.5, 0.5, 0.005, 0.003)
     self.paddle = paddle(0.4)
     self.state = (0.5, 0.5, 0.005, 0.003, 0.4)  #initial state
     self.q = {}
Example #12
0
import pygame
from player import *
from ball import *

pygame.init()
windowWidth = 600
windowHeight = 400
display = (windowWidth, windowHeight)
gameDisplay = pygame.display.set_mode(display)
pygame.display.set_caption("Pong Maybe?")
clock = pygame.time.Clock()

player1 = player(0, 0, 20, 100, 0, 1)
player2 = player(windowWidth - 20, 100, 20, 100, 0, 2)
ball = ball(200, 200, 10, 10)


def main():
    crashed = False
    timer = 0

    ##########  GAME LOOP  #################
    while not crashed:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                crashed = True

        pygame.display.update()
        clock.tick(60)
        gameDisplay.fill((255, 255, 255))
Example #13
0
def level_1():

    pygame.mixer.music.play(-1)

    Ball = ball(300, 554)

    global gravity
    global speed
    global goal
    goal.x = 480
    goal.y = 40

    element_1 = block(450, 450, 120)
    element_2 = block(250, 350, 120)
    element_3 = block(50, 250, 120)
    element_4 = block(250, 150, 120)

    platforms = [element_1, element_2, element_3, element_4]

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    speed = -7
                elif event.key == pygame.K_RIGHT:
                    speed = 7

                elif event.key == pygame.K_SPACE:
                    Ball.jump()

                elif event.key == pygame.K_p:
                    pause()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
                    speed = 0

        Ball.x += speed

        screen.fill(white)
        screen.blit(home, [goal.x, goal.y])
        Ball.update(gravity)
        Ball.render(screen)

        pygame.draw.rect(screen, green, (0, 570, 600, 30))

        for landing in platforms:
            landing.render(screen)
            if Ball.y < landing.y and Ball.y + 16 > landing.y:
                if Ball.x + 16 > landing.x and Ball.x - 16 < landing.x + landing.width:
                    Ball.y = landing.y - 15
                    Ball.onGround = True
                else:
                    Ball.onGround = False

            elif Ball.y > landing.y and Ball.y - 16 < landing.y + 30:
                if Ball.x + 16 > landing.x and Ball.x - 16 < landing.x + landing.width:
                    Ball.y = landing.y + 47
                    Ball.onGround = False

        if Ball.y + 16 >= 570:
            Ball.y = 554
            Ball.onGround = True

        if Ball.x + 16 > display_width:
            Ball.x = display_width - 16
        elif Ball.x - 16 < 0:
            Ball.x = 16

        if Ball.x > goal.x and Ball.x < goal.x + 80:
            if Ball.y > goal.y and Ball.y < goal.y + 80:
                screen.fill(white)
                message_to_screen("Level 2", green, 0, "medium")
                pygame.display.update()
                pygame.time.delay(1000)
                level_2()
        clock.tick(40)
        pygame.display.update()
Example #14
0
def level_3():
    global gravity
    global speed
    global goal
    goal.x = 260
    goal.y = 40

    Ball = ball(320, 435)

    element_1 = block(50, 320, 60)
    element_2 = block(270, 450, 60)
    element_3 = block(350, 250, 60)

    platforms = [element_1, element_2, element_3]

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    speed = -7
                elif event.key == pygame.K_RIGHT:
                    speed = 7

                elif event.key == pygame.K_SPACE:
                    Ball.jump()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
                    speed = 0

        Ball.x += speed

        screen.fill(white)

        Ball.update(gravity)
        Ball.render(screen)

        pygame.draw.rect(screen, red, (0, 500, 600, 100))
        screen.blit(home, [goal.x, goal.y])

        for landing in platforms:
            landing.render(screen)
            if Ball.y < landing.y and Ball.y + 16 > landing.y:
                if Ball.x + 16 > landing.x and Ball.x - 16 < landing.x + landing.width:
                    Ball.y = landing.y - 15
                    Ball.onGround = True
                else:
                    Ball.onGround = False

            elif Ball.y > landing.y and Ball.y - 16 < landing.y + 30:
                if Ball.x + 16 > landing.x and Ball.x - 16 < landing.x + landing.width:
                    Ball.y = landing.y + 47
                    Ball.onGround = False

        if Ball.x > goal.x and Ball.x < goal.x + 80:
            if Ball.y > goal.y and Ball.y < goal.y + 80:
                screen.fill(blue)
                message_to_screen("Level 4", red, 0, "medium")
                pygame.display.update()
                pygame.time.delay(1000)
                level_4()

        if Ball.y + 15 > 500:
            game_over()

        if Ball.x + 16 > display_width:
            Ball.x = display_width - 16
        elif Ball.x - 16 < 0:
            Ball.x = 16

        clock.tick(40)
        pygame.display.update()
Example #15
0
def level_4():
    global gravity
    global speed
    global goal
    goal.x = 320
    goal.y = 0

    element_1 = block(50, 320, 40)
    element_2 = block(250, 450, 40)
    element_3 = block(540, 250, 40)
    element_4 = block(200, 200, 40)

    Ball = ball(550, 235)

    platforms = [element_1, element_2, element_3, element_4]

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    speed = -7
                elif event.key == pygame.K_RIGHT:
                    speed = 7

                elif event.key == pygame.K_SPACE:
                    Ball.jump()

            if event.type == pygame.KEYUP:
                if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT:
                    speed = 0

        Ball.x += speed

        screen.fill(white)
        screen.blit(home, [goal.x, goal.y])

        Ball.update(gravity)
        Ball.render(screen)

        pygame.draw.rect(screen, red, (0, 470, 600, 100))

        for landing in platforms:
            landing.render(screen)
            if Ball.y < landing.y and Ball.y + 16 > landing.y:
                if Ball.x + 16 > landing.x and Ball.x - 16 < landing.x + landing.width:
                    Ball.y = landing.y - 15
                    Ball.onGround = True
                else:
                    Ball.onGround = False

            elif Ball.y > landing.y and Ball.y - 16 < landing.y + 30:
                if Ball.x + 16 > landing.x and Ball.x - 16 < landing.x + landing.width:
                    Ball.y = landing.y + 47
                    Ball.onGround = False

        if Ball.x > goal.x and Ball.x < goal.x + 80:
            if Ball.y > goal.y and Ball.y < goal.y + 80:
                you_win()

        if Ball.y > 470:
            game_over()

        if Ball.x + 16 > display_width:
            Ball.x = display_width - 16
        elif Ball.x - 16 < 0:
            Ball.x = 16

        clock.tick(40)
        pygame.display.update()
Example #16
0
PADHEIGHT = 100.0

FPS = 60

#hole infos ueber die derzeitige displaykonfiguration
dinfo = pygame.display.Info()

#mache einen neuen Bildschirm in vollbild
screen = pygame.display.set_mode((dinfo.current_w, dinfo.current_h),
                                 FULLSCREEN | HWSURFACE, dinfo.bitsize)
#screen = pygame.display.set_mode(( 800, 600),HWSURFACE,dinfo.bitsize);

font = pygame.font.SysFont("arial", 30)

myball = ball(1050, 50, -5, 5)

batleft = bat(20, dinfo.current_h / 2 - PADHEIGHT / 2, 30, PADHEIGHT,
              PLAYER_SPEED, dinfo.current_h)
batright = bat(dinfo.current_w - 50, dinfo.current_h / 2 - PADHEIGHT / 2, 30,
               PADHEIGHT, KI_SPEED, dinfo.current_h)

e_handler = EventHandler()
keys = KeyHandler()
keys.registerKey(K_ESCAPE)
keys.registerKey(K_UP)
keys.registerKey(K_DOWN)

clock = pygame.time.Clock()

speed = GAMESPEED
Example #17
0
from levels import *
from paddle import *
from ball import *
from savescore import *
from graphicsload import *
pygame.init()                                                                   #initializing pygame

pygame.font.init()

font = pygame.font.SysFont("Impact", 150)
score_font = pygame.font.SysFont("Impact", 40)
clock = pygame.time.Clock()                                                     #setting the clock
window_height, window_width = 600, 1000                                         #setting the window
window = pygame.display.set_mode((window_width,window_height))
pygame.display.set_caption("BreakOut!")
real_ball = ball(window,12,(200,45,45))
real_paddle = paddle()
load_level(level_one)
win = False
lose = False
level_number = 1
fall_speed = level_number / 60
start = True
start_animation_number = 0
start_counter = 0
player_score = 0
view_scores = False
player_name = ("","")
game_over = False
player_lives = 3
elapsed_time = 0
Example #18
0
getfile=inputfile+'H2_save.txt'  
H2 = pickle.load( open(getfile, "rb" ) ) 
getfile=inputfile+'FZ_save.txt'  
FZ = pickle.load( open(getfile, "rb" ) )
getfile=inputfile+'K_save.txt'  
K = pickle.load( open(getfile, "rb" ) )
# 

#L=[['y1','y1'], ['x3','X2'],['x1','z1']]
#L1=[['a'],['b'],['c']]
#L2=[['y1','y1'], ['Y1','y2'],['Y2','Y1']]
#Kgrs=K.subgp_gens # not used at present - the generators for K in normal form 

#set the radius R
R=5# radius of ball to generate
S,T,B,B_nf=ball(R,Kgens,F1,F2,Hrank,H1,H2,logfile,verbose)

#w=B_nf[0][0]
#print(w)
if verbose[10]>0:
    ball_save=testfile+'ball_save.txt'
    pickle.dump(B_nf, open(ball_save, "wb" ))
#
if verbose[-1]>0:
    i=0
    with open(outputfile, "a") as out: #write to outputfile 
        for b in B:
            j=0
            out.write("list B: "+str(i)+"\n") 
            for w in b:
                out.write(" j "+str(j)+": "+str(w)+"\n")
Example #19
0
File: GUI.py Project: prai05/ProFun
import tkinter
from tkinter import *
from ball import *

root = tkinter.Tk()
root.title('Example')
canvas = tkinter.Canvas(root, width=600, height=400, bg='white')
canvas.grid(row=0, column=0)
canvas.create_line([0, 0, 600, 400], width=2, fill='blue')

# ball class
canvas.create_oval(0, 0, 120, 120, fill='red')

ball_2 = ball(canvas, 10, 10, 30, 30, 'blue')
ball_1 = ball(canvas, 100, 100, 180, 180, 'green')

root.mainloop()