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

Usman Javed #83

Open
wants to merge 3 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
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.7"
20 changes: 20 additions & 0 deletions Pipfile.lock

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

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


class Paddle(KineticBlock):
"""
Class for the player paddle
"""
def move_paddle(self, direction):

if direction == "l" and self.position.x > self.width / 2:
self.position.x -= 3
elif direction == "r" and self.position.x < 400 - self.width / 2:
self.position.x += 3
self.rectangle = pygame.Rect(
self.position.x - (self.width / 2),
self.position.y - (self.height / 2),
self.width,
self.height,
)

super().update();

class RowsOfBlock(KineticBlock):
pass


61 changes: 54 additions & 7 deletions src/draw.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pygame #TODO: Fix intellisense
import random
import sys

from pygame.math import Vector2

from ball import *
from block import *
from ball import GameBall
from block import KineticBlock, Paddle, RowsOfBlock

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

def debug_create_objects(object_list):
Expand All @@ -16,9 +17,53 @@ def debug_create_objects(object_list):
[255, 10, 0], 20)
object_list.append(kinetic)

block = KineticBlock(Vector2(200,200), 100, 100, [0, 0, 255])
paddle = Paddle(Vector2(200, 750), 100, 20, [0, 255, 0])
object_list.append(paddle)

block = RowsOfBlock(Vector2(40, 100), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(130, 100), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(220, 100), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(310, 100), 80, 30, [0, 255, 0])
object_list.append(block)


block = RowsOfBlock(Vector2(400, 100), 80, 30, [0, 255, 0])
object_list.append(block)
block = RowsOfBlock(Vector2(40, 60), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(130, 60), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(220, 60), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(310, 60), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(400, 60), 80, 30, [0, 255, 0])
object_list.append(block)
block = RowsOfBlock(Vector2(40, 140), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(130, 140), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(220, 140), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(310, 140), 80, 30, [0, 255, 0])
object_list.append(block)

block = RowsOfBlock(Vector2(400, 140), 80, 30, [0, 255, 0])
object_list.append(block)


def main():
pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE)
Expand All @@ -40,10 +85,12 @@ def main():
#TODO: Feed input variables into update for objects that need it.
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
left = True
direction = "l"
if keys[pygame.K_RIGHT]:
right = True
direction = "r"
for object in object_list:
if isinstance(object, Paddle):
object.move_paddle(direction)
object.update()
object.check_collision()

Expand Down