내 프로그램의 경우, 무작위로 배치 된 적을 윈도우 폼에 생성하고 플레이어가 시야에 있지 않을 때 방황하게합니다. 플레이어가 플레이어의 범위 내에 있으면 플레이어가 범위를 벗어날 때까지 플레이어를 따라 공격합니다.적의 오디오 및 스프라이트 시트가 플레이어가 보이면 시작/변경되지 않습니다.
이제 모든 코드가 완벽하게 작동하지만 내가 문제가되는 것은 적이 플레이어를 볼 때 적의 스프라이트 시트 (이 경우 검은 눈알 웜)를 변경하고 싶습니다. , 그것이 "적대적"임을 보여주는 다른 스프라이트 시트로. 동시에 오디오 큐가 재생되기 시작하고 플레이어가 범위를 벗어날 때까지 멈 춥니 다. 이 관련성 여부를하지만, 일정 간격 후에, 새로운 적이 나타납니다 경우에도
, 나는 확실하지 않다, 그래서 나는 확실하지 않다
화면에 다수의 적들이 왜 거기에 있지만, 적의 스프라이트는 스프라이트 시트를 전환하지 않으며 플레이어가 내가 가진 코드로 볼 때 오디오가 재생되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
public void ChangeSpriteSheet()
{
if (Hostile)
{
enemySprite = Properties.Resources.WormSheet;
CurrentPosition.seen = true;
}
else
{
enemySprite = Properties.Resources.WormSheetNeutral;
}
}
: 언제나처럼 :)
그래서 지금까지 함수가 스프라이트 시트를 변경하려면이 코드를 가지고, 어떤 도움에 감사드립니다
//The timer to determine direction, the current sprite sheet for the enemies, and whether or not the audio is enabled
private void wander_Tick(object sender, EventArgs e)
{
int count = 0;
List<bool> seenOrNot = new List<bool>(); // a List of bools
//Iterates through a list of enemies
foreach (Enemies en in enemyList)
{
Enemies enemy = en;
if (CurrentPosition.Hostile[count])
{
//The 'hostile' sprite sheet for the enemy
enemy = new Enemies(Properties.Resources.WormSheet, CurrentPosition.enemyX[count], CurrentPosition.enemyY[count], Sapling.ReturnWidth(), Sapling.ReturnHeight());
seenOrNot.Add(true); //The player has been seen
}
else
{
//The 'neutral' sprite sheet for the enemy
enemy = new Enemies(Properties.Resources.WormSheetNeutral, CurrentPosition.enemyX[count], CurrentPosition.enemyY[count], Sapling.ReturnWidth(), Sapling.ReturnHeight());
seenOrNot.Add(false); //The player hasn't been seen
}
en.Direction(); //Generates a random number every tick of the timer
count++;
}
//This foreach loop will play audio when any of the enemies sees the player
foreach (Boolean b in seenOrNot)
{
if (seenOrNot.Contains(true))
{
wplayer.controls.play();//Plays music when player is in view
}
else
{
wplayer.controls.stop();//Stops the music
}
}
}
: 여기
코드입니다방황 타이머를 다음으로 변경했습니다.
private void wander_Tick(object sender, EventArgs e)
{
CurrentPosition.seen = false;
int count = 0;
foreach (Enemies en in enemyList)
{
en.ChangeSpriteSheet(); //Changes the sprite sheet for the current enemy
en.Direction(); //Generates a random number every tick of the timer
count++;
}
//This foreach loop will play audio when any of the enemies sees the player
if (CurrentPosition.seen)
{
wplayer.controls.play();//Plays music when player is in view
}
else
{
wplayer.controls.stop();//Stops the music
}
}
이 '원더'타이머에서 스프라이트 시트를 변경하는 기능이 호출되며 모든 스프릿 시트를 반복하여 스프라이트 시트를 변경해야하는지 여부를 확인해야합니다.
이렇게하면 오디오가 정상적으로 작동하고 플레이어가 범위 내에있을 때 오디오가 시작되고 오디오가 출력되지 않을 때 오디오가 멈 춥니 다.
그러나 나는 아직도 적을위한 스프라이트 시트를 어떻게 바꿀 것인지 잘 모르겠습니다. 실제 이미지/스프라이트 시트가 Windows Form이 아닌 Enemies 클래스에 설정되도록 코드를 변경 했으므로 같은 위치에 있지만 모두 어디로 가야할지 모르겠습니다.
댓글에 대한 응답으로, 당신은 이런 뜻인가요?
public Image NeutralHostile() //Returns the current sprite sheet
{
return enemySprite;
}
public void ChangeSpriteSheet(Image image)
{
if (Hostile)
{
image= Properties.Resources.WormSheet;
CurrentPosition.seen = true;
}
else
{
image = Properties.Resources.WormSheetNeutral;
}
}
이어서 타이머 I는 ChangeSpriteSheet위한 파라미터로서 NeutralHostile 함수 참조 것이다. 올바른 방향으로 가고 있습니까, 아니면 완전히 벗어 났습니까?
오, _oh_조차도 몰랐습니다. 정말 고마워요. 나는 지금 그것에 대해 갈 것이다. 감사! : D – ThatOneCanadian
그리고 처음에는 오디오에 대해 하나의 bool 만 사용해 보았을 것이라고 생각합니다.하지만 플레이어가 항상 "false"로 설정되어 있는지 확인하기 위해 체크 한 이후로, 't'see the player – ThatOneCanadian
@ThatOneCanadian 적이 플레이어를 볼 수 없다면 부울 값을 false로 변경하지 말고, 적 *이 플레이어를 볼 수 있으면 참으로 변경하십시오. –