48
1 TouchDevelop Chapter 8-10 Presenter: Jing Xu

1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

Embed Size (px)

Citation preview

Page 1: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

1

TouchDevelop Chapter 8-10

Presenter: Jing Xu

Page 2: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

2

Outline

Interactions Game Board Tiles and Printing

Page 3: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

3

Interactions

SMS messages Social messages Calendar and appointments Contacts Locations, places, maps Emails Phone Calls 2D barcodes

Page 4: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

4

SMS messages

SMS is an abbreviation for Short Message Service.

The TouchDevelop API allows a script to generate an SMS message ready for transmission but it will not actually send it.

Demo: SMS(phone)

Page 5: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

5

Social messages

Several websites, including Twitter and Facebook in particular, provide the ability to post messages for other people to read. The TouchDevelop API provides facilities for downloading such messages and for posting new messages.

Demo: SocialMessage

Page 6: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

6

Calendar and appointments

The Windows phone provides a calendar where each day’s schedule, comprised of various meetings or appointments, is recorded.

A TouchDevelop script has read-only access to the phone’s calendar and can retrieve all the appointments for a specific range of times.

Demo: Calendar(phone)

Page 7: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

7

Contacts

Each contact contains several fields. All fields except for the name are optional.

We can use the API to access and change the list of contacts.

When some part of the contact’s information has been changed, the updated contact may be saved back to the phone’s contact list by using the social→save contact method.

Page 8: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

8

Locations&Maps

A location can be created or described by using the methods of the locations resource.

Page 9: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

9

Locations&Maps(Cont.)

In addition to the methods provided by the locations service, location values can be obtained from several other sources. Here is a list of the possibilities.

– senses → current location– senses → current location accurate– maps → directions– location method of the Link datatype– center method of the Map datatype– location method of the Message datatype– location method of the Picture datatype– location method of the Place datatype

Demo: Locations(phone)

Page 10: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

10

Emails

A TouchDevelop script can prepare an email message ready for transmission, but it does not actually send it.

Demo: Email(phone)

Page 11: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

11

Phone Calls

A script can prepare for a phone call by setting up the number and transferring control to the phone’s software for making the call.

Demo: Phone(phone)

Page 12: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

12

2D barcodes

TouchDevelop provides access to the Microsoft Tag service which generates two-dimensional barcodes for text messages and for URLs.

Page 13: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

13

Page 14: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

14

Game Board

Introduction Board Datatype Sprite Datatype Sprite Collection Datatype Touching and board event Debugging game

Page 15: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

15

Sprite

Sprites are 2D bitmaps that are drawn directly to the screen.

Sprites are commonly used to display information such as health bars, number of lives, or text such as scores.

TouchDevelop allows creation and use of several types of sprite, such as ellipse, rectangle, text and picture.

Page 16: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

16

Game program structure

The game loop event is triggered approximately every 50 milliseconds

Page 17: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

17

The Board datatype

Page 18: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

18

Methods of Board datatype: appearance

Page 19: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

19

Sprite

Sprites are associated with particular game boards and are created by methods of the Board type

Page 20: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

20

Methods of Board datatype: creating / accessing sprites

Page 21: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

21

Obstacles and boundaries

Obstacles are walls that can be added to the board

Walls cannot be moved once created. Moving sprites which encounter an obstacle

will bounce back with a speed determined by the product of the obstacle’s elasticity and the sprite’s elasticity.

Page 22: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

22

Methods of Board datatype: obstacles / boundaries

Page 23: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

23

Forces and animation

A uniform force can be applied to all sprites on the board.

The force need not remain constant.

Page 24: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

24

Methods of Board datatype: forces / animation

Page 25: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

25

Demo

MovingBall(phone)

Page 26: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

26

Springs

A spring can be added between two sprites to make them accelerate towards each other.

The force of the spring is proportional to the distance between the two sprites. The further they are apart, the stronger the force.

Demo: CreateSpring

Page 27: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

27

Anchors

One way to produce an unmovable sprite is to set its friction to 1. An alternative possibility is to use an invisible anchor sprite.

The create anchor method creates the invisible sprite with its friction set to 1.0.

Page 28: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

28

The Sprite datatype

Sprites are movable objects which visually represent parts of a game.

Page 29: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

29

Position and motion

A sprite has a current position and a current angular orientation. Both of these change at rates determined by the sprite’s speed and its angular velocity.

Page 30: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

30

Methods of Sprite datatype: mass, friction, elasticity

Demo: CreateSprite

Page 31: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

31

The Sprite Collection datatype

When writing simple games with multiple objects of the same kind (e.g. multiple shots, missiles, etc.), it quickly becomes necessary to group related sprites into collections.

A Sprite Set is an ordered set. A value can appear at most once in the set. The elements of the set are ordered by their index positions.

Page 32: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

32

Touching and board events

These events are triggered when the user touches the screen and taps, swipes or drags a finger across the board.

Page 33: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

33

tap board event

The tap board event fires if there is tap anywhere on the board except on a position where a sprite is located.

The tap board event has two parameters x and y which give the position where the tap occurred.

Demo: TapBoard

Page 34: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

34

swipe board event

The swipe board event is similar, except that the event code is passed four parameters.

The first two show where the swipe started and the second two show the extent of the swipe in the x and y dimensions.

Demo: SwipeBoard

Page 35: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

35

tap sprite in XXX event

Tap events can be provided for sprites held in different sprite collections.

Demo: TapinXXX

Page 36: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

36

swipe sprite in XXX event

The swipe sprite event is similar to the tap sprite event, except that one’s finger is swiped across the screen and the extent of the swipe is passed as two additional parameters.

Page 37: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

37

drag sprite in XXX event

A drag event does not wait for the finger to be lifted from the screen, as with the tap and swipe events. It fires while one’s finger is still on the screen. It will repeatedly fire while the finger is in motion across the screen.

Demo: TapinXXX

Page 38: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

38

tap sprite SSS, swipe sprite SSS, drag sprite SSS

We can also have events associated with an individual sprite.

The sprite must be promoted to be a global data variable

Page 39: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

39

Debugging games

If debug mode is on, the board will display the position and speed of a sprite next to the sprite content. Additionally, the width and height is displayed as a box around the sprite. Also, in debug mode, even invisible sprites are displayed.

Demo: SwipeBoard

Page 40: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

40

Tiles

Pinning the tile simply means creating a tile on the home screen

Tiles always have a front side; they optionally can have a back side. When there is both a front side and a back side, the phone’s software randomly flips the tile over to show the other side.

Page 41: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

41

Tiles

A tile can be associated with an action in a TouchDevelop script.

If the script contains more than one publicly visible action, there can be more than one tile for the script.

Page 42: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

42

General steps

Create the action which is to be invoked when the tile is tapped. The action need not contain any code at this point.

Run the action to its conclusion. When the action has finished, a row of

icons appears across the bottom of the phone’s screen. One of the icons is a pushpin. This icon should be tapped.

Page 43: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

43

Programming the tile’s content

A new global data item. It has the name XXX tile.

Demo-SMS(phone)

Page 44: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

44

Printing via a home server

A home network may include one or more printers. These printers would normally be attached to the network via their WiFi capabilities.

Page 45: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

45

Two API for connecting to a printer

The TouchDevelop script provides two API methods for connecting to a printer.

Page 46: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

46

References

[1] https://www.touchdevelop.com/book

Page 47: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

47

Questions?

Page 48: 1 TouchDevelop Chapter 8-10 Presenter: Jing Xu. 2 Outline Interactions Game Board Tiles and Printing

48

Thank you!