Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2008
    Posts
    1

    Evil monkey character problem

    Hey I seem to be having a problem getting my code to work properly, the way it's going I can get my character to appear on screen but he's confined to the top left corner only.

    Been trying to figure it out for a while and figured I might as well ask, somebody might have run into the problem before. Or they might see something I keep missing.

    Here's the code for my character header and cpp files.

    Character.h
    Code:
    #ifndef CHARACTER_H
    #define CHARACTER_H
    #include "sprite.h"
    class Character: Sprite
    {
    public:
    	Character(DrawEngine *de,int s_index, float x=1, float y=1, int lives=3, char up_key = 'w', char down_key = 's', char right_key = 'd', char left_key = 'a');
    	virtual bool keyPress(char c);
    
    private:
    	char upKey;
    	char downKey;
    	char leftKey;
    	char rightKey;
    };
    
    #endif
    Character.cpp
    Code:
    #include "character.h"
    
    
    Character::Character(DrawEngine *de, int s_index, float x, float y, int lives, char u, char d, char r, char l):Sprite(de,s_index,x,y,lives) 
    {
    	upKey=u;
    	downKey=d;
    	leftKey=l;
    	rightKey=r;
    
    	classID=CHARACTER_CLASSID;
    }
    bool Character::keyPress(char c)
    {
    	if (c==upKey)
    	{
    		return move(0,-1);
    	}
    	else if (c==downKey)
    	{
    		return move(0,1);
    	}
    	else if (c==rightKey)
    	{
    		return move(1,0);
    	}
    		else if (c==leftKey)
    	{
    		return move(-1,0);
    	}
    	return false;
    }

  2. #2
    Join Date
    Nov 2006
    Location
    UK
    Posts
    3,774
    First thing to do is check that the keypress event is being called, then, debug it, as when you step through it you should find out what "c" contains and why maybe its not working.
    Delphi !ROCKS!
    Got a question? Read this first!!!
    "You gotta help us, Doc. We've tried nothin' and we're all out of ideas"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •