VK Computer Games Mathias Lux & Horst Pichler Universitt - - PowerPoint PPT Presentation

vk computer games
SMART_READER_LITE
LIVE PREVIEW

VK Computer Games Mathias Lux & Horst Pichler Universitt - - PowerPoint PPT Presentation

VK Computer Games Mathias Lux & Horst Pichler Universitt Klagenfurt This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 2.0 License. See http://creativecommons.org/licenses/by-nc-sa/2.0/at/ Agenda http://


slide-1
SLIDE 1

VK Computer Games

Mathias Lux & Horst Pichler Universität Klagenfurt

This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 2.0 License. See http://creativecommons.org/licenses/by-nc-sa/2.0/at/

slide-2
SLIDE 2

http://www.uni-klu.ac.at

2

Agenda

  • Collision Detection
  • Game Framework

Sprites Sprite-behavior Bricks

  • Short Introduction into AI
  • Your Game … some advices
slide-3
SLIDE 3

http://www.uni-klu.ac.at

3

The Game Loop Revisited

Double Buffering with repaint-method

slide-4
SLIDE 4

http://www.uni-klu.ac.at

4

Collision Detection

  • Detect if two objects try to occupy the same space at

the same time (overlap)

  • Needed in

physical simulations computational geometry

  • CAD
  • GIS

robotics computer games

[www.vis.uni-stuttgart.de/~frisch/h/diss.htm ]

slide-5
SLIDE 5

http://www.uni-klu.ac.at

5

Game Loop + Collision

Remark: example assumes, that there is no z-axis

slide-6
SLIDE 6

http://www.uni-klu.ac.at

6

Detection Types

  • a priori

predict upcoming collision

  • bjects never really penetrate

respond to collision before it occurred

  • a posteriori

advance movement by small time step check if collision occurs respond to collision after it occurred much easier; used in games

slide-7
SLIDE 7

http://www.uni-klu.ac.at

7

2D Games with Static Arrays

Object moves 1 field per round Collision: (x1‘ == x1) and (y1‘ == y2)

slide-8
SLIDE 8

http://www.uni-klu.ac.at

8

Circles

  • bjects move n pixels per loop

collision detection with Pythagoras: V = sqrt( (x2-x1)2 + (y2-y1)2 ) if V < r1 + r2 collision

slide-9
SLIDE 9

http://www.uni-klu.ac.at

9

Problems with Circles

  • Easy to calculate, but … ● Bounding box

Bounding Volume

slide-10
SLIDE 10

http://www.uni-klu.ac.at

10

Rectangles

Object moves n pixels per loop Collision detection: „inelegant“ approach check possible combinations of lines [ A1B1xA2D2, A1B1xB2C2, … ] if lines cut collission

slide-11
SLIDE 11

http://www.uni-klu.ac.at

11

Example

Collision detected B1C1xA2D2 bounce left (if jumps) stop x-movement Collision detected C1D1xA2B2 new ground-level stop y-movement Collision detected C1D1xA2B2 bounce down reverse y-movement

[ The Great Giana Sisters, Rainbow Arts: http://www.youtube.com/watch?v=zrRHAisdIRg ]

slide-12
SLIDE 12

http://www.uni-klu.ac.at

12

Example

  • Optimization issues

check only objects in rows and/or columns

  • f relevant x/y-coords

check moving objects

  • nly (?)

[ The Great Giana Sisters, Rainbow Arts ]]

slide-13
SLIDE 13

http://www.uni-klu.ac.at

13

Convex Polygons

  • Collision detection:

bounding box

  • imprecise

checking every possible pair?

  • what exactly means “possible”?
  • complex polygons meshes!

prerequisites:

slide-14
SLIDE 14

http://www.uni-klu.ac.at

14

Useful Java Methods

  • Interface Shape

(objects with geometric shape)

  • boolean: contains(Point2D p)
  • boolean: contains(Rectangle2D r)
  • Rectangle2D: getBounds2d()
  • PathIterator: getPathIterator(AffineTransformation t)
  • Implementing classes
  • Area
  • Polygon
  • Rectangle
  • Line2D
  • CubicCurve2D, QuadCurve2D
  • Polygon
  • addPoint(int x, int y)
  • Area
  • constructor: Area(Shape s)
  • Rectangle2D: getBounds(Area a)
  • boolean: isPolgonyal()
  • void: add(Area a)
  • void: subtract(Area a)
  • void: intersect(Area a)
  • void: exclusiveOr(Area a)

subtract add intersect exclusiveOr

collision detection with intersect but: no projection vector!

slide-15
SLIDE 15

http://www.uni-klu.ac.at

15

Example

call: detect(polygon1, polygon2)

[ See Code Example: PolygonCollision ]

slide-16
SLIDE 16

http://www.uni-klu.ac.at

16

Separating Axis Theorem

  • Intersect-method provides no projection vector

separating axis theorem

  • Convex shape: an object is convex if for every

pair of points within one object, every point on the connecting straight line is within the object

slide-17
SLIDE 17

http://www.uni-klu.ac.at

17

Separating Axis Theorem

  • Given two convex shapes, if we can find an axis

along which the projection of the two shapes does not overlap, the shapes don’t overlap. [Herman Minkowski, 1864-1909]

Collision detection: no separating axis collision

  • r:

1 separating axis no collision problem: infinite number of axis to test?

slide-18
SLIDE 18

http://www.uni-klu.ac.at

18

Separating Axis Theorem

  • For convex polygon meshes: each faces normal

is used as an axis to test for separating axis

[ projection ]

slide-19
SLIDE 19

http://www.uni-klu.ac.at

19

Collision Detection with SAT

no collision! collision! [ collision ]

slide-20
SLIDE 20

http://www.uni-klu.ac.at

20

Fast Moving Objects

position at t1 position at t2 collision???

sweep test collision

  • Sweep test

create a new polygon along the trajectory test collision with the new polygon

  • Multi-sampling

create additional polygons in between test for each of them

Tutorials and further examples [http://www.harveycartel.org/metanet/tutorials/tutorialA.html#jakobsen ]

slide-21
SLIDE 21

http://www.uni-klu.ac.at

21

Is this sufficient?

R-Type, Irem[ http://www.youtube.com/watch?v=xPv5lqpA4c4&feature=related ]

slide-22
SLIDE 22

http://www.uni-klu.ac.at

22

Multiple Bounding „Boxes“

Big sprite is non-convex, therefor compose it from several convex polygons … Bounding Volumes

slide-23
SLIDE 23

http://www.uni-klu.ac.at

23

Collisions on the Pixel-level

  • to avoid collision „over-

detection“ we need an even more accurate method

first test on polygon-level then test on pixel-level

slide-24
SLIDE 24

http://www.uni-klu.ac.at

24

Collission Response

  • Change the object‘s status (e.g. to „exploding)
  • Remove one or both objects
  • Projection methods

find the smallest possible displacement direct modification of object positions

  • Penalty force methods [ collision.html ]

use spring forces to pull object out of collision modify the objects acceleration / direction

  • Impulse based methods

use changes in velocity to prevent interpenetration (e.g. stop object)

slide-25
SLIDE 25

http://www.uni-klu.ac.at

25

Games Framework

  • Bug Runner

see also: Java-code

Killer Game Programming in Java, Andrew Davison ]

slide-26
SLIDE 26

http://www.uni-klu.ac.at

26

xxx

Bug Runner Class Diagram

slide-27
SLIDE 27

http://www.uni-klu.ac.at

27

State Chart State Transition Table

Locked Lock Pass Unlocked Unlocked Thanks Coin Unlocked Locked Alarm Pass Locked Unlocked Unlock Coin Locked New State Action Event Current State

slide-28
SLIDE 28

http://www.uni-klu.ac.at

28

Transition Table Java Code

slide-29
SLIDE 29

http://www.uni-klu.ac.at

29

Ball Sprite State Diagram

slide-30
SLIDE 30

http://www.uni-klu.ac.at

30

Bug (Player) Sprite State Diagram

slide-31
SLIDE 31

http://www.uni-klu.ac.at

31

JumpingJack - Bricks

  • Brick-images are stored in an image-strip

/images/

  • Brick-patterns are stored in text-files

/images/bricksinfo.txt

44444 222222222 111 2222 11111 444 444 22222 444 111 1111112222222 23333 2 33 44444444 00 000111333333000000222222233333 333 2222222223333301 00000000011100000000002220000000003300000111111222222234

3 2 4 1

slide-32
SLIDE 32

http://www.uni-klu.ac.at

32

JumpingJack - Drawing

  • Drawing sequence

background

  • wrap-around ribbons
  • parallax scrolling)

bricks sprites

slide-33
SLIDE 33

http://www.uni-klu.ac.at

33

JumpingJack – Offset for Bricks

slide-34
SLIDE 34

http://www.uni-klu.ac.at

34

„Intelligence“ in Games

  • originally „enemy-intelligence“ was stored in

fixed patterns, e.g. Pacman:

Blinky – chases the player Pinky – ambushes (roundabout) Inky – random movement, starts chasing when close Clyde – stupid, moves completely randomly [ remark: combination Blinky-Pinky is deadly ]

  • usually bosses in „boss-fights“ have fixed

movement patterns

Pacman [http://www.youtube.com/watch?v=OsLGvm5-29w ]

slide-35
SLIDE 35

http://www.uni-klu.ac.at

35

AI in (non-board) Games

  • In the 1990s

pathfinding problems incomplete information algorithms („fog of war“)

  • In the 2000s

machine learning algorithms (e.g. neural networks) emergent behavior

  • study and design of complex/multi-agent systems
  • swarm-intelligence (flocking of birds)

enemies without „cheating“ AI

Fog of War – Warcraft II [http://www.youtube.com/watch?v=OsLGvm5-29w ]

slide-36
SLIDE 36

http://www.uni-klu.ac.at

36

Pathfinding with A*

Images taken from Pathfinding for Beginners [ http://www.policyalmanac.org/games/aStarTutorial.htm ]

  • Given
  • terrain
  • starting position
  • goal position
  • Find shortest path
  • span tree
  • calculate new position according to possible movement
  • calculate f = g + h

– g … cost from starting position (covered distance) – h … heuristic: estimated distance to goal

  • span tree from new position
  • stop

– if shortest path found – depth or time limit reached

  • Move to first position on calculated shortest path
  • Admissibility Theorem
  • h must be less or equal to the real rest-distance!
  • for our example: h calculated by the manhattan distance
slide-37
SLIDE 37

http://www.uni-klu.ac.at

37

Pathfinding with A*

slide-38
SLIDE 38

http://www.uni-klu.ac.at

38

AI-Thread

  • Own thread for AI-calculations

PathFinder(GameState state) implements Runnable

  • run

[ implements loop ] – calculate path(s) – store path(s) information in game state – sleep(n), value of n depends on » wanted behavior » CPU utilization

  • Attention:

synchronization!

slide-39
SLIDE 39

http://www.uni-klu.ac.at

39

Some thoughts on Tactial AI

  • Tactical movement
  • avoid cones of fire
  • do not move in „lines of sight“
  • seek cover: move to cover locations (predefined)

shortest path can be modified quite easily

  • Choke point analysis
  • choke-point = points where a player must go through
  • use navigation graph to find choke points
  • graph expresses connections between „rooms“ and „corridors“
  • go to choke points
  • wait for player (ambush)
  • Influence Maps
  • dominance of teams per area
  • needed for tactical reasoning
  • Commander AI
  • determine kinds of units available
  • select pre-defined tactics based on available information (e.g. „tank-rush“ in C&C)
  • produce needed units
  • command units to hot spots, choke points, under-dominated areas

Line of Sight – Commandos 3 [ http://www.youtube.com/watch?v=4CLp3D5h6RU&feature=related ]

slide-40
SLIDE 40

http://www.uni-klu.ac.at

40

The game project

Schedule:

  • Schedule

Deadline: 20.06.2008

  • Organizational Issues

form groups (3 students)

Source: http://www.cs.wisc.edu/graphics/Courses/679-s2007/Main/GameDesign

slide-41
SLIDE 41

http://www.uni-klu.ac.at

41

It‘s still just software

  • try to finish the brainstorming & design phase

before you start programming

  • late design changes will cost a lot of time
  • differentiate between must-have and nice-to-

have

  • try to split it up in packages

allows to develop in a distributed fashion synchronization

  • define interfaces
  • create mock-ups
slide-42
SLIDE 42

http://www.uni-klu.ac.at

42

Prototyping Approach …

  • gather a kickass team and a good advisor
  • gather concept art & music to create an emotional target
  • constrain creativity (you‘ll want it even more)
  • complexity is not necessary for fun
  • create a sense of ownership
  • mindset is as important as talent
  • enforce short development cycles
  • build towards a well defined game goal
  • develop in parallel
  • if you can get away with it, fake it

How to protoype a game in 7 days [ http://www.gamasutra.com/features/20051026/gabler_pfv.htm ]

slide-43
SLIDE 43

http://www.uni-klu.ac.at

43

Team Work

[ http://www.gamasutra.com/features/20051026/gabler_pfv.htm ]

slide-44
SLIDE 44

http://www.uni-klu.ac.at

44

Plan carefully

  • planning

try to make a schedule (I know: it‘s hard to estimate …) be fair to your team-mates and hold the schedule! a lot of time is usually consumed by testing, debugging and refinement

  • be aware of other engagements and commitments

there are still other courses & exams summer is approaching soccer fans: EM is approaching do not underestimate the time you will have to invest on new tools (graphics, sound, etc.)

slide-45
SLIDE 45

http://www.uni-klu.ac.at

45

Last but not least

  • be motivated, but not over-motivated

hard deadline!

  • be aware of your own limits

a C&C-clone would certainly be a great game, but ….