You are not logged in. | Register | Resend Activation
Browsing this Thread: 1 Anonymous Users


Register To Post




#21
Re: Castle of Doom
Posted on: 4/27 18:25:22
VUE(xpert)
Joined 2008/4/26
USA
265 Posts
CoderContributorTop10 PosterHOTY09 3rdLong Time User (2 Years)
Offline
OK, I worked on the collision detection of the walls. How is this? Better? Next up: Working on the jumping.

Attach file:


vb cd.VB Size: 256.00 KB; Hits: 18
c cd.c Size: 10.97 KB; Hits: 9
Top

#22
Re: Castle of Doom
Posted on: 4/27 20:21:42
Nintendoid!
Joined 2/15
Netherlands
110 Posts
Offline
Yes, the movement and collision are a LOT smoother, good job. :)

I did notice that it's very easy to fall off the top of the little wall parts sticking out, perhaps a bit *too* easy. Also, after touching the end door, collision detection stopped working on the sprites and I could jump through some of the lower ceilings.

(post edited)
Top

#23
Re: Castle of Doom
Posted on: 4/28 13:04:06
VUE(xpert)
Joined 2008/4/26
USA
265 Posts
CoderContributorTop10 PosterHOTY09 3rdLong Time User (2 Years)
Offline
OK, I can't come up with a good jumping code, so I'm asking you guys. What should I do about this? I've changed the code around so the walking animation is back, but I have removed the jumping code.

Attach file:


vb cd.VB Size: 256.00 KB; Hits: 16
c cd.c Size: 9.72 KB; Hits: 7
Top

#24
Re: Castle of Doom
Posted on: 4/28 14:42:49
Nintendoid!
Joined 2/15
Netherlands
110 Posts
Offline
Crashes for me in Mednafen, not sure if it's the emulator.
Top

#25
Re: Castle of Doom
Posted on: 4/28 15:03:31
VUE(xpert)
Joined 2008/4/26
USA
265 Posts
CoderContributorTop10 PosterHOTY09 3rdLong Time User (2 Years)
Offline
That's odd, it works fine in Reality Boy.
Top

#26
Re: Castle of Doom
Posted on: 4/28 15:06:46
Nintendoid!
Joined 2/15
Netherlands
110 Posts
Offline
Wait, nevermind... Something odd is going on on my side. Time to reboot I guess, sorry for the false alarm.

Edit: pretty good. There's something about the animation that makes the movement speed seems like it's varying, though. Not sure what causes it, maybe his back moving like it does.

As for jumping, something like this works decently (very much pseudo code):


yspeed 
0;
gravity 1;  //Change this to whatever gravity value works well.

while (gameloop)
{
  
yspeed += gravity;
  
player_y += yspeed;  //You can divide yspeed or lower gravity to alter jump speeds.

  
if (pressing jump key)
    
yspeed = -some_value;  //You can tweak this value to alter jump height.

  
if (touching floor)
    
yspeed 0;
}


Sorry for not having checked your .c file yet, if it's obvious.

Also, the above system is VERY simple, not taking into account for pixel-perfect collision detection. You need a bit more for that (and to avoid your character getting stuck in the floor), but I'm sure you can figure it out from here. :)


EDIT: just checked the code... It's a pretty big mess of if conditions I see. You can at least make the engine itself a bit more efficient by using "else if"s where appropriate.

Example:

if (0"something";
else if (
== 0"something else";
else 
"something when x > 0";

Why is this more efficient? Well, if the first if ran, we already know that all other related conditions WILL be false (if x < 0 we know it can't be 0 or higher). Thus the engine doesn't actually NEED to check these extra conditions, and an else if / else in the code WILL actually skip them for you. That's less checking and code execution per frame. ;)
Edited by DaVince on 2010/4/28 15:19:05
Edited by DaVince on 2010/4/28 15:24:15
Top

#27
Re: Castle of Doom
Posted on: 4/29 5:14:44
Virtual Freak
Joined 2009/8/11
USA
81 Posts
Long Time User (1 Year)
Offline
DaVince, your code seemed to be missing stuff. Looking at the code, it looks like the y distance would increase by 1 acceleration unit whenever speed = 0. I think this would work better.


while (loop_condition == TRUE) {
    if(
y_dist == 0) {
        
/* We are on the floor, so check if a jump is requested */
        
if ((keys jump_key) == jump_key) {
            
/* Only checks if key is pressed when on the floor */
            
y_speed max_jump_velocity;
            
y_dist  y_speed;
        } else {
            
/* No jump requested, make velocity equal to 0 */
            
y_speed 0;
        }
    } else {
        
/* Middle of a jump, update speed, calculate distance */
        
y_speed -= accel;
        
y_dist  += y_speed;
    }
}


Once again, untested code.

Could be beneficial to check to make sure y_dist is within range for the original if statement. If you are outside of the possible range a y could be, then you have to error handle. But this was intentionally left out.

This code assumes ground is 0, and you jump in the positive y direction.

A more realistic feel would include checking how long the button was held for to adjust the length of the jump, which is not included in the above code.

I have not looked at the game's C code either, or even tried out the game. I will get around to it sometime, just been busy.
Top

#28
Re: Castle of Doom
Posted on: 4/29 13:55:15
Nintendoid!
Joined 2/15
Netherlands
110 Posts
Offline
Yeah, I did it really quickly to give just a push in the right direction, so there's bound to be things missing. :P You're right about that part, but it could be avoided simply by not adding to the yspeed (or velocity, in your case) at all when he's on the floor (or one pixel above it, anyway).
Top



Register To Post