All pastes #55407 Raw Edit

Untitled

public cpp v1 · immutable
#55407 ·published 2006-05-12 16:18 UTC
rendered paste body
/* main.h */#ifndef MAIN_H#define MAIN_H// Basically, first, as on top of all HAM files, the most// important include is the mygba.h, which contains all the// macro definitions, and the HAMlib function prototypes.#include <mygba.h>#include "model/Sprite.h"#include "model/Character.h"/********************************************************************************* * MULTIBOOT is interesting. * If you write this on the top of your main file, * the GBA ROM you build will automatically be capable of running both * from FLA carts and, in addition directly over the MBV2 cable. * If you do not need this, simply comment it out. ********************************************************************************/MULTIBOOT/********************************************************************************* * Globals ********************************************************************************/bool g_NewFrame=true;/********************************************************************************* * Prototypes ********************************************************************************/void vblFunc(void);#endif /* MAIN_H *//* END OF FILE *//* main.cpp *//********************************************************************************* * Includes ********************************************************************************/#include "main.h"#include "DrawEngine.h"#include "model/World.h"#include "model/Character.h"World* world;DrawEngine* de;Character joe;/********************************************************************************* * Program entry point ********************************************************************************/int main(void){    // Initialize HAMlib    // Then we call the single most important function of ham, ham_Init .    // This function must be called first thing when working with HAMlib,    // because all ham_* functions will only work correctly after this has been called.    // Behaviour of HAMlib is undefined if you comment this out.    ham_Init();    // Will, once activated, trigger the specified interrupt,    // and then call the function specified    ham_StartIntHandler(INT_TYPE_VBL,         // The Interrupts ID you want to start.                        (void *)&vblFunc);    // The adress of a function that should be called when the interrupt is fired    char* str = "debug";    world = new World();    de = new DrawEngine();        // Loop    while(true)    {        // It's a new frame?        if(g_NewFrame)        {            // Frames isn't new anymore            g_NewFrame=false;        }    }    return 0;}/********************************************************************************* * vblFunc(void) * * This function is called whenever the GBA is about * to draw a new picture onto the screen. ********************************************************************************/void vblFunc(void){    // Call this (preferably during a VBL interrupt) to commit your    // ham_obj information to the hardware. Only after you did this your    // sprite changes will appear on screen.    de->redraw(world);    ham_CopyObjToOAM();    // It's a new frame yet    g_NewFrame=true;}/* END OF FILE *//* DrawEngine.h */#ifndef DRAWENGINE_H#define DRAWENGINE_H#include <mygba.h>#include "model/World.h"#include "model/Character.h"class DrawEngine {    public:        DrawEngine();        ~DrawEngine();        void redraw(World*);    private:        char* str;        World* world;};#endif/* END OF FILE *//* DrawEngine.cpp */#include <mygba.h>#include "DrawEngine.h"#include "model/World.h"#include "model/Sprite.h"#include "model/Character.h"#include "../art/aczid.pal.c"#include "../art/aczid.raw.c"DrawEngine::DrawEngine(){    // Initialize the sprite palette    ham_LoadObjPal((void*)aczid_Palette, 256);    //ham_SetFxMode(FX_LAYER_SELECT(1,0,0,0,0,0), FX_LAYER_SELECT(0,1,0,0,0,0), FX_MODE_ALPHABLEND);    ham_InitText(0);    str = "debug";}void DrawEngine::redraw(World* world){    //ham_SetObjX(aczid,aczid_x);    //ham_SetObjY(aczid,aczid_y);    for(int i = 0; i<=world->getNumberOfBaddies(); i++){        // Create the sprite and store the object number        Character* test = new Character(1,12,23,34,45);        ham_DrawText(1,1,"%s %d",str,(int) test->getX());        Sprite* bla = world->baddies[i];        ham_DrawText(1,2,"%s %d",str,(int) bla->getX());        bla->setX(20);        ham_DrawText(1,3,"%s %d",str,(int) bla->getX());        //ham_DrawText(1,3,"%s %d",str,(int) world->baddies[i]->getX());        //bla->sprite = ham_CreateObj((void*)aczid_Bitmap,OBJ_SIZE_64X64, OBJ_MODE_SEMITRANSPARENT,1,0,0,0,0,0,0,bla->getX(),bla->getY());        //ham_DrawText(1,1,"%s %d",str,(int) &bla);        //ham_DrawText(1,2,"%s %d",str,(int) ->getX());        //ham_DrawText(1,3,"%s %d",str,(int) i);        //ham_DrawText(1,4,"%s %d",str,(int) world->a);        //delete bla;        //ham_CopyObjToOAM();    }}DrawEngine::~DrawEngine() {}/* END OF FILE *//*World.h */#ifndef WORLD_H#define WORLD_H#include "Sprite.h"#include "Character.h"#include <mygba.h>class World {    public:        World();        ~World();        int getNumberOfBaddies();        Character* player;        Character* baddies[10];        int a;};#endif/* END OF FILE *//*World.cpp */#include "World.h"World::World(){    ham_InitText(1);    a = 25;    player = new Character(1,10,20,1,1);    for(int i = 1; i<getNumberOfBaddies(); i++){        baddies[i] = new Character(i,12,23,34,45);    }}int World::getNumberOfBaddies(){    return sizeof(baddies)/4;}World::~World() {}/* END OF FILE *//* Sprite.h */#ifndef SPRITE_H#define SPRITE_H#include <mygba.h>enum{        SPRITE_CLASSID,};struct vector{    int x;    int y;    int z;};class Sprite {    public:        Sprite(int s_index, int x = 1, int y = 1, int z = 1, int i_lives = 1);        virtual ~Sprite();        Sprite();        void redraw();        vector& getPosition(void);                int getX();        int getY();        int getZ();                void setPosition(vector pos);                void setX(int x);        void setY(int y);        void setZ(int z);                virtual void addLives(int num = 1);        int getLives(void);        bool isAlive(void);                virtual bool move(int x, int y, int z = 0);        void draw(int x, int y, int z = 0);        void erase(int x, int y, int z = 0);                u8 sprite;    private:    protected:        vector pos;        int classID;        int spriteIndex;        int numLives;};#endif/* END OF FILE *//* Sprite.cpp *//*#include "DrawEngine.h"*/#include "Sprite.h"Sprite::Sprite(int s_index, int x, int y, int z, int i_lives){    pos.x = x;    pos.y = y;    pos.z = z;    spriteIndex = s_index;    numLives = i_lives;        classID = SPRITE_CLASSID;}Sprite::Sprite(){}Sprite::~Sprite(){    // destroy!}void Sprite::redraw(){	// update the position}vector& Sprite::getPosition(){    return pos;}int Sprite::getX(){    return pos.x;}int Sprite::getY(){    return pos.y;}int Sprite::getZ(){    return pos.z;}void Sprite::setX(int i_x){    pos.x = i_x;}void Sprite::setY(int i_y){    pos.y = i_y;}void Sprite::setZ(int i_z){    pos.z = i_z;}void Sprite::addLives(int num){    numLives += num;}int Sprite::getLives(void){    return numLives;}bool Sprite::isAlive(void){    return (numLives > 0);    /*    if(numLives <= 0){        return false;    }    return true;    */}bool Sprite::move(int x, int y, int z){    pos.x += x;    pos.y += y;    pos.z += z;        return true;}void Sprite::draw(int x, int y, int z){    //}void Sprite::erase(int x, int y, int z){}/* END OF FILE *//* Character.h */#ifndef CHARACTER_H#define CHARACTER_H#include "Sprite.h"#include <mygba.h>class Character : public Sprite {    public:        Character(int s_index, int x = 1, int y = 1, int z = 1, int i_lives = 1);        Character();        int Punch(Character*);        int Kick(Character*);        int FlyingKick(Character*);    private:        float energy;};#endif/* END OF FILE *//* Character.cpp */#include "Character.h"#include "Sprite.h"Character::Character(int s_index, int x, int y, int z, int i_lives) : Sprite(s_index, x, y, z, i_lives) {    energy = 20;}Character::Character() : Sprite() {}/* The following methods are for attacking another character. * The return type should indicate if the attack was successful. -Aram */int Character::Punch(Character*){    return 1;}int Character::Kick(Character*){    return 1;}int Character::FlyingKick(Character*){    return 1;}/* END OF FILE */