0
2D 마리오 스타일 게임을 만들려고합니다. 내가 시작하기 전까지는 모든 것이 '객관적'이였습니다. 마리오는 창문 끝에서 멈추지 않습니다. 심판없이 방법을 만들면 마리오도 멈추지 않습니다.C# 방법으로 심 볼을 사용하는 간단한 2D 게임에서 콜리 전이 없음
마리오 클래스
class Mario: System.Windows.Forms.PictureBox
{
public Mario(int x, int y)
{
Image = Image.FromFile("Mario.png");
Location = new Point(x, y);
Size = new Size(16, 32);
SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
TabIndex = 0;
TabStop = false;
}
public void colision(System.Windows.Forms.Panel s,ref bool l, ref bool r)
{
if (this.Right > s.Right) { r = false; }
if (this.Left < s.Left) { l = false; }
}
}
Main 클래스 - Form1에
public partial class Form1 : Form
{
bool right=false,left=false;
public Form1()
{
InitializeComponent();
player.Top = screen.Height - player.Height;
}
private void timer1_Tick(object sender, EventArgs e)
{
if(right== true) { player.Left += 1; }
if (left == true) { player.Left -=1; }
player.colision(screen, ref left, ref right);
}
화면이 System.Windows.Forms.Panel이며, 플레이어는 Form1.designer.cs입니다 초기화 된 마리오 유형입니다
관련없는 필드와 메소드를 삭제했습니다.
왜이 태그 [태그입니다 :
당신은 이미 (
Height
대신Bottom
의 사용) 수직 위치에 옳은 일을했다의 Graphics2D ]? – devRicher디버거가 가장 친한 친구입니다. 문제가있는 곳을 알아 내기 위해 그것을 사용하는 방법을 배우십시오 : –
프로그램은 if 조건으로 들어갑니다. – Xalion