-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cs
120 lines (79 loc) · 2.45 KB
/
Game.cs
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntWorldCSharp
{
class Game
{
public Point Position { get; set; }
public Point Velocity { get; set; }
public Point ObjSize { get; set; }
public Point PlaygroundSize { get; set; }
private Ant[] ants = new Ant[2];
public Game()
{
ants[0] = new Ant();
ants[1] = new Ant();
//for each
foreach(Ant actual in ants)
{
Position = new Point(actual.Position.X, actual.Position.Y);
Velocity = new Point(actual.Velocity.X, actual.Velocity.Y);
ObjSize = new Point(actual.ObjSize.X, actual.ObjSize.Y);
}
}
public void Update(TimeSpan frameTime)
{
//for each
Position = new Point(
Position.X + (int)(Velocity.X * frameTime.TotalSeconds),
Position.Y + (int)(Velocity.Y * frameTime.TotalSeconds));
ObjSize = new Point(
ObjSize.X,
ObjSize.Y);
// Oben abprüfen
if (Position.Y < 0)
{
Velocity = new Point(Velocity.X, -Velocity.Y);
}
// Unten abprüfen
if ((Position.Y + 50) > PlaygroundSize.Y)
{
Velocity = new Point(Velocity.X, -Velocity.Y);
}
// Links abprüfen
if (Position.X < 0)
{
Velocity = new Point(-Velocity.X, Velocity.Y);
}
// Rechts abprüfen
if ((Position.X + 50) > PlaygroundSize.X)
{
Velocity = new Point(-Velocity.X, Velocity.Y);
}
}
}
}
//if (Position.X < 0)
//{
// Velocity = new Point(-Velocity.X, Velocity.Y);
// //Position = new Point(0, Position.Y);
//}
//else if ((Position.X + 50) > PlaygroundSize.X)
//{
// Velocity = new Point(-Velocity.X, Velocity.Y);
// //Position = new Point(PlaygroundSize.X, Position.Y-50);
//}
//if (Position.Y< 0) //oben
//{
// Velocity = new Point(Velocity.X, -Velocity.Y);
// //Position = new Point(Position.X, 75);
//}
//if ((Position.Y + 75) > PlaygroundSize.Y) // unten
//{
// Velocity = new Point(Velocity.X, -Velocity.Y);
// //Position = new Point(Position.X, PlaygroundSize.Y);
//}