Jump to content
  • Advertisement
Sign in to follow this  
willthiswork89

Looking for someone with lots of experience in tile/sdl programming

This topic is 4529 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

there is somthing critically wrong with my program... im looking for someone to take the time to look at it... its like 800 lines maybe? basically its close.. my first attempt on this tile engine after doing tons of research and having a friend help me i got this kinda working but not really lol.. i can get it working per tile but the smooth scrolling it posing to be a challenge... regardless of all the game dev ive read... i know im close but not quite...
//define.h(just in case your were curious)

#ifndef DEFINE_H
#define DEFINE_H

#include <SDL/SDL.h>
#include <string>
using namespace std;
#define SWIDTH 640
#define SHEIGHT 480
#define BPP 32
#define FPS 10
#define TileW 32
#define TileH 32
#define Wizzy_Height 64
#define Wizzy_Width 32
#define Wizzy_Right 0
#define Wizzy_Left 1
#define Wizzy_Up 2
#define Wizzy_Down 3
#define Wizzy_AttackL 4
#define Wizzy_AttackR 5
#define Dead_Ball 0
#define Left_Ball 1
#define Right_Ball 2

SDL_Surface* Wizzy = NULL;
SDL_Surface* MainScreen = NULL;
SDL_Surface* Rock = NULL;
SDL_Surface* Grass = NULL;


int Map[100][100];
int ViewCenterX,ViewCenterY;
SDL_Event event;
SDL_Rect clipsLeft[10];
SDL_Rect clipsRight[10];
SDL_Rect clipsUp[10];
SDL_Rect clipsDown[10];
SDL_Rect clipsAttackL[10];
SDL_Rect clipsAttackR[10];
SDL_Rect clipLaser;

Uint8 *keystates = SDL_GetKeyState( NULL );


void SetClips();
SDL_Surface* Load_Image(string filename);
void Blit_Surface(int x, int y, SDL_Surface* Source, SDL_Surface* Destination, SDL_Rect* Clip = NULL);
void Blit_Tile(int x, int y, int mapC, int mapR);
bool init();
bool Fire = false;
int xPos,yPos;
bool LockCamera;
bool set = false;
bool Load_Files();
void CheckCamera();
void Ending();
void SetArray();
void DrawTiles();
bool Walkable();
class Wizard
{
private:


    int FrameX,FrameY;




public:
int VelocityX,VelocityY,FrameA;
int OffsetX,OffsetY;
Wizard();
int Status;
void Handle_Event(SDL_Event &event);
void Show(SDL_Surface* screen);

};

class Attack
{
    private:
    int OffsetX, OffsetY;
    int VelocityX, VelocityY;


    public:
    int Status;
    Attack(int X, int Y);
    void Show();
};
#endif

okay theres my define nothing really... heres my code...
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "TIMERC.H"
#include "define.h"
#include <string>
using namespace std;





int main(int argc, char* args[])
{
    bool quit = false;

    if(init() == false)
    {
        return 1;
    }

    if(Load_Files() == false)
    {
        return 1;
    }
SetArray();
    SetClips();

    Timer fps;

    Wizard Walk;

    Attack test(0,0);

    ViewCenterX = SWIDTH/2;
    ViewCenterY = SHEIGHT/2;
    Walk.OffsetX = 0;
    Walk.OffsetY = 0;
    LockCamera = false;

    while(quit == false)
    {
        SDL_Delay(0);
        fps.start();

        while(SDL_PollEvent(&event))
        {
            if(event.key.keysym.sym == SDLK_ESCAPE)
            {
                quit = true;
            }
            if(event.type == SDL_QUIT)
            {
                quit = true;
            }

        }

        if(keystates[SDLK_UP])
        {
            Walk.VelocityY -= 15;
        }
        else if(keystates[SDLK_DOWN])
        {
            Walk.VelocityY += 15;
        }

        else if(keystates[SDLK_LEFT] )
        {
            Walk.VelocityX -= 15;
        }
        else if( keystates[SDLK_RIGHT])
        {
            Walk.VelocityX += 15;
        }
        else if(keystates[SDLK_SPACE])
        {
            if(Walk.Status == Wizzy_Left && test.Status == Dead_Ball)
            {
                Walk.Status = Wizzy_AttackL;
            }
            else if(Walk.Status == Wizzy_Right && test.Status == Dead_Ball)
            {
                Walk.Status = Wizzy_AttackR;
            }
        }

        if(keystates[SDLK_w])
        {
            if(!LockCamera)
            {
                ViewCenterY -= 15;
            }
        }
        if(keystates[SDLK_a])
        {
            if(!LockCamera)
            {
            ViewCenterX -= 15;
            }
        }
        if(keystates[SDLK_s])
        {
            if(!LockCamera)
            {
            ViewCenterY += 15;
            }
        }
        if(keystates[SDLK_d])
        {
            if(!LockCamera)
            {
            ViewCenterX += 15;
            }
        }
        if(keystates[SDLK_c])
        {
            LockCamera = !LockCamera;
        }
        CheckCamera();
        DrawTiles();
        Walk.Show(MainScreen);
        if(Walk.Status == Wizzy_AttackL && test.Status == Dead_Ball && Walk.FrameA == 5)
        {
            test.Status = Left_Ball;

            Fire = true;

        }
        else if(Walk.Status == Wizzy_AttackR && test.Status == Dead_Ball && Walk.FrameA == 5)
        {
            test.Status = Right_Ball;
            Fire = true;
        }

        Walk.VelocityX = 0;
        Walk.VelocityY = 0;
        xPos = Walk.OffsetX;
        yPos = Walk.OffsetY;
        if(Fire == true)
        {
            test.Show();
        }

        if(SDL_Flip(MainScreen) == -1)
        {
            return 1;
        }
        while(fps.GetTicks() < 1000 / FPS)
        {
            //waiting
        }
Uint8 st=SDL_GetAppState();
 if ((st==SDL_APPACTIVE) || (! st) )
 SDL_Delay(1500);
else SDL_Delay(0);

    }
    Ending();
    return 0;
}

//wizard class Definition
Wizard::Wizard()
{
    OffsetX = SWIDTH /2 - Wizzy_Width / 2;
    OffsetY = SHEIGHT / 2 - Wizzy_Height /2;
    FrameY = 0;
    FrameX = 0;
    FrameA = 0;

    VelocityX = 0;
    VelocityY = 0;
    Status = Wizzy_Right;
}



void Wizard::Show(SDL_Surface* screen)
{

    OffsetX += VelocityX;
    ViewCenterX += VelocityX;
    if(VelocityX == 0)
    {
        OffsetY += VelocityY;
        ViewCenterY += VelocityY;

    }
    xPos = OffsetX;
    yPos = OffsetY;
    if(Walkable() == false)
    {

        ViewCenterX -= VelocityX;
        ViewCenterY -= VelocityY;
        OffsetX -= VelocityX;
        OffsetY -= VelocityY;
    }


    if(VelocityY < 0)
    {
        Status = Wizzy_Up;
        FrameY++;
    }
    else if(VelocityY > 0)
    {
        Status = Wizzy_Down;
        FrameY++;
    }


    if(Status == Wizzy_AttackL)
    {
        FrameA++;
    }
    else if(Status == Wizzy_AttackR)
    {
        FrameA++;
    }


     else if(VelocityX < 0)
    {
    Status = Wizzy_Left;
    FrameX++;

    }
    else if(VelocityX > 0)
    {
    Status = Wizzy_Right;
    FrameX++;

    }
    if(Status == Wizzy_Left)
    {
        FrameX++;
    }
    else if(Status == Wizzy_Right)
    {
        FrameX++;
    }
    else if(Status == Wizzy_Down)
    {
        FrameY++;
    }
    else if(Status == Wizzy_Up)
    {
        FrameY++;
    }

    if(FrameX > 9)
    {
        FrameX = 0;
    }
    if(FrameY > 9)
    {
        FrameY = 0;
    }
    if(FrameA > 9)
    {
        FrameA = 0;
        if(Status == Wizzy_AttackL)
        {
            Status = Wizzy_Left;
        }
        else if(Status == Wizzy_AttackR)
        {
            Status = Wizzy_Right;
        }
    }

xPos = OffsetX;
yPos = OffsetY;

    if(Status == Wizzy_Up)
    {
        Blit_Surface(SWIDTH/2 - (ViewCenterX-OffsetX), SHEIGHT/2 - (ViewCenterY-OffsetY), Wizzy,MainScreen, &clipsUp[FrameY]);
    }
    if(Status == Wizzy_Down)
    {
        Blit_Surface(SWIDTH/2 - (ViewCenterX-OffsetX), SHEIGHT/2 - (ViewCenterY-OffsetY), Wizzy,MainScreen, &clipsDown[FrameY]);
    }


    if(Status == Wizzy_Left)
    {
        Blit_Surface(SWIDTH/2 - (ViewCenterX - OffsetX),SHEIGHT/2 - (ViewCenterY -  OffsetY), Wizzy, MainScreen, &clipsLeft[FrameX]);

    }
    else if(Status == Wizzy_Right)
    {
        Blit_Surface(SWIDTH/2 - (ViewCenterX - OffsetX),SHEIGHT/2 - (ViewCenterY -  OffsetY), Wizzy, MainScreen, &clipsRight[FrameX]);

    }
    if(Status == Wizzy_AttackL)
    {
        Blit_Surface(SWIDTH/2 - (ViewCenterX - OffsetX), SHEIGHT/2 - (ViewCenterY -OffsetY), Wizzy, MainScreen, &clipsAttackL[FrameA]);



    }
    if(Status == Wizzy_AttackR)
    {
        Blit_Surface(SWIDTH /2 - (ViewCenterX - OffsetX), SHEIGHT/2 - (ViewCenterY - OffsetY), Wizzy, MainScreen, &clipsAttackR[FrameA]);

        }


}

//End Wizard Class Definition

//Attack Definition

Attack::Attack(int X, int Y)
{
OffsetX = X;
OffsetY = Y;
VelocityX = 16;
VelocityY = 16;
Status = Dead_Ball;

}
void Attack::Show()
{
    if(set == false)
    {
        set = true;

    OffsetY = yPos + 20;
    OffsetX = xPos;
    }
if(Status == Left_Ball)
{


    OffsetX -= VelocityX;
}
if(Status == Right_Ball)
{

    OffsetX += 20;

}

    if(OffsetX < 0)
    {

        Status = Dead_Ball;
        OffsetX = 0;
        Fire = false;
        set = false;
    }
    if(OffsetX + 32 > SWIDTH)
    {

        Status = Dead_Ball;
        OffsetX = 0;
        Fire = false;
        set = false;
    }
if(Status != Dead_Ball)
{
        Blit_Surface(SWIDTH/2 - (ViewCenterX - OffsetX),SHEIGHT/2 - (ViewCenterY - OffsetY),Wizzy,MainScreen, &clipLaser);
}



}
void SetClips()
{

    clipsLeft[0].x = 0;
    clipsLeft[0].y = 0;
    clipsLeft[0].w = Wizzy_Width;
    clipsLeft[0].h = Wizzy_Height;

    clipsLeft[1].x = Wizzy_Width;
    clipsLeft[1].y = 0;
    clipsLeft[1].w = Wizzy_Width;
    clipsLeft[1].h = Wizzy_Height;

    clipsLeft[2].x = Wizzy_Width *2;
    clipsLeft[2].y = 0;
    clipsLeft[2].w = Wizzy_Width;
    clipsLeft[2].h = Wizzy_Height;

    clipsLeft[3].x = Wizzy_Width *3;
    clipsLeft[3].y = 0;
    clipsLeft[3].w = Wizzy_Width;
    clipsLeft[3].h = Wizzy_Height;

    clipsLeft[4].x = Wizzy_Width *4;
    clipsLeft[4].y = 0;
    clipsLeft[4].w = Wizzy_Width;
    clipsLeft[4].h = Wizzy_Height;

    clipsLeft[5].x = Wizzy_Width *5;
    clipsLeft[5].y = 0;
    clipsLeft[5].w = Wizzy_Width;
    clipsLeft[5].h = Wizzy_Height;

    clipsLeft[6].x = Wizzy_Width *6;
    clipsLeft[6].y = 0;
    clipsLeft[6].w = Wizzy_Width;
    clipsLeft[6].h = Wizzy_Height;

    clipsLeft[7].x = Wizzy_Width *7;
    clipsLeft[7].y = 0;
    clipsLeft[7].w = Wizzy_Width;
    clipsLeft[7].h = Wizzy_Height;

    clipsLeft[8].x = Wizzy_Width *8;
    clipsLeft[8].y = 0;
    clipsLeft[8].w = Wizzy_Width;
    clipsLeft[8].h = Wizzy_Height;

    clipsLeft[9].x = Wizzy_Width *9;
    clipsLeft[9].y = 0;
    clipsLeft[9].w = Wizzy_Width;
    clipsLeft[9].h = Wizzy_Height;

    clipLaser.x = Wizzy_Width *10;
    clipLaser.y = 0;
    clipLaser.w = 32;
    clipLaser.h = 32;


    clipsRight[0].x = 0;
    clipsRight[0].y = Wizzy_Height;
    clipsRight[0].w = Wizzy_Width;
    clipsRight[0].h = Wizzy_Height;

    clipsRight[1].x = Wizzy_Width;
    clipsRight[1].y = Wizzy_Height;
    clipsRight[1].w = Wizzy_Width;
    clipsRight[1].h = Wizzy_Height;

    clipsRight[2].x = Wizzy_Width *2;
    clipsRight[2].y = Wizzy_Height;
    clipsRight[2].w = Wizzy_Width;
    clipsRight[2].h = Wizzy_Height;

    clipsRight[3].x = Wizzy_Width *3;
    clipsRight[3].y = Wizzy_Height;
    clipsRight[3].w = Wizzy_Width;
    clipsRight[3].h = Wizzy_Height;

    clipsRight[4].x = Wizzy_Width *4;
    clipsRight[4].y = Wizzy_Height;
    clipsRight[4].w = Wizzy_Width;
    clipsRight[4].h = Wizzy_Height;

    clipsRight[5].x = Wizzy_Width *5;
    clipsRight[5].y = Wizzy_Height;
    clipsRight[5].w = Wizzy_Width;
    clipsRight[5].h = Wizzy_Height;

    clipsRight[6].x = Wizzy_Width *6;
    clipsRight[6].y = Wizzy_Height;
    clipsRight[6].w = Wizzy_Width;
    clipsRight[6].h = Wizzy_Height;

    clipsRight[7].x = Wizzy_Width *7;
    clipsRight[7].y = Wizzy_Height;
    clipsRight[7].w = Wizzy_Width;
    clipsRight[7].h = Wizzy_Height;

    clipsRight[8].x = Wizzy_Width *8;
    clipsRight[8].y = Wizzy_Height;
    clipsRight[8].w = Wizzy_Width;
    clipsRight[8].h = Wizzy_Height;

    clipsRight[9].x = Wizzy_Width *9;
    clipsRight[9].y = Wizzy_Height;
    clipsRight[9].w = Wizzy_Width;
    clipsRight[9].h = Wizzy_Height;

    clipsDown[0].x = 0;
    clipsDown[0].y = Wizzy_Height *2;
    clipsDown[0].w = Wizzy_Width;
    clipsDown[0].h = Wizzy_Height;

    clipsDown[1].x = Wizzy_Width;
    clipsDown[1].y = Wizzy_Height *2;
    clipsDown[1].w = Wizzy_Width;
    clipsDown[1].h = Wizzy_Height;

    clipsDown[2].x = Wizzy_Width *2;
    clipsDown[2].y = Wizzy_Height *2;
    clipsDown[2].w = Wizzy_Width;
    clipsDown[2].h = Wizzy_Height;

    clipsDown[3].x = Wizzy_Width *3;
    clipsDown[3].y = Wizzy_Height *2;
    clipsDown[3].w = Wizzy_Width;
    clipsDown[3].h = Wizzy_Height;

    clipsDown[4].x = Wizzy_Width *4;
    clipsDown[4].y = Wizzy_Height *2;
    clipsDown[4].w = Wizzy_Width;
    clipsDown[4].h = Wizzy_Height;

    clipsDown[5].x = Wizzy_Width *5;
    clipsDown[5].y = Wizzy_Height *2;
    clipsDown[5].w = Wizzy_Width;
    clipsDown[5].h = Wizzy_Height;

    clipsDown[6].x = Wizzy_Width *6;
    clipsDown[6].y = Wizzy_Height *2;
    clipsDown[6].w = Wizzy_Width;
    clipsDown[6].h = Wizzy_Height;

    clipsDown[7].x = Wizzy_Width *7;
    clipsDown[7].y = Wizzy_Height *2;
    clipsDown[7].w = Wizzy_Width;
    clipsDown[7].h = Wizzy_Height;

    clipsDown[8].x = Wizzy_Width *8;
    clipsDown[8].y = Wizzy_Height *2;
    clipsDown[8].w = Wizzy_Width;
    clipsDown[8].h = Wizzy_Height;

    clipsDown[9].x = Wizzy_Width *9;
    clipsDown[9].y = Wizzy_Height *2;
    clipsDown[9].w = Wizzy_Width;
    clipsDown[9].h = Wizzy_Height;

    clipsUp[0].x = 0;
    clipsUp[0].y = Wizzy_Height *3;
    clipsUp[0].w = Wizzy_Width;
    clipsUp[0].h = Wizzy_Height;

    clipsUp[1].x = Wizzy_Width;
    clipsUp[1].y = Wizzy_Height *3;
    clipsUp[1].w = Wizzy_Width;
    clipsUp[1].h = Wizzy_Height;

    clipsUp[2].x = Wizzy_Width *2;
    clipsUp[2].y = Wizzy_Height *3;
    clipsUp[2].w = Wizzy_Width;
    clipsUp[2].h = Wizzy_Height;

    clipsUp[3].x = Wizzy_Width *3;
    clipsUp[3].y = Wizzy_Height *3;
    clipsUp[3].w = Wizzy_Width;
    clipsUp[3].h = Wizzy_Height;

    clipsUp[4].x = Wizzy_Width *4;
    clipsUp[4].y = Wizzy_Height *3;
    clipsUp[4].w = Wizzy_Width;
    clipsUp[4].h = Wizzy_Height;

    clipsUp[5].x = Wizzy_Width *5;
    clipsUp[5].y = Wizzy_Height *3;
    clipsUp[5].w = Wizzy_Width;
    clipsUp[5].h = Wizzy_Height;

    clipsUp[6].x = Wizzy_Width *6;
    clipsUp[6].y = Wizzy_Height *3;
    clipsUp[6].w = Wizzy_Width;
    clipsUp[6].h = Wizzy_Height;

    clipsUp[7].x = Wizzy_Width *7;
    clipsUp[7].y = Wizzy_Height *3;
    clipsUp[7].w = Wizzy_Width;
    clipsUp[7].h = Wizzy_Height;

    clipsUp[8].x = Wizzy_Width *8;
    clipsUp[8].y = Wizzy_Height *3;
    clipsUp[8].w = Wizzy_Width;
    clipsUp[8].h = Wizzy_Height;

    clipsUp[9].x = Wizzy_Width *9;
    clipsUp[9].y = Wizzy_Height *3;
    clipsUp[9].w = Wizzy_Width;
    clipsUp[9].h = Wizzy_Height;

    clipsAttackL[0].x = 0;
    clipsAttackL[0].y = Wizzy_Height *4;
    clipsAttackL[0].w = Wizzy_Width;
    clipsAttackL[0].h = Wizzy_Height;

    clipsAttackL[1].x = Wizzy_Width;
    clipsAttackL[1].y = Wizzy_Height *4;
    clipsAttackL[1].w = Wizzy_Width;
    clipsAttackL[1].h = Wizzy_Height;

    clipsAttackL[2].x = Wizzy_Width *2;
    clipsAttackL[2].y = Wizzy_Height *4;
    clipsAttackL[2].w = Wizzy_Width;
    clipsAttackL[2].h = Wizzy_Height;

    clipsAttackL[3].x = Wizzy_Width *3;
    clipsAttackL[3].y = Wizzy_Height *4;
    clipsAttackL[3].w = Wizzy_Width;
    clipsAttackL[3].h = Wizzy_Height;

    clipsAttackL[4].x = Wizzy_Width *4;
    clipsAttackL[4].y = Wizzy_Height *4;
    clipsAttackL[4].w = Wizzy_Width;
    clipsAttackL[4].h = Wizzy_Height;

    clipsAttackL[5].x = Wizzy_Width *5;
    clipsAttackL[5].y = Wizzy_Height *4;
    clipsAttackL[5].w = Wizzy_Width;
    clipsAttackL[5].h = Wizzy_Height;

    clipsAttackL[6].x = Wizzy_Width *6;
    clipsAttackL[6].y = Wizzy_Height *4;
    clipsAttackL[6].w = Wizzy_Width;
    clipsAttackL[6].h = Wizzy_Height;

    clipsAttackL[7].x = Wizzy_Width *7;
    clipsAttackL[7].y = Wizzy_Height *4;
    clipsAttackL[7].w = Wizzy_Width;
    clipsAttackL[7].h = Wizzy_Height;

    clipsAttackL[8].x = Wizzy_Width *8;
    clipsAttackL[8].y = Wizzy_Height *4;
    clipsAttackL[8].w = Wizzy_Width;
    clipsAttackL[8].h = Wizzy_Height;

    clipsAttackL[9].x = Wizzy_Width *9;
    clipsAttackL[9].y = Wizzy_Height *4;
    clipsAttackL[9].w = Wizzy_Width;
    clipsAttackL[9].h = Wizzy_Height;



    clipsAttackR[0].x = 0;
    clipsAttackR[0].y = Wizzy_Height *5;
    clipsAttackR[0].w = Wizzy_Width;
    clipsAttackR[0].h = Wizzy_Height;

    clipsAttackR[1].x = Wizzy_Width;
    clipsAttackR[1].y = Wizzy_Height *5;
    clipsAttackR[1].w = Wizzy_Width;
    clipsAttackR[1].h = Wizzy_Height;

    clipsAttackR[2].x = Wizzy_Width *2;
    clipsAttackR[2].y = Wizzy_Height *5;
    clipsAttackR[2].w = Wizzy_Width;
    clipsAttackR[2].h = Wizzy_Height;

    clipsAttackR[3].x = Wizzy_Width *3;
    clipsAttackR[3].y = Wizzy_Height *5;
    clipsAttackR[3].w = Wizzy_Width;
    clipsAttackR[3].h = Wizzy_Height;

    clipsAttackR[4].x = Wizzy_Width *4;
    clipsAttackR[4].y = Wizzy_Height *5;
    clipsAttackR[4].w = Wizzy_Width;
    clipsAttackR[4].h = Wizzy_Height;

    clipsAttackR[5].x = Wizzy_Width *5;
    clipsAttackR[5].y = Wizzy_Height *5;
    clipsAttackR[5].w = Wizzy_Width;
    clipsAttackR[5].h = Wizzy_Height;

    clipsAttackR[6].x = Wizzy_Width *6;
    clipsAttackR[6].y = Wizzy_Height *5;
    clipsAttackR[6].w = Wizzy_Width;
    clipsAttackR[6].h = Wizzy_Height;

    clipsAttackR[7].x = Wizzy_Width *7;
    clipsAttackR[7].y = Wizzy_Height *5;
    clipsAttackR[7].w = Wizzy_Width;
    clipsAttackR[7].h = Wizzy_Height;

    clipsAttackR[8].x = Wizzy_Width *8;
    clipsAttackR[8].y = Wizzy_Height *5;
    clipsAttackR[8].w = Wizzy_Width;
    clipsAttackR[8].h = Wizzy_Height;

    clipsAttackR[9].x = Wizzy_Width *9;
    clipsAttackR[9].y = Wizzy_Height *5;
    clipsAttackR[9].w = Wizzy_Width;
    clipsAttackR[9].h = Wizzy_Height;



}

SDL_Surface* Load_Image(string filename)
{
    SDL_Surface* Temporary = NULL;
    SDL_Surface* Final = NULL;

    Temporary = IMG_Load(filename.c_str());

    if(Temporary != NULL)
    {
        Final = SDL_DisplayFormat( Temporary );
        SDL_FreeSurface(Temporary);

        if(Final != NULL)
        {
 SDL_SetColorKey(Final, SDL_RLEACCEL|SDL_SRCCOLORKEY, 0x00FFFF);
        }

    }
    else if(Temporary == NULL)
    {
        printf("Unable To Load: %s", filename.c_str());

    }
    return Final;
}

void Blit_Surface(int x, int y, SDL_Surface* Source, SDL_Surface* Destination, SDL_Rect* Clip)
{
   SDL_Rect Ofs;

   Ofs.x = x;
   Ofs.y = y;

   SDL_BlitSurface(Source, Clip, Destination, &Ofs);
}

bool init()
{
    if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_CDROM) == -1)
    {
        printf("Unable To Init Video: %s", SDL_GetError());
        return false;
    }

    MainScreen = SDL_SetVideoMode(SWIDTH,SHEIGHT,BPP, SDL_HWSURFACE|SDL_DOUBLEBUF);

    if(MainScreen == NULL)
    {
        printf("Unable to Set Video Mode: %s", SDL_GetError());
        return false;
    }

    SDL_WM_SetCaption("Animation Test", NULL);

    return true;
}

bool Load_Files()
{
    Wizzy = Load_Image("Robot.bmp");

    if(Wizzy == NULL)
    {
        printf("Unable To Load Wizard");
    return false;
    }

    Grass = Load_Image("Grass.png");
    Rock = Load_Image("Rock.png");

    if(Grass == NULL)
    {
        printf("Unable to Load Grass");
        return false;
    }

    return true;
}
void Ending()
{
    SDL_FreeSurface(Wizzy);
    SDL_FreeSurface(Rock);
    SDL_FreeSurface(Grass);
    SDL_FreeSurface(MainScreen);
    SDL_Quit();
}
void SetArray()
{
    for(int row = 0; row < 100; row++)
    {
        for(int col = 0; col < 100; col++)
        {
            if(row == 0 || row == 99)
            {
                Map[row][col] = 1;
            }
            else if(col == 0 || col == 99)
            {
                Map[row][col] = 1;
            }
            else
            {
                Map[row][col] = 0;
            }

        }
    }
}
void BlitTile(int x, int y, int mapC, int mapR)
{
    SDL_Rect Ofs;

    Ofs.x = x;
    Ofs.y = y;

    switch(Map[mapR][mapC])
    {
        case 0:
        SDL_BlitSurface(Grass, NULL, MainScreen, &Ofs);break;
        case 1:
        SDL_BlitSurface(Rock, NULL,MainScreen, &Ofs);break;
    }
}

void DrawTiles()
{


    int TileC = (int)(ViewCenterX / TileW);
    int TileR = (int)(ViewCenterY / TileH);

    float OfsX = -(ViewCenterX - TileC*32);
    float OfsY = -(ViewCenterY - TileR*32);

    int TileCInit = TileC;
    int TileRInit = TileR;

    for(int col = 0; col < 21; col++)
    {
        for(int row = 0;row < 16; row++)
        {
            printf("%i, ", col);
            printf("%i\n", row);
            int YCoord = (int)(row*32 + OfsY);
            int XCoord = (int)(col*32 + OfsX);

            BlitTile(XCoord, YCoord, TileCInit+col, TileRInit +row);
        }
    }
}

bool Walkable()
{
    int Column = xPos / 32;
    int Row = yPos / 32;
    int Column2 = (xPos + Wizzy_Width)/32;
    int Row2 = (yPos + Wizzy_Height) / 32;




    if(Map[Row][Column] == 1 || Map[Row2][Column2] == 1)
    {
        return false;
    }
    else
    {
        return true;
    }
}

void CheckCamera()
{
    int col = 100;
    int row = 100;
    int edgex = ViewCenterX-(SWIDTH/2);
	int edgey = ViewCenterY-(SHEIGHT/2);
if(edgex >= 0 && edgex <= col*32)
	{ViewCenterX = xPos;
	}
	if(edgey >= 0 && edgey <= row*32)
	{ ViewCenterY = yPos;
	}
}

if you have any question or anything you wanted to talk to me about just aim me at willthiswork89 thank you for your time and even considering reading this.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by willthiswork89
if you have any question or anything you wanted to talk to me about just aim me at willthiswork89 thank you for your time and even considering reading this.


Correct me if I'm wrong, but I thought you were the one who had a question?

Share this post


Link to post
Share on other sites
Quote:
Original post by Spoonbender
Quote:
Original post by willthiswork89
if you have any question or anything you wanted to talk to me about just aim me at willthiswork89 thank you for your time and even considering reading this.


Correct me if I'm wrong, but I thought you were the one who had a question?


I belive the OP meant if we had any question about his code, so he can help us help him...


To OP: I'm a bit too tired to dig into your code right now, but the way i solved smooth scrolling was that i kept the tile world as one entity or class, and gave it a center position, so that all tiles are calculated from that position. Then it's simple to just place the the player in the middle of the screen and then the world under it, and scroll the world around when the player moves. I never moved the player, it was always in the center of the screen. I just moved the world around. It worked like a charm... =)

Share this post


Link to post
Share on other sites
I'm using SDL and tiling for my port, but it is C# and .NET.
Lucky for you the logic should be the same without regard to language.

I did what Android_s did; I centered the player on the screen and positioned the world in relation to him. The player's position was in pixel position, so that he didn't have to be centered on the tile. To make the sides flow I drew off the edges a bit otherwise it wouldn't look correct.

My surface is 810x630, but you will notice I 840x660 worth of pixels. This is necessary if you are not centered on pixels. The main part of the logic is in pointx, pointy and a bit for the tilex, tiley.

private void DrawMap()
{
for (int y = 0; y < 22; ++y)
{
for (int x = 0; x < 28; ++x)
{
int pointx = (x * TILE_SIZE) - (posx % TILE_SIZE); // The point on the surface (in pixels)
int pointy = (y * TILE_SIZE) - (posy % TILE_SIZE);
int tilex = (posx / TILE_SIZE) - HALF_SCREEN_X + x; // The tile from the map (in tiles)
int tiley = (posy / TILE_SIZE) - HALF_SCREEN_Y + y;
Point pt = new Point(pointx, pointy);
Pair p = room.getGround(tilex, tiley);
Rectangle rect = new Rectangle((int)p.First * TILE_SIZE, (int)p.Second * TILE_SIZE, TILE_SIZE, TILE_SIZE); // The rect is from my room background picture
screen.Blit(background, pt, rect);

p = room.getBGround1(tilex, tiley);
if ((int)p.First != 0 || (int)p.Second != 0)
{
rect = new Rectangle((int)p.First * TILE_SIZE, (int)p.Second * TILE_SIZE, TILE_SIZE, TILE_SIZE);
screen.Blit(background, pt, rect);
}

}
}
screen.Update();
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!