Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5949267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:13:29+00:00 2026-05-22T17:13:29+00:00

The following code renders a zombie with interchangeable coordinates. The only issue is that

  • 0

The following code renders a zombie with interchangeable coordinates. The only issue is that I have to duplicate the code and create new coordinate variables myself for each zombie. Is there any way I can create copies of the variables so I only have to have one method for multiple zombies verses three methods and three separate variables for three zombies?

int zombieyCord;
int zombiexCord;

    -(void)renderZombie
{
    NSBezierPath * path = [NSBezierPath bezierPath];
    [path setLineWidth:4];
    NSPoint center = {zombieyCord,zombiexCord};
    [path moveToPoint: center];
    [path appendBezierPathWithArcWithCenter:center 
                                     radius:5
                                 startAngle:0 
                                   endAngle:360]; 
    [[NSColor greenColor] set];
    [path fill];
    [[NSColor greenColor] set];
    [path stroke];

}

Edit:

The spawning is great and works perfectly, but I want the zombies to move properly. Before, the code was that the method was called upon the player moving. This no longer works because I have to call an integer in the method.

+(void)entityZombie:(int)zombiexCord andY:(int)zombieyCord
{
    /* Handle Zombie Movement*/
    if (xcord != zombiexCord || ycord != zombieyCord)
    {
        if (xcord > zombiexCord){zombiexCord=zombiexCord+1;}
        if (xcord < zombiexCord){zombiexCord=zombiexCord-1;}
        if (ycord < zombieyCord){zombieyCord=zombieyCord-1;}
        if (ycord > zombieyCord){zombieyCord=zombieyCord+1;}

        /* Handle Zombie Render*/

        NSBezierPath * path = [NSBezierPath bezierPath];
        [path setLineWidth:4];
        NSPoint center = {zombieyCord,zombiexCord};
        [path moveToPoint: center];
        [path appendBezierPathWithArcWithCenter:center 
                                         radius:5
                                     startAngle:0 
                                       endAngle:360]; 
        [[NSColor greenColor] set];
        [path fill];
        [[NSColor greenColor] set];
        [path stroke];

    }
}

Player movement handling just involves rendering the player then [Entity entityZombie];
But as said above, no longer works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:13:30+00:00Added an answer on May 22, 2026 at 5:13 pm
    -(void)renderZombieWithX:(int)xCoord andY:(int)yCoord {
        NSBezierPath * path = [NSBezierPath bezierPath];
        [path setLineWidth:4];
        NSPoint center = {xCoord,yCoord};
        [path moveToPoint: center];
        [path appendBezierPathWithArcWithCenter:center 
                                         radius:5
                                     startAngle:0 
                                       endAngle:360]; 
        [[NSColor greenColor] set];
        [path fill];
        [[NSColor greenColor] set];
        [path stroke];
    }
    

    Call it like this:

    [self renderZombieWithX:10 andY:20];
    [self renderZombieWithX:13 andY:37];
    //...
    

    Further more there is a dedicated function for creating NSPoints:

    NSPoint center = NSMakePoint(xCoord, yCoord);
    

    which you might want to use in favor of:

    NSPoint center = {xCoord,yCoord};
    

    (see one of my answer’s comments on why)


    If performance is critical a cached approach like the following might bring performance gain:

    static NSImage *sharedZombieStamp;
    - (NSImage *)sharedZombie    {
        @synchronized(sharedZombieStamp) {
            if (!sharedZombieStamp) {
                CGFloat lineWidth = 4.0;
                CGFloat radius = 5.0;
                sharedZombieStamp = [[NSImage alloc] initWithSize:NSMakeSize((lineWidth + radius) * 2, (lineWidth + radius) * 2];
    
                [zombieImage lockFocus];
                NSBezierPath *path = [NSBezierPath bezierPath];
                [path setLineWidth:4];
                NSPoint center = NSMakePoint(lineWidth + radius, lineWidth + radius);
                [path moveToPoint: center];
                [path appendBezierPathWithArcWithCenter:center 
                                                 radius:radius
                                             startAngle:0 
                                               endAngle:360]; 
                [[NSColor greenColor] set];
                [path fill];
                [[NSColor greenColor] set];
                [path stroke];
                [zombieImage unlockFocus];
            }
        }
        return sharedZombieStamp;
    }
    
    -(void)renderZombieWithX:(int)xCoord andY:(int)yCoord {
        NSImage *zombie = [self sharedZombie];
        NSSize zombieSize = [zombie size];
        [zombie drawAtPoint:NSMakePoint(xCoord - zombieSize.width / 2, yCoord - zombieSize.height / 2)
                   fromRect:NSMakeRect(0.0, 0.0, zombieSize.width, zombieSize.height)
                  operation:NSCompositeSourceOver
                   fraction:1.0];
    }
    

    This code is just out of my head though. Went thru no testing, whatsoever. Use with caution 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following block of code that renders a form. The form will
I have the following code in my controller def create @severity = Severity.new(params[:severity]) if
I have a legacy application that, at some point, generates the following code in
Let's say I have the following code... StringBuilder sb = new StringBuilder(); for (int
I'm pretty new to MVC, but I have the following code: <td> @Html.DisplayFor(modelItem =>
The following code: <%= link_to content_tag(:span, 'foo'), :action => 'new' %> Renders the link
I have a dynamic forms with checkbox/radio-button lists & matrices: Following code renders checkbox
I have the following code in PHP: <?php if (function_exists(insert_audio_player)) {insert_audio_player([audio:|titles=]} ?> Which renders
The following code renders differently in IE7 and FF3 (NEW CODE POSTED OLD CODE
I have the following Code: def link_to_add_fields(name, f, association) new_object = f.object.class.reflect_on_association(association).klass.new fields =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.