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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ venv.bak/

# mypy
.mypy_cache/

# Mac specific
.DS_Store

# VS Code specific
.vscode/
31 changes: 31 additions & 0 deletions src/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,35 @@ class KineticBlock(Block):
# KineticBall will handle the collison
pass

class PaddleBlock(KineticBlock):

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

if left:
self.position.x -= 10

if right:
self.position.x += 10

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

class MultipleBounceBlock(KineticBlock):
# This block will chage colors each time the ball touch it
# And will disappear after 4th hit
pass




class SingleBounceBlock(KineticBlock):
# This block will disappear after the ball touch it
def update(self, **kwargs):
if self.touched_by_ball:
self.object_list.remove(self)
26 changes: 20 additions & 6 deletions src/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,34 @@

from ball import *
from block import *
# from paddle 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(10*random.random() - 2, 10*random.random() - 2),
Vector2(8, 8),
[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):
singleBounceBlock = SingleBounceBlock(Vector2(40*i,400), 39, 39, [0, 0, 255])
object_list.append(singleBounceBlock)

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

paddle = PaddleBlock(Vector2(200,700), 100, 30, [255, 0, 0])
object_list.append(paddle)

multipleBounceBlock = MultipleBounceBlock(Vector2(200,300), 50, 50, [0, 0, 255])
object_list.append(multipleBounceBlock)



def main():
pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE)
Expand All @@ -44,7 +58,7 @@ def main():
if keys[pygame.K_RIGHT]:
right = True
for object in object_list:
object.update()
object.update(left = left, right = right) # move paddle
object.check_collision()

# Draw Updates
Expand Down