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

april martinez #73

Open
wants to merge 5 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\User\\.virtualenvs\\Python-OOP-Toy-fSTVGyeN\\Scripts\\python.exe"
}
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.

56 changes: 56 additions & 0 deletions src/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self, position, width, height, color):


def update(self, **kwargs):
if self.touched_by_ball == True:
print(1)

self.touched_by_ball = False

def check_collision(self):
Expand All @@ -34,4 +37,57 @@ class KineticBlock(Block):
# KineticBall will handle the collison
pass

class Paddle(KineticBlock):
def __init__(self, position, width, height, color):
self.left = False
self.right = False
self.height = height
self.width = width
super().__init__(position, width, height, color)

this is too make blocks
def update(self):
if self.left == True:
self.position.x = (self.position.x - 3) if self.position.x > 30 else 30 #TODO: dynamic min
self.rectangle = pygame.Rect(
self.position.x - (self.width/2),
self.position.y - (self.height/2),
self.width,
self.height)
if self.right == True:
self.position.x = (self.position.x + 3) if self.position.x < 370 else 370 #TODO: dynamic max
self.rectangle = pygame.Rect(
self.position.x - (self.width/2),
self.position.y - (self.height/2),
self.width,
self.height)
self.left = False
self.right = False
super().update()

def move_left(self):
self.left = True

def move_right(self):
self.right = True

class Weak_Block(KineticBlock):
def __init__(self, position, width, height, color):
self.hp = 1
super().__init__(position, width, height, color)

def update(self):
if self.touched_by_ball == True:
print(self.hp)
super().update()


class Strong_Block(KineticBlock):
def __init__(self, position, width, height, color):
self.hp = 3
super().__init__(position, width, height, color)

def update(self):
if self.touched_by_ball == True:
print(self.hp)
super().update()
29 changes: 17 additions & 12 deletions src/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
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(random.randint(20, SCREEN_SIZE[0] - 20), random.randint(300, SCREEN_SIZE[1] - 20)),
Vector2(4*random.random() - 2, 4*random.random() - 2),
[255, 10, 0], 20)
[200, 10, 0], 20)
object_list.append(kinetic)

block = KineticBlock(Vector2(200,200), 100, 100, [0, 0, 255])
object_list.append(block)
paddle = Paddle(Vector2(SCREEN_SIZE[0] // 2, SCREEN_SIZE[1] - 50), 70, 15, [0, 0, 0])
object_list.append(paddle)

for i in range(5):
color = [random.randint(10, 250), random.randint(10, 250), random.randint(10, 250)]
for j in range(3):
block = KineticBlock(Vector2(52 + (i*74),100 + (j* 40)), 70, 30, color)
object_list.append(block)

def main():
pygame.init()
Expand All @@ -31,18 +37,17 @@ def main():
debug_create_objects(object_list)

while True: # TODO: Create more elegant condition for loop
left = False
right = False

for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()

#TODO: Feed input variables into update for objects that need it.
#this is too make the paddle move left to right
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
left = True
object_list[1].move_left()
pass
if keys[pygame.K_RIGHT]:
right = True
object_list[1].move_right()
pass

for object in object_list:
object.update()
object.check_collision()
Expand Down