GameWorkshop Pres 2

15
Object Oriented Programming and Games

Transcript of GameWorkshop Pres 2

Page 1: GameWorkshop Pres 2

Object Oriented Programming and Games

Page 2: GameWorkshop Pres 2

Building a ProjectThe building blocks of your game.

Variables Functions Conditions

These store data. These do actions.These perform checks and comparisons between variables and facilitate actions.

Page 3: GameWorkshop Pres 2

An Actionscript game is made up of several files with code in them.

These individual files in a program are called Classes. Classes make up the basic structure of every unique item in a game.

Building a ProjectClasses in code are a big deal.

Classes are made up of variables, functions, and conditions which are all put together to provide a purpose.

Classes are like mini programs.

We create classes to define unique objects in our code.

Page 4: GameWorkshop Pres 2

PackagesIn Actionscript 3 we use something called a Package.A package is a collection of classes.A game can be made from multiple or one package

Building a ProjectThe building blocks of your game.

Page 5: GameWorkshop Pres 2

Building a ProjectThe building blocks of your game.

Page 6: GameWorkshop Pres 2

This is Object Oriented ProgrammingObject oriented is how you will create your games.

Page 7: GameWorkshop Pres 2

• You have modular code that you can reuse.

• Because we kept our code in different classes, its modular and reusable.

This is Object Oriented ProgrammingWhat’s the benefit?

Page 8: GameWorkshop Pres 2

A game is made of:- Variables- Functions- Conditions- Classes- Package(s)

Lets apply this to a game model.

Building a gameUsing code structures to make something cool.

Page 9: GameWorkshop Pres 2

Applying the conceptsHow these coding terms fit into a game.

BrickBreaker - Classic and a good place to start

Page 10: GameWorkshop Pres 2

Applying the conceptsHow these coding terms fit into a game.

“We create classes for every unique object in our code.”

What are the unique objects in BrickBreaker?

What would the classes be?

Page 11: GameWorkshop Pres 2

Applying the conceptsHow these coding terms fit into a game.

What are the unique objects?

- Ball

- Paddle (Player)

- Bricks

- The stage we play on

All of these will need to be built as separate classes.

Page 12: GameWorkshop Pres 2

What attributes and actions do each class have?

Ball Stage- Graphics - Collision Detection- Speed - Keeping track of objects on stage- Bounce - Updating movement

Paddle Bricks- Graphics - Graphics- Speed - Knowing when they are hit

Applying the conceptsHow these coding terms fit into a game.

Page 13: GameWorkshop Pres 2

• The attributes will be comes the variables in each class, and the actions will become the functions.

Applying the conceptsHow these coding terms fit into a game.

Page 14: GameWorkshop Pres 2

• It was mentioned before that object oriented programming is reusable.

• If we built the classes to make brickbreaker, we could easily use those same classes to make Pong without rewriting an entire program.

• What would we change?- The ball class would be the same- The orientation of the paddles

would change- The bounds of the stage would be

different

Modular code = happinessThe benefit of Object Oriented.

Page 15: GameWorkshop Pres 2

BrickBreaker!

So lets make a game.