Embedded System Report
Embedded System Report
Name StudentID
Ngô Quang Việt 20194881
Nguyễn Mạnh Dũng 20194745
Trần Tấn Dũng 20194746
Hanoi, 07/2024
TABLE OF CONTENTS
INTRODUCTION........................................................................................................................
I. Project Overview......................................................................................................................
1. Objective.............................................................................................................................
2. Content................................................................................................................................
3. Workload.............................................................................................................................
II. Project Design..........................................................................................................................
1. Scaffolding game UI...........................................................................................................
2. Game Logic.........................................................................................................................
1) Movement......................................................................................................................
2) Collision detection.........................................................................................................
3) Scoring...........................................................................................................................
3. External hardware connection.............................................................................................
III. Conclusion.............................................................................................................................
INTRODUCTION
In this project, we recreated the Dinosaur Game on STM32F429 using the
TouchGFX library. The project is developed incrementally, from scaffolding
graphics using the TouchGFX designer, to the implementation of game
functions and the connection to external devices. As a consequence of the
project, we have gained practical knowledge and skills in developing an
embedded application with an ARM CPU.
I. Project Overview
1. Objective
The objective of the project is recreating the Dinosaur Game to run on the
STM32F4 hardware.
2. Content
The project is divided into 3 main parts :
- Scaffolding graphics and generate source code : To design and create
screens, we use the TouchGFX Designer software to place contents
(sprites, texts) and define the screen transitions. Furthermore, we generate
the source code for the STM32 application from the TouchGFX project.
- Developing the game logic : This game contains main functionalities:
+ The movement of the objects (dinosaur, enemies)
+ The enemies instantiation
+ Collision detection
+ Gameplay (Scoring, difficulty, game ending condition)
All of these functionalities are developed and tested incrementally by
connecting to the STM32.
- External hardware connection: In addition to the User button B1 which
is responsible for the screen transition, we utilize an external hardware
component, which is a joystick. This joystick is responsible for
controlling the movement of the Dinosaur.
3. Workload
Work Contributor
- Screen 1 is the start screen which only contains the start button for the user to
click on to begin playing the game.
- The first interaction happens when the user click on the start button on the
screen in the first screen or press the user button which will take them to the
gameplay screen :
- The second interaction is a placeholder transition, which will be used in code
to handle the game ending logic to transition into the game over screen :
- The last interaction is used to restart the game by transitioning into the
gameplay screen from the gameover screen :
After defining all the screens, images, and transitions, we generate the
application code for the project.
2. Game Logic
1) Movement
a) Dinosaur
- The Dinosaur is the main character of the game. In this project, we used
two widgets to implement two different states of the Dinosaur: dino for
the normal upright posture and dinoc for the crouched posture. Each of
these widgets is an Animated Image Widget created using the TouchGFX
Designer. Each widget contains two images, creating the appearance of
movement for the character.
- At the beginning, the character is placed near the left side of the screen.
The dino widget is used to represent the Dinosaur by default, with its
visibility set to True, allowing it to run normally. The dinoc widget, on
the other hand, has its visibility set to False while still being positioned at
the same location as the dino widget. The character remains in a fixed
horizontal position throughout the game, only changing in the vertical
direction while jumping.
- There are two actions available: jumping and crouching, which are
controlled via a joystick.
- Jumping: In this game, the Dinosaur jumps by moving the dino widget
vertically upwards then downwards. We use a quadratic function to
control the height of the dino in every tick during its jump.
We use function y=a∗t 2 + v 0∗t+ y 0 for calculate the next position at next
tick with the parameter below:
a is acceleration
v0 is base speed when dino jump.
y0 is the current position
When the user moves the joystick upward, the bool variable isJumping is
set to true and the dinoJump() function is called. This function performs
in every tick until the Dinosaur’s height is smaller than BASE_DINO_Y.
At that time, the Dinosaur landed, then we reset isJumping to false.
2) Collision detection
When the Dinosaur collides with an enemy, the game is over.
Therefore, we need to handle the collision between the Dinosaur and the
enemies. We treat the body of the objects as a box and apply the
bounding box collision detection technique. The implementation of this
collision detection is as follow:
- Each object participating in the collision detection will have its top,
bottom, left and right value calculated.
- In the case of the enemy, we need to check the current present enemy to
calculate its bounding box values.
- Since the objects in this game are not actually a box, we need to
compensate for it by making the Dinosaur’s box smaller than it actually
is.
The collision detection procedure is included in the main loop. If
the game detects a collision, it will navigate to the gameover screen,
signifying game ending. This is achieved through the call to the
predefined screen transition method generated by TouchGFX when we
define a placeholder screen transition :
3) Scoring
We have two variables for storing scores : score and highestScore, which
is stored in the model class. In the ScreenView, we use counter and
highestScore to keep track of the user score.
For each five ticks, we increase counter by 1. When the game over
occurs, we check whether the user score is higher than highestScore, if
yes, assign value to model’s highestScore.
- The User button is the blue button attached to the board. It serves two
purposes: it starts the game when the user first powers on the board and
displays the initial screen, and it restarts the game when it is over,
allowing the user to replay. This button's function is managed using a
buttonPressQueue queue. In the hardware_polling_task, a value (by
default, 1) is pushed to the queue to inform the system that the button has
been pressed, triggering the appropriate response.
- The joystick is an analog component used to control the Dinosaur
character. It utilizes the ADC1 channel in mode IN13 and the ADC2
channel in mode IN5, with each channel set to an 8-bit resolution. The
detailed wiring connection for the joystick is shown below:
Throughout the project, we faced various challenges, such as figuring out what
TouchGFX can do, how to solve problems with hardware, software. However,
these challenges allowed us to gain valuable experience in embedded systems
development and problem-solving.