#177749 - Skalbe - Sun Jan 27, 2013 2:38 pm
Hi guys. I`m trying to create a game on GBA that would resemble a classic D&D adventure, but I`m already stuck.. just with the basic drawing part of my program. What I have and what I`m trying to do is:
I got a class with variables, a member drawing function, a constructor and later in the main I initialize two objects off of this. I use the function to re-draw my object1 in the while loop and I use the constructor to initialize my both objects just outside of the while loop. The thing is I can`t initialize my variable values within the constructor as one usually would because I use it to draw my both objects, but then I use the function to `move` just one of them. I need to make it so that the function updates my initialized variable values of object1 and redraws it in a new position as I press the buttons. I feel like the problem resides in some faulty logic and I can`t figure it out. Yet I know it can be done. So far I have tried changing around the value increment/decrement with the draw function and also commenting out both FlipBuffers and ClearScreen, but nothing changes. Also the result of this code is my two objects are drawn at their starting positions and I can`t move them. Also hi Adam... if you are here for some reason I feel terribly ashamed for my stupidity, but at the same time I will feel more ashamed if I don`t go and try to understand this.
**********
Last edited by Skalbe on Mon Jan 28, 2013 12:36 am; edited 2 times in total
I got a class with variables, a member drawing function, a constructor and later in the main I initialize two objects off of this. I use the function to re-draw my object1 in the while loop and I use the constructor to initialize my both objects just outside of the while loop. The thing is I can`t initialize my variable values within the constructor as one usually would because I use it to draw my both objects, but then I use the function to `move` just one of them. I need to make it so that the function updates my initialized variable values of object1 and redraws it in a new position as I press the buttons. I feel like the problem resides in some faulty logic and I can`t figure it out. Yet I know it can be done. So far I have tried changing around the value increment/decrement with the draw function and also commenting out both FlipBuffers and ClearScreen, but nothing changes. Also the result of this code is my two objects are drawn at their starting positions and I can`t move them. Also hi Adam... if you are here for some reason I feel terribly ashamed for my stupidity, but at the same time I will feel more ashamed if I don`t go and try to understand this.
**********
Code: |
#include <stdint.h>
#include <stdlib.h> #include "gba.h" // A class with variables for the characters. class CHARBOX { public: int init_; int str_; int health_; int posx_; int posy_; int width_; int height_; int colour_; public: // Constructor. CHARBOX(int posx, int posy, int width, int height, int colour) : init_(0), str_(0), health_(0), posx_(posx), posy_(posy), width_(width), height_(height), colour_(colour) { DrawBox(); } // Drawing functions. void DrawBox() { for (int x = posx_; x < posx_ + width_; x++) { for (int y = posy_; y < posy_ + height_; y++) { PlotPixel8(x, y, colour_); } } } }; // The entry point for the game. int main() { // Put the display into bitmap mode 4, and enable background 2. REG_DISPCNT = MODE4 | BG2_ENABLE; // Defining some colour palettes. SetPaletteBG(1, RGB(90,0,0)); SetPaletteBG(2, RGB(0,90,0)); SetPaletteBG(3, RGB(0,0,90)); SetPaletteBG(4, RGB(90,90,0)); SetPaletteBG(5, RGB(90,0,90)); // Draw the player dude-box at a starting location. CHARBOX player(10, 24, 6, 8, 1); // Draw the enemy dude-box at a starting location. CHARBOX enemy(80, 24, 6, 8, 2); while (true); { // Flip buffers to smoothen the drawing. FlipBuffers(); // Clear screen and paint background. ClearScreen8(1); // Screen edges. if (player.posx_ > (SCREEN_WIDTH - 8)) { player.posx_ = (SCREEN_WIDTH - 8); } if (player.posx_ < 2) { player.posx_ = 2; } if (player.posy_ > (SCREEN_HEIGHT - 6)) { player.posy_ = (SCREEN_HEIGHT - 6); } if (player.posy_ < 1) { player.posy_ = 2; } // Redraw the player dude-box. if ((REG_KEYINPUT & KEY_LEFT) == 0) { player.DrawBox(); player.posx_--; } if ((REG_KEYINPUT & KEY_RIGHT) == 0) { player.DrawBox(); player.posx_++; } if ((REG_KEYINPUT & KEY_UP) == 0) { player.DrawBox(); player.posy_--; } if ((REG_KEYINPUT & KEY_DOWN) == 0) { player.DrawBox(); player.posy_++; } WaitVSync(); } return 0; } |
Last edited by Skalbe on Mon Jan 28, 2013 12:36 am; edited 2 times in total