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

WIP AFaris #85

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pygame = "*"
[dev-packages]

[requires]
python_version = "3.6"
python_version = "3"
4 changes: 2 additions & 2 deletions Pipfile.lock

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

3 changes: 3 additions & 0 deletions foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pygame
pygame.init()
pygame.display.list_modes()
20,649 changes: 20,649 additions & 0 deletions get-pip.py

Large diffs are not rendered by default.

Binary file added pygame-1.9.3-cp27-cp27m-win32.whl
Binary file not shown.
Binary file added pygame-1.9.3-cp27-cp27m-win_amd64.whl
Binary file not shown.
Binary file added pygame-1.9.3-cp35-cp35m-win32 (2).whl
Binary file not shown.
Binary file added pygame-1.9.3-cp35-cp35m-win32.whl
Binary file not shown.
Binary file added pygame-1.9.3-cp37-cp37m-win32.whl
Binary file not shown.
Binary file added pygame-1.9.3-cp37-cp37m-win_amd64.whl
Binary file not shown.
119 changes: 80 additions & 39 deletions src/ball.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

from pygame.math import Vector2


class Ball:
"""
base class for bouncing objects
"""

def __init__(self, bounds, position, velocity, color, radius):
self.position = position
self.velocity = velocity
Expand All @@ -15,48 +17,87 @@ def __init__(self, bounds, position, velocity, color, radius):

def update(self):
# bounce at edges. TODO: Fix sticky edges
if self.position.x < 0 + self.radius or self.position.x > self.bounds[0] - self.radius: # screen width
# screen width
if self.position.x < 0 + self.radius or self.position.x > self.bounds[0] - self.radius:
self.velocity.x *= -1
if self.position.y < 0 + self.radius or self.position.y > self.bounds[1] - self.radius: # screen height
# screen height
if self.position.y < 0 + self.radius or self.position.y > self.bounds[1] - self.radius:
self.velocity.y *= -1
self.position += self.velocity

def draw(self, screen, pygame):
# cast x and y to int for drawing
pygame.draw.circle(screen, self.color, [int(self.position.x), int(self.position.y)], self.radius)

# class BouncingBall(???):
# """
# ball effected by gravity
# """
# # TODO:

# class RainbowBall(???):
# """
# Ball that changes colors
# """
# # TODO:

# class BouncingRainbow(???):
# """
# Ball that changes color and is affected by gravity
# """
# # TODO:

# class KineticBall(???):
# """
# A ball that collides with other collidable balls using simple elastic circle collision
# """
# # TODO:

# class KineticBouncing(???):
# """
# A ball that collides with other collidable balls using simple elastic circle collision
# And is affected by gravity
# """


# class AllTheThings(???):
# """
# A ball that does everything!
# """
pygame.draw.circle(screen, self.color, [int(
self.position.x), int(self.position.y)], self.radius)


class RainbowBall(Ball):
"""
ball effected by gravity
"""

def update(self):
super().update()

r = (self.color[0] + 1) % 256
g = (self.color[1] + 2) % 256
b = (self.color[2] + 3) % 256
self.color = [r, g, b]


class BouncingBall(Ball):
"""
Ball that changes colors
"""

def update(self):
self.velocity.y += 0.3
super().update()


class BouncingRainbow(BouncingBall, RainbowBall):
"""
Ball that changes color and is affected by gravity
"""
pass


class KineticBall(Ball):
"""
A ball that collides with other collidable balls using simple elastic circle collision
"""

def __init__(self, object_list, bounds, position, velocity, color, radius):
self.object_list = object_list
super().__init__(bounds, position, velocity, color, radius)

def update(self):
for obj in self.object_list:

if not issubclass(type(obj), KineticBall):
continue

if obj == self:
continue

distance = obj.position.distance_to(self.position)

sumr = self.radius + obj.radius

if distance < sumr:
print("Collision!")


class KineticBouncing(KineticBall, BouncingBall):
"""
A ball that collides with other collidable balls using simple elastic circle collision
And is affected by gravity
"""
pass


class AllTheThings(RainbowBall, KineticBall, BouncingBall):
"""
A ball that does everything!
"""
pass
60 changes: 45 additions & 15 deletions src/draw.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pygame #TODO: Fix intellisense
import pygame # TODO: Fix intellisense
import random

from pygame.math import Vector2
Expand All @@ -9,52 +9,82 @@
SCREEN_SIZE = [640, 480]
BACKGROUND_COLOR = [255, 255, 255]


def debug_create_balls(object_list):
ball = Ball(SCREEN_SIZE, Vector2(50, 50), Vector2(3, 3), [255, 0, 0], 10)
ball = Ball(SCREEN_SIZE, Vector2(50, 50),
Vector2(3, 3), [255, 0, 0], 10)
object_list.append(ball)

ball = RainbowBall(SCREEN_SIZE, Vector2(20, 350),
Vector2(1, 5), [255, 0, 0], 10)
object_list.append(ball)

ball = BouncingBall(SCREEN_SIZE, Vector2(30, 200),
Vector2(5, 5), [0, 255, 0], 10)
object_list.append(ball)

ball = BouncingRainbow(SCREEN_SIZE, Vector2(40, 250),
Vector2(7, 7), [0, 255, 255], 10)
object_list.append(ball)

ball = KineticBall(object_list, SCREEN_SIZE, Vector2(
200, 100), Vector2(2, 0), [0, 255, 255], 30)
object_list.append(ball)

ball = KineticBouncing(object_list, SCREEN_SIZE, Vector2(
300, 400), Vector2(8, 8), [200, 255, 255], 30)
object_list.append(ball)

ball = AllTheThings(object_list, SCREEN_SIZE, Vector2(
200, 100), Vector2(9, 9), [255, 255, 255], 30)
object_list.append(ball)

# TODO: Create other ball types for testing



def debug_create_blocks(object_list):
block = Block(SCREEN_SIZE, Vector2(100,100), 20, 20, [0,255,0])
block = Block(SCREEN_SIZE, Vector2(100, 100), 20, 20, [0, 255, 0])
object_list.extend((block, ))



def main():
pygame.init()
screen = pygame.display.set_mode(SCREEN_SIZE)

# Used to manage how fast the screen updates
clock = pygame.time.Clock()
object_list = [] # list of objects of all types in the toy

object_list = [] # list of objects of all types in the toy

debug_create_balls(object_list)
debug_create_blocks(object_list)
while True: # TODO: Create more elegant condition for loop

while True: # TODO: Create more elegant condition for loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
# Logic Loop
for event in pygame.event.get():
if event.type == pygame.KEYDOWN: #TODO: Get working
if event.type == pygame.KEYDOWN: # TODO: Get working
if event.key == pygame.K_SPACE:
# TODO: Add behavior when button pressed
pass

for ball in object_list:
ball.update()

# Draw Loop
screen.fill(BACKGROUND_COLOR)
for ball in object_list:
ball.draw(screen, pygame)

clock.tick(60)
pygame.display.flip()

# pygame.display.get_caption()

# Close everything down
pygame.quit()



if __name__ == "__main__":
main()