Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Simple game concepts

$
0
0
Alright, here is my code
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 Chrono_Story
{
    public partial class Form1 : Form
    {
        private int x;
        private int y;
        private int if_jump;
        public Form1()
        {
            InitializeComponent();
        }

        public void Form1_Load(object sender, EventArgs e)
        {
            x = 0;
            y = 850;
            this.pictureBox1.Location = new System.Drawing.Point(x, y);
        }
        public void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (if_jump == 1)
            {
                y = y - 1;
                if (y == 840)
                {
                    if_jump = -1;
                }
            }
            if (if_jump == -1)
            {
                y = y + 1;
                if (y == 850)
                {
                    if_jump = 0;
                }
            }
            switch (e.KeyCode)
            {
                case Keys.None:
                    x = 0;
                    y = 0;
                    break;
                case Keys.Left:
                    x = x - 10;
                    if (x < 0)
                    {
                        x = 900;
                    }
                    break;
                case Keys.Right:
                    x = x + 10;
                    if (x == 900)
                    {
                        x = 0;
                    }
                    break;
                case Keys.Space:
                    if_jump = 1;
                    break;
            }
            this.pictureBox1.Location = new System.Drawing.Point(x, y);
        }
    }
    }
No when I run this, the figure only moves up if I hit left or right, I want the figure to move up and down whether or not any buttons are pressed.

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>