You are on page 1of 5

Assignment 14

1. Game ControlsThe arrow keys to set the direction of the game.


W,A,S,D is used to move the camera.
Q,E is used to zoom the camera in and out.
Z,C is used to rotate the camera about the y axis

Below is the screenshot from my game when it loads up with textures and the 2D eae sprite-

As we can see I have updated the snake body with a texture and also the snake has a cockroach
object to eat now.
Below is the screenshot of the game after a few frames. The snake has moved out of the screen but
the sprite is still in place.

Below is the screenshot of my game at 512x720 resolution as opposed to my default 1280x720.

As we can see the eae sprite is distorted.


I attempted to implement the sprite resolution functionality such that sprites work with the
irrespective of the aspect ratio. This was the formula I used-

float screen_aspect_ratio = (float)UserSettings::GetResolutionWidth() /


UserSettings::GetResolutionHeight();
m_position_screen.bottom = (screen_aspect_ratio * m_position_screen.top +
m_position_screen.left - m_position_screen.right) / screen_aspect_ratio;

Basically I was trying out this formula


Aspect ratio = (right left ) / (top bottom) of the sprite
I tried to match the screens aspect ratio with the relative position of the m_position_screen.bottom of
the sprite but this method did not work hence I reverted it back to the original code.
Now as for why the sprite appears distorted, This is because no matter the resolution of the screen,
it is represented in normalized co-ordinates. i.e (-1 to 1 in x and y). This means that the if the width
or height is increased or decreased and we still use the same screen co-ordinates, the graphics
system will stretch out the sprite texture within those extents hence causing the picture to distort.

An example of a human-readable effect file with all three render states set-

I chose to create a table called render_states. Inside this table we have three values for 3 of the
render states. Now I did this because in my lua interpreter this whole table is optional. If the table is
not found I set the render state bits as 0x02 which is for
Alpha disabled, depth buffering enabled and draw both sides disabled.
If the table is found, I go on to read the next three values and do this operationRender_state_bits = render_state_bits + 1 << (0,1 or 2) depending on the state
Then I store those bits in the binary file.

Above is the binary file for the effects. As we can see the first byte is 01. This means
Alpha enabled = 1 << 0
Depth Buffering disabled = 0
Draw both sides disabled = 0
Hence total value = 1 << 0 + 0 + 0 = 01, which is what gets stored in the binary file.

I designed my binary file as render states followed by the shader paths. This is because render states is
always going to be a single byte. This is always fixed because in case of render states being present we
store the states as shown above but if the user decides not to mention them they are defaulted to 0x02.
Now since the size of this is always 1 byte it is convenient to store it at the start. This goes by the rule
that we store all the fixed length data first and then add the variable length data to the binary file.

You might also like