Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to python3 and add functionality #11

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

Dimi20cen
Copy link
Contributor

@Dimi20cen Dimi20cen commented Apr 10, 2023

  • Fixed issue with adjusting pygame window to screensize
  • Added mouseclicking for changing lanes
  • Added pause functionality, either with clicking on pause button or by pressing space
  • Added homebutton, during scorescreen

@chimosky @sourabhaa

ayushnawal and others added 13 commits December 21, 2019 05:03
Two Python files did not have executable permissions.

Shouldn't cause any symptom, but was irritating.

Signed-off-by: James Cameron <[email protected]>
- camel case the game class name,

- rename source file to match lowercase class name,

- rename instance variable to match Sugargame test activity

Signed-off-by: James Cameron <[email protected]>
Sugargame test activity does not do this.

Was also found in other activities, such as Bridge and Jumble, it
changes the order of creation of the X11 windows.

The earlier port of thie activity to Sugargame 1.3 has not properly
followed the new API and test activity.

Signed-off-by: James Cameron <[email protected]>
EPERM is reported when the activity is run under Sugar when the source
code is in /usr/share/sugar/activities
- name the run method the same as the example program,

- use a running flag rather than a crashed flag; crashed could be
  misunderstood as referring to the cars, and running is how the
  example program is phrased,

- change initialisation of the display,

- properly exit the event loop if the stop button is pressed,

- handle all events in the message queue in one place.

Tested on Ubuntu 20.04 with Sugar.  Mostly works.

Signed-off-by: James Cameron <[email protected]>
@Dimi20cen Dimi20cen changed the title Port to python3 Port to python3 and added functionality Jul 9, 2023
@Dimi20cen Dimi20cen changed the title Port to python3 and added functionality Port to python3 and add functionality Jul 9, 2023
@Dimi20cen Dimi20cen marked this pull request as draft July 9, 2023 13:39
@Dimi20cen Dimi20cen marked this pull request as ready for review July 12, 2023 10:11
Copy link
Member

@chimosky chimosky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these changes are from Sourabha's PR then that PR contains 13 commits which it looks like you've merged all to one without retaining the commit authors.

If you intend to continue the work on that PR then fetch the PR and then continue on top of the latest commit.

activity.py Show resolved Hide resolved
activity/activity.info Outdated Show resolved Hide resolved
Copy link
Member

@chimosky chimosky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you keep flake 8 changes to another PR?

elements.py Outdated Show resolved Hide resolved
elements.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Show resolved Hide resolved
scorescreen.py Outdated Show resolved Hide resolved
sugargame/event.py Outdated Show resolved Hide resolved
welcomescreen.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
scorescreen.py Outdated Show resolved Hide resolved
scorescreen.py Outdated Show resolved Hide resolved
elements.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
activity.py Show resolved Hide resolved
elements.py Show resolved Hide resolved
@chimosky
Copy link
Member

Tested 27d2652, arrow keys no longer work and only mouse buttons work.

@Dimi20cen
Copy link
Contributor Author

In my environments it works just fine, seems to be the same issue I faced with flappy's toolbar not showing

@jriyyya
Copy link

jriyyya commented Aug 8, 2023

Tested 27d265, Arrow keys are working for me

@Dimi20cen
Copy link
Contributor Author

Dimi20cen commented Sep 4, 2023

If you intend to continue the work on that PR then fetch the PR and then continue on top of the latest commit.

Should I do that now? I think it's possible

Could you keep flake 8 changes to another PR?

I can't figure out how to approach flake8 for python2, can you help me? I did an attempt #13

@quozl
Copy link
Contributor

quozl commented Sep 5, 2023

I can't tell if this set of changes is based on the earlier pull requests by sourabhaa or ayushnawal, or if it discards all that work we(-all) did in favour of doing it over again. Can you explain if you used the earlier work and just forgot to use "git commit --author", or if you just didn't notice it?

Looking at the flake8 fixes for python2 seems unhelpful unless you plan to rebase your branch on top of them. Is that what you plan to do?

@Dimi20cen
Copy link
Contributor Author

Can you explain if you used the earlier work and just forgot to use "git commit --author", or if you just didn't notice it?

The changes in my first commit were based on the sourabhaa's repo, I honestly didn't know "git commit --author" was a thing. That's why in my commit message I wrote, "Using the already ported to Python3 fork from Sourabhaa's repo.".

Looking at the flake8 fixes for python2 seems unhelpful unless you plan to rebase your branch on top of them. Is that what you plan to do?

No, I don't think I want to rebase my branch on top of them. I thought it might be helpful for some other reason, since it was suggested.

@quozl
Copy link
Contributor

quozl commented Sep 5, 2023

The changes in my first commit were based on the sourabhaa's repo, I honestly didn't know "git commit --author" was a thing. That's why in my commit message I wrote, "Using the already ported to Python3 fork from Sourabhaa's repo.".

We usually use git to attribute developer work, and the format used by git for author ensures that the developer is identified properly. Sourabhaa is a GitHub username, and that isn't stored in git. Perhaps you could rebase your branch on their branch? That will ensure their commits are present.

No, I don't think I want to rebase my branch on top of them. I thought it might be helpful for some other reason, since it was suggested.

I expect Ibiam did this to keep flake8 work separate from more substantial changes. It is much harder to review a pull request or especially a commit where there is obvious confusion about what the commit is for; and mixing flake8 work with substantial change is an example of that.

In our guide to reviewers in the contributing guide, we have summarised this as a style issue;

  • is the changed code consistent in style with the existing code, see also coding standards, (on the other hand, expect flake8 changes to be in separate commits),

Perhaps you need to do some reviews yourself, to better understand the process. Have you done any?

Aim is to improve readability mainly by
- Use more descriptive naming for variables and functions
- Breaking up large functions
- Adding global variables

Other changes
- Incorporate score_path inside scorescreen
- Fill space that was unused by pygame with black color
Make the following adjust to screen size
- Background size
- Squares' and circles' size
- Cars' size
- Font size
- Perceived speed of cars
- Add home button image
- Use the same code that's used for restart button
When pause button is clicked or space button is pressed game is paused and screen darkens

Changes
- Add pause button image
- Display button at the top left
- Add handling for when pause is clicked
- Add handling for when space key is press
- Add method for when pause button or space key is pressed
@quozl
Copy link
Contributor

quozl commented Sep 10, 2023

Thanks. Reviewed to 988afb2.

This change also fixes the following Traceback that was caused when using the activity with newer pygame versions
-  Traceback (most recent call last):
  File "/home/dim/Activities/2-cars-activity/sugargame/event.py", line 128, in _keydown_cb
    return self._keyevent(widget, event, pygame.KEYDOWN)
  File "/home/dim/Activities/2-cars-activity/sugargame/event.py", line 169, in _keyevent
    mod = self._keymods()
  File "/home/dim/Activities/2-cars-activity/sugargame/event.py", line 145, in _keymods
    mod |= self.__keystate[key_val] and mod_val
IndexError: list index out of range
@Dimi20cen
Copy link
Contributor Author

Arrow keys should be working with the updated version of sugargame. @chimosky

@chimosky
Copy link
Member

chimosky commented Sep 11, 2023

Please drop 52ed8e0 as that's not related to this PR, you can open another PR for it.

I haven't looked at #13 yet but it should be there instead of here.

The refactor in ca712d3 isn't also needed here as it's not related to this PR, another PR for that would be helpful.

game.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
scorescreen.py Outdated Show resolved Hide resolved
welcomescreen.py Outdated Show resolved Hide resolved
game.py Outdated Show resolved Hide resolved
Comment on lines +321 to +323
if (pause_rect.collidepoint(mouse_x, mouse_y) and
event.type == pygame.MOUSEBUTTONUP and
event.button == 1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the outer parentheses.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the outer parentheses, I would get SyntaxError: invalid syntax

Copy link
Member

@chimosky chimosky Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use \ to indicate that the line doesn't end there.

@Dimi20cen
Copy link
Contributor Author

Please drop 52ed8e0 as that's not related to this PR, you can open another PR for it.
I haven't looked at #13 yet but it should be there instead of here.

The refactor in ca712d3 isn't also needed here as it's not related to this PR, another PR for that would be helpful.

I read that in the guide, but in this specific case, I fixed flakes and refactored the code and then on top of those I added new features. So my features were build on top of the flake fixes and the refactoring. Wouldn't the only other choice be to make a PR for the flakes, then a PR on top of it for the refactoring and then another PR on top of them for the added features? Wouldn't that create too much complexity? I also had in mind that in the case of this small project that would be to confusing.

Mainly
- Add empty lines above comments
- Rename self.soon_to_draw to pending_element
- Set line to execute when `if event.type == pygame.QUIT:` to `self.running = False`
@chimosky
Copy link
Member

chimosky commented Sep 12, 2023

I read that in the guide, but in this specific case, I fixed flakes and refactored the code and then on top of those I added new features. So my features were build on top of the flake fixes and the refactoring. Wouldn't the only other choice be to make a PR for the flakes, then a PR on top of it for the refactoring and then another PR on top of them for the added features? Wouldn't that create too much complexity? I also had in mind that in the case of this small project that would be to confusing.

My bad, I should've explained earlier, this PR should be for Port to Python 3, any new functionality should be in another PR, same goes for any other change that's not a Port to Python 3.
That means you can base a different branch on the necessary changes and keep each branch to changes that needs to be there, so flake8 on a different branch and added functionalities on a different branch.

@Dimi20cen Dimi20cen mentioned this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants