1 Replies - 1905 Views - Last Post: 16 May 2012 - 07:33 AM Rate Topic: -----

#1 netherdude  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-May 12

Basic rpg game in winform (using sprite, not full game)

Posted 16 May 2012 - 03:20 AM

Hi guys, I have been using c# for a couple of months now and have started to grow to it. I have seen that there are some people that want to make a basic game in a winform easily without xna, so I though I would just get my code out to see what you guys think of it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            KeyDown += new KeyEventHandler(Form1_KeyDown);
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            int x = pictureBox1.Location.X;
            int y = pictureBox1.Location.Y;

            if (e.KeyCode == Keys.Right) x += 5;
            else if (e.KeyCode == Keys.Left) x -= 5;
            else if (e.KeyCode == Keys.Up) y -= 5;
            else if (e.KeyCode == Keys.Down) y += 5;

            pictureBox1.Location = new Point(x, y);
            pictureBox2.Location = new Point(x, y);

            if (e.KeyCode == Keys.Up)
            {
                pictureBox1.Visible = false;
                pictureBox2.Visible = true;
                pictureBox2.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y);
            }

            if (e.KeyCode == Keys.Down)
            {
                pictureBox2.Visible = false;
                pictureBox1.Visible = true;
                pictureBox1.Location = new Point(pictureBox2.Location.X, pictureBox2.Location.Y);
            }
        }




You also need to go onto the properties window and make sure picturebox2 visible is false, so when you start the app it won't show two images. :bigsmile:

I hope this helped someone and this is a code idea btw guys, so DON'T HATE!

Is This A Good Question/Topic? 0
  • +

Replies To: Basic rpg game in winform (using sprite, not full game)

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,364
  • Joined: 12-June 08

Re: Basic rpg game in winform (using sprite, not full game)

Posted 16 May 2012 - 07:33 AM

Well sprites are not really pictureboxes..

I did something similar when going over OOP in this tutorial... vb.net though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1