【发布时间】:2019-09-13 13:00:25
【问题描述】:
我正在开发一个游戏项目,但我遇到了一个问题。所以我有一个游戏对象,如果向右移动然后再次进入左边的屏幕(吃豆人效果)有一个新屏幕,我的意思是屏幕是一样的,但应该有新的其他对象,但是如果游戏对象返回,我应该能够在屏幕上看到旧版本的对象。所以我有一个行星列表。我创建了它们,如果向前移动,我想“打印”列表的第一个元素,如果我向后移动,我想看到前一个元素。我确实想过尝试使用循环版本,但我决定我不会那样做。 https://imgur.com/a/vCjk9iW
class planet {
//an shape planet has these charateristics
sf::CircleShape shape;
//etc
};
struct nodeplanet
{
planet Planet;
nodeplanet *planet;
}
typedef nodeplanet *ptr_listplanet;
//here I make a list with planet
class listofplanets
{
private:
ptr_listplanet head;
public:
listofplanets()
{
head = NULL;
}
ptr_listofplanets create ()
//etc;
};
//then i create a system of planets;
struct nodeSystem
{
listofplanets ListOfPlanets;
nodeSystem*next;
nodeSystem *prev;
}
ptr_listSystem GenerateNode()
{
ptr_listSystem tmp;
tmp = new nodeSystem;
tmp->ListOfPlanets = ListOfPlanets();
tmp->ListOfPlanets.create(randomnumber());
tmp->prev = NULL;
tmp->next = NULL;
return tmp;
}
ptr_listSystem GenerateSystem ()
{
for (int i=0; i<3; i=i+1){ //just a trial, creating three systems
ptr_listSistema newNode = GenerateNode();
newNode->prev = NULL;
newNode->next = head;
if (head!=NULL)
head->prev = newNode;
head = newNode;
}
return this->head;
}
void Visualize(sf::RenderWindow &window, Player player)
{
ptr_listSistema current = this->head;
float x;
//while (current!=NULL){
x = player.shape.getPosition().x;
current->ListOfPlanet.draw(window);
//if ((player.shape.getPosition().x > 1269))
if (x>1269)
{
//current = GenerateSystem();
current = current->next;
window.clear();
current->ListaPianeta.draw(window);
}
//if ((player.shape.getPosition().x< 3) && (Keyboard::isKeyPressed(Keyboard::Left)))
{
if ((x<3) && (Keyboard::isKeyPressed(Keyboard::Left)))
//p = current->prev;
current = current->prev;
if (current == NULL)
{
current = current->next; //in the case I am in the "head" screen, I should see the head screen;
}
window.clear();
current->ListOfPlanet.draw(window);
}
// }
}
可视化功能是列表的经典打印功能。至少我认为,列表已经生成,如果玩家向前移动我应该能够看到下一个节点中生成的行星,如果玩家向后移动我应该能够看到前一个节点。我尝试使用循环,使用while,但这不是我应该继续“打印”,这取决于。 (不知道我的想法在逻辑上是否正确)
【问题讨论】: