SyntaxBomb - Indie Coders

Languages & Coding => Others => Topic started by: Pfaber11 on April 30, 2019, 02:13:49 PM

Title: Learning Python
Post by: Pfaber11 on April 30, 2019, 02:13:49 PM
As I posted elsewhere on this forum I have taken it on myself to try and learn Python . Well I'm 2 days in and am struggling a bit . wish they had some decent documentation like AGK2 . What I need is a list of all the key words and commands with examples of how to use them . I'm only on my second day and was hoping to at least by able to open a graphics window or any window for that matter . I'll post back here when I make some progress. installed another module for it  called pygame . It's a module for game programming  that's 3 I've got so far . If anybody has any advice on where to start it'd be most welcome . I've read a few tutorials and am watching videos on you tube.
Title: Re: Learning Python
Post by: Derron on April 30, 2019, 02:48:09 PM
Python itself does not have that many "commands" you have to learn.

If you use libraries/modules then of course you need to learn their commands - and it depends on the module on how well they are documented.


bye
Ron
Title: Re: Learning Python
Post by: MikeHart on April 30, 2019, 02:53:00 PM
Regarding pygame.... it took me not even a minute to google for it, find its website. Top menu.. getting started. And there tutorials.
Title: Re: Learning Python
Post by: MikeHart on April 30, 2019, 02:54:16 PM
Btw. google for w3schools and python. The damn internet is full of tutorials.
Title: Re: Learning Python
Post by: Pfaber11 on April 30, 2019, 03:04:01 PM
yes just gotta get used to the coding style . found some good stuff about pygame to get me started . This oop stuff is taking some getting used to. I will not give up . what I could really do with is some printed out example code to get the ball rolling.
Title: Re: Learning Python
Post by: MikeHart on May 01, 2019, 10:04:43 AM
Hey Pfaber11, did you see this?
https://www.humblebundle.com/books/python-oreilly-books?hmb_source=navbar&hmb_medium=product_tile&hmb_campaign=tile_index_2 (https://www.humblebundle.com/books/python-oreilly-books?hmb_source=navbar&hmb_medium=product_tile&hmb_campaign=tile_index_2)
Title: Re: Learning Python
Post by: Pfaber11 on May 02, 2019, 09:41:03 AM
Thanks MikeHart just downloaded the 4 python books in the bundle paid a dollar. not bad considering The AGK tutorials are 20 to 30 quid each. so far my python setup has only cost me a dollar. not bad really in fact it's awesome. gonna get some serious reading in today. the way I see it is if I don't get on with it by the 10th June I'll be downloading AGK studio so got over a month to try and get to grips with it. When I started with AGK2 it took a few months to find my feet so I'm going to be patient. Thanks and thumbs up on the books.
Title: Re: Learning Python
Post by: Rick Nasher on May 03, 2019, 11:48:28 PM
Perhaps this helps too:

https://projects.raspberrypi.org/en/codeclub (https://projects.raspberrypi.org/en/codeclub)

Then just follow the 3 python links and more if you have a Pi.

And as Mike suggested:
https://www.w3schools.com/python/default.asp (https://www.w3schools.com/python/default.asp)

They are usually pretty good at showing all that's possible.

For keywords etc: https://www.w3schools.com/python/python_reference.asp (https://www.w3schools.com/python/python_reference.asp)
Title: Re: Learning Python
Post by: Pfaber11 on May 04, 2019, 07:56:12 AM
Don't have a pie but the link to the school seems pretty good. thanks.
Title: Re: Learning Python
Post by: Krischan on May 04, 2019, 05:04:26 PM
Thanks for the books hint - I've just bought it too. I've never coded anything in Python until last week - I had to rewrite a Python script and so I got into it. It's a nice language but I've only scratched the surface yet.
Title: Re: Learning Python
Post by: Pfaber11 on May 09, 2019, 12:47:58 PM
Hey that's cool i've got a few lines down so far but that's about it . Installed pygame so will be taking a look at that soon .
I'm coming from AGK2 what is your main language before python ? I think it's gonna take months before I get  to grips with it but what the hell I've got the time  at the moment . I almost stopped after a few days but have got back on the wagon . The hardest thing is getting those first few lines down to start the ball rolling . Which I have now. We're off.
Title: Re: Learning Python
Post by: Pfaber11 on May 09, 2019, 10:22:07 PM
well I've been playing with python most of the evening and now know how to open a window using pygame. I am progressing slowly . trying to find a command the equivalent of sleep in AGK but am finding it hard at the moment . The documentation is very slow to use but I am getting there in small steps . according to what I have read using panda 3d is as fast as c++ . we'll see I suppose . sticking to pygame for now . Don't want to try and run before I can walk . Gonna try and write a simple ish game and see what I come up with . probably gonna take me a couple of months but should learn a bit from it . That's what I did with AGK and seems to be the way to do it . A way anyway. Bonjour
Title: Re: Learning Python
Post by: Pfaber11 on May 10, 2019, 07:12:00 AM
Well my task today will be to put some graphics on the screen , and maybe get them moving . onwards and upwards . I'll let you know how I get on once I've done it (if).
Title: Re: Learning Python
Post by: Pfaber11 on May 10, 2019, 07:22:20 PM
well I'm getting there got graphics working . Bought myself a notebook and a few pens and am making notes . Feeling much more confident I can do this now , The pieces of the puzzle are coming together and faster than I thought . The 16 months I spent learning AGK2 are really helping me now . I think I'm gonna like python after all. using pygame  at the moment but I think It only does 2d but also got panda3d for the 3d stuff but I'll concentrate on what I'm doing now to get me going then in a few weeks I should be ready to move onto the 3d side of it . I think I've put in about a week so far and am happy with my progress . So far I've spent 1 dollar on some e books and a quid on a notebook and some pens . would I recommend  python to anybody else  the truth is I don't know but I will in a couple of months . I'm hoping that the games I produce will be as good as the ones I've made with AGK2 and from the demo I've seen of panda3d I believe this is attainable. Have a nice evening I'm gonna take a quick look around on here then off to read a book on yes you guessed it python.
Title: Re: Learning Python
Post by: Pfaber11 on May 10, 2019, 07:32:14 PM
By the way guys thanks for all the links you guys have posted . This is the first time I've tried anything different to basic and I think it's sinking in now . Did have a problem converting my .py files to exe files . It does it then at the end says I don't have permissions at the end . Anybody know how I can resolve this . they run fine as .py files.
Title: Re: Learning Python
Post by: c0d3r9 on May 10, 2019, 09:14:21 PM
you know http://www.py2exe.org/ (http://www.py2exe.org/)   https://pypi.org/project/auto-py-to-exe/ (https://pypi.org/project/auto-py-to-exe/)
Title: Re: Learning Python
Post by: Pfaber11 on May 10, 2019, 10:14:30 PM
Thanks for the reply got it working now . Did it using pyinstaller in the end . Got it to compile to a single exe file but still have to include my media with the exe file in the same folder . As I do with AGK2 . Did try py2exe but pyinstaller seems easier and it compresses it all into a single exe without all the dll  files showing . It's pretty tidy. Only written a couple of short pieces of code so far but know enough to think this is for me . I haven't used or declared any classes yet . so far my programs are running ok without it but I guess there will come a time when it becomes necessary . I think it acts as a container for some procedures or something like that according to what I've read. It'll probably make more sense a little way down the track. We'll see . At least I've got some compiled code and it's working as it should . I think the next thing to do is dive in and write a game and work it out as I go along .
Title: Re: Learning Python
Post by: Pfaber11 on May 10, 2019, 10:24:14 PM
By the way I'm making notes of everything I do so kinda writing my own user manual as I go along . At least by doing that With a quick flick through the pages I can jog my memory so don't have to worry about forgetting anything. I think in a few months I won't be an expert but I will be able to build games the way I like them .
Title: Re: Learning Python
Post by: MikeHart on May 11, 2019, 06:57:44 AM
I am using pyinstaller too. Was super easy to integrate it into the ide. As an ide i use PyCharm. Nothing beats that.


 Btw, you mentioned somewhere that you hope that your code runs faster when it is compiled. Python is always interpreted. For making code sections faster i am interfacing with Cypthon. Which method
do you use?
Title: Re: Learning Python
Post by: MikeHart on May 11, 2019, 07:04:18 AM
What the py to exe tools do is to create a bundle that will be extracted at start. Depending on how big and how many files you have, it can take time. PyInstaller can also pack everything into one exe. I choose not to as for my app it is more important to start fast.





Title: Re: Learning Python
Post by: Pfaber11 on May 11, 2019, 07:27:42 AM
Hi mike I'm using wing personal 7 . Nice and simple . Didn't realise they take longer to start if packaged into one file . Seems to work fine though. Really starting to get into it now. I no longer find it intimidating . I'm using pygame with python 3.7.3   at the moment . I read last night that you can produce APK files to run on Android but will have to look more closely into that to see how it's done . If I get stuck on anything I'll give you a shout .
Title: Re: Learning Python
Post by: Pfaber11 on May 11, 2019, 07:35:53 AM
I did try pycharm first but found it a tad too complicated . Wing personal 7 is simpler . Did try wing 101 as well but for some reason I didn't like it it was very simple . I intend to build myself a nice portfolio of all my python apps on the internet and hopefully I'll get some good programs created . There's so much free stuff on the internet for python it's unbelievable . Have a nice morning.
Title: Re: Learning Python
Post by: Pfaber11 on May 11, 2019, 09:23:02 AM
Hi all been looking at running python apps cross platform and saw something called Briefcase on the Beeware site . It claims to transfer a .py app into a  apk file which runs natively on Android .  Think it does the same for ios too. Not sure how it handles the touch screen etc but will find out in due coarse . Just had a look at the python forum and posted and got told off by a mod . never mind .
A bit of snobbery going on I believe. I prefer this forum to any of the others anyway. I'm off Have a nice morning .
Title: Re: Learning Python
Post by: MikeHart on May 11, 2019, 02:07:41 PM

Chekc it out today!

https://www.packtpub.com/packt/offers/free-learning?from=block (https://www.packtpub.com/packt/offers/free-learning?from=block)
Title: Re: Learning Python
Post by: Pfaber11 on May 11, 2019, 03:00:36 PM
Had a look unfortunately there was no sound . Done a lot of research today. Will be starting my first project very shortly . Everything is in place . Think it's gonna be a 2d space shooter or something to that effect to get the ball rolling and cut my teeth on using pygame and after I've done that I'll start on Panda3d  and see how that goes .  I've been taking notes on things like putting graphics on the screen, drawing , sound and collisions . just stuff to jog my memory and steer me in the right direction. Did the same thing with AGK2 in the beginning and it helped enormously.  A bit like my own quick start guide with everything I need in it. Quite a bit anyway.  I'm running python 3.7.3 which I got from python.org  I think it's cpython but don't really know.
I'm glad now I didn't invest in AGK studio when I got all the python stuff for free . Apart from the 77p I spent on 4 books . Which I probably will read at some point .
Title: Re: Learning Python
Post by: LineOf7s on May 12, 2019, 12:29:14 AM
There is absolutely sound.  Try harder.
Title: Re: Learning Python
Post by: Pfaber11 on May 12, 2019, 01:13:07 PM
I just tried again but was too late . I've just been getting the sound up and running in my little program . Took me all morning neglected to initialize the mixer. Oh well won't forget that again in a hurry.
Title: Re: Learning Python
Post by: Pfaber11 on May 12, 2019, 01:15:12 PM
Hi line of 7s what's your language . Are you learning or learnt python?
I'm taking a break from it for a couple of hours . Then it's time to get my graphics moving  . After that I should be in the position to try a simple game . emphasis on simple . Haven't worked out how to put text on the screen either so maybe I'll tackle that first. Coffee time . Ding Ding
Title: Re: Learning Python
Post by: Pfaber11 on May 12, 2019, 08:29:40 PM
Well I've kinda ground to a holt just deleted my days work . What I was wondering is there a special way of organising a python program . Finding it a bit difficult with no goto or gosub or return . I do understand procedures and how to call them sort of . Don't really get classes and if someone could explain this to me and where to create them I would be most grateful.
Title: Re: Learning Python
Post by: c0d3r9 on May 12, 2019, 09:24:54 PM
As your native language is english i only can say read books and google.
Python is not an hard to learn language and it seems that you have many problems with simple language things.
Read ebooks, tutorials, and source codes....

but in short:  https://www.w3schools.com/python/python_classes.asp (https://www.w3schools.com/python/python_classes.asp) and https://docs.python.org/3/tutorial/classes.html (https://docs.python.org/3/tutorial/classes.html) and very important http://www.giyf.com/ (http://www.giyf.com/)  :))
Title: Re: Learning Python
Post by: MikeHart on May 13, 2019, 05:47:22 AM

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.
Title: Re: Learning Python
Post by: Pfaber11 on May 13, 2019, 12:58:08 PM
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 .
Title: Re: Learning Python
Post by: Pfaber11 on May 13, 2019, 01:13:11 PM
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.
Title: Re: Learning Python
Post by: Pfaber11 on May 16, 2019, 07:18:07 AM
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.
Title: Re: Learning Python
Post by: Derron on May 16, 2019, 08:10:37 AM
https://www.google.com/search?q=pygame%20sprite%20collision

First hits will help you ... documentation and samples

Code:  (Unknown Language)
  1. def checkCollision(self, sprite1, sprite2):
  2.     col = pygame.sprite.collide_rect(sprite1, sprite2)
  3.     if col == True:
  4.         sys.exit()
  5.  
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
Title: Re: Learning Python
Post by: Pfaber11 on May 16, 2019, 08:13:41 AM
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.
Title: Re: Learning Python
Post by: Pfaber11 on May 16, 2019, 08:26:31 AM
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 .
Title: Re: Learning Python
Post by: Pfaber11 on May 16, 2019, 10:03:05 AM
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.
Title: Re: Learning Python
Post by: Derron on May 16, 2019, 11:04:43 AM
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)


(http://i.imgur.com/Yz5GfAp.png)

A click later I land there:
(http://i.imgur.com/ha3w1ky.png)


Clicking on one of the listed collide functions leads to eg.:
(http://i.imgur.com/9BFbtay.png)
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:
(http://i.imgur.com/AlqeDfe.png)


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
Title: Re: Learning Python
Post by: c0d3r9 on May 16, 2019, 11:16:34 AM
Thanks a lot, Derron, I did not know how I could have said it nice.
You made pfaber´s day ;)
Title: Re: Learning Python
Post by: Pfaber11 on May 16, 2019, 11:42:27 AM
Why thanks guys , much appreciated. I will try harder. Thanks once again .
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 08:14:45 AM
Code: [Select]
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 .
Title: Re: Learning Python
Post by: Derron on May 17, 2019, 08:37:29 AM
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
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 09:05:09 AM
Thanks Ron I'll Give it a go.
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 09:32:30 AM
Code: [Select]
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.
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 09:45:15 AM
Code: [Select]
def collisioncheck():
    collisions = pygame.sprite.spritecollide(b.image1,b.image2,False)
    for objects in collisions:
         objects.collideWith(b.image2)
         exit
This is what I'm going to use to check for a collision . . I think I'm actually not doing that bad . This piece of code I'll be looking at next I know it's got little chance of running at the moment but I'll be doing this after I've sorted the other bit .
Title: Re: Learning Python
Post by: Derron on May 17, 2019, 09:55:43 AM
Code: [Select]
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)

I am not using pygame nor do I have access to Python on this computer now:
line #1: you create a sprite
line #2: you load an image into a property "image1" of your sprite (dunno if that exists)
line #3: you load an image into a property "image2" of your sprite (dunno if that exists)

line #5: you try to create a mask of the property "image" of "image1" which is already an image ... and you try to assign it to "mask" of that image while it should be "mask" of the sprite
line #6: you try to create a mask of the property "image" of "image2" which is already an image ...

Python might allow dynamic adding of properties (so "image1" and so on exist afterwards) but the functionality to draw the image of a sprite isn't aware of "image1" or "image2" then - you would need to override all that stuff to.
To keep it simple you behave as expected and only load a single image per sprite object ...

Appending ".image" to something is not calling a method/function but here trying to retrieve the value behind the property "image". So in your case you tried to pass the property "image" of the property "image1" of your sprite "b". You should pass property "image" of sprite "b". But "image" is empty as you loaded your stuff into "image1" (and "image2").


So without testing:
Code: [Select]
b1 = pygame.sprite.Sprite()
b1.image = pygame.image.load("picy.png").convert_alpha()

b2 = pygame.sprite.Sprite()
b2.image = pygame.image.load("picy1.png").convert_alpha()

title = pygame.image.load("aba2 title.png")

b1.mask = pygame.mask.from_surface(b1.image)
b2.mask = pygame.mask.from_surface(b2.image)


bye
Ron
Title: Re: Learning Python
Post by: Derron on May 17, 2019, 10:00:50 AM
Your collision code does not make sense to me too ...

Code: [Select]
def collisioncheck():
    collisions = pygame.sprite.spritecollide(b.image1,b.image2,False)

... did you READ the documentation?


pygame.sprite.spritecollide()
Find sprites in a group that intersect another sprite.
spritecollide(sprite, group, dokill, collided = None) -> Sprite_list


How does that even _loosely_ connects to what you want to do by passing two images into it? IMAGES!
You planned to set masks ... so why not do a mask collision check?

pygame.sprite.collide_mask()
Collision detection between two sprites, using masks.
collide_mask(SpriteLeft, SpriteRight) -> point

it wants you to pass two SPRITEs (not IMAGES!). So following my code above you will have something like
pygame.sprite.collide_mask(b1, b2)


Also the documentation states you need to define the "rect" property of your sprite - so "yoursprite.rect". Will leave that up to you to google for it.


bye
Ron
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 12:16:55 PM
Hi Ron I'm back yes I borrowed the collision code off an example and it doesn't make sense to me either . I'll check out some more examples on this shortly . It's amazing you can do this without a computer with python on it in front of you . That code you did worked though . Thanks for the input . I'm getting there slowly . I think I've been at this 11 days now . when I've got this all working I'll try for a simple game next then probably another 2d one then I'm going to take a look at panda3d. Thanks for all your help. I'm off to take a look at collision stuff. I'll be back.
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 02:19:55 PM
Hi . Well I didn't realize you had to do the rect code when using the mask method but I've done it without the mask thing now. just the rect thing . sorry for the bad English but my brain is fried . Anyway It's all up and running but it's not detecting a hit yet . I'll take a break and  see what's going on .
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 05:10:31 PM
Code: [Select]
image1=pygame.sprite.Sprite()
image1.image = pygame.image.load("picy.png").convert_alpha()
image2 = pygame.sprite.Sprite()
image2.image = pygame.image.load("picy1.png").convert_alpha()
title = pygame.image.load("aba2 title.png")
image1_rect = image1.image.get_rect(topleft=(x,y))
image2_rect = image2.image.get_rect(topleft=(x1,y1))
image1.mask = pygame.mask.from_surface(image1.image)
image2.mask = pygame.mask.from_surface(image2.image)
screen.blit(title,(0,0))
screen.blit(image2.image,(x1,y1))
screen.blit(image1.image,(x,y))
pygame.display.update()



what I'm trying to do is create a sprite with the rect attribute attached to it .just looking at the image1 code have I done this correctly . to detect a collision I've used this but so far although the code runs it does not detect a collision. Decided to put the mask code back in but the image1.mask and image1_rect stuff isn't working .

Code: [Select]
def collisioncheck():
 #   if pygame.sprite.collide_rect(image1.image,image2.image):
 #       exit()
    if image1.rect.colliderect(image2):
        exit()

what do you think I'm doing wrong . Any advice would be appreciated.
Title: Re: Learning Python
Post by: Derron on May 17, 2019, 06:41:34 PM
Code: [Select]
image1_rect = image1.image.get_rect(topleft=(x,y))
image2_rect = image2.image.get_rect(topleft=(x1,y1))

image1_rect is not the same as
image1.rect


Bye
Ron
Title: Re: Learning Python
Post by: Pfaber11 on May 17, 2019, 07:42:40 PM
Thanks for pointing that out. Still doesn't work unfortunately . Probably be one of those things it's gonna take a while to figure out . Had a look at a panda3D demo and it was really very good . I think It'll give AGK2 a run for it's money . I do think AGK is an excellent package though . I'm just trying to learn a professional language.
Title: Re: Learning Python
Post by: Derron on May 17, 2019, 08:02:38 PM
Quote
Code: [Select]
def collisioncheck():
 #   if pygame.sprite.collide_rect(image1.image,image2.image):
 #       exit()

I will repeat myself: did you read the documentation?
Quote
Collision detection between two sprites, using rects.
collide_rect(left, right) -> bool
Tests for collision between two sprites. Uses the pygame rect colliderect function to calculate the collision. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" attributes.
https://www.pygame.org/docs/ref/sprite.html#pygame.sprite.collide_rect

NOWHERE do they say: please use IMAGES as param.

(untested):
Code: [Select]
def collisioncheck():
   if pygame.sprite.collide_rect(b1, b2):
       exit()
b1 and b2 are your SPRITES not your image.
Just think about it: you define a mask for the sprite by the image assigned to the sprite. You define a rectangle to the sprite.
So the image does know what about the sprite? NOTHING

So why do you pass an image to a SPRITE(!) collide_rect() function?


Think it is better to use a language for now which is a bit more strict concerning types.
Java and libGDX is mighty.
C# and Godot or Unity
...


bye
Ron
Title: Re: Learning Python
Post by: Pfaber11 on May 18, 2019, 01:25:16 PM
Good afternoon . My problem is not detecting a hit or collision its assigning the rect attribute to a sprite . It just won't have it .
 
Code: [Select]
image1_rect = image1.image.get_rect(topleft(x,y))It's this piece of code that will not work . I guess you've had enough by now Ron
basically it will not work. What I want to know is how you do it .
A few lines of code would be good .
Code: [Select]
screen.blit(image1_rect,(x,y))
This is the code I use to draw it onto the screen . nothing wrong there I think .
Code: [Select]
pygame.display.update()
Anyway could somebody please show me how it's done . I have done a lot of reading and none of it is getting through .
Title: Re: Learning Python
Post by: Pfaber11 on May 18, 2019, 01:37:30 PM
If I just use
Code: [Select]
screen.blit(image1.image(x,y))It puts it on the screen no problem its when I use
Code: [Select]
/screen.blit(image1_rect,(x,y))[code]
A few lines of code please . come on it can't be that hard.
Thanks
Title: Re: Learning Python
Post by: Derron on May 18, 2019, 01:47:39 PM
LEARN TO READ

I already answered your question regarding the rect_collide.

(http://i.imgur.com/SlCFJ6u.png)



Code: [Select]
screen.blit(image1_rect,(x,y))

I do no longer know what to say. Move on to AGK and start posting your questions to the AGK users here, they might enjoy it.

According to your capability to read, understand and learn I assume you are in elementary school or maybe 1-2 classes higher (if this offends you, read it as "very young"), so I understand that this stuff here is a above what you are used to. Maybe begin with something which helps you to not mix up underscores, points, commands ... something which only accepts the right params and is strict on types.
Use Java, AGK, ... or whatever you like, but Python, JS, GDScript, ... they are all nothing for you until you grasped some more bits of programming.


You now edited your post, so the quoted code seems to be "corrected". Still you have a LOT to learn regarding READING and checking what you then WRITE. I mean ... just think about the command:

screen.blit(someRectVariable, (x,y))
screen: the object to blit something to
blit: the command to do so
someRectVariable: a rectangle object consisting of x, y, width and height
(x,y): a somehow grouped element consiting of coordinates x and y

... now think about this.
... think again!
... ask yourself: WHAT do I blit do the "screen"
... think again!

Isn't there the object missing which I want to see blit on the "screen" object?
Yes it is - and this is where the "docs" come reaching you a helping hand. LEARN TO READ.
I assume some IDEs for Python would even allow to integrate documentation into their workflow (F1 when cursor is over a command - or rightclick and context menu or so).


Again, I understand that this might be over your head - so maybe choose another language to start learning programming - BEFORE you even think of moving on to 3D.


And no - this time no excuse for using so harsh words and sounding arrogant.


bye
Ron
Title: Re: Learning Python
Post by: Pfaber11 on May 18, 2019, 02:01:05 PM
That's ok Ron sorry I've annoyed you yet again . The reason my code is in such a mess is I've been trying out everything I can think of and yes I do read . And no I'm not in school . I am not ready to throw in the towel just yet and so far I think I've done ok only started my journey 12 days ago with python . Just ground to a halt on this bit . Anyway Ron Have a nice day.
Title: Re: Learning Python
Post by: Derron on May 18, 2019, 02:34:42 PM
Thanks.

If something does not work:
- check if the thing you pass as param is of the right type (rect <> image <> sprite <> string ...)
- check if what you pass exists (b1_image does not exist - b1.image might exist)
- if you do not know how to reach a functionality of your library: use their documentation
- if you do not know how to tackle a certain problem logic wise: ask in forums (like here)


bye
Ron
Title: Re: Learning Python
Post by: Pfaber11 on May 20, 2019, 11:40:48 AM
Well Ron I did it in the end and it was real simple . All my fault . Anyway I now have collision detection working fine . This has taken me 4 days . Don't suppose I'll forget it in a hurry. Thanks for all your help. In the end I was just putting the code in the wrong place. Thanks again.
Code: [Select]
def collisioncheck():
    image1_rect = image1.image.get_rect(topleft=(x,y))   
   
    if image1_rect.colliderect(image2_rect):
        pygame.mixer.Sound.play(bells)
 
        image1_rect = image1.image.get_rect(topright=(x,y))   
       
        if image1_rect.colliderect(image2_rect):
            pygame.mixer.Sound.play(bells)
           
            image1_rect = image1.image.get_rect(bottomleft=(x,y))   
           
            if image1_rect.colliderect(image2_rect):
                pygame.mixer.Sound.play(bells)
               
                image1_rect = image1.image.get_rect(bottomright=(x,y))   
               
                if image1_rect.colliderect(image2_rect):
                    pygame.mixer.Sound.play(bells)       

Thought after all that I would show you what I did . Basically I put the image_rect part of code where I put all my variables at the start and not next to the image1_rect.colliderect code . Glad I stuck with it after 4 days and loads of attempts to get this working . Anyway thanks for all your efforts . wish I had of posted all the code now as you would of spotted more or less straight away where I had gone wrong . Have a nice day .
 I'm 14 days into the python now and after that major pain I am finally getting somewhere . When I was learning AGK I was getting stuck on things for upto a week in the first couple of months so nothing new . Just glad I didn't give up. I still think this is no harder to learn than AGK . But it did take me a year before I made a 3d game in AGK2 . Hoping it won't take this long this time as I know the process already albeit in a different language.  Took me 2 weeks to get a height map up and running in AGK2 but now I've done it a few times I'm looking at about half an hour . Made loads for my maze game . So at least I'm getting python drilled into me now . I downloaded a free book called games with python and  pygame . About 300 pages of useful information.
Title: Re: Learning Python
Post by: Pfaber11 on May 25, 2019, 09:18:23 AM
Well I've been at this 3 weeks or so now and am going to try a simple game . Hopefully when complete it'll be good enough to put on my website . We'll see I suppose . Just gotta come up with the right idea I suppose .  Was on my phone last night and typed  python into the play store . It came up with loads of stuff books and all sorts . Phone IDE s too . Downloaded about ten books so far and I feel I should take the time to read then . There's also a ton of stuff on you tube and I've watched a few videos on there . Also enrolled in a udemy coarse for free . Hopefully in twelve months I'll be answering questions on here instead of asking them . Have a nice day.
Title: Re: Learning Python
Post by: Pfaber11 on May 26, 2019, 03:11:09 PM
Picked up another free pdf book today called Python Pocket Reference 5th Edition. Definitely worth having . I've just discovered that windows ten will read your pdf files to you . It's not perfect but is pretty good and I read along with it . Watched a few videos on you tube for beginners and now going to move onto the intermediate  ones . I had a go at Java last year for a couple of weeks and got nowhere with it Python is a lot easier than that in my opinion. According to what I have read Python is a procedural language as well as an oop  language  so I guess it can be used either way . Bonjour
Title: Re: Learning Python
Post by: Pfaber11 on May 28, 2019, 11:20:01 AM
I was reading somewhere that C++ is around 400 times faster than Python and have also read that Panda3d is nearly as fast as C++ . I've  done an example program of panda3d and it does look pretty impressive . Was a bit put off by all this talk of nodes but have found out it's just another name for objects . Still practising with pygame and to be honest it is a bit slow for my liking . Tried all the ways I can think of to smooth out the graphics and speed things up but I now Know panda3d does 2d stuff as well as 3d so I might just head off in that direction .   
Title: Re: Learning Python
Post by: Pfaber11 on May 30, 2019, 12:25:01 PM
Just completed a very small coarse on Udemy for free . Learnt a couple of things with it  Got the certificate . Although I watched all of it and paid attention I could of slept through it and still got the certificate . But what would of been the point of that. Thinking of doing another one this afternoon. I think using video tutorials seems to be a good way to learn . Have a nice day.
Title: Re: Learning Python
Post by: Pfaber11 on June 01, 2019, 01:57:43 PM
Decided to try pypy3.6 again . I've got it installed ok as when  I click on pypy3.exe it takes me into the shell . However when I try to use it with wing personal7 which is the python IDE I use it just doesn't seem to work . I've taken a screen shot which I'll place here and maybe somebody can tell me where I'm going wrong . If not I'll try another IDE and see if that helps . Here's the screen shot.
(http://)
Title: Re: Learning Python
Post by: Pfaber11 on June 01, 2019, 08:50:00 PM
Well I got pypy3.6 v.7.1.1 up and running on pycharm community addition along with pyglet . Can't get pygame running as of yet but hoping pyglet will be ok for now. Still got python 3.7.3 installed and running in the wing personal 7 IDE. Anyway if anybody wants to try this pypy out and want's any tips just ask away.   It's still python but on steroids running at 5 or 7 times as fast. Can't wait to get into both of these and do some comparisons. Good evening.
Title: Re: Learning Python
Post by: Pfaber11 on June 11, 2019, 09:50:04 PM
Had some problems using pyglet  in that the program kept getting stuck anyway decided for now just to use standard python with pygame and ratcave . Apparently ratcave can expand pygame for 3d graphics . Found some documentation on it and will try it out shortly . All going well with python although I should imagine I'm  just scratching the surface . Now I'm getting used to the syntax and the style of it I'm finding it ok . At first I couldn't get ratcave to install and what cured it was installing ms c++ build tools . Works fine now . It's just over a gig to download but did the trick. Feels good to be using pygame again after trying out pyglet and really not liking it . Anyway that's it from me . Happy coding .
Title: Re: Learning Python
Post by: Pfaber11 on August 13, 2019, 05:57:02 PM
Well guys after learning python for a couple of months I have decided it's not the language for me . Much prefer AGK classic for a few reasons . If I would of wanted to do the same stuff as I'm used to doing I would of had to learn Panda 3d  as well as python and I don't think I want to spend the next year learning it especially when I can do some cool stuff in AGK classic. So that's it I'm back to AGK classic which I know and love .  By the way was on steam earlier and for the next couple of days you can pick up AGK classic for £16.50 on steam. It's a bargain in my opinion. Bonjour.
Just thought I would add to this and that is Python and pygame are not a patch on AGK . Just my opinion. AGK is a lot smoother too.  8) 8)
Just to add I did enjoy python and it is very flexible with all the modules  just not my cup of tea.