Sunteți pe pagina 1din 11

DogeBall

Nicholas Diley

TAE ENTERTAINMENT STUDIO

The Creation Of, by Nicholas


Diley

When faced with the task of creating a video game, there are many ideas
that come to mind. When the criteria is limited for parameters of trigonometry, the
options become slightly more limited, however there is still plenty left on the table.
Now we at TAE Entertainment Studios could have easily chosen a simpler game,
such as asteroids or maybe a simple tanks game, however, we decided to go with
not only a simple game, but the simplest in the entire world!
Revamped with the experience that is Doge, the internet sensation of 2014,
we present to the world, DogeBall!

Pong has been a worldwide favorite for a while now, so why not go ahead and
try to remake something that has been already a huge success?

In this step by step guide, I will be going over the production process of
creating a game similar to that of DogeBall, however, it would be much appreciated

if there would be no exact plagiarism of my work! This is strictly for educational


purposes.

Before we begin, these are the features that will be included in our project:

UI for the title screen (User Interface)


Interactive AI
Doge Ball sprite and custom background
Playable up to as many points as you set
Music playing in the background
Collisions set for all walls except the far right and left
Collisions set for the paddles
Trigonometric randomizer for position of the ball
Randomized increase of ball speed amongst a certain interval
Auto exit upon completion with proper winning or losing text

To begin with, there are a few materials that you will need to be able to create
your game. The first being a working version of Python. For this project I used
Python version 2.7.6 as opposed to the newest versions available in 3.3.x and
above. This version has a fully functional version of PyGame available for download
for development or fun purposes, so its readily available to find and use.

The next thing that you will need for this version is the corresponding version of
PyGame installed AFTER you install Python. This will install the libraries into the
proper folders to make proper use of the directories and libraries that exist within
PyGame to be able to actually create your game and run it. Otherwise the game
mechanics and aspects will not be included, but we need them!

Aside from the Python and PyGame versions, you technically dont need any
more, however if you are to follow the steps that will be included within the tutorial,
it is recommended to have pictures and music readily available to import into the
game for entertainment purposes.

Where to begin?
To begin on your project, the first thing to do would be to load up the actual
Python 2.7.6 Shell or the GUI for you to actually be able to write your code. After

installation of Python, you should be able to search within your machine for the
Python GUI, most commonly called IDLE, but it will be located within the proper
Python folder within your computer. After you installed PyGame, you shouldnt need
anything else other than a picture editor to go with creating the game.
Now we can actually move into programming aspects.

Your Python shell should look just like this upon pulling it up. This is where the
general ability to run functions is located at, and however much it is necessary, this
is not where the work will be done at. This window is solely for single line inputs,
which would make creating a game tedious if not impossible so what you need to do
is go to the top, click on file then New File.

You should now have an untitled text box. This is a new file that you will be creating
with Python, and where EVERY bit of the code you write will be located in. Once you
hit save or hit the f5 key to run the program, you will be prompted to save the file
somewhere, I usually put mine on the desktop for easy access, but this is for the
purpose of being able to write the code in an area not limited to single line inputs.
Next would be importing the proper libraries into the system for you to use in
creating your game!

PreProcessor Directives:
import pygame, random, sys
from pygame.locals import *
global wins, comp, main, deaths, KeepGoing, box_x, box_y
pygame.init()
KeepGoing = True
deaths = 0
wins = 0
main = 1
comp = 0

It is very important to import the actual resources that you will be using to create
the game, namely to even use the functionality of the PyGame, you need to import
the files into your program. This is simply done by doing the import pygame
function, and this will be included at the top. Other than that, you will need two
other preprocessor directives, namely random (for random ball place and speed
(The random function generates random integers on a set scale so that you can get
these values in place)), and the sys directive so that you can run the game.
If you are familiar with how python works, you will know that after the preprocessor
directives, you will also have to import different libraries, such as from the pygame
files, you will need to import the general files. This is done with the from
pygame.locals import *. This gets you the directories you need and the files to be
able to run your game later on.
After these directories and files are imported, next would be the declaration of
variables that will be used throughout the game. Such is the variables for the wins,
comp (computer), deaths (losses), KeepGoing (The parameter to see if the
game continues or not), box_x (The size of the window in the x direction), and
box_y (The size of the box in the y direction). Having them set as global variables
allows them to be used throughout the program.
Next up is the initialization of the pygame functionality, which is utilizing the files on
hand imported from the pygame libraries using the pygame.init() function. This is
just included with the variables.
Whether or not you are fluent in the programming language, you need to know that
in order to use variables or certain functions, you need to initialize them with some
sort of value, the most common being set to 0 (zero) or 1 (one), and because they

are global variables, they will be overwritten as necessary to be able to have the
information you need. KeepGoing will be set to True so that the game will know to
run, and everything else will either be set to default at 0 or 1, depending on the
data type (If it is wins or losses, it would make sense to have them set to zero!).

Winning Parameters:
def main_seq():
global main, KeepGoing, winning, deaths, wins

pygame.init()

deaths = 0
wins = 0
color = (200, 200, 150)
display = True

For the winning parameters, we are creating a function named main_seq() for the
understanding of running the game and the parameters for completing or winning/losing the
game. This is set so that we have a base understanding of the mechanics and variables that
are going into the function. Such functions would be the utilization of the global variables
main() (the initialization of the entire program), KeepGoing, winning, deaths and wins,
specifically for the reason of keeping track of a score and defining the parameters for
running the game.

Window Properties:
def check_key():

global box_y, main

keystate = pygame.key.get_pressed()
if box_y > 0:

if keystate[pygame.locals.K_UP]:
box_y -= 5

if box_y < 430:

if keystate[pygame.locals.K_DOWN]:
box_y += 5

if keystate[pygame.locals.K_ESCAPE]:
main = 1

Keycheck is very important in this section as it includes the mouse press option and what
happens when the mouse is pressed within a certain box included on the home menu. This
will include the means of having the Press to Start button and functionality along with
defining the parameters of the box itself, setting the y parameters and the keystate of the
game.

Game Properties:
while display:

keystate = pygame.key.get_pressed()

if keystate[pygame.locals.K_ESCAPE]:
display = False
KeepGoing = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
KeepGoing = False
display = False
winning = False

mouse = pygame.mouse.get_pos()

if mouse[0] >= 220 and mouse[0] <= 545 and mouse[1] >= 200 and mouse[1] <= 250:

if event.type == pygame.MOUSEBUTTONDOWN:
color = (250, 250, 250)
else:
color = (225, 225, 225)

if event.type == MOUSEBUTTONUP:
display = False
main = False
main = 0

else:
color = (200, 200, 200)

bar = pygame.Surface((325, 50))


bar = bar.convert()
bar.fill(color)

screen.blit(background, (0,0))
screen.blit(bar, (180, 200))
screen.blit(label, (200, 220))
pygame.display.flip()

This snippet of code covers movement, the paddles, creating the player controls and the methods of
playing the game. It is as simple as creating the paddle, along with the play area and the sizes of the
paddle in reference to the size of the window. Skipping ahead a little bit, you will find the bar = x
where x is anything form surface, convert and fill. These create the paddles that you will be utilizing
throughout the game, along with filling them in with a base color, and giving it form. Earlier in the code
you will see the definition of the various event types, such as the mouse button down or key press.
These are specific for the inputs you will be putting into your code, such as that of pressing the arrow
keys or whatever you have set as your down or up arrow keys. As such these set the events for what

happens upon when these keys are pressed, and as such should allow movement for the character at a
set pace!

Extras:
pygame.mixer.music.load("C:/Users/Nicholas/Desktop/DogeBallNew/Doge Adventure.mp3")
pygame.mixer.music.play(0)

This little snippet of code is specifically for adding the music function mixer into the game,
useful if you wanted to import your own music. This gets tricky as you want to try and load
the music, as you need to know how to access various folders and directories using a
different syntax, if you have experience doing so its rather easy, just follow the basic
mechanic of which hard drive the music is on, followed by the user, folder (in my case I
stored it on the desktop, it could also be downloads), the folder on the desktop in my case,
then the mp3 file! Its as simple as just including that one line of code, and then you just pull
up the second line of code, the pygame.mixer.music.play(0), and music should be
implemented in the final stages of the game!

Actual Code needed to run the game:


def game():
global deaths, wins, comp, main, KeepGoing

main = 1

while KeepGoing:
if main == 0:

if comp == 0:
deaths += 1
elif comp == 1:
wins += 1

elif main == 1:

main_seq()
winning_game()

if __name__ == "__main__":

game()

pygame.quit()

As with any familiarity that you may have in the developing for python, youd know that the
final step would be finally initializing the game. As such we define our main() function and
tie into it every other piece that we have created so far. We load the various functions
created earlier into main(), specifically the KeepGoing and the game() funcitons. As long as
they were created prior to main(), they should run properly, and under normal
circumstances, the game should work!
Enjoy!

S-ar putea să vă placă și