精品导航

Creating my fist app

Creating my fist app

Where do I start?

Creating a whole app is not an easy task. There are a lot of little details that need to be considered in order to make the app work as good as possible.When creating your own app, always set the goals at the beginning, so you can work from the bottom up with some structure in mind.Writing code without a bigger picture in mind can be a big problem later on in the code development.

The app that we're going to create is one that is going to showcase pretty much every feature we've gone through so far.
It will look like a simple video game, kind of like Snake, where you'll be able to move a circle and change its properties.

Main loop

random image



This is what the main part of the program looks like. It doesn't say much since it has several functions that run the show in separate blocks.

We're going to go through each of those functions in order to see what are they exactly doing.
You can notice the clever use of if-else here - a different function will be called depending on the value of the global variable color.


Using joystick

random image



At the beginning of each loop, the program checks whether the joystick has been moved or not.

If it has been moved in a certain direction, it will change the location variables of our character.
Placing multiple ifs instead of if-else we can get the diagonal movement, since one if doesn't exclude another.
The sensitivity of joystick can be changed by changing the values of comparison to the X and Y values.

LEDs

random image



Here we're using the mighty power of our LEDs to create some really cool wall effects.

Whenever the ball touches the wall, the LEDs at the back of the phone will light up and thus create an indication of the collision.
Notice that since both X and Y values are actually the center of the ball, we must keep in mind the radius size of our ball so that we know when the collision actually appears.
Since the length of the screen is 160 pixels and is taking up the values between 0 and 159, we are comparing it to the values of 0 and 159.
Same works with the height, where the most important values are 0 and 127.

Object size

Here we can choose our radius size by pressing buttons A and B.
Button A will increase its size by two and button B will decrease it.
There are also checks at specific values so we can stop our circle from getting too big or too small.

Colors

We've created the variable color so we can easier change circle colors.
This is probably the easiest way to do it, but it can also be done in other ways.
Pressing on of buttons 1, 2 or 3, this variable changes. We will use it in another function.

random image



This is the part of the code where we come across the if-else part.
Depending on the color variable that we've previously changed, we are entering one of the three functions.
They all work in the same way but have a tiny little difference that makes them special.
Depending on which function is called, the color of the circle will be different.
Clearing the screen with the black color allows the circle to move swiftly and look like an animation.
Also, the function prints out the color of the circle at the bottom of the screen.
We've already set the font type and font size at the beginning of the program so there is no need in doing that now.


Print data

random image



And finally, we're printing out some additional data on the screen.

At the bottom of the screen, right below the color code, there will be the current radius size shown.
Also, the coordinates of the circle center will be shown in the upper left corner.
This will perfectly track the circle along with its size.
Since this function was called after the draw_circle function, this text will always be visible even when the circle is at the same location on the screen.
If you want it to be otherwise, just call the draw_circle function after this one.
The next picture represents the entire program.

Conclusion

When we finally write the entire thing, we can export it as an app and voila!
In chapter 3 there is a detailed tutorial on how to do this, so go check it out!
There is a new app on your main menu ready to go!

友情链接:蘑菇视频网站 | 四虎影视 | 午夜在线观看 | 蘑菇短视频入口 | 蜜芽视频 | 六月婷婷 | 老司机视频 | 蘑菇tv网页版 | fltou.com | zhuoyemall.com | 红桃视频 | 色妞 | 天天综合 | 久久视频 | 蘑菇在线观看网页版 | 在线午夜 | 久久久久久 | 蘑菇网 | 最新av | 秋霞影院 | 蘑菇視頻 | jxty00.com | 蘑菇视频ios | 色啪 | 龙物视频 | 番号网 | 蘑菇网页版入口 | bt搜索 | 小草社区 | 宅男影院 | 亚洲精品 | 超碰视频 | btupic.com | p站视频 | 小蓝视频 | 伊人色 | 秋霞网 | 酒色世界 | woqidz.com | 天堂在线 | 在线亚洲 | zpzb2008.com | 色婷婷 | hebeijiaoyuwang.com | gzdksw.com | mogutv | 4008108885.com | 蓝色导航 | 蘑菇影视 | lf397.com | 久久香蕉 | 永久网站 | 五月丁香 | 青草草 | 蘑菇视频入口 | 汤姆影院 | 樱花视频 | 青娱 | 久久爱 | 导航大全 | 永久地址 | 欧美午夜 | 蘑菇传媒 | 蘑菇app | 综合影院 | 协和影院 | 看片神器 | 福利精品 | 迷妹网 | 玖玖资源站 | 玖玖爱 | tsxhyq.com | mogus.cc | 青青伊人 | 资源导航 | 精品免费 | mogu视频 | 琵琶妞 | 摩天轮社区 | 亚洲网 | sanzhucare-zhpg.com | 老王影院 | tissu-premier.com | dk99999.com | 琳琅导航 | 屁屁影院 | dna0126.com | 扒哥黑料 | 草莓视 | 日本高清 | 福利盒子 | 蘑菇传媒在线观看 | 无名网 | rencai98.com | 青草青青 | 第一福利 | mogu | 五福影院 | 性知音