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
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 |
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; using System.Collections; using System.Windows.Input; namespace Snake { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { /*timer1.Interval = 1000 / 60; //60 FPS timer1.Start();*/ int posX = 50; int posY = 50; SolidBrush kreis = new SolidBrush(Color.Black); Graphics kreis_ = pictureBox1.CreateGraphics(); kreis_.FillEllipse(kreis, new Rectangle(posX, posY, 20, 20)); kreis.Dispose(); kreis_.Dispose(); if (Form.ModifierKeys == Keys.Up) { posY += 4; } if (Form.ModifierKeys == Keys.Down) { posY -= 4; } if (Form.ModifierKeys == Keys.Left) { posX -= 4; } if (Form.ModifierKeys == Keys.Right) { posX += 4; } } private void pictureBox1_Click(object sender, EventArgs e) { } } /* class Schlange { public int x { get; set; } public int y { get; set; } public Schlange() { x = 0; y = 0; } }*/ } |
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 |
public partial class Form1 : Form { private int positionX = 0; public Form1() { InitializeComponent(); this.DoubleBuffered = true; // Flackern verhindern } private void timer1_Tick(object sender, EventArgs e) { // Berechnungen durchführen, z.B. Position if (this.positionX > this.ClientSize.Width) this.positionX = 0; else this.positionX += 4; // Erzwingt ein neuzeichnen der Form --> Form1_Paint this.Invalidate(); } private void Form1_Paint(object sender, PaintEventArgs e) { // Zeichnen e.Graphics.FillEllipse(Brushes.Red, this.positionX, 50, 20, 20); } } |
Lass solche persönlichen Angriffe lieber bleiben, meine sind härter.
... und diese Signatur kürzer!
- übersichtlicher
- logischer
- verständlicher
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Das ist sehr langsam. Besser wäre es den Abstand des Punkts zum Mittelpunkt zu berechnen (Pythagoras) und zu schauen, ob er im Radius liegt. Dafür braucht man nur Addition und Multiplikation, nicht mal eine Wurzel.(Hinweis: mit Sinus und Kosinus kann man das prüfen.)
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »BlueCobold« (11.02.2016, 07:22)
Werbeanzeige