![]() |
|
This thread is locked; no one can reply to it.
![]() ![]() |
1
2
|
throw bone |
a b
Member #8,092
December 2006
|
THANKS !! I study library from one day (today) and I almost write my first game and it is my pawn (checker?): Could you tell me what is wrong - I am so excited
|
BAF
Member #2,981
December 2002
![]() |
You should be passing NULL to load_bitmap, NOT default_palette. Quote: blit(pawn,screen,0,0,*index,400,pawn->w,pawn->h); WTF is that? *index? Is that even valid code? |
a b
Member #8,092
December 2006
|
BAF 0,0,*index,400 *index is my "x" and "400" is my "y" because I have so my pawn is starting (x,y) (550, 400) so it is field number 6 on board (chart ?) : |
BAF
Member #2,981
December 2002
![]() |
Ah, okay. |
a b
Member #8,092
December 2006
|
THANK YOU A LOT - it is my code:
My code is yet full mess and chaos, but it runs - this my first game ! |
LennyLen
Member #5,313
December 2004
![]() |
A couple of things. Why are you using a pointer to point to an array of the numbers 1..11 when you can just use the numbers 1..11? Instead of: Quote:
int tab2[11]={1,2,3,4,5,6,7,8,9,10,11}; int *index=&tab2[5]; int *start=&tab2[0]; int *end=&tab2[10];
You can use: int index = 5; int start = 0; int end = 10; And then replace any instances of *index, *start and *end in your program with index, start and end. This is simpler and will not effect the way your game works. It's also not a good idea to hardcode in pixel values like this: Quote: int tab1[11]={30,130,230,330,450,550,690,820,900,1000,1150}; If you change the width of your bitmap, you need to rewrite every value. Try to encode a formula instead. Something like: for (n = 0; n < 11; n++) tab[n] = START + ( width * (n - 1) ) + (GAP * n); where START and GAP are #DEFINE values.
|
a b
Member #8,092
December 2006
|
LennyLen thank You very much for your advices - I will use it - thank you |
Steve Terry
Member #1,989
March 2002
![]() |
I have some more advice... read a god damn C book! Learn proper code indentation. Lean the difference between C and C++ (your code is not C++ besides the fact you included some C++ headers and a namespace which are completely unused anyway). Once you grasp those concepts you can begin to learn the difference between 8-bit and high color depth concepts, they do work in very different ways and you should not mix the two. Lastly learn what a double buffer is and use it. ___________________________________ |
a b
Member #8,092
December 2006
|
Steve Terry: I know c++, I don't use classes because I wanted only to see use library allegro. "Once you grasp those concepts you can begin to learn the difference between 8-bit and high color depth concepts, they do work in very different ways and you should not mix the two." Where in my code is mix two ways ? |
Jonatan Hedborg
Member #4,886
July 2004
![]() |
a b said: Where in my code is mix two ways ?
Well, if you knew the difference, you wouldn't have to ask that set_color_depth(32); //High bit-depth. set_palette(default_palette); //Only useful in 8bpp mode... ... textout_ex(screen,font,"ESC - The end of program",10,990,2,-1); //You can't really use "2" as a color. Use makecol(redpart,bluepart,greenpart)
|
a b
Member #8,092
December 2006
|
I change my code according with your hands
|
Archon
Member #4,195
January 2004
![]() |
Don't use "goto" statements. Use "break"s and while(...) loops. |
Steve Terry
Member #1,989
March 2002
![]() |
a b: if you are comfortable with classes there is nothing that is stopping you from writing classes. C++ is an extension of C and is backwards compatible. You just can't use some C/C++ functionality like cin/cout/printf/scanf/etc. These only work on console windows. Your indentation needs some work as well. ___________________________________ |
a b
Member #8,092
December 2006
|
I will do this with classes but first I would like you check my code if everything is ok because it is the most important (if everything is ok I will wrote this and other thing using classes) I am starting write with allegro and you are masters in using allegro so |
Tobias Dammers
Member #2,604
August 2002
![]() |
Quote: I know c++, I don't use classes because I wanted only to see use library allegro.
C++ is more than just "C with classes". Nonetheless, a proper C program usually passes C++ compilation just fine. --- |
ngiacomelli
Member #5,114
October 2004
|
a b: You'll get better responses if you present your code properly. I went through with Notepad and did some basic indentation. I also added a timer in, and separated your logic from your drawing. I got rid of that strange goto statement. People have suggested reading up more on C/C++. I suggest you do that, and also stop copy and pasting code without considering it. You had a while loop checking: !key[KEY_ESC] and then an if statement checking for the exact same thing, later on. I haven't tested this code, so I've probably made errors. But I hope it helps. EDIT: I also added a check for problems when setting the graphics mode. Check for errors!
|
Tobias Dammers
Member #2,604
August 2002
![]() |
Another tip: Modularize your code. Split code into dedicated functions. I suggest: This is useful for several reasons: Oh, and clearing the buffer bitmap right before you destroy_bitmap() it is pretty useless... --- |
a b
Member #8,092
December 2006
|
Tobias and Nial thank you for help my. VARY THANK !!;D I don't agree with one thing - you wrote: I want that: first player see map (not black screen), throw bone, player decide if he want to go on left or on right and he press <- or ->, map is cleared and player see new map with pawn on definite field after moving about definite number of fields on left or right, throw bone, press <- or ->, clearing screen and again .... so I think it is good: (before this code I didn't use "blit" so my screen is black so I first must use "blit")
|
ngiacomelli
Member #5,114
October 2004
|
I don't understand what you're asking here. As far as I can see: you render everything each frame (chart, etc, etc). By adding the call to clear_to_color before you do your rendering, you basically make the buffer bitmap totally white. Imagine starting a painting with a blank canvas. Once you've made the buffer totally white, you can then render everything onto it. As far as having the clear_to_color call where you initially placed it: there is no point. You destroy the bitmap right after making it white. EDIT: Of course, if your chart bitmap is >= the set resolution, you wouldn't need to clear the bitmap. It is still good practice, though.
|
|
1
2
|