Punching and Hp not so easy huh? (Help Appreciated!)

Non-platform specific questions.

Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Sun Aug 18, 2013 2:29 pm

I can create a game were there is punch. I can create a game with HP, but I cannot make a game with Punching and hp.
I was planning on making the Octopus punch in my game. And I Did! But it was short lived, when I tried to polish it up (add sound effects and make
stars come out of the enemy) I ruined it. octopus can be killed by the enemy while standing still. but when running i can kill the enemy.
I tried to fix it by undoing what I did but it was no use.
But obviously the code I am using is not the ideal and there is a better way of doing it.
but here is my code all the same:
this is the code in the collision event with the enemy:
Code: Select all
switch(animindex)
{
    case 0:
    HP--;
    DestroyActor("Collide Actor");
    break;
    case 1:
    DestroyActor("Collide Actor");
    break;
}

if(HP==0)
{
    DestroyActor("Event Actor");
}
and this is the punch code when you press "z"
Code: Select all
if(kickright==0)
{
  ChangeAnimation("Event Actor", "Player Right Attack", NO_CHANGE);
}
if(kickleft==0)
{
  ChangeAnimation("Event Actor", "Player Left Attack", NO_CHANGE);
}
animindex=1;
this is a section from the event with the "right" key
Code: Select all
kickright=1;
if(kickleft=1)
{
  kickright=0;
}

this is a section from the event with the "left" key
Code: Select all
 
}
kickleft=1;
if(kickright=1)
kickleft=0;



if that still does not make sense Ive got the ged here.
even if you can not help me fix what I have can you give me a substitute punch system that works well with HP?
Attachments
Octopus Game (4).zip
(156.6 KiB) Downloaded 148 times
Last edited by Turon on Tue Sep 03, 2013 6:32 pm, edited 6 times in total.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh?

Postby Turon » Thu Aug 22, 2013 12:09 pm

Ehem! I had made a punch system work before,
It's not working anymore, but something like this
Has been achieved before! Look at winter blast!
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Mon Aug 26, 2013 7:02 am

Any Ideas?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby skydereign » Mon Aug 26, 2013 10:19 am

Nothing about hp should actually change your punching code. The main logic should stay identical, the one difference being instead of DestroyActor immediately, you decrease hp (and if the player has no more hp, destroy it). In your case, you are using animindex, which may be contributing to the problem. Your code doesn't make much sense to me, so could you explain exactly what you are trying to do?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Mon Aug 26, 2013 12:54 pm

Thank you for responding!
I am trying to make the player punch
and kill the enemy without losing HP while punching.
and losing HP when not punching.
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated Great

Postby skydereign » Tue Sep 03, 2013 7:49 am

Turon wrote:Thank you for responding!
I am trying to make the player punch
and kill the enemy without losing HP while punching.
and losing HP when not punching.

Then all you need to do is set up the collision event between the enemy and player as you normally would. Then place an if around the lowering of hp, which triggers only when the player is not punching. I recommend having some variable hold what the player is doing, so you can use it to check if the player is not punching, but using animindex would work as well.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated Great

Postby Turon » Tue Sep 03, 2013 4:57 pm

Do you know a better way of lowering hp on collision? :?
cause I think that my hp system is a little inefficient.
and I have tried the "if" idea and it.. does not really work with
the strange Hp system I use which was not even made for a platform
game! :lol:
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby skydereign » Tue Sep 03, 2013 8:44 pm

Turon wrote:the strange Hp system I use which was not even made for a platform
game! :lol:

This isn't made for a platformer either. Normally in platformer games you have some knock back when you get hit, and a moment of invulnerability. Also there is a small amount of hp, where this doesn't necessarily do that.
player -> Collision with enemy (repeat enabled) -> Script Editor
Code: Select all
if(player is not punching) // you need to change this line to actual code
{
    hp--;
    if(hp<=0)
    {
        DestroyActor("Event Actor");
    }
}
else // this means the player is punching
{ // so destroy the enemy actor
    DestroyActor("Collide Actor");
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Wed Sep 04, 2013 9:18 am

Is this right? cause the Player will lose HP as should but punching does not kill the enemy
and the player is killed when punching.
Code: Select all
if(Notpunching=1) // you need to change this line to actual code
{
    HP--;
    if(HP<=0)
    {
        DestroyActor("Event Actor");
    }
}
else(ispunching=1);
{ // so destroy the enemy actor
    DestroyActor("Collide Actor");
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby skydereign » Wed Sep 04, 2013 10:31 am

Turon wrote:Is this right? cause the Player will lose HP as should but punching does not kill the enemy
and the player is killed when punching.

No. First off you didn't put the double equal for the if comparison. Second that else should be an else if, since you put a condition after it. Also, if you have a variable that represents if the actor is punching or not, you don't need a different variable to tell that the actor is not punching. Use one variable, it is cleaner, and you won't make as many mistakes because of it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Wed Sep 04, 2013 11:18 am

I did what you said the code is now cleaner :) . and I added the "else if" like you said but it
does not change anything visible. :?
this is how my code looks like.
Code: Select all
if(Notpunching==0) // you need to change this line to actual code
{
    HP--;
    if(HP<=0)
    {
        DestroyActor("Event Actor");
    }
}
else if(Notpunching==1);
{ // so destroy the enemy actor
    DestroyActor("Collide Actor");
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby skydereign » Wed Sep 04, 2013 8:20 pm

First major problem, you have a semicolon after the else if. This will end the else if, and make it so the enemy will always be destroyed on collision. From your initial code, that is probably what you actually want, but you should simply remove the else if. You should try stepping through your code line by line. You'll notice that when Notpunching is equal to 0 (which should only be true when the player is punching) that hp is decreased. This is the opposite of what you want. You could fix this by using Notpunching!=0. Another thing, you'll need to change the Notpunching variable when punching and finishing a punch.

Really I suggest using the state method, instead of a variable that only holds the punch state. http://game-editor.com/State_Method
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Wed Sep 04, 2013 9:08 pm

I am definably not doing something right. I am trying
To make it so that when "Notpunching==1;" is triggered
The player won't lose HP, how can I do that?
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby skydereign » Wed Sep 04, 2013 9:32 pm

Don't use notpunching as a variable. It makes more sense to use punching, since the default value for an int is 0. When punching is equal to zero, the player can be damaged, therefore the code would look like this.
Code: Select all
if(punching==0)
{
    HP--;
    if(HP<=0)
    {
        DestroyActor("Event Actor");
    }
}
DestroyActor("Collide Actor");

Now make sure to set punching equal to one when the player presses the punch key. And set it back to zero when the punch is finished.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Punching and Hp not so easy huh? (Help Appreciated!)

Postby Turon » Thu Sep 05, 2013 10:59 am

Do you think the problem may be in the way I trigger the variables?
I just trigger it like this: punching==0; as simple as that! I am still unable
to do what what I would like with the code.
if you want to have another look at the ged its here.
Attachments
Punching and HP Problem.zip
(64.98 KiB) Downloaded 135 times
Turon
 
Posts: 862
Joined: Sun Jan 24, 2010 5:23 pm
Score: 32 Give a positive score

Next

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron