55
LECTURE 2 Announcements

Lecture 2

Embed Size (px)

DESCRIPTION

Lecture 2. Announcements. Tac 1 is done!. Initial feedback for Tac1 Lots of nice-looking maps Viewports are important – fix them now! Don’t hardcode map paths to your home folder – always us relative paths! Hand in an Eclipse project, not just your source code - PowerPoint PPT Presentation

Citation preview

Lecture 2Announcements1Tac 1 is done!Initial feedback for Tac1Value noise is looking good! Nice maps!Viewports are important fix them now!Anti-aliasing can destroy your framerate in some scenarios make it toggleable!Use Vecs! We will give INCOMPLETES!Next week your game will really start to take form, and youll pick a genre!TBS or RTS!

2

Dont Forget TicRetries should all be inA few more tips for the futureWatch out for edge casesPlan out game/engine separation before you start3Youre Almost ThereYou are here4Override codesAre on the wayWe promise Questions?Announcements6Lecture 2PathfindingMotivationPathfinding8Why is pathfinding important?NPCs need to navigate an environment that has obstructionsGoal: find minimum cost path from A to BCost includes factors such as distance, terrain, position of enemies.Typically uses a graph to represent navigable states.

9Dijkstras AlgorithmPathfinding10DijkstrasBasic idea:Process nodes in order of shortest distance from startTo process a node, update cost to each neighbor and add to PriorityQueue, then never process this node againEach node keeps track of shortest distance and pointer to previous nodeWhen its time to process the end node, youre done

11Why Dijkstras can be gross

12A*Pathfinding13General ideaDijkstras assumes its impossible to predict costThis is overly pessimisticIn pathfinding, we at least know the general direction we want to goA* is a graph traversal algorithm that takes advantage of this

How does it work?Uses a heuristic to guess the cost from any given node to the destination nodeHeuristic passed by the callerIn addition to tracking distance from start, track heuristic value for each nodePrioritize in PriorityQueue based on distance+heuristicThis can be as simple as the Euclidean distance between the given and destination node, but also try to take other factors Get creative better heuristics help A* run faster!What could possibly go wrong?Overestimating the cost from start to finish can result in sub-optimal resultsTrying to find a path from S to G Note that G is a neighbor of S, but the shortest path is actually S,A,C,G (4 vs. 12)!What if the heuristic estimate of A to G was 25?Explore G first -> done!Avoids expanding the optimal path because the heuristic indicates no, no, trust me, A is SO much further from GMost distance-based heuristics should be fine

Questions?PathfindingLecture 2Graphics II18WHATS A SPRITE?Graphics II19THIS is a sprite

20Sprites as Bitmap DataRaster graphicsPre-constructed images dynamically placed on the screenDesigned to represent one type of object in a gameObjects may reference different sprites depending on state

21Sprites as Animation DataSprites as a filmstripDesigned to represent frame-by-frame snapshots of a single game objectStandardized padding, size, and spacing allows for easy drawing

22 Typical Sprite File FormatMultiple frames per fileMultiple directions per fileMultiple objects per fileAdditional information often (but not always) in config files:PaddingBounding boxesLocations of a particular objects spritesStandard sprites: /course/cs1971/support/tac/sprites.png

Why not every frame in a different file?23Formatting Standards

24Additional Sprite InfoBounding boxes forPhysicsEntity logic (collides, contains, etc)Screen area distributionOther types of information?Optional for nowBut think how you might need this in Tou or M

Fighting game vs platformer needs etc25IMPLEMENTING SPRITESGraphics II26Sprite LoadingYou should only load a sprite sheet onceEach object using the sprite maintains a reference to itConsider making a Resource class which loads in sprite sheetsDynamically load in sprites when you need themHandle sprite indexing for animationsGeneralizable to other assets like maps, sounds, text, etc

Why is this a good idea?27Drawing SpritesAbout Graphics2D.drawImage()Write a custom sprite drawing routine, and pick the one that works best for youIf youre using affine transforms, theres a special method availableYour drawing routine should handle different padding and formats

28Drawing FramesDraw rectangular chunks from sprite sheet to the canvasCalculate based on elapsed time, frame width and heightDont cache scaled imagesScaling up every time is worth the space/speed tradeoffRemember to draw from your single sprite sheet reference

29Animating on TicksAnimate by drawing frames like a flipbook: one after another, then resetUpdate frame state on tick, draw correct frame on drawDraw is read-onlyUse modulo (%) operator to start over

30Questions?Graphics II31Lecture 2Tips for Tac 232Unit movementTiles best stored in an array (discrete indices)But game space is continuous!Define tile x,y to take up space [x,x+1) and [y,y+1)Move unit centers with Vec2f.lerpTo()

0,01,02,00,11,12,10,21,22,23.0, 0.00.7, 0.61.5, 2.1RTS - Unit exclusionUnit sitting on tile is obviousBut what about while moving?When is it no longer on the first tile?When does it officially reach the second tile?Can it briefly monopolize two tiles at once?

??????

???

???

Removing UnitsBeware the ConcurrentModificationException!Doesnt actually have anything to do with threadsConsider a removal queueThis can be generalized to multiple phases of ticksConsider iterating over a copy of the game data

35SpritesYoull need to have sprites in your game to make it pretty!We have tank sprites:/course/cs1971/support/sprites.pngMore random sprites:http://jessefreeman.com/category/game-artwork/

36Java Tip of the WeekTips for Tac IGenerics are cool!Youve used generics before but have you ever written them?Its as easy as:

public class SimpleContainer {private T object;public void setObject(T ob) { object = ob; }public T getObject() { return object; }}

Generics are cool!Can use extends and super to bound the type

public class AnimalHouse {private A animal;public void houseAnimal(A a) { animal = a; }public void feedAnimal() { animal.eat(); }}

AnimalHouse kennel; // okayAnimalHouse mountain; // compile errorWant to know more?Effective Java by Joshua Bloch has an excellent chapter on genericsGives examples of where advanced generics are usefulCan be found in the back of the SunLab

40Questions?Tips for Tac 241Game Design 1Intro to Game DesignWhat is a game designer?A game designer creates the experience and the feel, and is not just a programmerThe game is not by itself the experience, just the delivery system for your ideas

Sub-disciplines of game designWorld designBackstory, setting, themeSystem designGame rules (and math)UI designControls, menus, overlaysLevel designActual playable environments

The sadly wonderful truthA game designer will never experience what he or she createsIt is the player that ultimately interacts with the creationTheir experience cannot be sharedListening is fundamental to designersCompared to other mediaDesigners of movies, books, and plays are creating a linear experienceInteractivity is the defining feature of video games as a medium of entertainmentA game is a problem-solving activity approached with a playful attitude. Jesse SchellJesse Schells Four Elements

MDA Framework

Where to begin?Approach from the players perspectiveWhat aesthetics do you want your game to have?What do you want your players to feel?Create a basic idea that encapsulates those aestheticsCome up with dynamics that evoke the aestheticsFirst and foremost: know your audience!Sunlab users? Competitive MOBA veterans? Kids?Bartles Taxonomy of Player Types

How to become a better designer?At BrownMake games, play games, come to BGDPlay lots of games!More specifically, play games like a designerExtra Credits Season 2, Episode 2Case Study: Super Mario Bros.

Main idea: show just how much thought went into Super Mario BrosTextless tutorialUse of sound

Aesthetics -> Dynamics -> Mechanics52

Building an aesthetic in TacHeres one way you could build an aesthetic with A* in your Tac:MechanicsDynamicsAestheticsWhen a tile is clicked, then all selected units will path-find using A* to that tileWhen an enemy is clicked, then all selected units will attack itWhen the mouse is pressed and dragged, then all units inside the box become selectedMoving a mass of units to a particular locationAttacking something with a mass of unitsPlayer feels empowered by managing and controlling a swarmThings to SeeExtra Credits: Playing Like a Designerhttps://www.youtube.com/watch?v=_HmtmoGwpZcGamasutra - articles and news about game developmenthttp://www.gamasutra.comMDA: A Formal Approach to Game Designhttp://www.cs.northwestern.edu/~hunicke/MDA.pdf

Tac1 playtesting!YAY!