Wiki source code of Inclination Sensor
Last modified by dvd48 on 2020/06/14 20:24
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | (% style="text-align:center" %) | ||
2 | [[image:ezgif-5-1ccd7399998a.gif||alt="neigung_gif.gif" height="204" width="316" class="img-rounded"]] | ||
3 | |||
4 | (% class="box infomessage" %) | ||
5 | ((( | ||
6 | Use your phone as a steering wheel to avoid the approaching traffic. Will you be the next super racer? | ||
7 | ))) | ||
8 | |||
9 | (% class="box" %) | ||
10 | ((( | ||
11 | == What bricks and objects do you need? == | ||
12 | |||
13 | Create a new program and add the following objects from the media library: | ||
14 | |||
15 | (% style="text-align:center" %) | ||
16 | [[image:0.png]] | ||
17 | |||
18 | (% style="text-align:center" %) | ||
19 | [[image:0-1.png]] | ||
20 | ))) | ||
21 | |||
22 | (% class="row" %) | ||
23 | ((( | ||
24 | (% class="col-xs-12 col-sm-6" %) | ||
25 | ((( | ||
26 | (% class="box" %) | ||
27 | ((( | ||
28 | = Now add these scripts to the obstacle object: = | ||
29 | |||
30 | **~1. Step** | ||
31 | |||
32 | (% style="text-align:center" %) | ||
33 | [[image:0-1.png]] | ||
34 | |||
35 | When your program starts set the color and size of your **car**. | ||
36 | |||
37 | (% style="text-align:center" %) | ||
38 | [[image:6.png]] | ||
39 | ))) | ||
40 | ))) | ||
41 | |||
42 | (% class="col-xs-12 col-sm-6" %) | ||
43 | ((( | ||
44 | (% class="box" %) | ||
45 | ((( | ||
46 | **2. Step** | ||
47 | |||
48 | Pick the set Y to-brick and set a value which places the object outside of your phone’s screen. For the x-position insert the “**random function” **which you find under the category functions in the formula editor. Set the limits of the random function to -700 and +700. Now your obstacle is randomly placed on the horizontal axis. | ||
49 | |||
50 | (% style="text-align:center" %) | ||
51 | [[image:8.png]] | ||
52 | ))) | ||
53 | ))) | ||
54 | ))) | ||
55 | |||
56 | (% class="row" %) | ||
57 | ((( | ||
58 | (% class="col-xs-12 col-sm-6" %) | ||
59 | ((( | ||
60 | (% class="box" %) | ||
61 | ((( | ||
62 | **3. Step** | ||
63 | |||
64 | To make the obstacle move from the top to bottom you need the set velocity to-brick. Set the y-value to a **random number** between -500 and -1500. | ||
65 | |||
66 | (% style="text-align:center" %) | ||
67 | [[image:9 (1).png]] | ||
68 | ))) | ||
69 | ))) | ||
70 | |||
71 | (% class="col-xs-12 col-sm-6" %) | ||
72 | ((( | ||
73 | (% class="box" %) | ||
74 | ((( | ||
75 | **4. Step** | ||
76 | |||
77 | When the program starts the obstacle is placed at the top and moves with a random velocity down the screen. This only happens one time. So we need to put it on top again when it leaves the screen. Pick the when becomes true-brick and insert **“position_y < -600”.** You can find “position_y” in the object category and “<” in the logic category while in the formula editor. So if your obstacle is outside your screen, this script starts. In this case set the obstacle to its start position again. | ||
78 | |||
79 | (% style="text-align:center" %) | ||
80 | [[image:10.png]] | ||
81 | ))) | ||
82 | ))) | ||
83 | ))) | ||
84 | |||
85 | (% class="row" %) | ||
86 | ((( | ||
87 | (% class="col-xs-12 col-sm-6" %) | ||
88 | ((( | ||
89 | (% class="box" %) | ||
90 | ((( | ||
91 | **5. Step** | ||
92 | |||
93 | Add another set velocity to-brick to make your obstacle go down the screen again. Set the y-value to a **random number **between -500 and -1500 so every time the obstacle has a different velocity. | ||
94 | |||
95 | (% style="text-align:center" %) | ||
96 | [[image:11 (1).png]] | ||
97 | ))) | ||
98 | ))) | ||
99 | ))) | ||
100 | |||
101 | (% class="row" %) | ||
102 | ((( | ||
103 | (% class="col-xs-12 col-sm-6" %) | ||
104 | ((( | ||
105 | (% class="box" %) | ||
106 | ((( | ||
107 | = Now add these scripts to the car object: = | ||
108 | |||
109 | **6. Step** | ||
110 | |||
111 | (% style="text-align:center" %) | ||
112 | [[image:0.png]] | ||
113 | |||
114 | When your program starts you first have to change the size of your car. Then place it on the screen at a certain position. | ||
115 | |||
116 | (% style="text-align:center" %) | ||
117 | [[image:3.png]] | ||
118 | ))) | ||
119 | ))) | ||
120 | |||
121 | (% class="col-xs-12 col-sm-6" %) | ||
122 | ((( | ||
123 | (% class="box" %) | ||
124 | ((( | ||
125 | **7. Step** | ||
126 | |||
127 | Add a forever loop-brick because the car needs to change it’s position all the time. Pick the change x by-brick because the car should move only on the horizontal axis. Go to the formula editor and insert **“inclination_x” **which you find under the category device. In order to move the car smoothly according to the phones inclination, multiply the sensor value by minus 4. | ||
128 | |||
129 | (% style="text-align:center" %) | ||
130 | [[image:4.png]] | ||
131 | ))) | ||
132 | ))) | ||
133 | ))) | ||
134 | |||
135 | (% class="row" %) | ||
136 | ((( | ||
137 | (% class="col-xs-12 col-sm-6" %) | ||
138 | ((( | ||
139 | (% class="box" %) | ||
140 | ((( | ||
141 | **8. Step** | ||
142 | |||
143 | Insert a when becomes true-brick with the condition:** “touches_edge OR touches_object(Obstacle)”**. You find these properties under the category object respectively in the category logic in the formula editor. At last insert two switch to looks-bricks and one wait-brick. So every time your car hits the edge or an obstacle it changes it’s look for a short period of time. | ||
144 | |||
145 | (% style="text-align:center" %) | ||
146 | [[image:12.png]] | ||
147 | ))) | ||
148 | ))) | ||
149 | ))) | ||
150 | |||
151 | (% class="box" %) | ||
152 | ((( | ||
153 | == Remix Inspirations == | ||
154 | |||
155 | [[Ultimate steering wheel racer>>https://share.catrob.at/pocketcode/program/33937]] | ||
156 | ))) | ||
157 | (% class="box infomessage" %) | ||
158 | ((( | ||
159 | [[Download the program>>https://share.catrob.at/pocketcode/program/33931]] | ||
160 | ))) |