Jo ich habe es endlich gelöst
und wollt ihr auch wissen, wo das Problem war, ich habe nicht referenziert ;D (bisschen irronisch)
|
C#-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
public void UpdatePlayer(Rectangle[] Red_block, Rectangle[] Tree_block, ref Rectangle bomb_rect)
{
Red_rect = Red_block;
Tree_rect = Tree_block;
this.bomb_rect = bomb_rect;
if (Keyboard.GetState().IsKeyUp(Keys.W))
{
active[0] = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.A))
{
active[1] = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.S))
{
active[2] = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.D))
{
active[3] = false;
}
if (Keyboard.GetState().IsKeyUp(Keys.Space))
{
active[4]= false;
}
if (Keyboard.GetState().IsKeyDown(Keys.W))
{
if (!active[0])
{
active[0] = true;
if (player_rect.Y >= 30)
{
player_rect.Y -= 30;
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.A))
{
if (!active[1])
{
active[1] = true;
player_rect.X -= 30;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.S))
{
if (!active[2])
{
active[2] = true;
player_rect.Y += 30;
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.D))
{
if (!active[3])
{
active[3] = true;
if (player_rect.X <= 810 - 70)
{
player_rect.X += 30;
}
for (int i = 0; i < 216; i++)
{
if (player_rect.Intersects(Red_block[i]))
{
//player_rect.X -= Red_block[i].Width;
Red_block[i].Offset(30,0);
}
}
for (int a = 0; a < 225; a++)
{
if (player_rect.Intersects(Tree_block[a]))
{
player_rect.X -= Tree_block[a].Width;
}
}
}
}
else if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
if (!active[4])
{
active[4] = true;
bomb_rect = new Rectangle(player_rect.X + 30, player_rect.Y, 30, 30);
}
}
}
|
|
C#-Quelltext
|
1
2
3
4
|
protected override void Update(GameTime gameTime)
{
Block_map.myPlayer.UpdatePlayer(Red_Blocks, Tree_Blocks, ref bomb_rect);
}
|
Da sieht man mal, wie wichtig Referenzen sind