Jump to content


King Pikmin

Member Since 21 Jul 2011
Offline Last Active Oct 05 2011 08:02 PM

Topics I've Started

With(other) not working as intended

03 September 2011 - 01:21 AM

So I have an obj_Player1, and an obj_Player2. I'm testing out something similar to SSBB, and it was all going fine until I hit this problem. So basically, this code is on obj_Player1, and when Space is pressed:

if cooldown = 0{
    cooldown = 1;
    alarm[0] = 10;
    if sprdirection = 1{
        sprite_index=spr_PlayerLeft_Sword;
        if collision_rectangle(x+2,y+10,x-3,y+30,obj_Player2,1,1){
            with(other){
                percentage += floor(random_range(3,7)/1)*1;
            }
        }
    }
    else{
        sprite_index=spr_PlayerRight_Sword;
        if collision_rectangle(x+26,y+10,x+31,y+30,obj_Player2,1,1){
            with(other){
                percentage += floor(random_range(3,7)/1)*1;
            }
        }
    }
}
Alarm 0 sets cooldown to 0, spr_direction just checks which direction the player is facing, and the collision rectangle checks to see if the other player gets hit by the sword. The problem is, when obj_Player2 is hit, it increases the percentage variable on obj_Player1, which is the object attacking.

Problems with my "Whack-a-Mole" Game

04 August 2011 - 01:01 PM

So I have 2 prolems.

1. When the hammer is swung, it destroys itself rather than the mole. This is on global left pressed of my hammer:

if hammerdown = 0{
    hammerdown = 1;
    cursor_sprite = spr_HammerDown;
    alarm[0] = 30;
    if collision_rectangle(mouse_x,mouse_y-4,mouse_x+10,mouse_y,obj_Mole,1,1){
        score += 1;
        with other{
            instance_destroy();
        }
    }
}
Hammerdown just makes it so you can't spam the hammer nonstop. Alarm 0 sets hammerdown to 0, and turns the sprite back to normal.

2. Moles can be created on top of eachother. So they spawn from this molehill, and multiple molehills exists on the level. Here is the on step command for the molehill:

if floor(random(room_speed*10)) = 0 && !collision_point(0,-8,obj_Mole,1,1){
    instance_create(x,y-28,obj_Mole);
}

[SOLVED]Changing Drawing Depth

01 August 2011 - 05:15 PM

So I have objectA that draws a local variable on objectB, but objectA is below objectB in terms of depth. How do I change the drawing depth so it draws OVER objectB without changing the depth of objectA.

[SOLVED]Drawing Variable not Working

01 August 2011 - 03:25 PM

So this is on the draw command of an object that only 1 of exists, but it is never destroyed. So I want it to display your money at the top-left corner of the view, and the opponent's money at the top-right corner. When I put this on the draw command, it isn't drawn. Other things are drawn if they are int he same draw command, but not this. Also, sometimes I can see the number flash for a frame when the game starts.

draw_set_halign(fa_left);
draw_text(view_xview+8,view_yview+8,string(global.money));
draw_set_halign(fa_right);
draw_text(view_xview+632,view_yview+8,string(global.bluemoney));

Guard Mode

01 August 2011 - 02:07 AM

So when guard mode is activated, it sets attack to 1, and the object should wander around a bit, but when it gets over 128 pixels away, it stops moving randomly and moves back towards the position it starting guarding (guardx, and guardy). The problem is, it never detects itself as being too far away. What's wrong with my code? Btw this is on alarm 1:

if (attack=1){
    if guard = 0{
        guardx = x;
        guardy = y;
        guard = 1;
    }
    if moveback = 0{
        if (floor(random(2-1))=0){
            motion_set(random_range(0,360),3);
        }
        else{
            motion_set(0,0);
        }
        if x >= guardx + 128 or x <= guardx - 128 or y >= guardy + 128 or y <= guardy - 128{
            move_towards_point(guardx,guardy,3);
            moveback = 1;
        }
    }
    else{
        if x = guardx && y = guardy{
            moveback = 0;
        }
    }
}