Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C++CLI / VB .Net / .Net-Framework » Problem bei der steuerung meines Spiels

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
22.04.2006, 16:56 Uhr
Marco Griep



Hallo Leute, ich Programmiere mir grad ein
Game mit C#.
Es soll so ein "Galaxy Shooter" werden.
In dem man das Spaceship mit der Maussteuert.
Was ja auch kein problem ist.
Es lässt sich steuern ist aber immer an der falschen position.
Ich habe es programmiert das mein Mauscurser das fadenkreuz ist, und 50 Pixel unter dem fadenkreuz mein Raumschiff sein soll
jedoch befindet sich das raumschiff extrem weit rechts unterhalb des
fadenkreuzes. Und nach jedem Spielstart ist es entweder weniger weit echts oder noch weiter rechts als zuvor (häää????????).
Ich hab keinen Plan an was das liegen kann.
Hier ist mein Kompletter Code für den Hauptsächelichen Spielablauf so wie er momentan ist:

C++:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WindowsApplication1
{
    public partial class Space : Form
    {
        /* Variablen */
        // Spieler
        int p_fuel, p_ammo, p_health, p_ships, p_speed, p_powerofweapon;
        // Gegner
        int emy_health, emy_powerofweapon;
        //sonstige
        int level;
        int score;
        byte rot, grün, blau;
        byte easy_medium_hard;
        byte easy, medium, hard;

        public Space()
        {

            InitializeComponent();
            //
            // Hauptmenü
            //
            // checkboxen
            mittel.Checked = true;
            Sndon.Checked = true;
            hgsnein.Checked = true;

            //wert zuweisungen
            p_ammo = 500;
            p_fuel = 3000;
            p_health = 1000;
            easy = 10;
            medium = 5;
            hard = 3;
            easy_medium_hard = medium;
            p_ships = easy_medium_hard;
            level = 1;
            rot = 128;
            grün = 66;
            blau = 186;
            score = 0;
          
            /* Oberfläche Einstellungen */
            this.Text = "Space Battle 2006";
            this.BackColor = Color.Black;
            ClientSize = new Size(800, 600);
            neuGAME.Text = "Neues Spiel";
            Optionen.Text = "Optionen";
            Exit.Text = "Spiel Beenden";
            Continue.Text = "Fortsetzen";
            Health.Text = "Health: " + p_health; // + variable
            Ammo.Text = "Ammo: " + p_ammo;// + variable
            Ships.Text = "Ships: "  + p_ships;// + variable
            Fuel.Text = "Fuel: " + p_fuel;//variable
            Level.Text = "Level: " + level;
            GOMess.Text = "Game Over";
            this.StartPosition = FormStartPosition.CenterScreen;
            Spaceship.BackColor = Color.FromArgb(128, 255, 128);
            MyName.Text = "Ein Spiel von Griep Marco";

            //sichtbar
            neuGAME.Visible = true;
            Optionen.Visible = true;
            Exit.Visible = true;
            Continue.Visible = false;
            Health.Visible = false;
            Ammo.Visible = false;
            Ships.Visible = false;
            Fuel.Visible = false;
            GOMess.Visible = false;
            Level.Visible = false;
            Scoreshow.Visible = false;
            Spaceship.Visible = false;
            backtomenü.Visible = false;
            Hgsshow.Visible = true;
            TheScore.Visible = false;
            TheScore.Enabled = false;
            MyName.Visible = true;

            //checkboxen
            leicht.Visible = false;
            mittel.Visible = false;
            schwer.Visible = false;
            Sndon.Visible = false;
            Sndof.Visible = false;
            hgsja.Visible = false;
            hgsnein.Visible = false;
            Highscoresave.Visible = false;
            Sound.Visible = false;
            Schwierigkeit.Visible = false;

            //bedienung
            neuGAME.Enabled = true;
            Optionen.Enabled = true;
            Exit.Enabled = true;
            Continue.Enabled = false;

            //immer aktive timers
            GameOver.Start();
            Colorset.Start();
        }
....

 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
22.04.2006, 16:56 Uhr
Marco Griep




C++:
        #region timers
        private void Fuelcount_Tick(object sender, EventArgs e)
        {
            if (p_fuel == 0)
            {
                //gehe zu ship -
            }
            else
            {
                p_fuel--;
                Fuel.Text = "Fuel: " + p_fuel;
            }
        }

        private void GameOver_Tick(object sender, EventArgs e)
        {
            if (p_ships == 0)
            {
                Streamwriter.Start();
            }
            else
            {

            }
        }

        private void Shipcount_Tick(object sender, EventArgs e)
        {
            if (p_health == 0)
            {
                p_ships--;
                p_health += 1000;
            }
            else
            {

            }
        }

        private void Ammocount_Tick(object sender, EventArgs e)
        {

        }
        #endregion

        #region Steuerung

        private void Ship_shoots(object sender, EventArgs e)
        {
            if (p_ammo == 0)
            {
                //sound abspielen
            }
            else
            {
                //sound abspielen
                p_ammo -= 2;
                Ammo.Text = "Ammo: " + p_ammo;
            }

        }
        private void Ship_flyes(object sender, EventArgs e)
        {
            Spaceship.Location = new Point(MousePosition.X, MousePosition.Y + 50); //Spaceship position = 50 Pixel unter fadenkreuz
        }

        #endregion

        #region menü
        private void neuGAME_Click(object sender, EventArgs e)
        {
            Gamego.Start();
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void beendenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }

        private void neuesSpielToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Gamego.Start();
        }

        private void Gamego_Tick(object sender, EventArgs e)
        {
            //munitionregelung
            p_ammo = 500;
            p_fuel = 3000;
            p_health = 1000;

            //texte
            Health.Text = "Health: " + p_health; // + variable
            Ammo.Text = "Ammo: " + p_ammo;// + variable
            Ships.Text = "Ships: " + p_ships;// + variable
            Fuel.Text = "Fuel: " + p_fuel;//variable

            //sichtbar
            neuGAME.Visible = false;
            Optionen.Visible = false;
            Exit.Visible = false;
            Continue.Visible = false;
            Health.Visible = true;
            Ammo.Visible = true;
            Ships.Visible = true;
            Fuel.Visible = true;
            GOMess.Visible = false;
            Level.Visible = false;
            Spaceship.Visible = true;
            Scoreshow.Visible = true;
            Spaceship.Visible = true;
            leicht.Visible = false;
            mittel.Visible = false;
            schwer.Visible = false;
            Sndon.Visible = false;
            Sndof.Visible = false;
            hgsja.Visible = false;
            hgsnein.Visible = false;
            Highscoresave.Visible = false;
            Sound.Visible = false;
            Schwierigkeit.Visible = false;
            backtomenü.Visible = false;
            Hgsshow.Visible = false;
            MyName.Visible = false; ;


            //bedienung
            neuGAME.Enabled = false;
            Optionen.Enabled = false;
            Exit.Enabled = false;
            Continue.Enabled = false;


            //timers
            Fuelcount.Start();
            Healthcount.Start();
            Shipcount.Start();
            Scorecount.Start();
            Gamego.Stop();
        }

        private void Colorset_Tick(object sender, EventArgs e)
        {
            if (rot >= 245)
            {
                rot = 0;
            }
            else if (grün >= 245)
            {
                grün = 0;
            }
            else if (blau >= 245)
            {
                blau = 0;
            }
            else
            {
                rot += 3;
                grün += 3;
                blau += 3;
            }
            GOMess.ForeColor = Color.FromArgb(rot, grün, blau);
            Scoreshow.ForeColor = Color.FromArgb(rot, grün, blau);
        }

 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
22.04.2006, 16:57 Uhr
Marco Griep




C++:
        private void Scorecount_Tick(object sender, EventArgs e)
        {
            Scoreshow.Text = "Score: " + score;
        }

        private void hauptmenüToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //texte
            Health.Text = "Health: " + p_health; // + variable
            Ammo.Text = "Ammo: " + p_ammo;// + variable
            Ships.Text = "Ships: " + p_ships;// + variable
            Fuel.Text = "Fuel: " + p_fuel;//variable

            //sichtbar
            neuGAME.Visible = true;
            Optionen.Visible = true;
            Exit.Visible = true;
            Continue.Visible = true;
            Health.Visible = false;
            Ammo.Visible = false;
            Ships.Visible = false;
            Fuel.Visible = false;
            GOMess.Visible = false;
            Level.Visible = false;
            Scoreshow.Visible = true;
            Spaceship.Visible = false;
            backtomenü.Visible = false;
            Hgsshow.Visible = true;
            MyName.Visible = true;

            //bedienung
            neuGAME.Enabled = true;
            Optionen.Enabled = true;
            Exit.Enabled = true;
            Continue.Enabled = true;

            //timers
            Fuelcount.Stop();
            Healthcount.Stop();
            Shipcount.Stop();
            Scorecount.Stop();
        }

        private void Continue_Click(object sender, EventArgs e)
        {
            //texte
            Health.Text = "Health: " + p_health; // + variable
            Ammo.Text = "Ammo: " + p_ammo;// + variable
            Ships.Text = "Ships: " + p_ships;// + variable
            Fuel.Text = "Fuel: " + p_fuel;//variable

            //sichtbar
            neuGAME.Visible = false;
            Optionen.Visible = false;
            Exit.Visible = false;
            Continue.Visible = false;
            Health.Visible = true;
            Ammo.Visible = true;
            Ships.Visible = true;
            Fuel.Visible = true;
            GOMess.Visible = false;
            Level.Visible = false;
            Scoreshow.Visible = true;
            Spaceship.Visible = true;
            leicht.Visible = false;
            mittel.Visible = false;
            schwer.Visible = false;
            Sndon.Visible = false;
            Sndof.Visible = false;
            hgsja.Visible = false;
            hgsnein.Visible = false;
            Highscoresave.Visible = false;
            Sound.Visible = false;
            Schwierigkeit.Visible = false;
            backtomenü.Visible = false;
            Hgsshow.Visible = false;
            MyName.Visible = false;

            //bedienung
            neuGAME.Enabled = false;
            Optionen.Enabled = false;
            Exit.Enabled = false;
            Continue.Enabled = false;

            //timers
            Fuelcount.Start();
            Healthcount.Start();
            Shipcount.Start();
            Scorecount.Start();
        }

        private void Optionen_Click(object sender, EventArgs e)
        {
            //checkboxen
            leicht.Visible = true;
            mittel.Visible = true;
            schwer.Visible = true;
            Sndon.Visible = true;
            Sndof.Visible = true;
            hgsja.Visible = true;
            hgsnein.Visible = true;
            Highscoresave.Visible = true;
            Sound.Visible = true;
            Schwierigkeit.Visible = true;

            //menü
            backtomenü.Visible = true;
            neuGAME.Visible = false;
            Optionen.Visible = false;
            Exit.Visible = false;
            Continue.Visible = false;
            Hgsshow.Visible = false;
            MyName.Visible = true;
        }

        private void backtomenü_Click(object sender, EventArgs e)
        {
            //texte
            Health.Text = "Health: " + p_health; // + variable
            Ammo.Text = "Ammo: " + p_ammo;// + variable
            Ships.Text = "Ships: " + p_ships;// + variable
            Fuel.Text = "Fuel: " + p_fuel;//variable

            //sichtbar
            neuGAME.Visible = true;
            Optionen.Visible = true;
            Exit.Visible = true;
            Continue.Visible = false;
            Health.Visible = false;
            Ammo.Visible = false;
            Ships.Visible = false;
            Fuel.Visible = false;
            GOMess.Visible = false;
            Level.Visible = false;
            Scoreshow.Visible = false;
            Spaceship.Visible = false;
            leicht.Visible = false;
            mittel.Visible = false;
            schwer.Visible = false;
            Sndon.Visible = false;
            Sndof.Visible = false;
            hgsja.Visible = false;
            hgsnein.Visible = false;
            Highscoresave.Visible = false;
            Sound.Visible = false;
            Schwierigkeit.Visible = false;
            backtomenü.Visible = false;
            Hgsshow.Visible = true;
            MyName.Visible = true;

            //bedienung
            neuGAME.Enabled = true;
            Optionen.Enabled = true;
            Exit.Enabled = true;
            Continue.Enabled = true;

            //timers
            Fuelcount.Stop();
            Healthcount.Stop();
            Shipcount.Stop();
            Scorecount.Stop();
        }
        #endregion

        #region Highscore aufschreiben

        private void Streamwriter_Tick(object sender, EventArgs e)
        {
            if (hgsja.Checked == true)
            {
                StreamWriter write_Highscore = File.CreateText(@"C:\Spaceship Battle 2006\Highscore.txt" + DateTime.Now);
                write_Highscore.WriteLine(TheScore.Text);
                write_Highscore.Close();
                Streamwriter.Stop();
            }
            else
            {
                Streamwriter.Stop();
            }
        }

        private void Hgsshow_Click(object sender, EventArgs e)
        {
            Form2 Form2 = new Form2();
            Form2.Show();
        }
        #endregion

    }
}


so das wars

Ich hoffe ihr könnt mir helfen
danke schonmal im voraus

Gruß
Marco
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
22.04.2006, 17:00 Uhr
Marco Griep



Das Ihr nicht so lange suchen müsst...

Das Für die Steuerung ist bei dem void "private void Ship_flyes"
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C++CLI / VB .Net / .Net-Framework ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: