Presentation is loading. Please wait.

Presentation is loading. Please wait.

L ECTURE 1 Announcements. Tic is over! Collaboration policies!

Similar presentations


Presentation on theme: "L ECTURE 1 Announcements. Tic is over! Collaboration policies!"— Presentation transcript:

1 L ECTURE 1 Announcements

2 Tic is over!

3 Collaboration policies!

4 Design checks How was the signup process? Were they helpful? Would you rather have more TA hours instead?

5 You can run demos! cs195n_demo tac2 zdavis cs195n_demo tic zdavis

6 Tic first impressions Lots of carrying around separate x, y – This leads to copy-pasting x’s code to write y’s code – Which leads to forgetting to replace an x with a y – Use Vec2i and Vec2f instead! Lots of mouse usage, better than TAs – :-D

7 BGD plug The Brown Game Developers group is meeting on Friday, 4:30p-5:30p in 345 Can be a useful source of advice, within the bounds of collab policy

8 QUESTIONS? Announcements

9 L ECTURE 1 Viewports

10 MOTIVATION Viewports

11 Sometimes screen space is hard Theoretically everything can be done in screen space – But some things can be very hard – Most notably, when the entire game isn’t visible at one time Video time!

12 0,01,02,0 0,11,12,1 0,21,22,2 0,01,02,0 0,11,12,1 0,21,22,2 Game-space Game space vs. Screen space In nearly all games, it makes sense to think of the game as existing in its own “space” The UI in screen space has a “view” into the game world which is just like any other UI element Screen UI

13 0,01,02,0 2,1 0,21,22,2 The math Scale = screen size / game size – (in pixels per game coordinate unit) Game point to screen: 1.Minus game upper left 2.Multiply by scale 3.Add screen upper left Screen point to game: – Do the OPPOSITE of the steps IN REVERSE 1.5, 2.0 0.5, 0.8 120, 20 Scale: 100 px/unit 1.5, 2.0 1.1.0, 1.2 2.100, 120 3.220, 140 220, 140

14 IMPLEMENTATION Viewports

15 Implementing viewports 1.(Optional) Set the clip ( g.clipRect() ) a.You will draw out of bounds otherwise 2.“Set” the “transform” 3.Draw the game-space in its own coordinates 4.“Restore” the “transform” 5.Restore the clip (if you set it)

16 The “transform” For many of you, this is as simple as: – When drawing a viewport, make a note inside your Graphics2D wrapper that you need to transform game->screen coordinates whenever a shape is drawn – Unmark when finished drawing the viewport For cs123 students who want to be fancy, use AffineTransform and the setTransform() and getTransform() of Graphics2D – AffineTransform used like OpenGL

17 QUESTIONS? Viewports

18 L ECTURE 1 Pathfinding

19 MOTIVATION Pathfinding

20 Why is pathfinding important? NPCs need to navigate an environment that has obstructions Represented as a graph Goal: find minimum cost path from A to B – Cost includes factors such as distance, terrain, position of enemies.

21 DIJKSTRA’S ALGORITHM Pathfinding

22 Dijkstra’s Basic idea: – Process nodes in order of shortest distance from start – To process a node, update cost to each neighbor and add to PriorityQueue, then never process this node again – Each node keeps track of shortest distance and pointer to previous node – When it’s time to process the end node, you’re done

23 Why Dijkstra’s can be gross

24 A* Pathfinding

25 General idea Dijkstra’s assumes it’s impossible to predict cost – This is overly pessimistic In pathfinding, we at least know the general direction we want to go A* is a graph traversal algorithm that takes advantage of this

26 How does it work? Uses a “heuristic” to guess the cost from any given node to the destination node – Heuristic passed by the caller In addition to tracking distance from start, track heuristic value for each node – Prioritize in PriorityQueue based on distance+heuristic This can be as simple as the Euclidean distance between the given and destination node, but can also try to take other factors – Just be sure to NEVER OVERESTIMATE (suboptimal results)

27 QUESTIONS? Pathfinding

28 L ECTURE 1 Content Management I

29 WHAT IS CONTENT? Content Management I

30 Content Types of content – Sprites, images, textures – Music, sound effects – Level/map files – Scripts – Dialogue A single logical piece of content is called an “asset”

31 WHY NOT HARDCODE ASSETS? Content Management I

32 Hardcoding Extreme executable bloat Large games cannot fit in memory Have to recompile entire program every time an asset changes Still okay sometimes (e.g. the program icon in Windows) Your RAM: 8GB Dragon Age: Origins: 20GB

33 Solution: break into files Engine/game can load and unload assets as necessary or desired – It’s like JIT for your game content! Non-programmers don’t need to compile – Level designers only need to touch map files – Artists only need to touch image files – Programmers compile builds for everyone else More maintainable in general

34 QUESTIONS? Content Management I

35 L ECTURE 1 Tips for Tac I

36 FILE PARSING Tips for Tac I

37 File parsing! Good news: game-side Bad news: So many things can go wrong! – Map file can’t be opened – Map file is empty – Map file is a directory – Map file is a JPEG – Is a map file, but has inconsistent data

38 Parse safely Read in a line, then parse it, repeat – At least you can report the line count where an error happened Recommended classes: – BufferedReader (for reading lines) – Scanner + StringReader (for parsing each line) Catch, wrap, and rethrow exceptions – Level parsing should only throw a LevelParseException that is caused by other exceptions

39 If possible, report errors nicely Good errors: – “Line 1: ‘,’ is not a valid map size” – “Line 7: Row 3 was 24 tiles wide, map is 25 tiles wide” – “Line 2: Expected boolean, got ‘FLSE’ instead” Bad errors: – “java.util.InputMismatchException (null)” – “The map could not be parsed. Goodbye.” – (program crashes with giant stack trace) If this happens you will get an incomplete

40 UNIT MOVEMENT Tips for Tac I

41 Unit movement Tiles 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) – Then: Vec2i.fromFloored() Move unit centers with Vec2f.lerpTo() 0,01,02,0 0,11,12,1 0,21,22,2 3.0, 0.0 0.7, 0.6 1.5, 2.1

42 Unit exclusion Unit sitting on tile is obvious But 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? ???

43 MISCELLANEOUS TIPS Tips for Tac I

44 Miscellaneous Tips Zooming is multiplicative, not additive – Rolling mouse wheel should * or / the scale factor Watch out for weird behavior when changing a unit’s path while it’s moving – E.g. units moving diagonally

45 JAVA TIP OF THE WEEK Tips for Tac I

46 Generics are cool! You’ve used generics before… but have you ever written them? It’s as easy as: public class SimpleContainer { private T object; public void setObject(T ob) { object = ob; } public T getObject() { return object; } }

47 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; // okay AnimalHouse mountain; // compile error

48 Bounds can be confusing Ever used enums in Java? (if not, you will soon!) This is the declaration of the Enum superclass: public class Enum > Starts to make sense once you realize it doesn’t infinitely expand You will have to do something similar if you want to have a generified GraphNode object

49 Want to know more? Effective Java by Joshua Bloch has an excellent chapter on generics Gives examples of where advanced generics are useful Can be found in the back of the Sun Lab

50 QUESTIONS? Tips for Tac I

51 T IC PLAYTESTING ! YAY!


Download ppt "L ECTURE 1 Announcements. Tic is over! Collaboration policies!"

Similar presentations


Ads by Google