Mushroom Kingdom Fusion Reactor > Game Maker Boards > MKF Level Design
Your Ad Here
Full Version: Coding assistance.
Lars Luron
I'm having some trouble with coding one of the enemies for Journey to Funkotron, the Giant Hamster Ball. The way it's supposed to work is that it works like a Koopa Troopa, except it's bigger, and it can't be picked up or thrown. Well, I've gotten it to mostly work, but I've encountered a bug that I have no idea whatsoever what it's being caused by.

The problem is; for some reason while the "shell" form is rolling around, it's unaffected by Mario's spin jump. If you jump on it with a regular jump, it stops moving like it's supposed to. But if you do a spin jump on it, you simply pass through and take damage. Also, the spin jump defeats it just fine when you use it before stomping it into a "shell".

I've been looking at this code up and down, comparing it to the normal shell object and whatnot, and I just can't figure out what's wrong with this thing.
Here's the altered code I have for the thing:

CREATE:
CODE
image_speed = 0.15
gravity = 0.25
hitpoint = 0
bam = 0
rolling = 0
hurtmario = 0


END STEP:
CODE
if collision_rectangle(x-22,y+47,x+22,y+47,obj_solidtop,1,1)
{
gravity = 0
vspeed = 0
}
else
gravity = 0.25
while collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_slopeparent,1,1)
y-=1
if vspeed > 4
vspeed = 4
if hspeed > 0
and collision_rectangle(self.x+hspeed+22,self.y,self.x+hspeed+22,self.y+45,obj_solid,1,1)
{
if x>view_xview[0]-22
and x<view_xview[0]+342
and y<view_yview[0]+240
and y>view_yview[0]-44
sound_play(snd_bump)
instance_create(x,y,obj_blockbumper)
hspeed = -hspeed
image_xscale = -1
}
if hspeed < 0
and collision_rectangle(self.x+hspeed-22,self.y,self.x+hspeed-22,self.y+45,obj_solid,1,1)
{
if x>view_xview[0]-22
and x<view_xview[0]+342
and y<view_yview[0]+240
and y>view_yview[0]-44
sound_play(snd_bump)
instance_create(x,y,obj_blockbumper)
hspeed = -hspeed
image_xscale = 1
}
if visible = 0
and not instance_exists(obj_warpmario)
visible = 1
if bam = 0
and not collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_mario,1,1)
bam = 1
if rolling = 1
and hurtmario = 0
and not collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_mario,1,1)
hurtmario = 1


COLLISION <> OBJ_MARIO
CODE
if hurtmario = 0
and rolling = 0
{
   if obj_mario.direct = 1
   {
   image_xscale = 1
   hspeed = 2.5
   rolling = 1
   }
   if obj_mario.direct = -1
   {
   image_xscale = -1
   hspeed = -2.5
   rolling = 1
   }
sound_play(snd_kick)
sprite_index = spr_hamster_roll
image_speed = 0.1
}

//Sonic/Tails jumping and rolling attacks
if (global.playerclass = 3 || global.playerclass = 4)
   {
       if (obj_mario.spinattack >= 1)
       and not (other.y < y-24)
       {
           imdead = instance_create(x,y+16,obj_enemy_dead)
           imdead.sprite_index = sprite_index
           imdead.image_speed = 0
           imdead.image_xscale = image_xscale
           sound_play(snd_sonic_stomp)
           instance_create(x,y,obj_100pts)
           instance_destroy()        
           exit
       }
   }

if other.y < y-24
   {
   hspeed = 0
   if (obj_mario.stompgrade >= 2)
       {
       hurtmario = 0
       imdead = instance_create(x,y+48,obj_enemy_dead)
       imdead.sprite_index = sprite_index
       imdead.image_xscale = image_xscale
       scr_givepoints_stomp2()
       instance_destroy()
   }
   }
if hurtmario = 1
{
if instance_exists(obj_invincibility)
exit
if other.y < y-24
   {
   hspeed = 0
   if not(obj_mario.stompgrade >= 2)
   {
   ID = instance_create(x,y,hamster_stunned)
   }
   scr_givepoints_stomp()
   if keyboard_check(vk_shift)
   other.vspeed = -8
   else
   other.vspeed = -4
   other.jumpnow = 2
   instance_destroy()
   }
//Begin Hurt Code
else if other.invincible = 0
{
   scr_hurtmario()
}
//End Hurt Code
}


sprite size: 48x48
origin: x=24,y=0

These three events are the only ones that should really matter at all; I left out all those collision events designed to kill the thing in various ways.
I added in some extra code to switch the "shell" form between different sprites depending on if it's idle or rolling, and I also took the Sonic spin attack and spin jump out of the "if hurtmario=1" condition, because it made no sense that the "shell" couldn't be defeated while it was sitting around idle. Note that it was still having this problem before I took the spin jump code out of that condition.

Is there anyone good at coding who could take a look at all this and let me know how to fix the problem?
Lars Luron
Alright, well, I finally figured out what the problem was. Turned out it wasn't in the code at all.

Apparently with some enemies, the <same as sprite> setting for the object mask doesn't quite work if there's any transparency in the sprite. And for some odd reason it only has this problem when involving jump collision. Every other part of the code, including the part that hurts the player, still works just fine.
What this means is that if you ever run into this problem, where for some reason jumping on an enemy just results in you falling through it and taking damage, you need to set the enemy's mask to something that's a solid block of color, such as one of the enemy mask sprites. You may have to adjust the enemy sprite's origin, as well as any code pertaining to the origin in order to get the mask to sit right, though.
AuraLancer
Maybe this will solve my problem. Thanks Lars! Sorry I couldn't help you with yours.
Powered by IP.Board v1.3 © 2003 - iPBFree v.2.1 © 2007