第 4 个射击语句在 SFML 游戏中不起作用
4th Shooting statement not working in SFML game
我目前正在使用SFML 2.0创建游戏。基本上它是一个自上而下的射击游戏,我对下面的陈述有困难。当按下空格键时会射出一个箭头。有四种陈述取决于玩家精灵(archSprite)面对的方式。这是从此函数计算的 source.y 确定
的enum DirectionKeys { Up, Left, Down, Right};
sf::Vector2i source(0, 0);
int getCellY(DirectionKeys direction)
{
return (direction*64);
}
我遵循的逻辑是声明
int dir = source.y/64;
会用我正在使用的精灵表找出精灵面对的方向 0 = 向上 1 = 向左 2 = 向下 3 = 右 此语句对除向右射击以外的所有内容都正确射击 谁能弄清楚为什么我的箭头向右射击而箭头没有旋转?就像射击权的声明被完全忽略了一样。任何人都可以提供建议吗?
#include "Game.h"
#include "Tilemap.h"
#include <SFMLGraphics.hpp>
#include <iostream>
if(keypress == sf::Keyboard::Space && keyPressed)
{
int tblt = this->_game_data.curr_bullet;
this->_arr_bullet_data[tblt].active = true;
//every 100th bullet it is set to the up rotation
int dir = source.y/64;
if (dir == 0)
{
_arr_bullet_spr[tblt].rotate(90);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(64,-42);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(0,-1);
}
else if (dir == 1)
{
_arr_bullet_spr[tblt].rotate(360);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(-22,0);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(-1,0);
}
else if (dir = 2)
{
_arr_bullet_spr[tblt].rotate(270);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(0,96);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(0,1);
}
else if (dir = 3)
{
_arr_bullet_spr[tblt].setRotation(180);
this->_arr_bullet_data[tblt].startpos = this->archSprite.getPosition() + sf::Vector2f(0,0);
this->_arr_bullet_data[tblt].direction = sf::Vector2f(1,0);
}
this->_arr_bullet_spr[tblt].setPosition(this>_arr_bullet_data[tblt].startpos);
this->_game_data.curr_bullet++;
}
非常感谢
if(dir = 2)
和if(dir = 3)
必须分别if(dir == 2)
和if(dir == 3)
。
相关文章:
- 矢量下标超出SFML游戏中的范围
- 如何使用 SFML 在贪吃蛇游戏中定义游戏结束?
- SFML c ++ 当包含文件内游戏中发生事件时,如何使用铃声函数为我的游戏创建声音类?
- 游戏引擎 SFML C++错误
- 如何在主游戏循环中使用 sfml 只播放一次声音
- 如何在 SFML C++游戏中将资产加载与主循环分开
- 如何与他人共享我的 SFML 游戏而不会出错?
- SFML多个房间游戏设计,如何组织程序
- 使用碰撞检测来增加SFML 2.4中的游戏分数的问题
- SFML游戏C++中的瓷砖地图碰撞
- 哈勒2D Diagonal Movement的SFML游戏开发书
- 访问冲突写入位置0x00000000.C++/SFML游戏
- 如何将SFML游戏服务器部署到Linux服务器
- 第 4 个射击语句在 SFML 游戏中不起作用
- 为什么我的 SFML 游戏只能在终端中运行时使用
- 运行SFML游戏时出现奇怪错误
- C++ SFML游戏编程链接错误
- 如何在另一台计算机上玩SFML游戏
- SFML游戏减速射击子弹
- 如何定义在 SFML 游戏中使用多少 CPU