Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,625 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,048 people online right now. Registration is fast and FREE... Join Now!




Graphics in games

 
Reply to this topicStart new topic

Graphics in games, <codeless>

davidcatnc
post 19 Aug, 2008 - 08:13 PM
Post #1


New D.I.C Head

*
Joined: 19 Aug, 2008
Posts: 3

OK, well... Hi I'm David and I'm a high school student who has been programming for about 5 years doing small time stuff, school projects... Usually stuff that involved more number crunching or coding keywords and classes and I haven't done much but I'm very interested in Game Programming... Now before everyone starts flaming or yelling about "get your own code", I am not looking for code, I'm looking for ideas on how to logically set something up. I'm interested in AI and I thought the best place to start AI would to be a simple program with a dot that follows another dot that you move... simple enough... Now growing in increasing boredom of my moving dots I want to move forward and make a small "map" if you would put it... I've done some reading and many people suggest that I use a text file that would be read and used as a tiling system of bitmaps as objects.... from a coding standpoint, what I see so far is doing something along the lines or reading a say 4x4 tile section and drawing the objects on screen.... an lets say one of the tiles has a rock, endow that as a class make sure collision properties are help and such... Do I want to have the "map" preloaded before anything starts and then have the window only show 4x4 tiles.... So my question comes down to scrolling, and the code that goes with it... I'm codding in C# but know C++ well so I could easily figure out the differences in that. I have tried to find code on this before but have failed to find anything on how to scroll a set of tile bitmaps in a window... any and all code is appreciated but even if you point me to a post that would help me better that would be nice... Thank you in advance tongue.gif

!David!

PS... sorry for the length of the post
User is offlineProfile CardPM

Go to the top of the page

Tom9729
post 19 Aug, 2008 - 08:18 PM
Post #2


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,447



Thanked 10 times

Dream Kudos: 325
My Contributions


Just a bit of advice, but reading walls of text [f.ex. your post] is painful. smile.gif

That said, I think what you're looking for might be something called A-star pathfinding.

Also, what are you using for graphics?
User is offlineProfile CardPM

Go to the top of the page

davidcatnc
post 20 Aug, 2008 - 12:17 PM
Post #3


New D.I.C Head

*
Joined: 19 Aug, 2008
Posts: 3

Hmm... my post was a bit long >.> but on the other hand I believed I figured out my problem.... so... next time i'll keep it shorter smile.gif
User is offlineProfile CardPM

Go to the top of the page

Tom9729
post 20 Aug, 2008 - 12:57 PM
Post #4


Debian guru

Group Icon
Joined: 30 Dec, 2007
Posts: 1,447



Thanked 10 times

Dream Kudos: 325
My Contributions


The post length isn't really what's important.

Just try to space out what you have to say, whitespace is a good thing. icon_up.gif
User is offlineProfile CardPM

Go to the top of the page

davidcatnc
post 20 Aug, 2008 - 01:56 PM
Post #5


New D.I.C Head

*
Joined: 19 Aug, 2008
Posts: 3

Well I have another question come up... and I'll keep whitespace in mind this time. I've started a program.... and well I'm having a bit of trouble with it...

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


namespace DeadRealm
{
    public partial class Form1 : Form
    {
        int intx;
        int inty;
        string tester;

        public Form1()
        {
            InitializeComponent();
            intx = 0;
            inty = 0;
        }

        public void changeX(int passedx, int modifierx)
        {
            if (intx != 0)
            {
                intx = passedx + modifierx;
            }

        }

        public void changeY(int passedy, int modifieryy)
        {
            if (inty != 0)
            {
                inty = passedy + modifieryy;
            }
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            switch(e.KeyCode.ToString())
            {
                case "Up":
                    changeY(inty, -1);
                    break;
                case "Down":
                    changeY(inty, 1);
                    break;
                case "Left":
                    changeX(intx, -1);
                    break;
                case "Right":
                    changeX(intx, 1);
                    break;
                default:
                    break;
            }
        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //Create Image
            Image newImage = Image.FromFile("C:\\Documents and Settings\\Davids\\Desktop\\DeadRealm\\testmap.bmp");

            //Create rectangle for drawing image
            Rectangle destRect = new Rectangle(0, 0, 400, 400);

            //Create rectangel for source image.
            Rectangle srcRect = new Rectangle(intx, inty, 400, 400);
            GraphicsUnit units = GraphicsUnit.Pixel;

            //Draw image to screen
            e.Graphics.DrawImage(newImage, destRect, srcRect, units);
        }
    }
}


this is in C# keep in mind but if you give the answer in C++ I'm sure I'll be fine

Anyways. what I want it to do is every time I press and arrow key it re-draws the bitmap on the screen starting from a different origin... if you look

CODE
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //Create Image
            Image newImage = Image.FromFile("C:\\Documents and Settings\\Davids\\Desktop\\DeadRealm\\testmap.bmp");

            //Create rectangle for drawing image
            Rectangle destRect = new Rectangle(0, 0, 400, 400);

            //Create rectangel for source image.
            Rectangle srcRect = new Rectangle(intx, inty, 400, 400);
            GraphicsUnit units = GraphicsUnit.Pixel;

            //Draw image to screen
            e.Graphics.DrawImage(newImage, destRect, srcRect, units);
        }


whatsthat.gif^ draws it the first time... and it works... its just not handling anything else right... suggestions?
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 03:29AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month