Help with game development

(JohnnydCoder) #81

I tried setTextSize and it works! :smile:


(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:

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;


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;


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?


(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;

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

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.


(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.


(JohnnydCoder) #96

Could anyone help me with my code organization? I’d really appreciate it.


(Pharap) #97

On the same game? Or a different game?

(JohnnydCoder) #98

Same game. Here’s the code I forgot to post:

(Pharap) #99

I might be able to look over it later, but I’m trying to take a break from programming for a few days.

To be honest the best thing you could do to improve organisation is to fix the indentation,
t the moment it’s a bit all over the place.

I can see quite a few other improvements,
but I think I’d have to stop to explain most of them.

(JohnnydCoder) #100

I understand! :wink:

Thanks for looking over it!