Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables,...

28
Score, Variables, Conditionals in Game Maker (BrickMania 2 of 2) Foundations of Interactive Game Design Professor Jim Whitehead January 30, 2008 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0

Transcript of Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables,...

Page 1: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Score, Variables, Conditionals in Game Maker (BrickMania 2 of 2)

Foundations of Interactive Game DesignProfessor Jim Whitehead

January 30, 2008

Creative Commons Attribution 3.0

creativecommons.org/licenses/by/3.0

Page 2: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Announcements

www.soe.ucsc.edu/classes/cmps080k/Winter08/Has syllabus, assignment descriptions, exam days, final exam time, link to gamelog

site, links to tool descriptions,

and more…

• Game club announcement► Meet Thursdays, 2:15pm► Conference room A

Go in entrance next to “Express It”

Help for making your Mac dual boot:► Contact Ian Rickard to arrange help time

[email protected]

Page 3: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Game Design Workshops

Game Maker►

Wednesdays (starting today)►

6-8pm►

Engineering 2, room 180 (Simularium)•

Enter on plaza level between E2 and JBE

RPG Maker►

Wednesdays (starting today)►

5-7:15pm►

Engineering 2, room 280•

2nd

floor, on front of building, on driving circle/Communications end (right side, east end) of the building

Arrive by 6pm to avoid external doors locking•

Knock on nearest door to be let in if late…

Page 4: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Game Design Workshops

CS 20/C# and XNA Game Studio Express►

Thursdays, 4:30-7pm►

Engineering 2, room 399 (third floor, by elevators)►

Starts this week

Page 5: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Upcoming Exams and Assignments

Exam #1: Friday, January 26►

Will cover all material in lectures►

Material from readings also fair game, even if not covered in lecture

Will give a list of study questions today►

Closed book, closed note►

Bring pencil/pen►

Arrive early, seating will be tight

Page 6: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Potential Exam Topics

As Univ. of California students, you are expected to be able to assess complex material and make judgments concerning its relative importance.

That said, it can be helpful to have some input from the Professor to help focus studying activity.

The following are questions/material that are likely, but not guaranteed to appear on the exam.

Anything covered in class or in the assigned readings may appear,

even if not explicitly mentioned today.►

Exception: Test will not cover new material covered in today’s class

Page 7: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Potential Exam Topics (2)

Rules, play, culture framework►

Know what each category represents►

Given a game, be able to describe elements of the game that match rules, play, & culture

Difference between games, toys, play►

Given an activity, be able to describe why it is a game, toy, or

play•

Know Abt, Costikyan, and Juul game definitions►

Know both the definitions, as well as differences among them►

Understand all six elements of Juul’s definition

Be able to describe whether an activity is a game according to each definition

Know Huizinga and Caillois definitions of play►

Understand differences between them►

Know six elements of Caillois definition

Page 8: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Potential Exam Topics (3)•

Know the concept of the magic circle

Understand the dichotomy of rules as limitations and rules as affordances►

Know what an affordance is (p. 57-58 of Juul)•

Describe how game rules create the structure of a game

Know the seven aspects (qualities) of rules►

On p. 55-56 of Juul•

Understand the difference between operational, constituative, and implicit rules

Understand the concept of a finite state machine•

Describe the difference between games of emergence and games of progression►

Be able to place a game in one or the other category►

Know the game guide test of progression and emergence (p. 71 Juul)

Page 9: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Potential Exam Topics (4)

Game Maker►

Know difference between Sprite and Object►

Know difference between Event and Action•

Know that events are received by objects, who take action based on them

Know what a Room is, and what it can be used for•

Know that a room contains objects and backgrounds►

Know what a Background is►

Understand the benefit of inheriting behavior from a parent object

CS 20 students are expected to answer Game Maker questions

Page 10: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Potential Exam Topics (5)

Understand difference between gameplay

rules and gameworld

rules

Temporal aspects of games►

Know cardinality of gameplay►

Different types of game exhaustion►

Know concept of segmentation of gameplay•

Also know different kinds of segmentation (challenge, spatial, temporal, narrative)

Should understand that Conway’s game of Life is:► Different from Milton Bradley game of Life► Example of emergent behavior from a simple rule set

Page 11: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

CS 20: Potential Exam Topics

Given an example of C# code, should be able to identify►

Array, property, loop constructs, class definition, method definition, variable definition

Understand meaning of private, protected, public•

Given a simple example of C# code, should be able to provide its output►

Including switch, conditionals, properties, foreach, lists, etc.

Should be able to write simple get and set accessor

code to create a property

Should be able to write a simple foreach

loop•

Know difference between value and reference types

Page 12: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Let’s create a simple Breakout game

Game elements►

Background►

Ball►

Paddle►

Score►

Lives►

3 brick types►

Playfield is smaller than

screen

Page 13: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Score System

Game Maker has a special system for maintaining score►

Can think of it as a global “score”

variable►

Use Set Score on score tab►

Typically with a “relative”

value to add to current score•

Below, if “relative”

not clicked, would reset score to 10, instead of adding 10

Page 14: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Displaying Score & Draw Events

Want to display score in lower left corner•

Game Maker has a “Draw the Value of Score”

action►

But, it can only be used inside a Draw Event•

Draw Event►

Typically, in each step Game Maker draws the sprite for an object on screen

Using a Draw Event, you can specify a different set of drawing commands

Could, for example, draw a halo around your sprite

Draw Event also used for utility drawing behavior•

Such as displaying the high score

Page 15: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Create Game State object

To display the current score, want an object that is invisible►

So its sprite isn’t affected by score drawing►

Create a “game state”

object►

Also useful for holding number of lives

Place in room►

Location doesn’t

matter, is invisible

Draw event

Set color to white (for white on black text)

Draw score in lower left of screen

No sprite -

invisible

Page 16: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Desired Lives Behavior

Player has 3 lives•

When ball goes offscreen

below paddle, need to

subtract one life•

Want a nice display of remaining lives

When there are no more lives, display a game over message

Page 17: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Lives System

Game Maker has a built-in lives system►

Similar to score, a built-in global variable►

Can set number of lives, check number of lives►

Draw a representation of number of lives•

Uses an existing sprite to represent a life•

General idea: hearts representing life in Zelda series

Page 18: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Displaying Lives

Select “Draw Life Images”

and place inside a Draw Event►

Place in Draw Event in Game State object•

Has no sprite, don’t need to worry about effect on object’s normal sprite drawing

Pick sprite to use for life image (small paddle image)

Place in absolute position on screen (upper left)

Page 19: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Set Initial Lives

Need to set the initial number of lives►

Do this in create event on game state object►

We do not want to do this on the paddle object•

Will be destroying paddle object instances when the ball goes offscreen•

Then re-creating paddle for a new ball•

Setting lives in the create event on the paddle would cause the lives to be reset to the starting amount each time a ball was lost

Page 20: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Ball Going Offscreen

When ball goes offscreen

below paddle►

Sound effect►

Decrease lives by one•

If no more lives, display “Game Over”•

Then, press key to restart game►

Visually remove paddle►

Pause game►

Create new paddle►

Create new ball►

Set ball moving

Check for this by putting a conditional (if …

then) in the End Step event►

I.e., check ball’s position every clock tick to ensure is still in-bounds

Page 21: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Variables

Variable►

A named value►

Can be read: look up the value ►

Can be written: change the value to something new

Examples►

The horizontal location of the player in the room is named “x”•

Its value is a number between 0 and the width of the room►

The vertical location of the player in the room is named “y”•

Its value is a number between 0 and the height of the room►

Need names to identify the value we want

Page 22: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Variables (2)

Full disclosure►

There appear to be two kinds of variables►

Variables defined on object instances•

x and y giving player position are defined on the player object instance•

Most of the dialog boxes in Game Maker default to instance variables, so don’t have to worry about this point usually

Global variables•

We’ll see these in a few slides, things like view information•

Seem to be able to access these anywhere

In Game Maker►

Can set the value of a variable using square “Var”

action•

Under “Control”

tab in Object window•

That is, setting a variable is a kind of action–

Set a variable in response to an event

Page 23: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Conditionals

If .. then behavior

Example►

If the player horizontal position is outside the view...►

Then make sure the player stays inside the view

Conditionals in Game Maker are represented by octagon shapes►

Found under “Control”

tab►

Are an action you can take in response to an event•

Often want to check condition all the time►

Place these in the step event►

Step event is called every game tick (1/30th of a second)

Page 24: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Ball Going Offscreen Logic

Play sound, remove paddle, decrease lives, and sleep

Lives < 1 means game over. Create game over message. Destroy ball.

Still have lives. Create new paddle. Move ball to starting position. Make ball move up and diagonally.

Conditional: if y > 480 then…

Page 25: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Control Tab

Page 26: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Conditional Dialog Box

Can check the value of a variable on yourself, or on the other object in a collision, or on any arbitrary object

Choices are:

larger than

equals

less than

Page 27: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should

Missing from the Game

The game still needs end-screen logic►

Need to count number of bricks►

When all are gone, go to next screen•

Could redraw the same screen•

Could create a new room with a new arrangement of bricks

Power-ups►

Could have many interesting powerups►

Multi-ball, bigger paddle, etc.

Page 28: Score, Variables, Conditionals in Game Maker - Courses · PDF fileScore, Variables, Conditionals in Game Maker ... on front of building, on driving circle/Communications end ... Should