Users browsing this thread: 2 Guest(s)
PBG Engine
#1
LATEST BUILVery Sad https://www.dropbox.com/s/wr0uonc71ykwrk...A.exe?dl=0

A little game engine demo for a possible PBG game. Thoughts? Glitches? It's just the basic engine so don't expect anything unique yet. Note that nothing in this is final.

Sprite Thread: http://www.vg-resource.com/thread-26110.html
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#2
For some reason, you jump higher when moving than when standing. I'm guessing this is meant to be a result of getting a running start, like in Jazz Jackrabbit, but since your movement speed is absolute and doesn't use momentum/acceleration, you could just as easily quickly tap left/right near an edge and then jump, so you might as well just give the player the full jumping height anyway. Also, is it just me, or do hearts respawn?
Reply
Thanked by:
#3
Yeah hearts respawn. It's just for this though since it's just a test level. Also, That gives me the idea to add acceleration... I'm gonna get on that.
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#4
https://www.dropbox.com/s/xwklns11htgmwa...e.exe?dl=0

Now with a WIP custom tile set. No acceleration because I couldn't get it to work right.
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#5
Create Event
Code:
xSpeed = 0;
ySpeed = 0;

Step Event
Code:
if(xSpeed > 0 && (!place_free(x, y + 1) || hitFloor(x, y + 2))) xSpeed -= 0.5; //If xSpeed is greater than 0, lower it.
if(xSpeed < 0 && (!place_free(x, y + 1) || hitFloor(x, y + 2))) xSpeed += 0.5; //If it's lower than 0, raise it.
if(xSpeed < 0.5 && xSpeed > -0.5) xSpeed = 0; //If xSpeed is stuck bouncing back and forth around 0, set it to 0.
if(place_free(x, y + 1) && !hitFloor(x, y + 2)) ySpeed += 1; //If the player is off the ground, increase ySpeed,
else if(ySpeed > 0 && (!place_free(x, y + 1) || hitFloor(x, y + 2))) ySpeed = 0; //else, set ySpeed to 0.
move(xSpeed, ySpeed); //See move script.

"move" Script
Code:
/*First we get a couple variables.
h is horizontal movement.
v is vertical movement.*/
h=argument0;
v=argument1;

/*Now what we do is instead of checking if a point is free a certain distance away,
we check every pixel ahead and then move a pixel until the loop runs out or we hit
a solid object.

i has to be absolute because if the speed is negative, it will cause the loop to
break, and we don't want that.*/
for(i=abs(h); i>0; i-=1){
    if(!place_free(x, y+1) && place_free(x+(h/abs(h)),y+1) && !hitFloor(x+(h/abs(h)), y+1) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width && !instance_place(x, y + 1, Floor)){
    x += h/abs(h);
    y += 1;
    }
    else
    if(!place_free(x, y+1) && place_free(x+(h/abs(h)),y-1) && !hitFloor(x+(h/abs(h)), y+1) && !place_free(x+(h/abs(h)),y) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width){
    x += h/abs(h);
    y -= 1;
    }
    else
    if(place_free(x+(h/abs(h)),y) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width) x+=h/abs(h)
    else break;
};

for(i=abs(v); i>0; i-=1){
    if(place_free(x,y+(v/abs(v))) && !hitFloor(x, y + (v/abs(v) + 1))) y+=v/abs(v)
    else break;
};

"hitFloor" Script
Code:
if(instance_exists(Floor)){
    if(instance_place(argument0, argument1 - 1, Floor)){
        var c;
        c = instance_place(argument0, argument1 - 1, Floor);
        if(y + (sprite_get_height(sprite_index) / 2) < c.y + 1) return 1;
        else return 0;
    } else return 0;
} else return 0;

The Floor object is the type of platform you can pass through. The height of the Floor's sprite does not matter, since this script checks if the sprite is above and only above the Floor. If you're using collision masks, it may be wise to substitute sprite height for the sprite's bounding box's lower edge.

Hope that solves your physics problems. Let me know if you have any trouble, and I'll see if I can fix it.

[EDIT AFTER PLAYING NEW BUILD]
I've noticed a few issues. One, when you get hurt, you always get pushed to the right. When mixed with walking, you can move right very fast. You should set it to push against the player's current direction, which I keep track of using a variable called "facing" which is 1 for right and -1 for left. Not only does this give me something to multiply the knockback speed by, but I can also multiply the image_xscale of the player by that so I don't have to make left-facing sprites. Two, when you die, the camera just goes off and freezes for a second, and it made me think I broke the game.
Reply
Thanked by: Joxon
#6
New version:
https://www.dropbox.com/s/xwklns11htgmwa...e.exe?dl=0

Yeah those are some glitches that I just fixed. Also the if you look at the sprite thread, you'll notice that the right and left sprites are now different. One problem, when you get hit in the back, you fly into the enemy. Any tips on how to fix that? Also I'm not using coding, I'm using the GameMaker premade... Things I guess... That you drag into an event. So perhaps, if possible, you could build an extention for any codes?Only if you want. And the death thing was fixed. For some reason that just started happening when ever you died. I didn't even edit anything in the dying event. Idk what happened oh well.
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#7
You don't need an extension, just put the code I gave you into a code action. It'll work just fine. I dunno why you're using the action icons anyway; they only slow down editing events.

As for the knockback, this is what I use:
Code:
if(state != hurt && !blinking && !attacking && other.state != hurt){ //This is just to make sure the player can be hurt. Chance it to whatever you need.
    if(x != other.x) facing = -((x - other.x) / abs(x - other.x));
    xSpeed = -3 * facing;
    ySpeed = -3;
};

I removed the code involving state and sprite changes, because I don't know what you're using. Anyway, this code will check which side of the player the enemy is on, and then knock them in the opposite direction.
Reply
Thanked by:
#8
One: I'm using two separate sprites for left and right.

Two: I'm using action icons because I don't know coding that well...

Three: I can just copy this code in to the event too, right?
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#9
One: You can still use a facing variable to keep track of what side your character is facing. That'll simplify a lot of things. Rather than checking every possible sprite when checking where the player is looking, you can just use facing.

Two: The action icons mimic coding, only using pictures instead of words. The coding language is very easy to learn, and can do things that icons can't, plus it's a lot faster to type things in than having to flip through pages for an icon each time you want to use it.

Three: Under the control tab in the actions library, you'll find an icon for "execute a piece of code". Put the code in there.
Reply
Thanked by: Joxon
#10
The code doesn't work... It says variable state unknown.

Edit: fixed with action icons. Wink Also what do you mean by sprites bounding box lower edge?
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#11
That's because you aren't using states. I forgot to remove that part. As for the sprite's bounding box, there are functions for that if you'll look in the code reference in the help file. There are no action icons for it though; you need to learn SOME code, otherwise you're limiting yourself. Converting my code into icons is just gonna make it even harder to edit. Seriously, man, you gotta get off the icons; they're holding you back.
Reply
Thanked by:
#12
Good news! I'm learning code! I've coded the step and floor events so far. I have one problem with moving though, how do you set a variable to reletive?
[Image: rHiHaRN.jpg]
Reply
Thanked by: puggsoy
#13
You don't. That's only for icons. In order to change a variable by a relative value in code, instead of doing something like v = 8, you'd do v += 8. You could also do v = v + 8, but that's just extra typing and only exists because older languages didn't support +=. The relative option in the icons is just asking if you wanna use += instead of =. It's a bit misleading, if you ask me, because I found myself asking the same question when I started coding.
Reply
Thanked by: Joxon
#14
Okay, but what about (x,y)? For example, if (place_free(-5,0))?
[Image: rHiHaRN.jpg]
Reply
Thanked by:
#15
For that, you'd do place_free(x - 5, y).
Reply
Thanked by: Joxon


Forum Jump: