SFML и C++ Уроки \ Разработка игр › Форумы › SFML System, Window и другие вопросы › нарушение прав доступа при чтении по адресу
В этой теме 0 ответов, 1 участник, последнее обновление ItForSex 7 года/лет, 10 мес. назад.
-
АвторСообщения
-
После компиляции в релизе вылезает ошибка:нарушение прав доступа при чтении по адресу
код:
C++12345678910111213141516171819202122#include <SFML/Graphics.hpp>#include <iostream>#include <cmath>#include "map.h"#define PI 3.1415926535897932384626433832795sf::View view;using namespace sf;Sprite herosprite;float x, y;float angle;float angleEnd = 0;float speed = 0;float speedLimit = 20;float speedStep = 0.5;float stopStep = 1;float rotStep = 0.3;float carRotate;float speedX;float speedY;float carRotation;void processKey() {
if (Keyboard::isKeyPressed(Keyboard::Left)) {
herosprite.rotate(-carRotate);
}
if (Keyboard::isKeyPressed(Keyboard::Right)) {
herosprite.rotate(carRotate);
}
if (Keyboard::isKeyPressed(Keyboard::Up)) {
speed += (speed < speedLimit) ? speedStep : 0;}
else if (Keyboard::isKeyPressed(Keyboard::Down)) {
if (speed > 0) {
speed += (speed > -speedLimit) ? -stopStep : 0;
}
else{
speed += (speed > -speedLimit) ? -speedStep : 0;
}
}
else{
speed += (speed < 0) ? speedStep : (speed > 0) ? -speedStep : 0;
}
if (abs(speed)) {
view.setCenter(herosprite.getPosition().x, herosprite.getPosition().y);
carRotate = speed / 3;
if (abs(speed) <= 0.2){
speed = 0;
}}
}
void rotate() {
angle = herosprite.getRotation();
angleEnd = angle * PI / 180;
speedX = speed * cos(angleEnd);
speedY = speed * sin(angleEnd);
herosprite.move(speedX, 0);
herosprite.move(0, speedY);
}int main()
{
RenderWindow window(sf::VideoMode(1000, 1000), “game”);window.setVerticalSyncEnabled(true);
Texture herotexture;
herotexture.loadFromFile(“images/car.png”);
herosprite.setTexture(herotexture);
herosprite.setOrigin(40, 45);
herosprite.setTextureRect(IntRect(0, 0, 201, 97));
herosprite.setPosition(1200, 1700);
//////////////////////////////////////////////////////////////////////////////////////////
Image map_image;
map_image.loadFromFile(“images/props.png”);
Texture map;
map.loadFromImage(map_image);
Sprite s_map;
s_map.setTexture(map);
/////////////////////////////////////////////////////////////////////////while (window.isOpen())
{sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
processKey();
rotate();
window.setView(view);
window.clear();/////////////////////////////Рисуем карту/////////////////////
for (int i = 0; i < HEIGHT_MAP; i++) {
for (int j = 0; j < WIDTH_MAP; j++)
{
if (TileMap[i][j] == ‘ ‘) s_map.setTextureRect(IntRect(0, 0, 200, 200));
if (TileMap[i][j] == ‘s’) s_map.setTextureRect(IntRect(200, 0, 200, 200));
s_map.setPosition(i * 200, j * 200);window.draw(s_map);
}
}
window.draw(herosprite);
window.display();
}return 0;
}` -
АвторСообщения
Для ответа в этой теме необходимо авторизоваться.