• Home
  • Blog
  • C# / Unity
  • C++ / Unreal Engine
  • Python strategy games
  • Python arcade games
  • Python other
  • Machine Learning
  • C
  • Scratch
  • Coding and electronics
  • How I learnt to code
  • Project Euler
  • Feedback
  James L.'s coding

James's blog

what I've been doing.

Table football scoreboard

23/10/2017

0 Comments

 
I have now tested my table football so it can sense a goal for both teams and have done the display in Pygame.  The next step is to install it on the table.
I found it hard to run it using .bashrc (allows you to run a program when you boot up) because you need to make a way of exiting other than the usual quit button.  I rescued it using remote access through puTTY on a PC.  In the code on the Electronics page, you can see I added buttons into the Pygame window to exit and reset.
0 Comments

Space Invaders done!

22/10/2017

0 Comments

 
I have finished Space Invaders, which uses lots of classes and is my first Pygame program using sound.  The code is on the Arcade Games page.
0 Comments

pygame.sprite.spritecollideany

13/10/2017

0 Comments

 
I've finally found out how to do collision detection for my new game Flappy Bird. 

How to do it (the full code is on the arcade games page)

​CODE FOR MAKING A GROUP OF CLASS  MEMBERS AND UPDATING THE GROUP
  1. class Pipe (pygame.sprite.Sprite):
  2.   def __init__(self, image,[...]):
  3.     pygame.sprite.Sprite.__init__(self)
  4.     self.image = image
  5.     self.rect = self.image.get_rect()​
  6.    self.x = 5
  7.   self.y = 5
  8.    [...]
  9.  
  10.  def update(self):
  11.   screen.blit(self.image, (self.x,self.y)
  12.  self.rect = Rect(self.x, self.y, 50,50)
  13. ​
  14. def main():
  15.    pipe_image = image.load('pipe.png')
  16.   pipeGroup = pygame.sprite.group()
  17.   for x in range(3):
  18.   pipeGroup.add(Flappy_class(flappy_image, [...]))
  19. while True:
  20.   pipeGroup.update()
  21. ​  pygame.display.update()
Picture
KEY
line 1. we create the class, inheriting from pygame.
line 2. we "__init__" like usual.  
 Note: "__init__" has 2 underscores
line 3. we call the pygame "__init__"
​line 4. we load the image
  Note: I don't load it in the class because if we had 40 pipes it would be too slow
line 5. we make a rect according to the image
lines 6&7. we create the x and y
​line 10. I make a method called update
  Note: its name is important because it it one of the only methods that you can call for all the sprites in a group.
line 11. we display the image
line 12. we create the rect(x pos, y pos, width, height)
   Note: using self.rect = Rect (...) for the updated image is important for collision detection 
line 15. we load the pipe image.
line 16: we create a sprite group
line 18. we add members to the sprite group
line 20. we call the update method for all the sprites in the group
We would do a similar thing for flappy bird (including updating using self.rect = Rect (...) and store it in the bird object and then call these lines
  1. if pygame.sprite.spritecollideany(bird, pipeGroup):
  2.   print ('collision')
0 Comments

Fifty Eulers done!

11/10/2017

0 Comments

 
I've finally done 50 Project Euler questions.
0 Comments

Flappy Bird

9/10/2017

0 Comments

 
My new pygame program is flappy bird. At first I zipped along until I had done the moving of flappy and the pipes. My first problem was that I couldn't get the collision detection to work. It was easy in scratch, if touching flappybird, but in pygame it looked like I had to try again but then I looked up how to do it and found some promising  results.
0 Comments

AIY Projects

1/10/2017

0 Comments

 
AIY Projects is a voice projects powered by google(at aiyprojects.withgoogle.com/voice#project-overview). I got the kit free with the MagPi magazine. I've got it to detect words and say something in response (I say"My name is James" and it says"Hello, I hear you have a blog").
I have considered a few projects e.g. a program were the computer sings (la, laaaa) and you have to sing the right pitch back (it is very hard to detect the pitch though).
0 Comments
    Advert:

    Author

    I am doing lots of projects every projects all the time and I can't put them all on the website so I've made a blog.

    Archives

    August 2022
    April 2022
    March 2022
    February 2022
    January 2022
    November 2021
    October 2021
    August 2021
    July 2021
    June 2021
    April 2021
    March 2021
    June 2020
    May 2020
    April 2020
    March 2020
    September 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    November 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017

    Categories

    All

Proudly powered by Weebly
  • Home
  • Blog
  • C# / Unity
  • C++ / Unreal Engine
  • Python strategy games
  • Python arcade games
  • Python other
  • Machine Learning
  • C
  • Scratch
  • Coding and electronics
  • How I learnt to code
  • Project Euler
  • Feedback