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

Obo Agboghidi Python pull request #92

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
11 changes: 11 additions & 0 deletions src/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"
11 changes: 10 additions & 1 deletion src/ball.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import math
import time

from pygame.math import Vector2
from pygame import Rect


from block import KineticBlock

class Ball:
Expand Down Expand Up @@ -32,9 +34,17 @@ def update(self, **kwargs):
if self.position.y <= 0 + self.radius: # screen height
self.position.y = self.radius + 1
self.velocity.y *= -1
print("top")
print("Ball has touched the top. The program will now quit in 3 seconds")
time.sleep(3)
pygame.quit()
if self.position.y >= self.bounds[1] - self.radius:
self.position.y = self.bounds[1] - self.radius - 1
self.velocity.y *= -1
print("Ball has touched the bottom. The program will now quit in 3 seconds")
time.sleep(3)
pygame.quit()


self.position += self.velocity
self.collision_rectangle = self.update_rectangle()
Expand All @@ -57,7 +67,6 @@ def __init__(self, mass, object_list, bounds, position, velocity, color, radius)
super().__init__(bounds, position, velocity, color, radius)

def collide_with_ball(self, object, relative_vector):

#TODO: Calculate the correct position and move there directly
while relative_vector.length() <= self.radius + object.radius:
self.position += relative_vector.normalize()
Expand Down
16 changes: 16 additions & 0 deletions src/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ def draw(self, screen, pygame):
class KineticBlock(Block):
# No custom code needed here, just want to be able to differentiate
# KineticBall will handle the collison

pass

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

def move(self):
keys = pygame.key.get_pressed()
print("update")
self.position.x += 1

#super().update()
pass





24 changes: 20 additions & 4 deletions src/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@
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(4*random.random() - 2, 4*random.random() - 2),
Vector2(1*random.random() - 6, 1*random.random() - 6),
[255, 10, 0], 20)
object_list.append(kinetic)

block = KineticBlock(Vector2(200,200), 100, 100, [0, 0, 255])
object_list.append(block)
#position, width, height, color
block1 = KineticBlock(Vector2(40,50), 75, 50, [0, 0, 255])
object_list.append(block1)
block2 = KineticBlock(Vector2(120,50), 75, 50, [255, 0, 0])
object_list.append(block2)
block3 = KineticBlock(Vector2(200,50), 75, 50, [80, 25, 175])
object_list.append(block3)
block4 = KineticBlock(Vector2(280,50), 75, 50, [43, 255, 1])
object_list.append(block4)
block5 = KineticBlock(Vector2(360,50), 75, 50, [100, 35, 0])
object_list.append(block5)
# block6 = KineticBlock(Vector2(490,50), 75, 50, [34, 90, 200])
# object_list.append(block6)

paddle = Paddle(Vector2(200,680), 75, 25, [0, 0, 0])
object_list.append(paddle)

print(object_list)

def main():
pygame.init()
Expand Down