Learning Python

Started by Pfaber11, April 30, 2019, 14:13:49

Previous topic - Next topic

MikeHart


Besides what coder, i and others suggested before...


You don't need classes in Python. You can work fine with just functions/procedures. And a procedure is similar to a gosub and return. Goto is only available in a few BASIC languages.

But Pfaber11, here is a good advice. I said it before. Stick with AGK. You seem to have somehow mysterial managed to create some apps in it, so stick with that.
Somewhere i read that you program for a long time but you seem to have difficulties to understand the most simple things. Stick with AGK.

Pfaber11

Well I have rewritten my code and am finally getting it . I have sound and sprites working . Gonna keep going at this . You know it's true I'm not the sharpest pencil in the pack but I am persistent . I get the class thing now and really don't think I need to worry about it for now . Read up on it . now getting into the whole structure of python. Define procedures first and main program at the bottom. In Basic I've always done it the other way around or put my main program in the middle . Can't do that with python and that's where I was falling down . Anyway got it sorted now and everything is working . Getting used to no goto, gosub and return . I've always shied away from anything not basic
and I've now made the move away from it . As for speed really doesn't seem to be any difference between AGK2 and python but that maybe down to my slow laptop. Thanks for all your input on this forum. Don't think much of the python forum got very little response on there .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

You Know mike I've only been at this a week and I feel I am making good progress . When I started AGK it took me 6 weeks to complete my first game and it was crap . In one week I have nearly as much knowledge of python as I had of AGK in six weeks so I'm very pleased . There's still a few things I need to figure out but I would say another couple of weeks and I'll be ready to start producing some 2d games . I hope anyway . Got my loops working as they should do now and that was the problem I solved this morning . Sometimes it's best to just tear it up and start again. I think AGK was a very important stepping stone for me and am really glad I learnt as much about it as I did . All that knowledge is coming through in what I'm doing now . Now this time yesterday I would of agreed with you to stick with AGK but today it's all coming together . Have an excellent day.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

Well all's going well and I learnt a few things yesterday . One thing I've decided to do today is work out how to detect a collision between two sprites. Had a quick look last night and that is my task today , created another sprite on the screen for this process. There's a fair bit of documentation available on the internet about python to sift through. If anybody knows of a simple collision method please post it here . Thanks.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Derron

https://www.google.com/search?q=pygame%20sprite%20collision

First hits will help you ... documentation and samples

Code (Python) Select

def checkCollision(self, sprite1, sprite2):
    col = pygame.sprite.collide_rect(sprite1, sprite2)
    if col == True:
        sys.exit()

Source: https://stackoverflow.com/questions/16227616/how-to-use-sprite-collide-in-pygame


pygame offers multiple collision approaches:
https://www.pygame.org/docs/ref/sprite.html


bye
Ron

Pfaber11

Well I've looked at a few websites and am not finding what I'm looking for . would like to use the mask method preferably is there a simple solution to this . The stuff I found on the internet seemed to be complicated and incomplete. I'll keep looking but if you know how this is done please let me know.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

Thanks Ron just taking my lad to school and when I get back I'll try out that code . Thanks again for the speedy reply .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

#37
Hi not having much luck with the above code . Think I need to give my sprites an attribute (rectangle) . I'm using python 3 if that makes any difference . This is more or less the last piece of the puzzle then I'm going to attempt a simple game and see how I get on . At the moment I'm just moving some graphics around the screen (sprites) and playing some sounds . Did a background as well and worked out how to go full screen . My notebook is full of useful information for when I start my first project .

I will be a python programmer yet.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Derron

Quote from: Pfaber11 on May 16, 2019, 10:03:05
Hi not having much luck with the above code . Think I need to give my sprites an attribute (rectangle) . I'm using python 3 if that makes any difference .
[...]
I will be a python programmer yet.

Before you can become a programmer you need to:
- learn to read posts
- learn to use google (or whatever search engine you prefer)




A click later I land there:



Clicking on one of the listed collide functions leads to eg.:

Choose your preferred example from the result list.

If you clicked on the mask function you even would get the code right in that page:



As said it is only a matter of learning to _read_ and to surf around in the web (not talking about procrastinating ;-)).
Asking stuff here which is rather simple to find in the internet and answers are in the first hits on google does not shed the best light on your motivation and basic skills.

I understand that language barriers can create issues finding specific things as you just do not know the "right word to look for" but here you already knew the terms:
python sprite collision example

And I also understand that this posting sounds rather arrogant - so do not feel attacked, feel "not too gently" pushed into the right direction ;-)


bye
Ron

plenatus

Thanks a lot, Derron, I did not know how I could have said it nice.
You made pfaber´s day ;)

Pfaber11

Why thanks guys , much appreciated. I will try harder. Thanks once again .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

#41
sprite.mask = pygame.mask.from_surface(sprite.image)

Questions
At the start where it says sprite.mask came I change this to whatever I want
and at the end where it says (sprite.image) what do I put in here.
Tried many permutations but my computer throws a wobbly every time I try and run this code .
Your help is much appreciated.
I know I'm gonna get ridiculed for asking this question but I am stumped as to why I can't get this piece of code to run . Tried changing the attributes to rect as well and having the same problem. Must be doing something wrong .
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Derron

Post the piece of code (so some lines earlier plus the line with the "mask") in which you execute these commands?

myspritevariable.mask = pygame.mask.from_surface(myspritevariable.image)

"mask" and "image" are not changeable - they are properties of the object "myspritevariable".
"myspritevariable" is wherever you loaded your image to (at least in earlier posts you were creating the sprite out of an image loading command thingy).


@ asking
you might ask. But you need to learn to give enough hints for "us" helpers to be able to see where the culprit might be. Else it is pure guessing - which eats your time reading our posts and our time for posting them.


bye
Ron

Pfaber11

Thanks Ron I'll Give it a go.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz

Pfaber11

#44
b=pygame.sprite.Sprite()
b.image1 = pygame.image.load("picy.png").convert_alpha()
b.image2 = pygame.image.load("picy1.png").convert_alpha()
title = pygame.image.load("aba2 title.png")
b.image1.mask = pygame.mask.from_surface(b.image1.image)
b.image2.mask = pygame.mask.from_surface(b.image2.image)


here is my code every time it gets to the 5 th line down it throws up an error .
I have tried everything I can think of .
This is only a practice run but I need to get this sorted I've been going round in circles the last couple of days. I'm really sorry for annoying you so if you don't want to answer I perfectly understand.
HP 15s i3 1.2 upto 3.4 ghz 128 gb ssd 16 gb ram 15.6 inch screen. Windows 11 home edition .  2Tb external hard drive dedicated to Linux Mint .
  PureBasic 6 and AppGameKit studio
ASUS Vivo book 15 16gb ram 256gb storage  cpu upto 4.1 ghz