Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - AGP

#1471
Support / Re: KeyMapper Class
June 23, 2009, 08:27:26 AM
That did it, thank you.

And man, Mizuki just showed me that jPCT off-road car game. Wow, I'm going to have to to try to step up to dmouse's level. Very, very, cool, if you read this, dmouse.
#1472
Support / KeyMapper Class
June 22, 2009, 11:44:50 PM
Egon suggested I used the KeyMapper class to improve keyboard-input-reading for the racing game, and so it is that I am. Problem is, the input is at least as bad as it was before with the following code. The idea is that the car speeds up while you're holding down the UP key and slows down when you're holding DOWN, but in practice it only speeds up and slows down when I press, release, and press again. keyPressed at VK_UP sets speedingUp to true, and at VK_DOWN sets slowingDown to true. Shouldn't the car speed up with every loop iteration? It turns just fine. And I did remove the awt KeyListener, by the way, I'm just using its keyPressed because I'm being lazy.


      KeyState state = keyMapper.poll();
      if (state.getState() == KeyState.PRESSED || (speedingUp && state.getKeyCode() == KeyEvent.VK_UP) || (slowingDown && state.getKeyCode() == KeyEvent.VK_DOWN))
keyPressed(new KeyEvent(this, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, state.getKeyCode(), KeyEvent.CHAR_UNDEFINED));
#1473
Support / Re: Very Very Simple C Question
June 22, 2009, 07:01:24 PM
That's what happens when you let your fingers do the typing for you! In the code I did it your way, though.
#1474
Support / Re: Very Very Simple C Question
June 22, 2009, 03:30:11 AM
I thought this represented the index in the char array, or why would *cursor->canvas++ be possible? It must then be the char, and the compiler treats *cursor->canvas++ as a shortcut to increasing the index. What I needed ws to tell it not to go outside the bounds of the string, so I changed the code to keep track via a separate int.

EDIT: But the source of the crash had actually been strlen itself, since the string for a reason I hadn't seen was NULL.
#1475
Support / Re: Very Very Simple C Question
June 22, 2009, 12:52:55 AM
OK, here's another question: why doesn't
if(*cursor->canvas < strlen(cursor->canvas))
work? It seems to crash my program (no message, I just have to CTRL-C out of it).
#1476
Support / Re: Very Very Simple C Question
June 21, 2009, 04:25:14 AM
Including stdio.h did it. So thanks again.
#1477
Support / Re: Very Very Simple C Question
June 21, 2009, 04:21:13 AM
Oh, and while (cursor->next != NULL) is giving me a "NULL undeclared; first use in this function" message (same for lower-case). So what's the C equivalent? I think I do remember testing for 0 or something but a quick Google seems to have suggested I could use NULL. But gcc won't take it, so what's the equivalent?
#1478
Support / Re: Very Very Simple C Question
June 21, 2009, 04:07:55 AM
Man, C can be so weird! It now compiles, except for the fact that it tells me that I'm returning the address of a local variable (so I just put it outside the function but I wanted to mention it anyway). Thanks again, pal.
#1479
Support / Re: Very Very Simple C Question
June 21, 2009, 02:33:37 AM
Same here, pal! Java and C# rot our brains. : -) But no, unfortunately I have to use what I have. It's an assignment, and not even mine at that, but I'm trying to re-learn this so I can pass it on to my friend.
#1480
Support / Re: Very Very Simple C Question
June 21, 2009, 01:28:51 AM
a.title = title can't be right. It looks weird even to me and besides gcc has a problem with it. : -)
#1481
Support / Re: Very Very Simple C Question
June 21, 2009, 12:28:42 AM
Another quick pointer question. Given:

struct animation {//LIST
     char title[80];
     int lines;
     int columns;
     Frame* start; // (HEAD)
     Frame* end; // (TAIL)
};
struct frame {//NODE
     char* canvas;
     Frame* next;
};
typedef struct animation Animation;
typedef struct frame Frame;

How do I implement the following method, specifically assigning the title (allocated with []) to to its char* pointer?

Animation* createAnimation(char* title, int lin, int col) {
Animation a;
a.title = title;
a.lines = lin;
a.columns = col;
return &a;//THIS IS RIGHT, RIGHT?
}
#1482
Support / Re: Very Very Simple C Question
June 20, 2009, 11:52:46 PM
Got it, thanks a lot. But I would still, then have to put in

struct animation {
   variables
};


in my .c file from what I understand.
#1483
Support / Very Very Simple C Question
June 20, 2009, 07:27:27 PM
I figure at the very least paulscode and Egon will know: what does the line "typedef struct animation Animation" do in a header file? I see no other defining reference to animation (lower or upper case) anywhere in this little assignment. I haven't done C programming in so long, I forgot more than I knew I had known. And to clarify, the assignment uses Animation* pointers a lot, I meant that this line is the only part that defines it.
#1484
Thanks. And well, I would add generally-useful trigonometric functions. The difference between SimpleVector and Math would be that Math doesn't assume specific use. You can create a SimpleVector instance just to get the result of a function and apply as you will to your object, but that's counter-intuitive. With Math, you can have your objects oriented however you want to, for instance, and all you're really doing is calculating the product of your input (as opposed to necessarily applying a certain way).
#1485
Egon, if you're thinking of making a separate download with utilities such as a gif loader, why not include my previously-requested Math class?