Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 8 commits into
base: feedback
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.REPL.enableREPLSmartSend": false
}
107 changes: 92 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,126 @@
[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-718a45dd9cf7e7f842a935f5ebbe5719a5e09af4491e668f4dbf3b35d5cca122.svg)](https://classroom.github.com/online_ide?assignment_repo_id=14588388&assignment_repo_type=AssignmentRepo)

:warning: Everything between << >> needs to be replaced (remove << >> after replacing)

# << Project Title >>
## CS110 Final Project << Semester, Year >>
# "Dreamcatcher"
# Course Number: 110

## CS110 Final Project Spring, 2024

## Team Members

<< List team member names >>
Caitlin Bullock and Anya Wester

***

## Project Description

<< Give an overview of your project >>
A game where you count the stars in the sky before time runs out

***

## GUI Design

### Initial Design

![initial gui](assets/gui.jpg)
![Alt text](assets/InitialGUIDesign.png)

### Final Design

![final gui](assets/finalgui.jpg)
![final gui](assets/finalGUIDesign.png)

## Program Design

### Features

1. << Feature 1 >>
2. << Feature 2 >>
3. << Feature 3 >>
4. << Feature 4 >>
5. << Feature 5 >>
1. Timer
2. Controlled player
3. Randomly placed stars
4. Clicker feature
5. Ending statement

### Classes

- << You should have a list of each of your classes with a description >>
class Player(pygame.sprite.Sprite):
def __init__(self, width=800, height=600):


"""
Description: Initalizes the player
args:
-pygame.sprite.spite arguement is being used as a base class for this "Class Player"
- width and height argument is used to set the parameter for the player movement of the box
return: None
"""
super().__init__()
self.WHITE = (255, 255, 255)
self.image = pygame.Surface((50, 50))
self.image.fill(self.WHITE)
self.rect = self.image.get_rect()
self.rect.centerx = width // 2
self.rect.bottom = height - 10
self.speedx = 0

def update(self, width=800, height=600):

"""
inserts the specficed function to the dictioary with the new added items in this function
args: self, width=800, height=600
return: None
"""

self.speedx = 0
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
self.speedx = -5
if keys[pygame.K_RIGHT]:
self.speedx = 5
self.rect.x += self.speedx
if self.rect.right > width:
self.rect.right = width
if self.rect.left < 0:
self.rect.left = 0


class Star(pygame.sprite.Sprite):
def __init__(self, width=800, height=600):

"""
description: intializes the yellow "stars" (the boxes)
args: self, and width=800
return: None
"""
super().__init__()
self.WHITE = (255, 255, 255)
self.YELLOW = (255, 255, 0)
self.image = pygame.Surface((30, 30))
self.image.fill(self.YELLOW)
self.rect = self.image.get_rect()
self.rect.x = random.randint(0, width - self.rect.width)
self.rect.y = random.randint(-100, -40)
self.speedy = random.randint(3, 7)

def update(self, width=800, height=600):

"""
descritption: it resets the position of the stars and handles the different speed of the stars
args: self, width = 800, and height=600
return: None
"""

self.rect.y += self.speedy
if self.rect.top > height:
self.rect.y = random.randint(-100, -40)
self.rect.x = random.randint(0, width - self.rect.width)
self.speedy = random.randint(3, 7)


## ATP

| Step |Procedure |Expected Results |
|----------------------|:--------------------:|----------------------------------:|
| 1 | Run Counter Program |GUI window appears with count = 0 |
| 2 | click count button | display changes to count = 1 |
etc...
| 1 | Start game |GUI window appears immediately. The timer starts immediately and stars start to fall |
| 2 | Click left and right arrow keys| The white box moves left and right|
| 3 | Collect yellow "stars" | The counter in the top left goes up by 1 each time a yellow star touches the white box|
| 4| The timer runs out (after 30 seconds)| Statement appears on the screen saying you won if you collected more than 60 stars. If not, you lose|
|5| Screen closes | When Q key is pressed, the application closes|
Binary file added assets/InitialGUIDesign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/finalGUIDesign.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/gui.jpg
Binary file not shown.
13 changes: 0 additions & 13 deletions main.py

This file was deleted.

175 changes: 175 additions & 0 deletions src/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import pygame
import sys
import star
import player

class Controller:
def __init__(self, width=800, height=600):

"""
descrption: initalizes the game screen
args: self, width=800, and height= 600
return=None
"""
pygame.init()
self.width = width
self.height = height
self.screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("DreamCatcher")
self.clock = pygame.time.Clock()
self.font = pygame.font.SysFont(None, 36)
self.WHITE = (255, 255, 255)
self.BLACK = (0, 0, 0)
self.YELLOW = (255, 255, 0)
self.score = 0
self.game_over = False
self.start_time = pygame.time.get_ticks()
self.play_time = 30
self.player = player.Player(self.width, self.height)
self.stars = pygame.sprite.Group()
for _ in range(10):
stars = star.Star(self.width, self.height)
self.stars.add(stars)

def end_menu(self, score):

"""
descrption: displays end menu where it says if you won the game and you can press Q for quit
Args: self, score
return: None
"""

self.screen.fill(self.BLACK)
game_over_text = self.font.render("GAME OVER", True, self.WHITE)
result_text = self.font.render("You Win!" if score > 60 else "You Lose!", True, self.WHITE)
instruction_text = self.font.render("Press Q to quit", True, self.WHITE)
self.screen.blit(game_over_text, (self.width // 2 - game_over_text.get_width() // 2, self.height // 3))
self.screen.blit(result_text, (self.width // 2 - result_text.get_width() // 2, self.height // 2))
self.screen.blit(instruction_text, (self.width // 2 - instruction_text.get_width() // 2, self.height // 2 + 50))
pygame.display.flip()

waiting = True
while waiting:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
pygame.quit()
sys.exit()

def main_game(self):

"""
descrption: runs a loop of where the stars fall down from the sky at different speeds
args: self
return=None
"""

all_sprites = pygame.sprite.Group()
stars = pygame.sprite.Group()

playerOne = player.Player()
all_sprites.add(playerOne)

for _ in range(10):
starObject = star.Star()
all_sprites.add(starObject)
stars.add(starObject)

score = 0
start_time = pygame.time.get_ticks()
game_over = False

while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

all_sprites.update()


hits = pygame.sprite.spritecollide(playerOne, stars, True)
for hit in hits:
score += 1
starHit = star.Star()
all_sprites.add(starHit)
stars.add(starHit)


self.screen.fill("BLACK")
all_sprites.draw(self.screen)


score_text = self.font.render("Score: " + str(score), True, "WHITE")
self.screen.blit(score_text, (10, 10))


current_time = pygame.time.get_ticks()
time_left = max(0, 30 - (current_time - start_time) // 1000)
timer_text = self.font.render("Time: " + str(time_left), True, "WHITE")
self.screen.blit(timer_text, (self.width - 120, 10))

if time_left == 0:
game_over = True

pygame.display.flip()
pygame.time.Clock().tick(60)
self.end_menu(score)





def game_over_loop(self,width=800, height=600):

"""
descrption: this allows for the game over screen to be on display for a duration amount of time, allows the user to exit out of the game using the alloted keys illustrated
args: self, width=800 and height=600 of the screen
return: None
"""
self.WHITE = (255, 255, 255)
self.BLACK = (0, 0, 0)
self.YELLOW = (255, 255, 0)
self.screen.fill(self.BLACK)
self.screen.blit(self.game_over_text, (width // 2 - self.game_over_text.get_width() // 2, height // 2 - 50))
pygame.display.flip()

pygame.time.delay(3000)
pygame.quit()
sys.exit()
pass

def update(self):
"""
this displays the score of the player and also it updates the system by redisplaying the screen
args: self
return: None
"""
self.player.update(self.width, self.height)
self.stars.update(self.width, self.height)

hits = pygame.sprite.spritecollide(self.player, self.stars, True)
for self.hit in hits:
self.score += 1
new_star = star.Star(self.width, self.height)
self.stars.add(new_star)

current_time = pygame.time.get_ticks()
elapsed_time = (current_time - self.start_time) // 1000
remaining_time = max(self.play_time - elapsed_time, 0)
if self.score == 10:
self.game_over = True
if self.score > 60:
self.game_over_text = self.font.render("GAME OVER. You Win!", True, self.WHITE)
else:
self.game_over_text = self.font.render("GAME OVER. You Lose!", True, self.WHITE)







11 changes: 11 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pygame
import controller


def main():
pygame.init()
game = controller.Controller()
game.main_game()
if __name__ == '__main__':
main()

Loading