lecture 10

Post on 30-Dec-2015

26 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Lecture 10. Announcements. Final 1 Feedback. Almost completely done with your 2D game engine! Congratulations! Feel free to use it/improve after the class is over (some of us have/still are) Time to start showing off your product ~2.5 weeks of gameplay coding! Content creation! - PowerPoint PPT Presentation

TRANSCRIPT

LECTURE 10Announcements

Final 1 Feedback• Almost completely done with

your 2D game engine!– Congratulations!– Feel free to use it/improve after

the class is over (some of us have/still are)

• Time to start showing off your product– ~2.5 weeks of gameplay coding!– Content creation!– Tons of playtesting!

• More on public playtesting later…

Hours change?• For specific problems you

should be talking to your mentor TA

• We’ll hold hours for issues with finishing up late projects– What times work best?

• Will announce times after grading meeting today

Special topics AI lecture!• It’s the week after

thanksgiving• It’ll be great

Next Week Doesn’t Exist• No lecture• No hours• No assignment due

• Final II due the next week

• Doesn’t count against retries• Final I retries due the

next week

Deadline Approaching• Course policy: you must turn in a working

version of all projects• Deadline for incomplete projects is

December 20• Same day as Final V• Make sure to email the TA staff when you

re-turn in!

QUESTIONS?Announcements

LECTURE 10Sound

SOUND APPLICATIONSSound

Sound in Games• In the real world,

computers have sound• Background music• Sound effects• Can be an important

part of gameplay– Listening for footsteps– Dramatic music

Sound File Formats• Many ways to encode

and store sound• Open standards

– Ogg Vorbis– FLAC

• Closed standards– mp3– m4a– wav

Sampled Audio• mp3, wav, and most other

familiar extensions• Usually recordings of live

sounds• Samples of sound wave at

regular intervals• Prevalent in modern games• Refers to data type, not

origin– Touchtone telephone is

generated but still sampled11001001101010110111010110010001

10101

Generated Audio• MIDI• File provides information on

instruments and notes– Similar to sheet music

• Sound cards translate from instruments/notes to sound

• Can instruct computer to play something even if you can’t play it

• Used to be popular to save space, not as common now

Compressed vs. UncompressedCompressed Sound Files• Lossy or Lossless?

– Lossy remove “least important” parts of sound wave

– Lossless just use smart compression on raw wave

• Smaller file size (esp. lossy)• Lossy is lower quality• Slower to decode and play• Often used for music

Uncompressed Sound Files

• Record as much as possible of sound wave

• Much larger file size• Usually high quality• Faster to decode and

play• Often used for sound

effects

Buffering• Decompressing and

decoding is slow• Read sound into buffer,

play back from buffer• Size of buffer depends

on speed of system• Playback delay while

buffer is filled

Buffer

Sound file

Sound device

Decoding

SOUND IMPLEMENTATIONSound

javax.sound.sampled• AudioSystem: Provides factory

methods for loading audio sources

• Clip: Any audio that can be loaded prior to playback

• Line: Any source of streaming audio

• DataLine: An implementation of Line with helpful media functionality (start, stop, drain, etc)

• Other classes for mixing, ports, and other utilities

File file = new File(“mysound.wav”);InputStream in =

new BufferedInputStream(new

FileInputStream(myFile));

AudioInputStream stream = AudioSystem .getAudioInputStream(in);

Clip clip = AudioSystem.getClip();clip.open(stream);clip.start();

javax.sound.midi• MidiSystem: The

AudioSystem for MIDI files• Sequencer: Plays MIDI

sounds• Other classes for

manipulation of instruments, notes, and soundbanks– So you can create MIDI sounds

in realtime– Much harder to manipulate

samples

Sequence song = MidiSystem.getSequence(new File(“mysong.midi”));Sequencer midiPlayer = MidiSystem.getSequencer();midiPlayer.open(); midiPlayer.setSequence(song);midiPlayer.setLoopCount(0);midiPlayer.start();

Alternatives?• Some drawbacks of the built-in

sound classes…– Imprecise control over exact

playback start/stop positions– Almost impossible to manipulate

or even examine samples in realtime

– While Java offers pan and reverb, other libraries offer more varied effects

• But it’s very effective for simple background music and sfx!

OpenAL• Cross-platform audio API

modeled after OpenGL• Pros:

– Built for positional sound (distance attenuation, Doppler shift, etc all built in)

– More fine-grain control available

• Cons:– Single listener model– Modeled on OpenGL

Others• Most other libraries are

platform-specific or wrappers for OpenAL

• …except for synthesis libraries!– Jsyn, Beads, etc– Useful for composer

programs and the like, not so much for sound playback

QUESTIONS?Sound

LECTURE 10Data Persistence

What to Save?• Settings

– User profile– Game settings

• Game state– Progress through the

game– Maybe the state of

the world or current level

Where to Save?• Data should be saved somewhere that

is always accessible by your program!– Oftentimes the user’s home directory can

be used for this purpose

• Saving data to the current directory will not work, as your program can be run from anywhere!

PERSISTENT CONFIGURATION

Data Persistence

User Settings• Player name• Custom controls• Other In-game

preferences• Considerations

– Need to save per user– Should be able to export

between game instances– Ideally put in cloud sync

Saving Game Settings• Preferred resolution• Graphics detail level• Input source (keyboard,

peripheral, etc)• Considerations

– Need to save per installation of game

– Should not go in cloud storage – machine-specific, can’t “sync”

Strategies• Serialize a Java object• Java properties file• XML/JSON file

– Easy for humans to read

– Harder to parse

• Custom text format– Can be more concise,

easy to parse

User Interface• User probably doesn’t

need to know file location– Still make it easy to find

so user can back it up

• Don’t save automatically, revert graphics changes if no response

SAVING GAME STATEData Persistence

When to Save Game• Only at checkpoints

– Easier to implement– Each checkpoint is a

level, reload level when player dies

– Potentially more frustrating for player

– Ensure they’re frequent enough

When to Save Game• Any time at save

stations– Like checkpoints, but user

can go back and resave– Better for nonlinear

games– Need to save level state/

progress, but not exact positions (save room usually empty)

When to Save Game• Whenever user wants

– Harder to implement, need a “snapshot” of current game state

– Good for difficult games with frequent failure

– Can still restrict when user can save (e.g. not during combat)

Automatic Saving• A good idea if the player is

responsible for saving– Just because saves are

available doesn’t mean user will use them

• Don’t set user too far back when they fail

• Depending on implementation, can simplify saved state (ie, only save when no enemies are around)

User Interface• Save slots

– Easy, simple, annoying

• Native file browser– Easy way to allow

arbitrary saves– Doesn’t mesh well

with game, unprofessional

User Interface• Custom save-file browser

– Harder to implement, but most flexible/featureful

• Features– Screenshot of saved game– Show only current player’s

saves– Sort by time & type of save

Strategies• Save serialized copy of game world

– On restore, use serialized data as the world

• Save information about which level the player is on and where entities are located– On restore, load the level fresh and then apply changes

• Save some concise file with relevant state information– On restore, act accordingly… like warp to nearest

checkpoint, or load the level and place player at save point

Gotchas• Serializing the world…

– Whoops! We just serialized input states, the screen stack, player preferences…

– Solution: correctly label with Serializable

• Saving generated levels…– Can’t just store level file name!– Solution: Either save the seed

and a list of changes, or convert generated map into some savable format

• The same error-handling warnings from Tac apply

QUESTIONS?Data Persistence

LECTURE 10Procedural Content II

CLASSIFICATIONProcedural Content

What is procedural content?• Procedural content:

game content generated in an algorithmic way rather than by a designer

• Procedural content generation: the generation of this content via a semi-random process

Generated Content• “Procedural generation”

in common usage usually refers to any randomized aspect of game content

• All procedural content need not be generated, or generated randomly– Content deterministically

inferred from other content

Why use procedural content?• Historically: memory

restrictions required it• Generating by hand is

tedious and/or expensive• In the case of procedurally

generated content, provide a new experience with every game

• Provide a personalized experience

Online vs. Offline• Online

– Game content is generated on the fly

– Limitless potential!

• Offline– Game content is generated

by algorithm and then packaged with the game

– Can be perfected by a human designer

Necessary vs. Optional• Necessary

– Required by the player to progress in the game

– Must always be correct or useable

• Optional– Player can choose to

avoid or bypass– Some weirdness is fine

Random vs. Parameterized• All procedural content

performs some sort of expansion from compressed data to real content– What is the compressed form?

• Random– Compressed form is RNG seed

• Parameterized– Compressed form is a

parameter vector– Most often used for

personalized content

Constructive vs. Verified• Constructive

– Generate the content and be done with it

– Need to make sure it’s correct at every step

• Verified– Both a content generator

and a content verifier– Generate the content

until it’s suitably fit

QUESTIONS?Procedural Content

Classification quiz!

Classification quiz!

APPLICATIONSProcedural Content

Procedural Animation• Animating every pose

of a character can be difficult

• Generate poses by joints and constraints

• Can even animate each portion separately

• Could also refer to particle effects

Dynamic Lightmaps• Lightmaps are used to

store lighting information– Separate from textures– Provides significant

graphical speedup

• Rather than defining them for each object, generate them algorithmically

Natural Textures and Terrain• Perlin noise: generated

visual effect that simulates natural texture

• Even used in CGI for flames, smoke, clouds etc

• Computed by calculating distance to grid vertices then interpolating

Level Generation• Create random level

layouts at runtime• Can be used to make

dungeons, interiors, cities, maps, etc

• Algorithms are numerous and vary by purpose– Popular dungeon algorithm:

subdivide dungeon in a binary tree, add a room to each

Design of Level Content• Generate many enemies

or weapons with different attributes, then pick those that most satisfy the scenario

• Alternatively, generate many levels then evaluate them via a fitness function

• Underpins most sandbox games

Dynamic World Generation• Entire game world is

generated on the fly• No part of the world is

written to disk– Unneeded parts are

immediately disposed

• Hinges on deterministic generation and a single RNG seed

• Used in EVE Online as well as a variety of older games

Instancing In-Game Entities

• Each entity has some value randomized– All entities are similar,

but have some distinguishing feature

• Usually used to create names, faces, item or weapon properties

Dynamic Systems• Model complex behaviors

with simple sets of rules• Used for weather,

crowds, spreading fire, and other bottom-up effects

• Strong ties to certain areas of AI, like swarm intelligence

Plot and Puzzle Generation• Think of a game’s storyline as

a dependency graph• Graph dependencies can be

changed– For example, move a key to a

random accessible location

• Graph structure can be changed– Alters order of events

• Can also use natural language processing to create characters and stories

QUESTIONS?Procedural Content

LECTURE 10Tips for Final 2

EFFECTIVE PLAYTESTINGTips for Final 2

Finding Playtesters

• CS students are easy targets, try the sun lab or MS lab– Ask nicely– Don’t ask busy people

• Keep your audience in mind, however– It probably isn’t all CS

students

Don’t Interrupt!• Be a fly on the wall

– Say as little as possible

– Don’t offer hints or instructions

• Your game should speak for itself– You won’t be there to

offer instructions when your game is released

When to Interrupt• Player is frustrated or

taking too long in a single area

• You’re no longer getting good feedback

• If the player moves on, you will resume getting good feedback

Keep a Log• What is the player getting

stuck on?– Make it smoother

• What is the player enjoying?– Emphasize it

• What is the player ignoring?– Take it out if it’s unnecessary

• Consider having the game keep an automated log– Analytics is wonderful!

QUESTIONS?Tips for Final 2

JAVA TIP OF THE WEEKTips for Final 2

Default Visibility

• You already know public, private, protected

• What happens when there’s no visibility modifier?

• Then the field/method is visible to anything in the same package

A Helpful Table

Own Class Same Package

Subclass All Others

public Visible Visible Visible Visible

protected Visible Visible Visible No

(default) Visible Visible No No

private Visible No No No

Some General Visibility Tips

• Use private wherever possible– “Encapsulation”

• If you have a large amount of protected methods you want truly protected, consider separating them into an interface

QUESTIONS?Tips for Final 2

NO PLAYTESTING?

Playtest with random people this week!

top related