Background collision checking? [Help]

J

Jeshuakrc

Guest
I have the following problem:

Have this level:

When the room is created, the code in Creation code of the room sets my mouse's curson in where obj_Cursor (the blue circle) is, but even if the obj_Cursor is created upon a obj_Surface (the white square), the room is restarted over and over, entering in a infinite loob.

I am trying to:

The obj_Cursor must follow the mouse´s cursor of my PC, and the room must be restarted when the obj_Cursor is touching the bachground.

That's the code of the step event of obj_Cursor:
Code:
 //Followoriginar cursor
x=mouse_x
y=mouse_y

//Death
if place_free(x,y){
   show_debug_message("place free")
    }else{
    show_debug_message("not place free")
    }
That's the room's creation code's one:
Code:
display_mouse_set(ins_Cursor.x,ins_Cursor.y)
I have tried:
  • Seting the ins_Cursor(the obj_Cursor's instance of the room) to create after the other instances in Creation list.

  • Inveting the code (restart the room the touching the obj_surface), and it works.
I am using:
  • GameMaker: Studio 1.4
  • GML
 
J

Jeshuakrc

Guest
Hy guys, thanks for support.
I would recommend searching up ds_grid based collisions.
I'm not sure about that. What if I want to do levels like this:...?

In fact I think to makes levels like that. The first one is just a test

Don't make anything solid. Use place_empty instead of place_free.

That's just one idea.
I tried it, It doesn't was any change.
 

TheouAegis

Member
So the white is an object and the black is emptiness and you want to make it so the object under the mouse must be in contact with the object at all times?
 
J

Jeshuakrc

Guest
So the white is an object and the black is emptiness and you want to make it so the object under the mouse must be in contact with the object at all times?
Exactly that! I tried creating alarms in order to set a dalay before the tecettión, but it still being issues. I need that none pixel be outside of the white object. But the room only resets whent it isn't any pixel touching the white object.
 

TheouAegis

Member
if !place_meeting(x+sprite_width/2-1,y,obj_surface) return true
if !place_meeting(x-sprite_width/2+1,y,obj_surface) return true
if !place_meeting(x,y+sprite_height/2-1,obj_surface) return true
if !place_meeting(x,y-sprite_height/2+1,obj_surface) return true
return false

Throw that in a script and check if the scripts is true every step. If it is ever true, game over.
 
J

Jeshuakrc

Guest
Thank you so much, but... your code don't works as I'd like it do. Th first probles is that I don't undertand that coda, I try to figure out what it exactly does but I can't get it. However, i did what you said me, I Throw it into a scrip and changed up the place_free() of my if by the new script, but didn't do what I needed. I need that if one single pixe is out of the surface, game over, but our code lets the cursor get a half out of the surface before reset the room; and i can't know why due I can't get the code of the script.

An other issue is that I think the code works as a acuare shape detection box, and it doesn't is good for me beacause the cursor wiil have an normal curor arrow form. So I need a more precice denection. ¿Any idea? Again, thanks for your help.
 
J

Jeshuakrc

Guest
I solved it! As I said before, your code didn't work as I needed; but it gaves me an idea! I made a new script, this:

Code:
var collision=0

for(var w=0;w<sprite_width;w++){
    for(var h=0;h<sprite_height;h++){
        if collision_point(x+w,y+h,obj_Cursor,true,false){
            if !collision_point(x+w,y+h,obj_Surface,true,true){
                collision+=1
                }
            }
        }
    }
    
if(collision>0){
    return true
    }else{
    return false
    }
It works perfect, but I thinks is too work for th CPU check for every pixel of the cursor. What do you think?
 

TheouAegis

Member
Actually I think my issue was I used sprite_width/2 and sprite_height/2 when it should have just been sprite_width and sprite_height without the /2's added in.
 
Top