Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075929 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:03:09 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Top Down Block Pushing Help Needed
Pages: [1]
Print
Author Topic: Top Down Block Pushing Help Needed  (Read 525 times)
reibeatall
Level 0
*


View Profile Email
« on: August 23, 2013, 07:13:28 PM »

Hey all, I hate for my first post to be something that's probably a pretty easy problem, but I've scoured this forum and others and haven't found a good solution. This is my first time using GameMaker and I have essentially no coding/scripting experience. I've done a few tutorials, but first solo game.

I'm trying to make a top down puzzle game where you have to push blocks. Four way directional movement (udlr), pretty basic.

I can get my character to push the block, and I can get the block and player to stop when they collide with a wall, but (for example) if the block's against the left wall, and I press both left and up, the block will slide up.

I'm using the following "execute code"s for my player and my object.
Player-> Step event

Code:
if keyboard_check(vk_up) and place_free(x,y-playerSpeed ) {
     y -= playerSpeed;
}
if keyboard_check(vk_left) and place_free(x-playerSpeed,y) {
     x -= playerSpeed;
}
if keyboard_check(vk_down) and place_free(x,y+playerSpeed) {
     y += playerSpeed;
}
if keyboard_check(vk_right) and place_free(x+playerSpeed,y) {
     x += playerSpeed;
}

obj_crate -> Collision w/ obj_player
Code:
if keyboard_check(vk_up) and place_free(x,y-obj_player.playerSpeed ){
     y -= obj_player.playerSpeed;
}
if keyboard_check(vk_left) and place_free(x-obj_player.playerSpeed,y) {
     x -= obj_player.playerSpeed;
}
if keyboard_check(vk_down) and place_free(x,y+obj_player.playerSpeed) {
     y += obj_player.playerSpeed;
}
if keyboard_check(vk_right) and place_free(x+obj_player.playerSpeed,y) {
     x += obj_player.playerSpeed;
}

Any help is greatly appreciated, and if there's a better way to do my movement, I'm all ears.

Thanks in advance!

--Andy K
Logged
Eigen
Level 10
*****


Jebus backups.


View Profile WWW
« Reply #1 on: August 23, 2013, 11:05:46 PM »

You simply need to add a check if the player is on the side of the pushable that is opposite to the direction you want to push. So if you want to push left you have to be on the right side of the pushable (check by comparing X coordinate). If you want to push up you have to be down from the pushable (check by comparing Y coordinate). So if you're left or right of the pushable you can't push up. Makes sense?
Logged

reibeatall
Level 0
*


View Profile Email
« Reply #2 on: August 24, 2013, 06:47:26 PM »

Awesome, that makes sense. I just didn't know if there was a clean, GML specific way to do that or not.

Thanks!
Logged
Eigen
Level 10
*****


Jebus backups.


View Profile WWW
« Reply #3 on: August 24, 2013, 10:45:01 PM »

Sorry, I'm not familiar with GML.
Logged

Titanium
Level 0
**


View Profile Email
« Reply #4 on: September 27, 2013, 10:23:03 PM »

The reason you weren't moving the block was because you never collided with it btw.
Logged


Please Play My Games.
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic