Presentation is loading. Please wait.

Presentation is loading. Please wait.

Collision testing. learning targets Increase awareness of the struggles that of game development; Recognize computer science elements for game logic;

Similar presentations


Presentation on theme: "Collision testing. learning targets Increase awareness of the struggles that of game development; Recognize computer science elements for game logic;"— Presentation transcript:

1 collision testing

2 learning targets Increase awareness of the struggles that of game development; Recognize computer science elements for game logic; Applying CS vocabulary to coding logic

3 collision testing demo a finished app to students… Script ID: touchdevelop.com/jpevtouchdevelop.com/jpev

4 entry task 1. Write down the basic programming logic for app 2. Write line of learning underneath your explanation 3. Turn and talk with neighbor for pair - share… Write additional answers to game logic underneath 4. Classroom share out… Groups discuss their answers

5 drawing 1. Distribute graphing paper 2. Students spec out their own path game 3. Identify obstacles, sprites, board, etc. 4. Best drawings displayed to class

6 word wall o board: boundary, game board o sprites: objects that move o physics: speed, gravity, friction o add on every frame o collision o touch: tap, drag, swipe

7 coordinates and units o positions are based on pixels o origin (0, 0) is top left corner o extent (width,height) is just outside of bottom right corner X: width pixel Y: height pixel (0,0) (width/2,height/2) (width,height)

8 coordinates and units o sprite positions refer to center of sprite (makes rotation easy) o speed measured in pixels/second o acceleration measured in pixels/second 2

9 demo/exercise: static layout action main var board := game→start board→create ellipse(20,20) game is a library, you need to add it to your project. X ellipse +(20,20) Y (0,0)

10 create ellipse create ellipse(w, h) o w is width of enclosing rectangle o h is height w h

11 acceleration o set acceleration for single sprite board→set acceleration(0, 100) o set the acceleration for all objects to pixels/seconds 2 var p := senses→acceleration quick→scale(800) board→set gravity(p→x, p→y)

12 demo: gravity action main var board := game→start board→create ellipse(20,20) board→add on every frame(perform) where perform() var p := senses→acceleration quick→scale(800) board→set gravity(p→x, p→y) X ellipse +(20,20) Y (0,0) (p→x, p→y)

13 exercise o try replacing var p := senses→acceleration quick→scale(800) with var p := senses→acceleration quick→scale(2000) or var p := senses→acceleration quick→scale(100) o What happens?

14 obstacles o by default, board is open, has no boundary; objects moving off the visual part of the board will simply continue moving away. Use Board→create boundary to create reflecting walls around the boardBoard→create boundary o use Board→create obstacle(x,y,w,h,elasticity) to create line obstacle with elasticity:Board→create obstacle 1 means the entire impulse is maintained 0 means full absorption of the impulse (a sprite will stick to the wall).

15 demo: boundary action main var board := game→start board→create ellipse(20,20) board→create boundary(0) board→add on every frame(perform) where perform() var p := senses→acceleration quick→scale(800) board→set gravity(p→x, p→y) X ellipse +(20,20) Y (0,0) (p→x, p→y)

16 create obstacle create obstacle(x, y, w, h, elasticity) o (x, y) is upper left corner o obstacle is a straight line o (w, h) is size of bounding rectangle w h (x, y) obstacle

17 demo: obstacle action main var board := game→start board→create ellipse(20,20) board→create boundary(0) board→create obstacle(100, 100, 200, 200,1) board→add on every frame(perform) where perform() var p := senses→acceleration quick→scale(800) board→set gravity(p→x, p→y) X ellipse +(20,20) Y (0,0) (p→x, p→y) obstacle +(200,200) (100,100)

18 friction o “A friction is the fraction of the forward speed that is experienced as a backwards force.” friction of 0 corresponds to no friction at all friction of 1 means the sprite will not move at all o without friction, ball doesn’t slow down board→set friction(0.01) sprite→set friction(0.01)

19 demo: friction action main var board := game→start board→create ellipse(20,20) var ball := board→create ellipse(20,20) ball→set friction(0.05) board→create boundary(0) board→create obstacle(100, 100, 200, 200,1) board→add on every frame(perform) where perform() var p := senses→acceleration quick→scale(800) board→set gravity(p→x, p→y) X ellipse +(20,20) Y (0,0) (p→x, p→y) obstacle +(200,200) (100,100)

20 testing border o is the sprite on the left? board->add every frame(perform) where perform() if sprite->x vibrate(0.1) else (50,0) (0,0) ( sprite→ x, sprite→ y)

21 exercise o is the sprite on the top? board->add every frame(perform) where perform() if _____________________ then phone->vibrate(0.1) else (0,0) ( sprite→ x, sprite→ y) (0,50)

22 o is the sprite on the left or bottom? board->add every frame(perform) where perform() if _________________________ then phone->vibrate(0.1) else (0,0) ( sprite→ x, sprite→ y) (0,50) exercise

23 extra-exercises o is the sprite on the bottom? o is the sprite on the right? o is the sprite on the any of the sides? o is the sprite in the center?

24 collision testing o if sprite2 overlaps with (sprite) then game -> ends else ( sprite2→ sprite ) sprite2 sprite

25 picture sprite o use create picture instead of create ellipse o resize the picture sprite := board->create picture(art->fruit) sprite := board->create picture(pic) sprite->set width(200)

26 score/life o Add 100 points game->add score(100) o remove a life: game->remove life(1)

27 exercise o try replacing ball→set friction(0.05) with ball→set friction(0.95) or ball→set friction(0.001) o What happens?

28 path – sample code

29 checkpoint o Create: wall with picture o Create variables: Board with gravity Sprites with three requirements (ie. A, B, C) A game piece, B 3 losing objects, C 1 winning object o Create obstacles (logical placement of maze figures) o Publish homework to the class group


Download ppt "Collision testing. learning targets Increase awareness of the struggles that of game development; Recognize computer science elements for game logic;"

Similar presentations


Ads by Google