Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Could my code have bugs?

A topic by Victoneix created 18 days ago Views: 90 Replies: 1
Viewing posts 1 to 3

Hello everyone. I'm developing a platform game. In this game, I created an object called a ladder, and I wanted to know if the code I wrote might have any logic problems or be poorly constructed.
Please don't be alarmed by any error I may have made; I'm still a beginner in programming logic. =3

The variable rising is from obj_steps.
OBJ_STEPS - EVENT STEP
with(obj_player){

var _velr = 2;

var _keys_h = keyboard_check(ord("W")) || keyboard_check(ord("S"));

if(_keys_h) other.rising = true;

if(instance_place(x, y, obj_steps) && other.rising){

velv = 0;

if(keyboard_check(ord("W"))){

velv -= _velr;

}

if(keyboard_check(ord("S"))){

velv += _velr;

}

if(keyboard_check_pressed(vk_space)){

other.rising = false;

velv -= jump_height;

} else if(!instance_place(x, y, obj_steps)){

other.rising = true;

}

}


OBJ_PLAYER - EVENT CREATE
vel = 3.2;

velh = 0; 

velv = 0;

grav = 0.24;

jump_height = 4;

moving = function(){

var _right = keyboard_check(ord("D"));

var _left = keyboard_check(ord("A"));

var _jump = keyboard_check_pressed(vk_space);

velh = (_right - _left) * vel;

velv += grav;

velv = clamp(velv, -12, 12);

if(_jump && place_meeting(x, y+1, obj_collision)){

velv = -jump_height;

}

}

collision = function(){

repeat(abs(velh)){

if(place_meeting(x+sign(velh), y, obj_collision)){

velh = 0;

break;

} else{

x+=sign(velh);

}

}

repeat(abs(velv)){

if(place_meeting(x, y+sign(velv), obj_collision)){

velv = 0;

break;

} else{

y+=sign(velv);

}

}

}

Moderator moved this topic to General Development
Moderator(+1)

It would help to tell people what language it’s in and for what engine or framework; you should also use a code block, because the forum made a mess of your code.