PDA

View Full Version : Platformer Game with Wallslide and Walljump



fredthemonkey
08-02-2008, 03:50 PM
Hey guys, a friend of mine wanted to make a 2d platformer game. He asked me which program language / engine to use and so i looked around the internet. After a few days of research i was sure, that novashell is perfect for this job.

I am a Kubuntu (Linux) user, but novashell didn't run from the last release nor from the svn (couldn't compile because some files where missing). So i just installed the windows version via wine. I'll fill out a bugreport on that later - describing exactly what didn't work.

My friend showed me what he'd like to have in a tech-demo made with Multimedia Fusion 2 - but this software is very limited and you couldn't even play this natively on other OS (works fine with wine though).

Then I tried to port this tech-demo in novashell. For a start I modified the Tree World Sidescroller Test-Example, because it had a lot of features i needed already included. Changing the controls to jump on space and walk with wsad was easy, but i got really stuck on the wallslide.

Here is what I changed in ent_player.lua:

My modified ProcessMovement function:

function ProcessMovement(step)

//#check for movement
local facing = C_FACING_NONE;

if (m_bLeft) then facing = C_FACING_LEFT; end;
if (m_bRight) then facing = C_FACING_RIGHT; end;

if (this:GetOnGround() and m_jumpTimer < GetApp:GetGameTick() ) then
//#this:GetBrainManager():Remove("ForceVisual"); //#all "ForceVisual" brains are removed
this:SetVisualStateOverride(C_VISUAL_STATE_NONE); //#same as above but faster
else
CheckForSlide(facing);
end

if (facing != C_FACING_NONE) then

//#they are pressing towards a direction
this:SetFacingTarget(facing); //#turn the way we want
this:GetBrainManager():SetStateByName("Walk");
m_lastDirection = facing; //#store this for later, like when we get off the ladder
else
this:GetBrainManager():SetStateByName("Idle");
end

end

And here's my CheckForSlide function:

function CheckForSlide(facing)

//#check if there is something to slide on
local scale = this:GetScale();
local scale = scale.x;
local scale = scale / 2;
local wall_l = this:GetNearbyZoneByMaterialType(this:GetPos() + Vector2(-1*scale,0), C_MATERIAL_TYPE_NORMAL);
local wall_r = this:GetNearbyZoneByMaterialType(this:GetPos() + Vector2( scale,0), C_MATERIAL_TYPE_NORMAL);


GetTextManager:Add("l:"..wall_l.materialID..";r:"..wall_r.materialID,this);
if(wall_l.materialID!=C_MATERIAL_TYPE_NONE) then //#facing == C_FACING_LEFT
LogMsg("Sliding on Wall @ " .. tostring(wall_l.vPos) .. " (l)");


elseif(wall_r.materialID!=C_MATERIAL_TYPE_NONE) then //#facing == C_FACING_RIGHT
LogMsg("Sliding on Wall @ " .. tostring(wall_r.vPos) .. " (r)");
else
//#no there's nothing. just a normal jump.
this:SetVisualStateOverride(C_VISUAL_STATE_JUMP);

end
end

This piece of code should basicly tell whether the player is directly near a wall - but it always says it is sliding when the player jumps anywhere.

PS: I use //# because only then my editor displays the following chars as comment. Maybe the interpreter should be able to detect both // and # as comments?

EDIT: I just uploaded a screenshot if you don't want to download the game. The thing is that when you touch a wall in a jump and press the direction you touch it, then the gravity gets lower and you fall slower. Also you can jump *again* from this position.

Thanks for reading this post - and it would be great if someone could explain what i am doing wrong :)

illspirit
08-02-2008, 06:52 PM
Easiest way to do a wallslide would be to use the friction. If you set the player's collision material to No Bounce and the walls' to High Friction, you should slide down if pressed against them. If the speed is wrong, I think you can make your own material type, or just tweak gravity and/or density a bit.

As for checking to see if the player is against a wall, have a look at how the OnCollision function in TreeWorld checks to see if the player is bumping his head. I haven't played with the depth checking yet, but you can probably use it on the X axis too.

fredthemonkey
08-03-2008, 09:17 AM
Thanks for your answer. Well your solution is sort of a workaround because i need to know if the player is sliding and on which side in order to let him perform a walljump. But thanks anyway :)