Está en la página 1de 18

Chapter 5

Collision Theory and Logic


Part 1

Students will understand computer logic


and scripting languages used in video
game development
4

I can design a playable video game with sound and music


effects and animation by applying object oriented
programming and computer scripting languages

I can construct a playable video game using computer logic


and scripting language

I can develop basic programming logic statements to test


conditions and determine actions based on these statements

I can define basic computer logic and list features of object


oriented programming
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Objectives
Use game design software to create a playable
video game.
Integrate animated objects into a video game.
Create sound and music effects in a video game.
Describe basic computer logic.
Build applied mathematics logic statements.
List features of object-oriented programming.

Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic
The first concept of designing and
programming a video game is an action
reaction relationship
Programmers use logic statements to
break down these actionreaction
relationships
To begin the programming process
You will need to understand the five basic
operators of a programming language: IF,
THEN, AND, OR, and ELSE
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic continued

IF Action / condition
Then- Reaction
AND allows for multiple events to occur
OR allows for multiple results
ELSE (T/F) (otherwise) what will happen if a
certain action or reaction does not take place

Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Basic Logic Statement


A logic statement tests a condition and
determines an action based on the result
An IFTHEN statement is the most basic
example of a logic statement
When programming a video game, the
formal term for an action is a condition
The operator IF is used with the basic
statement to test a condition

This is the action side of the logic statement


Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Basic Logic Statement


The operator THEN is used with the basic
statement to describe what should happen

This is the reaction side of the logic statement

The reaction side of the logic statement


describes what should happen when the
condition is met
An event is a change that occurs when a
condition is met
IF ACTION (if an action occurs)
THEN REACTION (a reaction takes place)
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued)
Cause and Effect

Action/reaction relationship
Action (cause)
Reaction (effect)
Shows everyday cause and-effect relationships for some everyday
occurrences
OPERATOR

CAUSE

OPERATOR

EFFECT

IF

YOUR TURN IN
HOMEWORK

THEN

YOU GET A
GOOD GRADE

IF

YOU BUY A TICKET

THEN

YOU WATCH A
MOVIE

IF

YOU MISS THE BUS

THEN

YOU ARE LATE


TO SCHOOL

Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Basic Logic Statement


When programming a video game the
formal term for an action condition

Computer checks to see if a condition is


met

When it finds a condition has been met


It executes the programmed events

An event is a change that occurs when a


condition is met
**it is a reaction to the condition**
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued)
Programming for the user interface uses listeners
and triggers
A listener is programming that directs the
computer to check or listen for a mouse click,
key press, or other input from the user
A trigger is programming for when a condition
is met that a series of actions will begin
In a logic statement, the trigger is the IF and the
actions it initiates are the THEN

Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued)

Goodheart-Willcox Publisher
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued)
The next step in basic programming is to add
multiple actions or multiple reactions to logic
statements
This is done using the AND and OR
operators
The AND operator will join two or more
outcomes for a given condition or action
The OR operator allows multiple results to
take place under a given condition or event
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued) AND operator


IF the dart object collides with the
balloon object
THEN destroy the balloon object
AND create an explosion animation
object
AND add 100 points to the players
score

(the AND operator allows three events to occur from a single collision action)
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued) OR operator


IF the dart object collides with the balloon object
OR
IF the dart object collides with a deflating balloon
animation object
THEN destroy the small balloon object
AND destroy the deflating balloon animation
AND create explosion animation
AND add 500 points to the players score
(the OR operator allows multiple results to take
place under a given condition or event)
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued)
The ELSE operator describes what will
happen if a certain action or reaction does
not take place
The ELSE operator works like a true/false
test
If the condition is true, the THEN events
are initiated
If the condition is false, the ELSE events
are initiated
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Logic (Continued) ELSE operator


IF player has gold > = 100
AND
IF player has Key = 1
THEN display the message Well done, You
may pass level 2,
ELSE display the message You need 100 gold
and the key to pass
(the ELSE works like a true/false test)
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Collision Theory
Collision Theory

deals with an object running into or hitting another object

When objects collide in a game, the movements,


animations, and events must provide an illusion of
reality
Interactivity is how one object behaves when it
encounters another object
A collision statement must exist for each object the
player touches for interaction

When programming a game, the fact that an object looks


like a wall does not make it act like a wall
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

Programming with Collision


Theory (Continued)

Goodheart-Willcox Publisher
Goodheart-Willcox Co., Inc.

Permission granted to reproduce for educational use only.

También podría gustarte