Skip to content
This repository has been archived by the owner on Aug 24, 2018. It is now read-only.

Kelly Manahan #90

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pygame = "*"

[dev-packages]

[requires]
python_version = "3.6"
46 changes: 46 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 31 additions & 2 deletions src/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ class Block:
Base class for square or rectangular object
"""

def __init__(self, position, width, height, color):
def __init__(self, bounds, position, width, height, color):
# Create a rectangle centered around the x and y
self.bounds = bounds
self.position = position
self.rectangle = pygame.Rect(
position.x - (width/2),
Expand All @@ -18,7 +19,7 @@ def __init__(self, position, width, height, color):
height)
self.color = color
self.touched_by_ball = False


def update(self, **kwargs):
self.touched_by_ball = False
Expand All @@ -35,3 +36,31 @@ class KineticBlock(Block):
pass


class Paddle(KeneticBlock):
SPEED = 3

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

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

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

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

class Breakable(KineticBlock):
def __init__ (self, object_list, bounds, position, width, height, color)
self.object_list = object_list
super().__init__(bounds, posotion,width height, color)

def update(self, **kwargs):
if self.touched_by_ball:
self.object_list.remove(self)
17 changes: 11 additions & 6 deletions src/draw.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pygame #TODO: Fix intellisense
import pygame
import random

from pygame.math import Vector2

from ball import *
from block import *

SCREEN_SIZE = [640, 480]
SCREEN_SIZE = [400, 650]
BACKGROUND_COLOR = [255, 255, 255]

def debug_create_objects(object_list):
Expand All @@ -16,9 +16,14 @@ 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)

for i in range(10): #fix
block = Breakable(object_list, SCREEN_SIZE,
Vector2( i * STANDARD_BLOCK_SIZE + STANDARD_BLOCK_SIZE/2)
j * STANDARD_BLOCK_SIZE * STANDARD_BLOCK_SIZE/2),
STANDARD_BLOCK_SIZE, STANDARD_BLOCK_SIZE, [20*j, 0]

paddle = Paddle(SCREEN_SIZE, Vctor2(200, 750), 100, 25, [128, 128, 128])
object_list.append(paddle)
def main():
pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE)
Expand All @@ -44,7 +49,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