ArbMehmeti / Bubble-Trouble

0 stars 0 forks source link

Ball #2

Open ArbMehmeti opened 6 years ago

ArbMehmeti commented 6 years ago

import pygame

gravity = 5 surface = pygame.display.set_mode((720,480)) class Ball: def init(self,size,x,y,xvel,height): self.size = size self.x = x self.y = y self.xvel = xvel self.yvel = 10 self.height = height

def update(self):

    self.x += self.xvel
    self.y -= self.yvel

    self.yvel += gravity
    if (self.y < self.height):
        self.yvel *= -1

    elif (self.y > 360):
        self.yvel *= -1

def display(self, surface):

    pygame.draw.circle(surface, (0,200,0),(self.x,self.y) ,self.size)

def split(self):
    ball1 = Ball(self.size/2, self.x, self.y, self.xvel, self.height/2)
    ball2 = Ball(self.size/2, self.x, self.y, -self.xvel, self.height/2)
    return [ball1, ball2]

pygame.init() first = Ball(10, 1, 360, 10, 350)

gameDisplay = pygame.display.set_mode((600,800))

pygame.display.set_caption('ballbounce') clock = pygame.time.Clock()

done = False

while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True

first.display(surface)
first.update()

pygame.display.update()
surface.fill((0, 0, 0))
clock.tick(5)

pygame.quit() quit()

ArbMehmeti commented 6 years ago

fixedForNow

import pygame

gravity = 5 surface = pygame.display.set_mode((720,480)) class Ball: def init(self,size,x,y,xvel,height): self.size = size self.x = x self.y = y self.xvel = xvel self.yvel = 20 self.height = height

def update(self):

    self.x += self.xvel
    self.y += self.yvel

    self.yvel -= gravity
    if (self.y < self.height):
        self.yvel += gravity 
        self.yvel *= -1

    elif (self.y > 480):
        self.yvel *= -1

def display(self, surface):

    pygame.draw.circle(surface, (0,200,0),(self.x,self.y) ,self.size)

def split(self):
    ball1 = Ball(self.size/2, self.x, self.y, self.xvel, self.height/2)
    ball2 = Ball(self.size/2, self.x, self.y, -self.xvel, self.height/2)
    return [ball1, ball2]

pygame.init() first = Ball(10, 1, 360, 10, 315)

gameDisplay = pygame.display.set_mode((600,800))

pygame.display.set_caption('ballbounce') clock = pygame.time.Clock()

done = False

while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True

first.display(surface)
first.update()
print(str(first.x) + "," + str(first.y))

pygame.display.update()
surface.fill((0, 0, 0))
clock.tick(5)

pygame.quit() quit()