KEMBAR78
Minor Assignment 06 Answers | PDF | Chess Theory
0% found this document useful (0 votes)
6 views3 pages

Minor Assignment 06 Answers

The document outlines various aspects of a game development assignment, including graphical assets, sound files, and code snippets for player and zombie classes. It details the implementation of views, event polling, and player movement within the game arena. Additionally, it covers spawning multiple players and zombies, dynamically allocating memory for zombies, and calculating angles for movement direction.

Uploaded by

moharanasid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Minor Assignment 06 Answers

The document outlines various aspects of a game development assignment, including graphical assets, sound files, and code snippets for player and zombie classes. It details the implementation of views, event polling, and player movement within the game arena. Additionally, it covers spawning multiple players and zombies, dynamically allocating memory for zombies, and calculating angles for movement direction.

Uploaded by

moharanasid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Minor Assignment-06 Answers

1. Count of graphical assets and images


There are multiple graphical assets used in the game including:
- Player sprite
- Zombie sprites
- Background tiles
- Bullets and pickups
In background sheet.png, there are 4 different tile images: mud-1, grass, mud-2, wall.

2. Sound files & purpose


- hit.wav: Played when a player is hit
- shoot.wav: Played when a bullet is fired
- reload.wav: Played during reloading
- pickup.wav: Played when a pickup is collected
- powerup.wav: Played on getting powerups

3. Create view
View view1(FloatRect(0, 0, 1920, 1080));
View view2(Vector2f(960, 540), Vector2f(1920, 1080));

4. Set and use a view in SFML


window.setView(view);
window.draw(sprite);

5. Complete the code snippet


Texture m_Texture;
Sprite m_Sprite;

Player::Player() {
m_Texture.loadFromFile("player.png");
m_Sprite.setTexture(m_Texture);
m_Sprite.setOrigin(25, 25);
m_Sprite.setPosition(120, 234);
}

6. Player class to draw player at center


class Player {
private:
Texture m_Texture;
Sprite m_Sprite;
public:
Player() {
m_Texture.loadFromFile("player.png");
m_Sprite.setTexture(m_Texture);
m_Sprite.setOrigin(25, 25);
}

void draw(RenderWindow &window) {


View view(Vector2f(960, 540), Vector2f(1920, 1080));
window.setView(view);
m_Sprite.setPosition(960, 540);
window.draw(m_Sprite);
}
};

7. Event polling with state transitions


Event event;
while (window.pollEvent(event)) {
if (event.type == Event::KeyPressed) {
if (event.key.code == Keyboard::Return)
cout << "Return key pressed\n";
else if (event.key.code == Keyboard::Num1)
cout << "Num1 key pressed\n";
}
}

8. Spawn 5 players and draw


void Player::spawn(float x, float y) {
m_Sprite.setPosition(x, y);
}
Player players[5];
for (int i = 0; i < 5; ++i) {
players[i].spawn(i*100 + 50, 500);
window.draw(players[i].getSprite());
}

9. Zombie::spawn function and 3 calls


void Zombie::spawn(float startX, float startY, int type, int seed) {
m_Sprite.setPosition(startX, startY);
}
Zombie z1, z2, z3;
z1.spawn(100, 100, 0, 1);
z2.spawn(200, 100, 1, 2);
z3.spawn(300, 100, 2, 3);

10. Array of Zombie objects


Zombie zombies[3];
zombies[0].spawn(100, 100, 0, 1);
zombies[1].spawn(200, 100, 1, 2);
zombies[2].spawn(300, 100, 2, 3);

11. Dynamically allocate Zombies


Zombie* zombies[3];
zombies[0] = new Zombie();
zombies[1] = new Zombie();
zombies[2] = new Zombie();
zombies[0]->spawn(100,100,0,1);
zombies[1]->spawn(200,100,1,2);
zombies[2]->spawn(300,100,2,3);
12. Angle between player and zombie
float angle = atan2(y2 - y1, x2 - x1) * 180 / 3.14159;
m_Sprite.setRotation(angle);

13. Update zombie to move toward player


Vector2f direction = playerLocation - m_Position;
float length = sqrt(direction.x * direction.x + direction.y * direction.y);
direction /= length;
m_Position += direction * speed * dt.asSeconds();

14. Keep player inside arena


if (m_Position.x < m_Arena.left) m_Position.x = m_Arena.left;
if (m_Position.y < m_Arena.top) m_Position.y = m_Arena.top;
if (m_Position.x > m_Arena.left + m_Arena.width - m_TileSize) m_Position.x =
m_Arena.left + m_Arena.width - m_TileSize;
if (m_Position.y > m_Arena.top + m_Arena.height - m_TileSize) m_Position.y = m_Arena.top
+ m_Arena.height - m_TileSize;

15. Generate random number between 80 and 100


int randomNum = rand() % 21 + 80;

You might also like