Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: 1 [2] 3 4   Go Down

Author Topic: Pokemon Walking Engine  (Read 12272 times)

0 Members and 1 Guest are viewing this topic.
Re: Pokemon Walking Engine
« Reply #20 on: August 22, 2008, 01:11:28 am »
  • Drop down and give me 9000!
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 426
Oh my, this is flawless!

The walking, the centred view and everything, you've done an exceptional job. I think this has just given me the spark I needed to actually do something in gm. Do you know if it's possible to do the exact same in GM 6.1A registered?

Not saying I want to do a Pokemon game, just enough functions and stuff to be able to have the same effect.

Anyway this is quite exceptional, it's getting better each time I see this, quite surprised when I compared it to the original. I do see what you mean by the transition, but it's not much of a big deal but it can be easily done like how you want it.
Logged
I like potato.
  • My Myspace
Re: Pokemon Walking Engine
« Reply #21 on: August 22, 2008, 01:19:56 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
lol, thanks Kingknight and HyperKnight32.  Oh, and this is being made in GM7 unregistered; which kind of sucks in that some of the fading effects are going to be more difficult to accomplish.  So yeah, you would be more than able to do the same in GM6.1A registered, in fact, you could probably do a little bit more.
Logged

Kingknight

SiMelon
Re: Pokemon Walking Engine
« Reply #22 on: August 22, 2008, 01:23:29 am »
  • The Hunter
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 495
looking forward to your surfing example
plz post it soon i can't wait XD
Logged
Re: Pokemon Walking Engine
« Reply #23 on: August 22, 2008, 01:25:40 am »
  • Drop down and give me 9000!
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 426
Ah ok, awesome, thanks for that :D. I only know how to do a grid based walking engine with drag and drop, of course if I bother to learn more gml it can be easily accomplished.

I like it how you've done this with the original Pokemon games and not one of the newer ones. I've always liked the original most XD, something about it just kept me captivated.
Logged
I like potato.
  • My Myspace
Re: Pokemon Walking Engine
« Reply #24 on: August 22, 2008, 01:38:54 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
looking forward to your surfing example
plz post it soon i can't wait XD
It's actually not that hard to do; I was working on it earlier, but it is not ready yet.  I was thinking about having a obj_surf character that has obj_ash as its parent, which makes the code easier.  However, the surf object does not need to do checks for obj_enter (enter door), obj_exit (exit door), obj_ledge_ (ledge), or obj_grass (grass), so I am thinking about just having it use its own code; if the water is in a "region" where Pokemon are as well, all of the water becomes similar to grass on land.  I might have the obj_bike character have obj_ash as its parent though as most of the code and place checks are the same.

Ah ok, awesome, thanks for that :D. I only know how to do a grid based walking engine with drag and drop, of course if I bother to learn more gml it can be easily accomplished.

I like it how you've done this with the original Pokemon games and not one of the newer ones. I've always liked the original most XD, something about it just kept me captivated.

Grid-based stuff is easy once you get into it really; all it is is normal movement with restrictions.  I like the original game too; its actually odd that I am remaking Pokemon Blue as the first game I had was Yellow and then I got Red - I only got Blue when I traded in a Gameshark.  I was playing Blue earlier though, and I think that I have an idea of how random NPC movement works (they just go in random directions within a set region, which is why characters don't walk out of towns and the one guy in Cerulean only walks up and down). 

Anyway, going from drag and drop to GML is not that difficult once you get the function names down. 
Logged
Re: Pokemon Walking Engine
« Reply #25 on: August 22, 2008, 01:47:19 am »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6206
So are you planning to make a Pokemon game? Anyway it's pretty nice.
Logged
Re: Pokemon Walking Engine
« Reply #26 on: August 22, 2008, 02:02:22 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Well, I would be getting ahead of myself to say that I am planning to make a game with it because I have just mainly done the overworld features and there are other overworld features that I have to work out (Sabrina's gym's warp tiles, refreshing areas in that area with the ghost Pokemon, stairs, biking downhill that gets forced although that is more of an obj_bike issue based on "region" or possibly room, etc). 

I looked at the GML Help file and it made me believe that font_add_sprite() was able to be used in the unregistered version by not stating that you could only use it in the registered version.  Getting past this is not that difficult, just time-consuming in that it takes longer.

Oh, and thanks.
Logged

Kingknight

SiMelon
Re: Pokemon Walking Engine
« Reply #27 on: August 22, 2008, 02:09:19 am »
  • The Hunter
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 495
will u make a flying example that would be really helpfull :P
Logged
Re: Pokemon Walking Engine
« Reply #28 on: August 22, 2008, 02:14:50 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Flying, doesn't seem like it would be that difficult to do, but I have not attempted it yet.  The way it happens though is that you navigate through a menu, select fly from a Pokemon that can, pick a spot on a map or back out of it, go back to the menu or do a graphical fly pattern, and then if you chose to fly, you land where you need to go and are facing something like left and then you face down.  It's not really difficult to get that into code, but it helps to have more than one location before I can test it.
Logged
Re: Pokemon Walking Engine
« Reply #29 on: August 23, 2008, 06:16:57 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Update: This is not so much a substantive update in terms of adding to what I have, but I feel confident enough to start this as a project soon.  I still have to get two more screenshots that show off a new feature (and for that I have to make new features) and I have to put together a stable demo with those features.  I have put up a project page though on the site and will update this whole thing as well as here (I will use here for the little stuff).

Here is the link to the page on the site: http://www.zfgc.com/index.php#?action=games&sa=view&id=65
Logged
Re: Pokemon Walking Engine
« Reply #30 on: August 24, 2008, 06:51:00 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I got bored, so I added some quick !@#$%.  I detailed this on my project page which is located under Games -> WIP Games on the Site, and the download is located under the downloads section which is also on my project page.  The room transition has not been fixed yet because it works well enough for now, but I added some new things such as:
- Multiple rooms (the previous version only had two locations, so the code was really smoke and mirrors)
- NPC that changes direction when you face him and are close to him and press "Z".
- Deactivating objects outside the view (if you play the Gameboy, you may notice that objects only appear once "Ash" is snapped to the grid, thus between grid spaces, the presence of NPCs and other objects ahead might not be "visible" - use Oak in my demo to see this better)

Download page is located at:
http://www.zfgc.com/index.php#?action=games&sa=view&id=65
Logged
Re: Pokemon Walking Engine
« Reply #31 on: August 24, 2008, 09:48:19 am »
  • The devil in the mirror.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 238
Hm... the "invisible" object thing worked well, except that it didn't work when walking in from the left to right, no big problem tho, I would not have noticed they popped in anyway, never did for the original game anyho =/
The rest looks as detailed and good as ever =P
Logged
Working on my Masters Degree in Computer Science.
Hey look, Zelda Coop....later.
Proud user of C++ for 9 years, and counting!
Re: Pokemon Walking Engine
« Reply #32 on: August 24, 2008, 03:40:13 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
I do not know what you are specifically referring to, but I think the reason that it might not be "working" from coming from the left is that when you are to the far left of Oak, you are actually off-screen with your x-coordinate as negative; it works fine for me from the right.  And yeah, in the original game they popped in, I checked it on an emulator.  Oh, and another thing, if you enter a building and between rooms you press left or right, when you get to the next room it will not always go left or right because the keyboard status is not checked when the window is invisible.  This is actually a flaw in Game Maker; if there was a function to check if the window was active, then I would be fine and I would have used keyboard_check_direct() (using it otherwise, you would be able to move even if the window of the game was not selected).

Edit: Actually, I just checked, and you were right, thanks.  It shouldn't be that hard to fix, I just have to lessen the width of the activation region on the right by one.
« Last Edit: August 24, 2008, 03:43:22 pm by 4Sword »
Logged
Re: Pokemon Walking Engine
« Reply #33 on: August 24, 2008, 04:40:50 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6206
A great update! it has become more gameboy-like!
Logged
Re: Pokemon Walking Engine (Now in SDL)
« Reply #34 on: September 19, 2008, 03:48:14 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
This is kind of a weird update and there seems to be something wrong in the code somewhere that I am trying to fix, but meh.  I have pretty much stopped major work on the Game Maker version of this and instead I have started C++ programming with SDL.  Here is just Ash walking around on a grid (the images mess up if you push keys funny on grid spaces, lol, although one of them shows the entire sheet so I think that it is partially based on how the image is displayed in my show() method)

Edit: Oh, I discovered part of the problem.  Mostly since my GM code was not so dependent on GM functions I was able to copy the way it was written from there into C++ and SDL for the most part.  In the up-down-left-right checking though, in the GM version, if you are on a walking frame instead of a standing one while you are on a tile, it updates it to be a standing one.  In my C++ code I forgot to check to make sure the image index was not 3.  It was going to a 4 index which didn't exist in the image memory so it was looking for something that wasn't there and getting something from overflow.  I will include this fix in the next release.

Edit2: Fixed an error where if you stopped you would sometimes be stuck on a walking frame.  This was because the index checking I mentioned in the previous Edit, if you were on index 3 which was completely legitimate, it would not update to the next legitimate index in my code.  I fixed it, but it doesn't seem optimism.

Edit3: I just decided to fix it and update the download so here:

http://www.zfgc.com/index.php?action=games&sa=getdownload&id=259

(The only big issue with it now is how if you tap the keys you can seemingly go a little faster, but meh, that might all just be in my head)
« Last Edit: September 19, 2008, 04:59:10 am by 4Sword »
Logged
Re: Pokemon Walking Engine
« Reply #35 on: September 19, 2008, 08:33:51 am »
  • Drop down and give me 9000!
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 426
It doesn't work :(. All I get is a black box that flashes for a split second then it closes without any error message or anything, was looking forward to it, ah well.
Logged
I like potato.
  • My Myspace
Re: Pokemon Walking Engine
« Reply #36 on: September 19, 2008, 08:44:17 am »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Yeah, I think I rushed parts of it.  It works for me if I put it on my Desktop, but running it out of a folder gives problems, lol.  Sorry about that.  I will look into it more to see if there is a good way to fix the problem.

Edit: It is late (4:02 AM and I have a test at 9:00 AM) so I will get back on this later today.  The test is actually going to be easy since I had the same one last year although this is a different class.  It's all about logical relationships.  I might also include the source code but it isn't that flashy; it is just a modified tutorial where I changed some functions and changed the sprites and the source would contain the means to compile it on your computer if you had SDL, meh.

Edit2: Try this: http://www.zfgc.com/index.php?action=games&sa=getdownload&id=260

Extract it anywhere or to the Desktop and try it, it has all the images and stuff with it.
« Last Edit: September 19, 2008, 09:29:06 am by 4Sword »
Logged
Re: Pokemon Walking Engine
« Reply #37 on: September 19, 2008, 10:58:26 am »
  • The devil in the mirror.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 238
Hehe, the second download worked. :) The grid movement seems to work, except for the tapping = walking faster part ;)

Hm.. now I'm curious...*Goes to look at source*

By the way, what compiler did you use?

EDIT: Awww, the .c file isn't a full source =(
Owell =P
« Last Edit: September 19, 2008, 11:00:11 am by wildex999 »
Logged
Working on my Masters Degree in Computer Science.
Hey look, Zelda Coop....later.
Proud user of C++ for 9 years, and counting!
Re: Pokemon Walking Engine
« Reply #38 on: September 19, 2008, 03:09:09 pm »
  • *
  • Reputation: +8/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6604
Yeah, I had to experiment with how key checking was done because it was not directly working correctly with the format where it checked to see if a key was up or down.  I ended up having to put in variables press_u, press_d, press_l, and press_r to hold Boolean values and that ended up working differently.  I don't really know fully why you can go faster by tapping the keys, it may just be how it processes.  As for the source, it is just:

Code: [Select]
//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>

//The screen attributes
const int SCREEN_WIDTH = 160;
const int SCREEN_HEIGHT = 144;
const int SCREEN_BPP = 32;

//The frame rate
const int FRAMES_PER_SECOND = 30;

//The dimensions of the dot
const int DOT_WIDTH = 16;
const int DOT_HEIGHT = 16;

//The surfaces
SDL_Surface *dot = NULL;
SDL_Surface *screen = NULL;

SDL_Rect clipsUp[ 4 ];
SDL_Rect clipsDown[ 4 ];
SDL_Rect clipsLeft[ 4 ];
SDL_Rect clipsRight[ 4 ];

//The event structure
SDL_Event event;

//The dot that will move around on the screen
class Dot
{
    private:
    //The X and Y offsets of the dot
    int x, y, xprev, yprev;
   
    //Psuedo-Keys
   
    bool press_u, press_d, press_l, press_r;
   
    //Direction Temp
    int d;
   
    //Animation Rate
    int anima;
   
    //Image Index
    int index;
   
    public:
    //Initializes the variables
    Dot();
   
    //Moves the dot
    void move();
   
    //Shows the dot on the screen
    void show();
};

//The timer
class Timer
{
    private:
    //The clock time when the timer started
    int startTicks;
   
    //The ticks stored when the timer was paused
    int pausedTicks;
   
    //The timer status
    bool paused;
    bool started;
   
    public:
    //Initializes variables
    Timer();
   
    //The various clock actions
    void start();
    void stop();
    void pause();
    void unpause();
   
    //Gets the timer's time
    int get_ticks();
   
    //Checks the status of the timer
    bool is_started();
    bool is_paused();   
};

SDL_Surface *load_image( std::string filename )
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;
   
    //The optimized surface that will be used
    SDL_Surface* optimizedImage = NULL;
   
    //Load the image
    loadedImage = IMG_Load( filename.c_str() );
   
    //If the image loaded
    if( loadedImage != NULL )
    {
        //Create an optimized surface
        optimizedImage = SDL_DisplayFormat( loadedImage );
       
        //Free the old surface
        SDL_FreeSurface( loadedImage );
       
        //If the surface was optimized
        if( optimizedImage != NULL )
        {
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 255, 0, 255 ) );
        }
    }
   
    //Return the optimized surface
    return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
    //Holds offsets
    SDL_Rect offset;
   
    //Get offsets
    offset.x = x;
    offset.y = y;
   
    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}

void set_clips()
{
    //Up Sprites
    clipsUp[ 0 ].x = 0;
    clipsUp[ 0 ].y = 0;
    clipsUp[ 0 ].w = DOT_WIDTH;
    clipsUp[ 0 ].h = DOT_HEIGHT;
   
    clipsUp[ 1 ].x = DOT_WIDTH;
    clipsUp[ 1 ].y = 0;
    clipsUp[ 1 ].w = DOT_WIDTH;
    clipsUp[ 1 ].h = DOT_HEIGHT;
   
    clipsUp[ 2 ].x = DOT_WIDTH * 2;
    clipsUp[ 2 ].y = 0;
    clipsUp[ 2 ].w = DOT_WIDTH;
    clipsUp[ 2 ].h = DOT_HEIGHT;
   
    clipsUp[ 3 ].x = DOT_WIDTH * 3;
    clipsUp[ 3 ].y = 0;
    clipsUp[ 3 ].w = DOT_WIDTH;
    clipsUp[ 3 ].h = DOT_HEIGHT;
   
    //Down Sprites
    clipsDown[ 0 ].x = 0;
    clipsDown[ 0 ].y = DOT_HEIGHT;
    clipsDown[ 0 ].w = DOT_WIDTH;
    clipsDown[ 0 ].h = DOT_HEIGHT;
   
    clipsDown[ 1 ].x = DOT_WIDTH;
    clipsDown[ 1 ].y = DOT_HEIGHT;
    clipsDown[ 1 ].w = DOT_WIDTH;
    clipsDown[ 1 ].h = DOT_HEIGHT;
   
    clipsDown[ 2 ].x = DOT_WIDTH * 2;
    clipsDown[ 2 ].y = DOT_HEIGHT;
    clipsDown[ 2 ].w = DOT_WIDTH;
    clipsDown[ 2 ].h = DOT_HEIGHT;
   
    clipsDown[ 3 ].x = DOT_WIDTH * 3;
    clipsDown[ 3 ].y = DOT_HEIGHT;
    clipsDown[ 3 ].w = DOT_WIDTH;
    clipsDown[ 3 ].h = DOT_HEIGHT;
   
    //Left Sprites
    clipsLeft[ 0 ].x = 0;
    clipsLeft[ 0 ].y = DOT_HEIGHT * 2;
    clipsLeft[ 0 ].w = DOT_WIDTH;
    clipsLeft[ 0 ].h = DOT_HEIGHT;
   
    clipsLeft[ 1 ].x = DOT_WIDTH;
    clipsLeft[ 1 ].y = DOT_HEIGHT * 2;
    clipsLeft[ 1 ].w = DOT_WIDTH;
    clipsLeft[ 1 ].h = DOT_HEIGHT;
   
    clipsLeft[ 2 ].x = DOT_WIDTH * 2;
    clipsLeft[ 2 ].y = DOT_HEIGHT * 2;
    clipsLeft[ 2 ].w = DOT_WIDTH;
    clipsLeft[ 2 ].h = DOT_HEIGHT;
   
    clipsLeft[ 3 ].x = DOT_WIDTH * 3;
    clipsLeft[ 3 ].y = DOT_HEIGHT * 2;
    clipsLeft[ 3 ].w = DOT_WIDTH;
    clipsLeft[ 3 ].h = DOT_HEIGHT;
   
    //Right Sprites
    clipsRight[ 0 ].x = 0;
    clipsRight[ 0 ].y = DOT_HEIGHT * 3;
    clipsRight[ 0 ].w = DOT_WIDTH;
    clipsRight[ 0 ].h = DOT_HEIGHT;
   
    clipsRight[ 1 ].x = DOT_WIDTH;
    clipsRight[ 1 ].y = DOT_HEIGHT * 3;
    clipsRight[ 1 ].w = DOT_WIDTH;
    clipsRight[ 1 ].h = DOT_HEIGHT;
   
    clipsRight[ 2 ].x = DOT_WIDTH * 2;
    clipsRight[ 2 ].y = DOT_HEIGHT * 3;
    clipsRight[ 2 ].w = DOT_WIDTH;
    clipsRight[ 2 ].h = DOT_HEIGHT;
   
    clipsRight[ 3 ].x = DOT_WIDTH * 3;
    clipsRight[ 3 ].y = DOT_HEIGHT * 3;
    clipsRight[ 3 ].w = DOT_WIDTH;
    clipsRight[ 3 ].h = DOT_HEIGHT;   
}

bool init()
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return false;   
    }
   
    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
   
    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return false;   
    }
   
    //Set the window caption
    SDL_WM_SetCaption( "Pokemon Blue SDL", NULL );
   
    //If everything initialized fine
    return true;
}

bool load_files()
{
    //Load the dot image
    dot = load_image( "character.bmp" );
   
    //If there was a problem in loading the dot
    if( dot == NULL )
    {
        return false;   
    }
   
    //If everything loaded fine
    return true;
}

void clean_up()
{
    //Free the surface
    SDL_FreeSurface( dot );
   
    //Quit SDL
    SDL_Quit();
}

Dot::Dot()
{
    //Initialize the offsets
    x = 0;
    y = 0;
    xprev = 0;
    yprev = 0;
    d = 1;
    anima = 0;
    index = 0;
    press_u = false;
    press_d = false;
    press_l = false;
    press_r = false;
   
}

void Dot::move()
{
    //If a key was pressed
    if( event.type == SDL_KEYDOWN )
    {
        switch( event.key.keysym.sym )
        {
            case SDLK_UP: press_u = true;; break;
            case SDLK_DOWN: press_d = true; break;
            case SDLK_LEFT: press_l = true; break;
            case SDLK_RIGHT: press_r = true; break;   
        }
    }
    else if( event.type == SDL_KEYUP )
    {
        switch( event.key.keysym.sym )
        {
            case SDLK_UP: press_u = false; break;
            case SDLK_DOWN: press_d = false; break;
            case SDLK_LEFT: press_l = false; break;
            case SDLK_RIGHT: press_r = false; break;   
       }       
    }
   
    if (x % 16 == 0 && y % 16 == 0)
    {   
      //if (xprev != x || yprev != y)
      //{
        xprev = x;
        yprev = y;
        //return;
      //}

      if (press_u)
      {
        y -= 2;
        d = 0;
       
        if (index % 2 != 0 && index < 4)
        {
          index++;
        }
       
        anima = 1;
        return;
      }
      else if (press_d)
      {
        y += 2;
        d = 1;
       
        if (index % 2 != 0 && index < 4)
        {
          index++;
        }
       
        anima = 1;
        return;
      }
      else if (press_l)
      {
        x -= 2;
        d = 2;
       
        if (index % 2 != 0 && index < 4)
        {
          index++;
        }
       
        anima = 1;
        return;
      }
      else if (press_r)
      {
        x += 2;
        d = 3;
       
        if (index % 2 != 0 && index < 4)
        {
          index++;
        }
       
        anima = 1;
        return;
      }
      else if (!press_u && !press_d && !press_l && !press_r)
      {
        if (index % 2 != 0 && index < 4)
        {
          index++;
          return;
        }
       
        if (index % 2 == 0)
        {
          anima = 0;
          return;
        }
      }
    }
    else
    {
      switch (d)
      {
        case 0: y -= 2; anima++; return; break;
        case 1: y += 2; anima++; return; break;
        case 2: x -= 2; anima++; return; break;
        case 3: x += 2; anima++; return; break;
      }
    }   
}

void Dot::show()
{
     
    if (index == 4)
    {
      index = 0;
    }
     
    switch (d)
    {
      case 0: apply_surface( x, y - 4, dot, screen, &clipsUp[ index ] ); break;
      case 1: apply_surface( x, y - 4, dot, screen, &clipsDown[ index ] ); break;
      case 2: apply_surface( x, y - 4, dot, screen, &clipsLeft[ index ] ); break;
      case 3: apply_surface( x, y - 4, dot, screen, &clipsRight[ index ] ); break;
    }
   
    if (anima == 3)
    {
      if (index <= 3)
      {
        index++;
      }
           
      if (index == 4)
      {
        index = 0;
      }
     
      return;
    }
    else if (anima == 4)
    {
      anima = 0;
      return;
    }

}

Timer::Timer()
{
    //Initialize the variables
    startTicks = 0;
    pausedTicks = 0;
    paused = false;
    started = false;   
}

void Timer::start()
{
    //Start the timer
    started = true;
   
    //Unpause the timer
    paused = false;
   
    //Get the current clock time
    startTicks = SDL_GetTicks();   
}

void Timer::stop()
{
    //Stop the timer
    started = false;
   
    //Unpause the timer
    paused = false;   
}

void Timer::pause()
{
    //If the timer is running and isn't already paused
    if( ( started == true ) && ( paused == false ) )
    {
        //Pause the timer
        paused = true;
   
        //Calculate the paused ticks
        pausedTicks = SDL_GetTicks() - startTicks;
    }
}

void Timer::unpause()
{
    //If the timer is paused
    if( paused == true )
    {
        //Unpause the timer
        paused = false;
   
        //Reset the starting ticks
        startTicks = SDL_GetTicks() - pausedTicks;
       
        //Reset the paused ticks
        pausedTicks = 0;
    }
}

int Timer::get_ticks()
{
    //If the timer is running
    if( started == true )
    {
        //If the timer is paused
        if( paused == true )
        {
            //Return the number of ticks when the timer was paused
            return pausedTicks;
        }
        else
        {
            //Return the current time minus the start time
            return SDL_GetTicks() - startTicks;
        }   
    }
   
    //If the timer isn't running
    return 0;   
}

bool Timer::is_started()
{
    return started;   
}

bool Timer::is_paused()
{
    return paused;   
}

int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;
   
    //The dot that will be used
    Dot myDot;
   
    set_clips();
   
    //The frame rate regulator
    Timer fps;
   
    //Initialize
    if( init() == false )
    {
        return 1;
    }
   
    //Load the files
    if( load_files() == false )
    {
        return 1;
    }

    //While the user hasn't quit
    while( quit == false )
    {
        //Start the frame timer
        fps.start();
       
        //While there's events to handle
        while( SDL_PollEvent( &event ) )
        {
            //Handle events for the dot
            myDot.move();
           
            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }
       
        //Fill the screen white
        SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 248, 248, 248 ) );
       
        //Move the dot
        myDot.move();
       
        //Show the dot on the screen
        myDot.show();
       
        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;   
        }
       
        //Cap the frame rate
        if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
        {
            SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
        }
    }
       
    //Clean up
    clean_up();
   
    return 0;   
}

Yeah, I just modified the dot movement Lazy Foo tutorial from that project page so that it moved in a grid and would animate.  It isn't that great and probably has redundancies in it due to that I was just seeing if I could get it to work.
Logged
Re: Pokemon Walking Engine
« Reply #39 on: September 19, 2008, 05:23:19 pm »
  • The devil in the mirror.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 238
Wow, all that code for... Ehhem, Well, good luck with it =D
Logged
Working on my Masters Degree in Computer Science.
Hey look, Zelda Coop....later.
Proud user of C++ for 9 years, and counting!
Pages: 1 [2] 3 4   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.117 seconds with 74 queries.

anything