Skip to content
This repository was archived by the owner on Aug 24, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

from pygame.math import Vector2
from pygame import Rect
import pygame

from block import KineticBlock


class Ball:
"""
base class for bouncing objects
Expand Down
21 changes: 21 additions & 0 deletions src/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,25 @@ class KineticBlock(Block):
# KineticBall will handle the collison
pass

class Paddle(KineticBlock):

MOVE = 3 #Pixel per frame

def update(self, **kwargs):
left = kwargs["left"]
right = kwargs["right"]

if left:
self.position.x -= self.MOVE

if right:
self.position.x += self.MOVE

self.rectangle = pygame.Rect(
self.position.x - (self.rectangle.width/2),
self.position.y - (self.rectangle.height/2),
self.rectangle.width,
self.rectangle.height,
)


41 changes: 36 additions & 5 deletions src/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
from ball import *
from block import *

SCREEN_SIZE = [640, 480]
BACKGROUND_COLOR = [255, 255, 255]
SCREEN_SIZE = [400, 800]
BACKGROUND_COLOR = [0, 0, 0]

BLOCK_WIDTH = 55
BLOCK_HEIGHT = 25
TOTAL_BLOCK = 6
BLOCK_POSITION = [53,60]
BLOCK_ROW = 5
BLOCK_COLUMN = 6
BLOCK_SPACING = 5

PADDLE_WIDTH = 100
PADDLE_HEIGHT = 30
PADDLE_POSITION = [200, 700]

def debug_create_objects(object_list):
kinetic = GameBall(1, object_list, SCREEN_SIZE,
Expand All @@ -16,8 +28,27 @@ def debug_create_objects(object_list):
[255, 10, 0], 20)
object_list.append(kinetic)

block = KineticBlock(Vector2(200,200), 100, 100, [0, 0, 255])
object_list.append(block)
# block = KineticBlock(Vector2(200,200), 100, 100, [0, 0, 255])
# object_list.append(block)

#Create Blocks
x = BLOCK_POSITION[0]
y = BLOCK_POSITION[1]

for i in range(BLOCK_ROW):
for j in range(BLOCK_COLUMN):
rand_color = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
block = KineticBlock(Vector2(x, y), BLOCK_WIDTH, BLOCK_HEIGHT, rand_color)

object_list.append(block)
x += BLOCK_WIDTH + BLOCK_SPACING
x = BLOCK_POSITION[0]
y += BLOCK_HEIGHT + BLOCK_SPACING

#Create Paddle
paddle = Paddle(Vector2(PADDLE_POSITION), PADDLE_WIDTH, PADDLE_HEIGHT, [255, 255, 255])
object_list.append(paddle)


def main():
pygame.init()
Expand All @@ -44,7 +75,7 @@ def main():
if keys[pygame.K_RIGHT]:
right = True
for object in object_list:
object.update()
object.update(left=left, right=right)
object.check_collision()

# Draw Updates
Expand Down