Switching to sfml
This commit is contained in:
parent
4536c62dad
commit
de72aead56
40 changed files with 462 additions and 2385 deletions
21
src/Enemy/Enemy.cpp
Normal file
21
src/Enemy/Enemy.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "Enemy.hpp"
|
||||
|
||||
Enemy::Enemy(sf::Vector2f position) : rectangle(sf::Vector2f{100, 100})
|
||||
{
|
||||
rectangle.move(position);
|
||||
rectangle.setFillColor(sf::Color::Red);
|
||||
}
|
||||
|
||||
void Enemy::look_at(sf::Vector2f target)
|
||||
{
|
||||
float dx = target.x - rectangle.getPosition().x;
|
||||
float dy = target.y - rectangle.getPosition().y;
|
||||
|
||||
float angle = atan2(dy, dx);
|
||||
rectangle.setRotation(sf::degrees(angle));
|
||||
}
|
||||
|
||||
void Enemy::draw(sf::RenderTarget& target, const sf::RenderStates states) const
|
||||
{
|
||||
target.draw(rectangle, states);
|
||||
}
|
13
src/Enemy/Enemy.hpp
Normal file
13
src/Enemy/Enemy.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
class Enemy : public sf::Drawable
|
||||
{
|
||||
sf::RectangleShape rectangle;
|
||||
public:
|
||||
explicit Enemy(sf::Vector2f position);
|
||||
|
||||
void look_at(sf::Vector2f target);
|
||||
|
||||
void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue