Skip to content
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
Binary file added .DS_Store
Binary file not shown.
Binary file added BlueTank.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 NewBackground.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions ProjectProposal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
What is the main idea of your project? What topics will you explore and what will you generate? What is your minimum viable product? What is a stretch goal?
- We will make a tank game based on wii tanks. Our MVP will be a 2 player PVP. A stretch goal is to add an AI.
What are your learning goals for this project (for each member)?

- Alex: getting better at using class and object, also make readable code

- Ricky: Get better at debugging, making more readable and modular code, and getting better with classes and objects.

What libraries are you planning to use? (if you don’t know enough yet, please outline how you will decide this question during the beginning phase of the project).
- Pygame and whatever else we need.
What do you plan to accomplish by the mid-project check-in? (See below for some generic goals; edit to suit your particular project)

- We plan to have a tank that can move (stretch: shooting projectiles?)

What do you view as the biggest risks to you being successful on this project?

- Ususlly time is the biggest factor in completing projects like this.
Binary file added RedTank.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 SoftdesMP4WriteUp.pdf
Binary file not shown.
13 changes: 13 additions & 0 deletions SoftdesMP4WriteUptxt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Abstract:
Alex and I made a collaborative tank game in which two players work to clear a map of blue squares. We got our idea from a mini-game within Wii Play called “tanks” and many other areal view tank games.
Results:
We mad the game as modular as possible so we could go from our “MVP” to as advanced as we want. Our “MVP” was one tank that was able to move around a screen. We then made a larger background and a second tank and also added rotation. After this, we added the capability for the tanks to fire. Finally we added randomized dots that the tanks were able to clear from the map. This is far from our MVP, but still short of our stretch goal, as the program is not always able to handle two people pressing keys at once.
Implementation:
We began by creating a window and bliting an image of equal size on to it. We next made a “Player” class that creates a sprite from an image and blits it on to the background. Within the player function is an update function that updates the position and rotation of the tank/sprite.
Our next class is “Bullet”, which creates another sprite (this time with a small rectangle), references the player’s position and current angle of rotation and sends the sprite along that angle from that position.
Next, we created a class called “Block” which generates squares at random locations around the field. We later reference this in a separate definition to create sprites that are deleted when they come into contact with our “Bullets”
Finally, we have a class called “Controller” which adds values to the player class, thus moving the player.

Reflection:
In terms of process, we did a good job at organizing the project from the very beginning. We created a Trello and distributed tasks to ourselves. We used a Scrum-like system to show to-do, doing, and done tasks, as well as a backlog for ideas that we could ad if we had time.
Overall this worked well and we scoped our project well. it was very doable and had a lot of room to scale upward, which we did to some degree. Alex and I had some time to pair program but not as much as we anticipated. We also had a lot of work outside of class with QEA and P&M. This made it difficult to balance, especially when some assignments (usually QEA) took longer than anticipated. This gave us less time to work on the project, thus we were not able to implement all of the features that we wanted to.
224 changes: 224 additions & 0 deletions Tank_Cop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import pygame
from pygame.locals import *
from math import *
import time
import random

# Define some colors
WHITE = (255, 255, 255) # have no idea what it does
BLACK = (0, 0, 0) # need to keep
BLUE = (0, 0, 255)
# Call this function so the Pygame library can initialize itself
pygame.init()

# Create an 800x600 sized screen
screen = pygame.display.set_mode([1024,768])

clock = pygame.time.Clock() # I sure this controls the time the game (how faster the puase is at the bottom)

class Player(pygame.sprite.Sprite): # player object right now is confusing do it postion here but not being used
""" Encodes the state of the paddle in the game """
def __init__(self,filename, a, b):
""" Initialize the player and position (x,y) """
super().__init__()


self.angle = 0
self.image = pygame.image.load(filename).convert() #image goes here
self.image.set_colorkey(WHITE)

self.rect = self.image.get_rect()
self.rect.x = a;
self.rect.y = b;

def update(self):# this may work idk yet
""" update the state of the paddle """

self.image_dom = rot_center(self.image, self.angle)

def __str__(self):
return "Player, x=%f, y=%f" % (self.x, self.y)

class Bullet(pygame.sprite.Sprite):
""" This class represents the bullet . """
def __init__(self, angle, x, y):
# Call the parent class (Sprite) constructor
super().__init__()

self.image = pygame.Surface([4, 10])
self.image.fill(WHITE)



self.speed = 5

self.angle = angle

self.rect = self.image.get_rect()

self.rect.x = x
self.rect.y = y

def update(self):
""" Move the bullet. """
self.rect.x += self.speed * cos(radians(-self.angle+3))
self.rect.y += self.speed * sin(radians(-self.angle+3))

class Block(pygame.sprite.Sprite):
""" This class represents the block. """
def __init__(self, color):
# Call the parent class (Sprite) constructor
super().__init__()

self.image = pygame.Surface([20, 15])
self.image.fill(color)

self.rect = self.image.get_rect()

class PyGameKeyboardController(object): #works well a little jumpy maybe use vx
""" Handles keyboard input for brick breaker """
def __init__(self):

self.x = 0
self.y = 0
self.j =0
self.i =0
def handle_event1(self, event, Player):
""" Left and right presses modify the x velocity of the paddle """
#link for event.key https://www.pygame.org/docs/ref/key.html
if event.type != KEYDOWN:
return
if event.key == pygame.K_a:
Player.rect.x += -2
if event.key == pygame.K_d:
Player.rect.x += 2
if event.key == pygame.K_w:
Player.rect.y += -2
if event.key == pygame.K_s:
Player.rect.y += 2
if event.key == pygame.K_q:
Player.angle += 1 %360
if event.key == pygame.K_e:
Player.angle += -1 %360
if event.key == pygame.K_2:
self.i +=1

def handle_event2(self, event, Player):
""" Left and right presses modify the x velocity of the paddle """
#link for event.key https://www.pygame.org/docs/ref/key.html
if event.type != KEYDOWN:
return
if event.key == pygame.K_j:
Player.rect.x += -2
if event.key == pygame.K_l:
Player.rect.x += 2
if event.key == pygame.K_i:
Player.rect.y += -2
if event.key == pygame.K_k:
Player.rect.y += 2
if event.key == pygame.K_u:
Player.angle += 1 %360
if event.key == pygame.K_o:
Player.angle += -1 %360
if event.key == pygame.K_8:
self.j +=1



# Fuction that rotate image on its center
def rot_center(image, angle):
"""rotate an image while keeping its center and size"""
orig_rect = image.get_rect()
rot_image = pygame.transform.rotate(image, angle)
rot_rect = orig_rect.copy()
rot_rect.center = rot_image.get_rect().center
rot_image = rot_image.subsurface(rot_rect).copy()
return rot_image



all_sprites_list = pygame.sprite.Group()
block_list = pygame.sprite.Group()
bullet_list = pygame.sprite.Group()
# Set positions of graphics
background_position = [0, 0]

# Load and set up graphics only back grond
background_image = pygame.image.load("NewBackground.jpg").convert()

for i in range(100):
# This represents a block
block = Block(BLUE)

# Set a random location for the block 1024,768
block.rect.x = random.randrange(1024)
block.rect.y = random.randrange(768)

# Add the block to the list of objects
block_list.add(block)
all_sprites_list.add(block)



clock = pygame.time.Clock()

score = 0
player1 = Player("BlueTank.png", 0, 0)
player2 = Player("RedTank.png", 100, 100)
#all_sprites_list.add(player)
controller = PyGameKeyboardController()
done = False

while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True


# Copy image to screen:
screen.blit(background_image, background_position)


controller.handle_event1(event,player1)
controller.handle_event2(event,player2)
player1.update()
player2.update()
all_sprites_list.update()

if controller.i > 0:
bullet = Bullet(player1.angle,player1.rect.center[0],player1.rect.center[1])
all_sprites_list.add(bullet)
bullet_list.add(bullet)
controller.i += -1
if controller.j > 0:
bullet = Bullet(player2.angle,player2.rect.center[0],player2.rect.center[1])
all_sprites_list.add(bullet)
bullet_list.add(bullet)
controller.j += -1


screen.blit(player1.image_dom, [player1.rect.x, player1.rect.y])
screen.blit(player2.image_dom, [player2.rect.x, player2.rect.y])
for bullet in bullet_list:

# See if it hit a block
block_hit_list = pygame.sprite.spritecollide(bullet, block_list, True)

# For each block hit, remove the bullet and add to the score
for block in block_hit_list:
bullet_list.remove(bullet)
all_sprites_list.remove(bullet)
score += 1
print(score)

# Remove the bullet if it flies up off the screen
if bullet.rect.y < -10:
bullet_list.remove(bullet)
all_sprites_list.remove(bullet)

all_sprites_list.draw(screen)
pygame.display.flip()

clock.tick(60)

pygame.quit()
12 changes: 12 additions & 0 deletions test/BasicsOfPythonGame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pygame
from pygame.locals import *
pygame.init()
SCREENRECT = Rect(0, 0, 640, 480)
background = [pygame.image.load('GrassBackground.jpg'),pygame.image.load('GrassBackground.jpg')]
screen_width=700
screen_height=400
screen=pygame.display.set_mode([screen_width,screen_height])
for i in range(6):
screen.blit(background[i], (i*1, 0))
playerpos = 3
screen.blit(playerimage, (playerpos*10, 0))
Binary file added test/GrassBackground.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions test/MiniProject4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pygame
#from pygame.locals import *
pygame.init()
screen = create_screen()
player = load_player_image()
background = load_background_image()
screen.blit(background, (0, 0)) #draw the background
position = player.get_rect()
screen.blit(player, position) #draw the player
pygame.display.update() #and show it all
for x in range(100): #animate 100 frames
screen.blit(background, position, position) #erase
position = position.move(2, 0) #move player
screen.blit(player, position) #draw new player
pygame.display.update() #and show it all
pygame.time.delay(100) #stop the program for 1/10 second
Loading