Just want to write something

作者原本打算在2006年的最后一天写下一些感想,但因学校网络速度过慢而未能如愿。临近期末考试,作者计划利用寒假期间每日记录学习C++及相关算法的心得体会。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   I wanted to write something for my 2006 at the last day of 2006, but that day,the speed of the school net is very slow, and i coundn't  keep my temper,so i didn't do it . and now i use my roommates' computer, they use the adsl,so i want to write something,the final exams is coming soon,so i think i will come here less time. i feel very sorry, at first i think i can write something about myself everyday, but i found that the speed of the net is very slow ,everytime i need to wait for a long time before i begin to write, maybe the time for write is shorter than wating,oh, it is very bad ,yes. but i think in my winter holiday, i will  write everyday about  the experience of studying c++,and the algrithms, and may be the qt, yes, hope i will do it sucessfully. god bless me.

Now, we have a way to perceive that the user is pressing a key. We know when we want to move up, down, left, and right. We know at each iteration of the main loop exactly, what the user wants; we just have to update the circle with a new position depending on this input. This method gives us a great advantage. So finally we can write something in our update() function, namely, the movement of our player. We check which of the four Boolean member variables is true, and determine the movement accordingly. By using += (instead of =) and if (instead of else if), we implicitly handle the case where two opposite keys, such as right and left are pressed at the same time—the movement stays zero. The update() function is shown in the following code snippet: void Game::update() { sf::Vector2f movement(0.f, 0.f); if (mIsMovingUp) movement.y -= 1.f; if (mIsMovingDown) movement.y += 1.f; if (mIsMovingLeft) movement.x -= 1.f; if (mIsMovingRight) movement.x += 1.f; mPlayer.move(movement); } We introduce two new things here: a vector and the move() function on the circle shape. The move() function does what its name says, it moves the shape by the amount we provide it. Vector algebra Vectors are an important part of algebraic mathematics. They imply lots of rules and definitions, which go beyond the scope of our book. However, SFML's sf::Vector2 class template is way more practical, both in concept and functionality. To be as simple as we could possibly be, we know that a coordinate in a two-dimensional Cartesian system would need two components: x and y. Because in graphics all coordinates are expressed with the decimal float data type, sf::Vector2 is instantiated as sf::Vector2<float>, which conveniently has a typedef named sf::Vector2f. Such an object is made to contain two member variables, x and y. This makes our life simpler, because now we don't need to pass two variables to functions, as we can fit both in a single sf::Vector2f object. sf::Vector2f also defines common vector operations, such as additions and subtractions with other vectors, or multiplications and divisions with scalars (single values), effectively shortening our code.翻译,要求每行中英文对照
03-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值