Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. Just before Christmas, the school of computing at my university ran a small game programming competition, and I decided I
  2. would enter it.
  3.  
  4. Like all competitions, there were rules and limitation in place, so lets quickly go through these now.
  5.  
  6. Rule one, we had to use python using a library called graphics.py, which isn't exactly a good library for making games at all,
  7. as it was specifically created for education and so is very basic, and you are limited in what can be done.
  8.  
  9. Rule two, we were not allowed to use other libraries such as pygame
  10.  
  11. Rules three, we were not allowed to create our own classes or types, which while annoying, it was likely in place to keep
  12. the contest fair for everyone as we hasn't covered classes yet at university at the time of the competition
  13.  
  14. And lastly, for some reason it had to be a game about an Android eating apples or a squahs ball game.
  15.  
  16. and as you have already seen in my last video, I decided to go with the former option
  17.  
  18. So without any further ado, lets get into this
  19.  
  20.  
  21.  
  22.  
  23. To start off, I wanted to create a game state system to make easier to organise different stages of the game ,
  24. such as the main menu and the game itself
  25.  
  26. Now, as mentioned in a previous video, I always implement this kind of system using polymorphic classes, but of course
  27. the rules of competition would not allow this, so I had to find another way.
  28.  
  29. What I did instead was created some constants to represent an "ID" of a game state, as seen here. I could then set a variable to
  30. one of those values, and jump to the different functions for those states using some if statements
  31.  
  32. After this, the next thing I wanted to do was create some code for the player and drawing the Android character.
  33.  
  34. I don't know why I did what I did, but I probably really overcomplicated this. Rather than just loading up a image, for
  35. some reason I decided to load up vertex positions of the Android from a text file and put them in to a polygon object.
  36.  
  37. While completely unnecessary, it was quite fun to implement anyway, and it ended up working just fine,
  38.  
  39. Now I had the player drawing, it was time to actually get it to move around using keyboard input. Usually this
  40. is really simple to do, but I had to graphics.py, which doesn't have very good keyboard support.
  41.  
  42. This means that I would hit a key to move the player and it would move a it, stop for a second, before starting to move again.
  43. This kind of thing feels awful for responsiveness, so I tried the best I could to fix this using some tricks with
  44. velocity values.
  45.  
  46.  
  47.  
  48.  
  49. Now that I had the basics, it was time to actually think about what I wanted the game to be.
  50.  
  51. This was quite hard to do, as it had to be a game about an Android eating apples, but I wanted to be a bit more
  52. exciting than that.
  53.  
  54. And so, I decided to make the game similar to something I made a very long time ago, in fact one of my first videos on this channel
  55.  
  56.  
  57. This was a simple game called Pyoro, and I thought I would simply put my own twist on this for the competiation game
  58.  
  59. My take on the concept was fairly simple. Apples would fall from the sky, and you would catch them. For each apple
  60. you catch, you get a point. However, if you missed an apple, then it would destroy the tiles the player walks on.
  61.  
  62. When tiles are destroyed, it limits the are the player can walk. If the apples get past the tiles, you lose a life.
  63.  
  64. Run out of lifes and it is game over.
  65.  
  66. So, in the video right now I have been creating the code for apples falling from the sky, and then destroying tiles the
  67. player is walking on, as well as making it so the player cannot walk on destroyed tiles.
  68.  
  69. And this can be seen working here. The apples destroy tiles, and the player is then limited to where they can walk.
  70.  
  71. Another thing I wanted to add was the ability for the player to throw apples that they had caught at the apples falling,
  72. before they hit the tiles. However, the penalty for this is -1 point.
  73.  
  74. Players would be able to aim where the apple is thrown by using the mouse.
  75.  
  76. This was done using some simple vector maths. First
  77. I took the X and Y difference between the player and the mouse, and then I would normalise this vector to make its
  78. magnitude equal to one, and then multiply the vector by a scaler speed value which would result in the final velocity
  79. of the apple.
  80.  
  81. This would make the projectile apples always travel at the same speed, no mattter where thrown.
  82.  
  83.  
  84.  
  85.  
  86. The next feature I wanted to add were different apple types.
  87.  
  88. For now, the only apple game in game was the one that added one point, which was kind of boring, so I wanted to add some more.
  89.  
  90. Now, this sort of thing would be very easy with classes, but again, I was not allowed to use them. So I had to ask myself,
  91. how on earth am I going to differ between apple types in the code?
  92.  
  93. So, my solution was to have different apple types to have a slightly different radius. In the graphics.py module, the
  94. apples are
  95. drawn using a Circle class, which hasa function called "getRadius()", which allowed me to differ the types.
  96.  
  97. --
  98.  
  99. The apples are drawn using a class defined in the graphics.py module called "Circle", which has a function called
  100. getRadius(). So, after creating the different apple types using a different radius, I could then differ the types by getting
  101. the circle's radius when needed.
  102.  
  103. The new apple types added can be seen here.
  104.  
  105. When the player collects the red apple, it just adds score as usual, but
  106. collecting the green apple repairs all the broken tiles, and collecting the yellow apple adds some lives.
  107.  
  108. After this, I wanted to add some kind of game over screen and a main menu. The main menu would have different options such
  109. as play game and exit game, and the game over screen would show the player's score, and then give the option of playing again
  110. or returning to the main menu.
  111.  
  112. However, before I could actually implement these menus, I first had to actually implement the components a menu needs, such
  113. as buttons.
  114.  
  115. The first basic version of the main menu and the game over screen can be working here, using buttons
  116.  
  117. However, it was looking very bland, and so I decided I would make it look more exciting by making apples
  118. fall in the background of the menu.
  119.  
  120. After this, i decided I would try add some kind of highscscore system to the game. This would allow players to
  121. submit their score after they get a game over, and see how good or bad they are compared to others.
  122.  
  123. To do this, I present a text box for a player to enter their name if they want to add themselves to the highscore. It will
  124. then load up the highscores from a file into a dictionary, and then add the player's score to it. Finally, I sort
  125. the scores into decsending order before rewriting the scroes to the file.
  126.  
  127. The submission screen for the highscores can be seen here.
  128.  
  129.  
  130. The final thing I wanted to do was actually make the game look good, rather than how bland it is currently looking now, and so
  131. I opened up good old paint dot net and started making some images for use of the background of the game, of which the ones
  132. being shown created here didn't actually end up being used.
  133.  
  134. And well, the finished game can be seen being played now.
  135.  
  136. As you can see, all of the menus are fully implemented, such as the how to play menu, and the highscores, and it is
  137. looking a lot better now that I have added a background.
  138.  
  139. So anyways, I hoped you enjoyed the video. Also, I am sorry I have not uploaded a video in a while, but university has kept me
  140. very busy, with all the coursework and social side of things.
  141.  
  142. And lastly, I just want to espically thank all my Patrons, who have continued to support me dispite my lack of
  143. uploads in last few months, so thank you have everyone listed here.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement