diff --git a/src/Pipfile b/src/Pipfile new file mode 100644 index 0000000..b9ba84f --- /dev/null +++ b/src/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/src/ball.py b/src/ball.py index 20e2792..ec28718 100644 --- a/src/ball.py +++ b/src/ball.py @@ -1,8 +1,10 @@ import math +import time from pygame.math import Vector2 from pygame import Rect + from block import KineticBlock class Ball: @@ -32,9 +34,17 @@ def update(self, **kwargs): if self.position.y <= 0 + self.radius: # screen height self.position.y = self.radius + 1 self.velocity.y *= -1 + print("top") + print("Ball has touched the top. The program will now quit in 3 seconds") + time.sleep(3) + pygame.quit() if self.position.y >= self.bounds[1] - self.radius: self.position.y = self.bounds[1] - self.radius - 1 self.velocity.y *= -1 + print("Ball has touched the bottom. The program will now quit in 3 seconds") + time.sleep(3) + pygame.quit() + self.position += self.velocity self.collision_rectangle = self.update_rectangle() @@ -57,7 +67,6 @@ def __init__(self, mass, object_list, bounds, position, velocity, color, radius) super().__init__(bounds, position, velocity, color, radius) def collide_with_ball(self, object, relative_vector): - #TODO: Calculate the correct position and move there directly while relative_vector.length() <= self.radius + object.radius: self.position += relative_vector.normalize() diff --git a/src/block.py b/src/block.py index f7966e2..07aeab9 100644 --- a/src/block.py +++ b/src/block.py @@ -32,6 +32,22 @@ def draw(self, screen, pygame): class KineticBlock(Block): # No custom code needed here, just want to be able to differentiate # KineticBall will handle the collison + + pass + +class Paddle(KineticBlock): + def __init__(self, position, width, height, color): + super().__init__(position, width, height, color) + + def move(self): + keys = pygame.key.get_pressed() + print("update") + self.position.x += 1 + + #super().update() pass + + + diff --git a/src/draw.py b/src/draw.py index 14ff036..0f62945 100644 --- a/src/draw.py +++ b/src/draw.py @@ -6,18 +6,34 @@ from ball import * from block import * -SCREEN_SIZE = [640, 480] +SCREEN_SIZE = [400, 800] BACKGROUND_COLOR = [255, 255, 255] def debug_create_objects(object_list): kinetic = GameBall(1, object_list, SCREEN_SIZE, Vector2(random.randint(20, SCREEN_SIZE[0] - 20), random.randint(20, SCREEN_SIZE[1] - 20)), - Vector2(4*random.random() - 2, 4*random.random() - 2), + Vector2(1*random.random() - 6, 1*random.random() - 6), [255, 10, 0], 20) object_list.append(kinetic) - block = KineticBlock(Vector2(200,200), 100, 100, [0, 0, 255]) - object_list.append(block) + #position, width, height, color + block1 = KineticBlock(Vector2(40,50), 75, 50, [0, 0, 255]) + object_list.append(block1) + block2 = KineticBlock(Vector2(120,50), 75, 50, [255, 0, 0]) + object_list.append(block2) + block3 = KineticBlock(Vector2(200,50), 75, 50, [80, 25, 175]) + object_list.append(block3) + block4 = KineticBlock(Vector2(280,50), 75, 50, [43, 255, 1]) + object_list.append(block4) + block5 = KineticBlock(Vector2(360,50), 75, 50, [100, 35, 0]) + object_list.append(block5) + # block6 = KineticBlock(Vector2(490,50), 75, 50, [34, 90, 200]) + # object_list.append(block6) + + paddle = Paddle(Vector2(200,680), 75, 25, [0, 0, 0]) + object_list.append(paddle) + + print(object_list) def main(): pygame.init()