Well, I’m doing a course on edx.org to do with learning Python (MITx: 6.00x Introduction to Computer Science and Programming) and over the weekend was the midterm exam. I managed to get a 78% which isn’t that bad considering I had to squeeze it in between family life and work. There are a few concepts that I’m still getting my head around such as the efficiency of code/searching (linear searching, binary searching). I tended to do better on the text manipulation problems than I did with the maths problems. I guess that’s how my brain is wired, but I’m trying.
The good thing about the course is that they really put a point on testing before you submit your code. They had a series of lectures regarding glass,white box testing and ensuring that you have a suite of test cases to ensure that the code that you have written covers a wide range of permutations. In this case, it really brings home the idea of only coding as much as you need to in order to get the code working. Like I said, it is hard but I’m enjoying it in my own way.
I’m glad that the next couple of weeks is to do with classes and objects as that’s where I’m going with my game. I’ve got the ship moving and the sprite to show up. What I’m having a little bit of problem with is the addition of the bullets. Although I know that I have to initialise it, give it co-ords, and then tell it the speed and tell it what to do.
#!user/bin/env python import pygame, os from pygame.locals import * from random import randrange # This class represents the bar at the bottom that the player controls class Player(pygame.sprite.Sprite): # -- Attributes # Set speed vector change_x=0 change_y=0 # -- Methods # Constructor function def __init__(self,x,y): # Call the parent's constructor pygame.sprite.Sprite.__init__(self) # Set height, width self.image = pygame.image.load(os.path.join("images","starship.png")).convert() self.image.set_colorkey((255,255,255)) # Make our top-left corner the passed-in location. self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y # Change the speed of the player def changespeed(self,x,y): self.change_x+=x self.change_y+=y # Find a new position for the player def update(self): self.rect.x += self.change_x self.rect.y += self.change_y # Call this function so the Pygame library can initialize itself pygame.init() MAX_STARS = 100 height,width = 640, 480 screen = pygame.display.set_mode((height, width)) clock = pygame.time.Clock() # Set the title of the window pygame.display.set_caption('Test') # Create the player object player = Player(50,50 ) movingsprites = pygame.sprite.Group((player)) clock = pygame.time.Clock() done = False stars =  for i in range(MAX_STARS): star = [randrange(0,height-1), randrange(0,width-1), randrange(1,16)] stars.append(star) score = 0 while done == False: for event in pygame.event.get(): if event.type == pygame.QUIT: done=True # Set the speed based on the key pressed if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: player.changespeed(-4,0) if event.key == pygame.K_RIGHT: player.changespeed(4,0) if event.key == pygame.K_UP: player.changespeed(0,-4) if event.key == pygame.K_DOWN: player.changespeed(0,4) # Reset speed when key goes up if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: player.changespeed(4,0) if event.key == pygame.K_RIGHT: player.changespeed(-4,0) if event.key == pygame.K_UP: player.changespeed(0,4) if event.key == pygame.K_DOWN: player.changespeed(0,-4) # This actually moves the player block based on the current speed player.update() # -- Draw everything # Clear screen screen.fill((0,0,0)) # Draw sprites movingsprites.draw(screen) for star in stars: star -= star if star < 0: star = height screen.set_at((star, star), (255,255,255)) # Flip screen pygame.display.flip() # Pause clock.tick(40) pygame.quit()
All that does is implement a scrolling star field and a moveable sprite (provided that you have a suitable sized sprite).
It is hard to implement what I want to do, but that’s the challenge I’m having. Learning about the progress along the way. So as mentioned before, the next steps are:
- Implement a level. I did scale an image of a nice star-field to be 2636×480 and put it in the background (so it would blit the background, then the scrolling stars, then the ship). It didn’t look to good to be honest.
- When the level is done, find and design some aliens/bosses and tell the program where there are going to live and their actions(Finite State Machine).
- Set up the guns, missiles and power-up classes so that the player can access it
- Ensure that the ship does not go out of bounds
- Design more levels once I have the above done.
As before, every time I make good progress, I shall upload to github where you will be able to have a look if you so wish. Any tips or tricks will be welcome. Of course, as time goes on, you will be able to test it if you wish and provide feedback. In a couple of weeks, a new course will be starting that should be helpful in my quest (https://www.coursera.org/course/interactivepython).
I have grand ideas, and as soon as I get to grips with the concepts, then I shall be doing small games to add to my ‘portfolio’. I want to do a platformer (I think my boy would like a game like that), an RPG and a text game. It shall be fun. One day, I’ll get to the level where I can use game engine frame works such as Panda36, UDK or Unity and develop my freelancer/x-wing clone.
Don’t worry, I’m not abandoning the QA world. I find it’ll all help me understand the software cycle of concept -> coding -> testing -> release -> riches 🙂
You never know, maybe the games could be used for Weekend testing purposes. Hey, if I get my head around it, maybe it could be a series of articles in the Testing Planet. I would just have to spin it to be more testing oriented.
In QA land, I’m still getting to grips with Data Driven Testing in order to navigate my work’s site. Any good books out there to read? I haven’t read a QA related book for a while. I think the last one was Agile Testing by Lisa Crispin and a few security related books.
Looks like the TestBash by the Software Testing Club was a success. One of these days, I will be going.