Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Treue Seele
XNA wurde eingestellt. MonoGame ist die aktuelle "Fortsetzung"
MonoGame ist ein Framework das sich nahtlos in Visual Studio einbinden lässt, keine IDE.
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 |
SolidBrush playerBrush = new SolidBrush(Color.Red); Graphics grafik = this.CreateGraphics(); Rectangle circle = new Rectangle(headX, headY, circleH, circleW); grafik.FillEllipse(playerBrush, circle); SolidBrush foodBrush = new SolidBrush(Color.Blue); Graphics futter = this.CreateGraphics(); Rectangle rekt = new Rectangle(rndFutterX, rndFutterY, 10, 10); futter.FillRectangle(foodBrush, rekt); |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SolidBrush playerBrush = new SolidBrush(Color.Red); Graphics grafik = this.CreateGraphics(); Rectangle circle = new Rectangle(headX, headY, circleH, circleW); grafik.FillEllipse(playerBrush, circle); SolidBrush player2Brush = new SolidBrush(Color.Yellow); Graphics grafik2 = this.CreateGraphics(); Rectangle circle2 = new Rectangle(head2X, head2Y, circleH, circleW); grafik2.FillEllipse(player2Brush, circle2); SolidBrush foodBrush = new SolidBrush(Color.Blue); Graphics futter = this.CreateGraphics(); Rectangle rekt = new Rectangle(rndFutterX, rndFutterY, 10, 10); futter.FillRectangle(foodBrush, rekt); |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
SolidBrush playerBrush = new SolidBrush(Color.Red); Graphics grafik = this.CreateGraphics(); Rectangle circle = new Rectangle(headX, headY, circleH, circleW); grafik.FillEllipse(playerBrush, circle); SolidBrush player2Brush = new SolidBrush(Color.Yellow); Graphics grafik2 = this.CreateGraphics(); Rectangle circle2 = new Rectangle(head2X, head2Y, circleH, circleW); grafik2.FillEllipse(player2Brush, circle2); SolidBrush foodBrush = new SolidBrush(Color.Blue); Graphics futter = this.CreateGraphics(); Rectangle rekt = new Rectangle(rndFutterX, rndFutterY, 10, 10); futter.FillRectangle(foodBrush, rekt); SolidBrush food2Brush = new SolidBrush(Color.Azure); Graphics futter2 = this.CreateGraphics(); Rectangle rekt2 = new Rectangle(rnd2FutterX, rnd2FutterY, 10, 10); futter2.FillRectangle(food2Brush, rekt2); |
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 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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace BubbleWars { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Timer timer = new Timer(); Random random1 = new Random(); Random random2 = new Random(); Random random3 = new Random(); Random random4 = new Random(); short headX = 100; //Spielerposition X short headY = 100; //Spielerposition Y short head2X = 200; short head2Y = 200; byte circleW = 10; //Breite des Kreises byte circleH = 10; //Höhe des Kreises int score = 0; //Punktzahl natürlich! int score2 = 0; int rndFutterX = 0; //eine Zufallszahl für die x-Achse des Futters int rndFutterY = 0; //eine Zufallszahl für die y-Achse des Futters| int rnd2FutterX = 0; int rnd2FutterY = 0; byte richtung = 0; //Variable für die Pfeiltasten byte richtung2 = 0; private void Form1_Load(object sender, EventArgs e) { this.Paint += Form1_Paint; //Aufruf Paint-Event timer.Interval = 1000; timer.Tick += new EventHandler(Update); timer.Start(); rndFutterX = 10 * random1.Next(0, 35); rndFutterY = 10 * random2.Next(0, 35); rnd2FutterX = 10 * random3.Next(0, 35); rnd2FutterY = 10 * random4.Next(0, 35); } private void Form1_Paint(object sender, PaintEventArgs e) { SolidBrush playerBrush = new SolidBrush(Color.Red); Graphics grafik = this.CreateGraphics(); Rectangle circle = new Rectangle(headX, headY, circleH, circleW); grafik.FillEllipse(playerBrush, circle); SolidBrush player2Brush = new SolidBrush(Color.Yellow); Graphics grafik2 = this.CreateGraphics(); Rectangle circle2 = new Rectangle(head2X, head2Y, circleH, circleW); grafik2.FillEllipse(player2Brush, circle2); SolidBrush foodBrush = new SolidBrush(Color.Blue); Graphics futter = this.CreateGraphics(); Rectangle rekt = new Rectangle(rndFutterX, rndFutterY, 10, 10); futter.FillRectangle(foodBrush, rekt); SolidBrush food2Brush = new SolidBrush(Color.Azure); Graphics futter2 = this.CreateGraphics(); Rectangle rekt2 = new Rectangle(rnd2FutterX, rnd2FutterY, 10, 10); futter2.FillRectangle(food2Brush, rekt2); } private void Update(object sender, EventArgs e) { if (richtung == 1) { headY += 10; this.Refresh(); } if (richtung == 2) { headY -= 10; this.Refresh(); } if (richtung == 3) { headX -= 10; this.Refresh(); } if (richtung == 4) { headX += 10; this.Refresh(); } if (richtung2 == 1) { head2Y += 10; this.Refresh(); } if (richtung2 == 2) { head2Y -= 10; this.Refresh(); } if (richtung2 == 3) { head2X -= 10; this.Refresh(); } if (richtung2 == 4) { head2X += 10; this.Refresh(); } //Schlange an Rand if (headY == 360 || headY == -10 || headX == 360 || headX == -10) { timer.Stop(); MessageBox.Show("Game Over. Player 1 ran into a wall.\nPlayer one score: "+score+"\nPlayer 2 score: "+score2); } if (head2Y == 360 || head2Y == -10 || head2X == 360 || head2X == -10) { timer.Stop(); MessageBox.Show("Game Over. Player 2 ran into a wall.\nPlayer one score: " + score + "\nPlayer 2 score: " + score2); } if (head2Y == headX && head2Y == headY) { timer.Stop(); MessageBox.Show("Game Over. You idiots crashed into each other!\nPlayer one score: " + score + "\nPlayer 2 score: " + score2); } //Schlange auf Futter if (headY == rndFutterY && headX == rndFutterX) { rndFutterX = 10 * random1.Next(0, 35); rndFutterY = 10 * random2.Next(0, 35); score += 1; if (timer.Interval > 250) { timer.Interval = timer.Interval - 250; } if (timer.Interval > 100 && timer.Interval <= 250) { timer.Interval = timer.Interval - 50; } if (timer.Interval > 20 && timer.Interval <= 100) { timer.Interval = timer.Interval - 20; } if (timer.Interval > 2 && timer.Interval <= 20) { timer.Interval = timer.Interval - 2; } } if (head2Y == rndFutterY && head2X == rndFutterX) { rndFutterX = 10 * random1.Next(0, 35); rndFutterY = 10 * random2.Next(0, 35); score2 += 1; if (timer.Interval > 250) { timer.Interval = timer.Interval - 250; } if (timer.Interval > 100 && timer.Interval <= 250) { timer.Interval = timer.Interval - 50; } if (timer.Interval > 20 && timer.Interval <= 100) { timer.Interval = timer.Interval - 20; } if (timer.Interval > 2 && timer.Interval <= 20) { timer.Interval = timer.Interval - 2; } } if (headY == rnd2FutterY && headX == rnd2FutterX) { rnd2FutterX = 10 * random3.Next(0, 35); rnd2FutterY = 10 * random4.Next(0, 35); score += 1; if (timer.Interval > 250) { timer.Interval = timer.Interval - 250; } if (timer.Interval > 100 && timer.Interval <= 250) { timer.Interval = timer.Interval - 50; } if (timer.Interval > 20 && timer.Interval <= 100) { timer.Interval = timer.Interval - 20; } if (timer.Interval > 2 && timer.Interval <= 20) { timer.Interval = timer.Interval - 2; } } if (head2Y == rnd2FutterY && head2X == rnd2FutterX) { rnd2FutterX = 10 * random3.Next(0, 35); rnd2FutterY = 10 * random4.Next(0, 35); score2 += 1; if (timer.Interval > 250) { timer.Interval = timer.Interval - 250; } if (timer.Interval > 100 && timer.Interval <= 250) { timer.Interval = timer.Interval - 50; } if (timer.Interval > 20 && timer.Interval <= 100) { timer.Interval = timer.Interval - 20; } if (timer.Interval > 2 && timer.Interval <= 20) { timer.Interval = timer.Interval - 2; } } } public void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Down) { richtung = 1; } if (e.KeyCode == Keys.Up) { richtung = 2; } if (e.KeyCode == Keys.Left) { richtung = 3; } if (e.KeyCode == Keys.Right) { richtung = 4; } if (e.KeyCode == Keys.S) { richtung2 = 1; } if (e.KeyCode == Keys.W) { richtung2 = 2; } if (e.KeyCode == Keys.A) { richtung2 = 3; } if (e.KeyCode == Keys.D) { richtung2 = 4; } } } } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Tician« (30.06.2016, 22:34)
Werbeanzeige