Basic level element


Update this week

(Make up for week 9)

This week we mainly designed player movement and scenes. At this stage, the elements we need are very simple, Ball, Player, Brick and basic interaction.

Player movement

The logic of the player's movement part is very simple. It only needs to accept the A, D, left arrow, and right arrow input from the user. In the process of learning, I found that I can directly use Input.GetAxis("Horizonzontal") to perform logical processing. It is much simpler. This method directly returns the left and right directions of the user without having to judge the key pressed by the user. After obtaining the direction, it can directly update the position of the paddle.

Of course, it is necessary to limit the position of the paddle to not exceed the entire screen. In the Start function of PaddleMovement, the following function is called to obtain the current maximum range. The reason for not setting the width directly is to prevent subsequent changes to the camera, and use attributes to obtain it. It will be much more flexible.

maxX = Camera.main.aspect * Camera.main.orthographicSize - transform.transform.localScale.x / 2;

Layout

Ball

For Ball, its basic form is a 2D circle, on which we added RigidBody2D and Circle collider attributes. In order to easily adjust its scope and settings, we created a new Ball.cs and bound it to BallPrefab. It is convenient to update its movement speed, Collide event, etc.

Same as PalyerMovement, in the Start event, we obtain the range that Ball can move in advance and store it in maxX and maxY, which is used to determine whether Ball has exceeded the range of movement in Update, and adjust the speed vector according to the boundary. Update, if it reaches the upper boundary, change the y component of Velocity, if it reaches the left and right boundaries, change the x component of Velocity, if it exceeds the lower boundary, trigger the Destory event.

Brick

The current Brick is relatively simple. It only contains the color attribute that can be adjusted, and the Brick position is fixed in the scene, rather than generated based on the code. This will be adjusted accordingly in subsequent work, and the Brick is planned to be The generation logic is placed in the LevelGenerator and used to generate the Brick location for each level.



What's next week

Improve the collision logic of Ball, add the corresponding collision effect to it, write LevelGenrator to implement level loading, first consider hard coding, and then consider reading from the corresponding level file.

Leave a comment

Log in with itch.io to leave a comment.