Squash (pong mod)

This is sort of a late blog post due to a busy weekend, so I’m posting now.

(Sorry if the language is confusing somewhere)

Last week we learned some fundamentals of programming by creating the simple game Pong. Allthough the simplicity I think I’ve learned alot from that!

I’ve been tweeking around on the Pong-code we did and made my own little game: Squash (it’s not complete though)

SquashSo basically, the mechanics are kind of the same as Pong, but instead of having the ball moving from right and left between each player the ball instead bounces on the roof while both player has their ”paddles” on the bottom of the window trying to prevent the ball from reaching the bottom edge. After the red player has stroken the ball it’s the blue players turn to stop the ball and vice versa. The ball will go right through the player who is not supposed to strike the ball.

Every time a player strikes the ball the paddle of the opposite player moves up a step indicating it’s their turn, plus that the color of their paddle is enhanced. Here’s the thing.. Each time a paddle moves up the game windows height is decreased. The longer the game is going the more difficult it is to save the ball from going out of bounds. Here’s an example to show what I mean:

1.

Squash2

2.

Squash3

3.

Squash4

I’ts pretty late right now when I’m writing this so I’m not going into the details too much on the code, but for resizing the window I used the method SDL_SetWindowSize(SDL_Window * window, int w, int h) which is called when the collision between the ball and the player is true. I also used an enum to tell which players turn it is. There’s of course alot more but I’ll probably going into more technical stuff on other post.

I hope this was somewhat interesting to read!

About Johannes Westberg

2014  Programming