Help with game development


(JohnnydCoder) #81

I tried setTextSize and it works! :smile:

Thanks!


(JohnnydCoder) #82

Got the basic game done: just fixing a couple of bugs and then I’ll be done! :grinning:


(JohnnydCoder) #83

Okay, I have one problem. When I try to catch up to the opponent when the opponent is in front of me, I can’t get past the opponent to get the ball.

Here’s a video of the problem:
ArduboyRecording%20(1)

Is there a way to slow the opponent down or speed the player up so it looks good?


(Simon) #84

Maybe both the player and the opponent should not be able to run as fast when they have the ball than when they do not.

You currently have code like :slight_smile:

if (!opp.hasBall && arduboy.everyXFrames(7)) {
  switch (opp.stance) {
    case OppStance::oppRunningR:
      if(ballx < opp.x)
        opp.x += OPP_SPEED;
      break;

      ...
  }
} 

Maybe if you change it to:

if ((opp.hasBall && arduboy.everyXFrames(8)) ||
    (!opp.hasBall && arduboy.everyXFrames(7)) {
  switch (opp.stance) {
    case OppStance::oppRunningR:
      if(ballx < opp.x)
        opp.x += OPP_SPEED;
      break;

      ...
  }
} 

This will slow them down a little when they the ball. The difference between 7 and 8 might be too much and you might be able to steal the ball too easily.


(JohnnydCoder) #85

I tried your idea but there is one problem with my code somewhere: the player cannot pass the opponent for some reason. Can you take a look?

Thanks!


(Simon) #86

Is this a new issue or did it exist before adding the code I suggested?

Can you explain to me what the various stance values actually mean?


(Stephane C) #87

What I would do is adding a Sprint option that uses stamina so that you can’t just Sprint all the time, to that way you would need to make sure you manage your stamina and that would let you catch up


(JohnnydCoder) #88

This could’ve been the problem instead of getting past the opponent by not running fast enough, because I tried slowing down the opponent by a different way before (your way looks better :smile:)

What do you mean by this?

@Vampirics, that sounds like a cool idea! I might try to put it into the game. :wink:


(Simon) #89

For example, what do the values RunningR1 and RunningR2 mean? I get R means Right but what is the 1 and 2?


(JohnnydCoder) #90

The 1 and the 2 are the positions of the player running. I used two sprites: one with the legs out spread and the other with its legs closed together. Showing Sprite, 1 and then showing Sprite 2, then Sprite 1 again etc. creates the image of a player running.

Here are the images:
04%20PM 01%20PM

Does that help? :grinning:


(JohnnydCoder) #91

I figured what was wrong with the code! I was restricting the opponent from moving past the player.

I’m still working on the solution.


(JohnnydCoder) #92

I was creating a tackle function and when ever I take the ball correctly when I let go of the button I am using to run, the ball is transported to the opponent again.

Here’s the code:

void tackle() {
Rect playerRect = {player.x, player.y, PLAYER_WIDTH, PLAYER_HEIGHT};
Rect oppRect = { opp.x, opp.y, OPP_WIDTH, OPP_HEIGHT };

   if (arduboy.collide(oppRect, playerRect)) {
    if (arduboy.justPressed(A_BUTTON)) {
      player.hasBall = true;
      ballx = PLAYER_X_OFFSET + PLAYER_WIDTH;
    }
  }
} 

Here’s a video of the problem (near the end when the player is nearing the other side of the field.):
ArduboyRecording%20(4)

Thanks for your help! :smile:


(Simon) #93

I don;t think the issue is with the snippet of code you posted. It is probably elsewhere in the game … did you end up putting the full code in GitHub or elsewhere?

Also, I don’t know how many times you are repeating this code …

Rect playerRect = {player.x, player.y, PLAYER_WIDTH, PLAYER_HEIGHT};
Rect oppRect = { opp.x, opp.y, OPP_WIDTH, OPP_HEIGHT };

…but it might make sense to put it as a method in the Player and Opp structs.

struct Player {
  int x;
  int y;
  Stance stance;
  bool sliding;
  const byte *image;
   
  Rect getRect() {
    return Rect {player.x, player.y, PLAYER_WIDTH, PLAYER_HEIGHT};
  }
};

Then you can just say

if (arduboy.collide(opp.getRect(), player.getRect())) {

(JohnnydCoder) #94

Here is the full code:

I will try your suggestion about the structs as well.

Thanks!


(JohnnydCoder) #95

I just found another problem with the game that I can’t figure out how to fix: after the player scores the opponent stays still and faces to the right.

ArduboyRecording%20(2)