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

Login with username, password and session length

 
Advanced search

879200 Posts in 32967 Topics- by 24359 Members - Latest Member: colinvella

May 23, 2013, 01:10:46 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Need help with a certain enemy
Pages: [1]
Print
Author Topic: Need help with a certain enemy  (Read 504 times)
Zack Bell
Level 8
***



View Profile WWW
« on: December 18, 2011, 12:19:43 PM »

I really need some help with an enemy that I'm working on.  WTF

The enemy hides under a hat, similar to a mettaur from Megaman.
Then, when the player is within range, he should stretch himself to block off the player.
So he draws a stretched body, then draws the hat on the end.



Here's a two second mockup, thanks to MS Paint. The green square being the player and the arrow being the mettaur. The tip would be the hat.

As you can see from the picture, I want him to be able to sit on multiple surfaces (walls, ceilings, floors).

Code:
//Create Event

hitPoints = 20;
canGetHurt = false;

UP = 10;
DOWN = 11;
RIGHT = 12;
LEFT = 13;

facing = UP;

//facing up
if (place_meeting(x, y + 1, oSolid)) {
    image_angle = 0;
    facing = UP;
}

//Facing right
if (place_meeting(x - 1, y, oSolid)) {
    image_angle = 270;
    x -= 1;
    facing = RIGHT;
}

//Facing left
if (place_meeting(x + 1, y, oSolid)) {
    image_angle = 90;
    facing = LEFT;
}

//Facing down
if (place_meeting(x, y - 1, oSolid)) {
    image_angle = 180;
    y += sprite_height - 1;
    facing = DOWN;
}

IDLE = 20;
ALERT = 21;

state = IDLE;


So again, he needs to stretch a sprite of his body from his origin to the player's position, then draw the hat on the end.

It probably isn't too complicated, but I haven't slept and have been running into issues...  Beg
Logged
Zack Bell
Level 8
***



View Profile WWW
« Reply #1 on: December 18, 2011, 01:34:15 PM »

A few cups of coffee and I was able to get them working.  Coffee

A for loop draws the body several times between the hat and the enemy's original coordinates.


Now my issue will be making the body sprites act as part of the enemy. Meaning you can only shoot the body, not the hat. Not quite sure how to pull that one off.
Logged
GZ
Level 1
*



View Profile WWW Email
« Reply #2 on: December 18, 2011, 03:41:03 PM »

Check out this example I made:

http://gzstorm.com/gmhelp/Hats.gmk

The method I used is reasonably optimized and uses a more advanced method of doing things, but accomplishes what you are aiming for. The code is lightly commented.

In brief, I grow the collision box using the image_xscale variable and detect the hat by getting the plane of the hat (vertical or horizontal) and comparing it to my bullet coordinate (controlled by the mouse).
« Last Edit: December 19, 2011, 01:06:50 AM by GZ » Logged

Zack Bell
Level 8
***



View Profile WWW
« Reply #3 on: December 18, 2011, 11:07:00 PM »

For whatever reason, the link just takes me to your web page. I don't get a download link.  Sad
Logged
GZ
Level 1
*



View Profile WWW Email
« Reply #4 on: December 19, 2011, 01:07:43 AM »

It looks like I put the wrong directory. Should have tested it before posting. Here is the fixed link:

http://gzstorm.com/gmhelp/Hats.gmk
Logged

Zack Bell
Level 8
***



View Profile WWW
« Reply #5 on: December 19, 2011, 09:30:58 AM »

Good stuff, man. That is a bit more effiecient than mine at the moment! I'm going to try to combine both methods in a way because I like bits of both!

Thanks again  Coffee
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic