Piotrek Obarowski

Hello everyone, I am new to Game Maker but I know basic commands and functions that I've learnt from my previous small platform game.

For this project I wanted to make a game where the player follows the mouse pointer (I have done this already) and picking up trash from the grass. I want the trash sprites to stick to the player as he collects them. After the player reached a limit of 3 pieces of trash for example, he will have to go to a bin to throw them away and start collecting again. I will have some obstacles but I can manage that for myself.

I have already attempted this but I can't collect multiple objects and I cannot release them when colliding with the bin object

If anyone has experience in game maker or knows how to deal with this I will be very thankful if you would help me out.

You could store the ids of trash that they've picked up - using a ds_list you can check if a value (in this case an ID) is found upon collision. If it isn't, it gets put on the list and then the collision event should ignore it.

The code here is done with the setting in the Global Game Settings 'short circuit evaluations' set to on. If you have that switched to off, then every 'IF' query should be "nestled" in another, so that if any prove false then the code block won't be acted upon.

if whatever
if another is true
do whatever
etc etc

collision event for player - with trash:
if ds_list_find_value( trash_list, other.id ) = = -1 && ds_list_size(trash_list) < 3
with (other)
ds_list_add ( trash_list, other.id );
collision event for player with bin:
if ds_list(trash_list) > 0
create event (trash):
end step event (trash)
if follow_player
if instance_exists (obj_player)
collision event (trash object colliding with bin)
If done like this it achieves several things:
1) The player will only check each piece of trash once, and can only carry less than 4 pieces. The ds_list size is checked to be less than 3, so once a third is added the statement should no longer be viable.
2) The trash destroys itself upon contact with the bin, and handles moving with the player. So the player object doesn't need to control it.
3) Upon contact with the bin, the player object clears the ds_list as the trash is destroyed.

I'm a little unsure about (3) - instead of the trash being destroyed upon collision with the bin, you may have to have the player object loop through the list (when it hits bin) and destroy the objects as part of the loop.

By having the trash as an object that can collide with the player you will have it constantly checking for a collision, and testing it. To avoid this make a second trash object - one that only collides with the bin, and not the player.

When you hit the original trash, the player itself creates this duplicate and controls it. The "normal" trash piece is then destroyed.

This is a little more effort to set up, but in the long run should be better. Because the "duplicate" trash has no collision with the player, it won't be constantly having to evaluate a collision event.
Last edited: