Sunday, December 13, 2009

Breakout in python for $100

After I posted myself to craigslist, someone emailed me offering to pay me $100 bucks to do their computer assignment. Needless to say, I accepted. The assignment was to create a breakout clone using pygame – the code and thoughts on it are below.

import math import random from pygame import * #graphics, position and size constants BACKGROUND_COLOR = Color("#99B3FF") PADDLE_COLOR = Color("#525252") BALL_COLOR = Color("black") WINDOW_X = 800 #size of the window WINDOW_Y = 600 GRID_X = 20 #size of the grid of bricks GRID_Y = 20 BRICK_SPACE = 5 #space around each brick BRICK_X = (WINDOW_X / GRID_X) - BRICK_SPACE #size of each brick BRICK_Y = (WINDOW_Y / GRID_Y) - BRICK_SPACE BRICK_ANGLE = math.degrees(math.atan(float(BRICK_X)/float(BRICK_Y))) #for collision BRICK_ANGLE_TOPLEFT = -90 - BRICK_ANGLE #for collision BRICK_ANGLE_TOPRIGHT = -90 + BRICK_ANGLE #for collision BRICK_ANGLE_BOTTOMLEFT = 90 + BRICK_ANGLE #for collision BRICK_ANGLE_BOTTOMRIGHT = 90 - BRICK_ANGLE #for collision PADDLE_LENGTH = 100 #size of the paddle PADDLE_WIDTH = 5 PADDLE_AIM_LENGTH = 40 #size of line to help the player aim the ball BALL_R = 10 #size of the ball #control sensitivity constants FRAMERATE = 100 #number of times to run the loop each second PADDLE_MOVE = 10 #amount to move the paddle left or right each loop PADDLE_AIM_MOVE = 5 #amount to angle the pointer up or down each loop BALL_LAUNCH_VEL = 5 #velocity of the ball - should stay constant PADDLE_SKEW = .1 #the amount that the ball will skew to the side when it hits the edges of the paddle #position variables paddle_pos_x = 0 ball_pos_x = 0 ball_pos_y = 0 ball_dx = 0 ball_dy = 0 ball_rect = Rect(0, 0, 0, 0) colliding_with_paddle = False launch_angle = 0 bricks = [] class Brick: alive = True def __init__(self, color, rect): self.color = color self.rect = rect def update(self, surface): if self.alive: draw.rect(surface, self.color, self.rect) #build the brick from a mapfile def build_brick_map(mapfile): bricks = [] color_scheme = {} f_scheme = open(mapfile + '.scheme', 'r') for line in f_scheme: color_scheme[int(line[0])] = Color(line[2:-1]) f_scheme.close() f_map = open(mapfile, 'r').readlines() if len(f_map) > GRID_Y: #allows the map to be smaller than the grid size, making it empty on the bottom print "map file wrong y size" return 0 ypos = 0 for line in f_map: if (len(line) - 1) != GRID_X: print "map file wrong x size" return 0 xpos = 0 for b in line[:-1]: b = int(b) if b > 0: rect = Rect(xpos + BRICK_SPACE, ypos + BRICK_SPACE, BRICK_X, BRICK_Y) bricks.append(Brick(color_scheme[b], rect)) xpos += BRICK_X + BRICK_SPACE ypos += BRICK_Y + BRICK_SPACE return bricks #game constants LEVELS = ["level1", "level2", "level3"] DEFAULT_NUM_LIVES = 3 #number of lives the player starts with STARTING_LEVEL = 0 #game variables score = 0 current_level = 0 lives = 0 launch_mode = False new_game = True new_level = True init() screen = display.set_mode((WINDOW_X, WINDOW_Y)) drawing_surface = Surface(screen.get_size()).convert() overlay = Surface(screen.get_size(), SRCALPHA).convert_alpha() small_overlay_font = font.Font("V5PRC___.TTF", 36) big_overlay_font = font.Font("V5PRC___.TTF", 72) overlay_text = "" overlay_sub = "" clock = time.Clock() quit = False paused = False while not quit: clock.tick(FRAMERATE) #reset objects if restarting or a new level if new_game: score = 0 lives = DEFAULT_NUM_LIVES current_level = STARTING_LEVEL new_level = True new_game = False if new_level: bricks = build_brick_map(LEVELS[current_level]) if bricks == 0 or len(bricks) == 0: print "couldn't build the brick map!" quit = True break paddle_pos_x = (WINDOW_X/2) launch_mode = True launch_angle = random.randint(15, 165) #discourage players shooting straight up new_level = False #manage input space_pressed = False left_pressed = False right_pressed = False up_pressed = False down_pressed = False for e in event.get(): if e.type == QUIT: quit = True break if e.type == KEYDOWN and e.key == K_SPACE: #space as an event so that it is only registered once per keypress space_pressed = True key_input = key.get_pressed() if key_input[K_LEFT]: #this, on the other hand, registers if the key is down every loop left_pressed = True if key_input[K_RIGHT]: right_pressed = True if key_input[K_UP]: up_pressed = True if key_input[K_DOWN]: down_pressed = True overlay_text = "" overlay_sub = "" if paused: overlay_text = "paused" overlay_sub = "press space to continue" #check if game or level is over if lives == 0: #game over paused = True overlay_text = "game over" if space_pressed: paused = False new_game = True elif len(bricks) == 0: paused = True if current_level + 1 == len(LEVELS): #game over overlay_text = "you win!" overlay_sub = "press space to quit" if space_pressed: quit= True break else: #next level overlay_text = "level " + str(current_level + 2) overlay_sub = "press space to continue" if space_pressed: paused = False current_level += 1 new_level = True elif space_pressed: if launch_mode: ball_dx = -math.cos(math.radians(launch_angle)) * BALL_LAUNCH_VEL ball_dy = -math.sin(math.radians(launch_angle)) * BALL_LAUNCH_VEL launch_mode = False else: paused = not paused #main loop if not paused: #move everything if left_pressed and paddle_pos_x > PADDLE_LENGTH/2: paddle_pos_x -= PADDLE_MOVE if right_pressed and paddle_pos_x < WINDOW_X - PADDLE_LENGTH/2: paddle_pos_x += PADDLE_MOVE if launch_mode: ball_pos_x = paddle_pos_x ball_pos_y = WINDOW_Y - PADDLE_WIDTH - BALL_R if up_pressed and launch_angle <= 165: launch_angle += PADDLE_AIM_MOVE if down_pressed and launch_angle >= 15: launch_angle -= PADDLE_AIM_MOVE else: ball_pos_x += ball_dx ball_pos_y += ball_dy ball_rect = Rect(ball_pos_x - BALL_R, ball_pos_y - BALL_R, 2*BALL_R, 2*BALL_R) #check for collisions if ball_dx != 0 or ball_dy != 0: if ball_pos_y > (WINDOW_Y - BALL_R - PADDLE_WIDTH) and \ math.fabs(ball_pos_x - paddle_pos_x) < (PADDLE_LENGTH/2): if not colliding_with_paddle: ball_dy = -ball_dy ball_dx += (ball_pos_x - paddle_pos_x) * PADDLE_SKEW colliding_with_paddle = True elif ball_pos_y > (WINDOW_Y - PADDLE_WIDTH) and \ math.fabs(ball_pos_x - paddle_pos_x) < ((PADDLE_LENGTH/2) + BALL_R): #bounce off the side of the paddle if not colliding_with_paddle: ball_dx = -ball_dx colliding_with_paddle = True else: colliding_with_paddle = False if ball_pos_y < BALL_R: ball_dy = -ball_dy elif ball_pos_y > (WINDOW_Y + BALL_R): lives -= 1 launch_mode = True if ball_pos_x < BALL_R or ball_pos_x > (WINDOW_X - BALL_R): ball_dx = -ball_dx for b in bricks: if ball_rect.colliderect(b.rect): b.alive = False #check which side it collided with theta = math.degrees(math.atan2(ball_pos_y - b.rect.center[1], ball_pos_x - b.rect.center[0])) if (theta > BRICK_ANGLE_TOPLEFT and theta < BRICK_ANGLE_TOPRIGHT) or (theta < BRICK_ANGLE_BOTTOMLEFT and theta > BRICK_ANGLE_BOTTOMRIGHT): #top or bottom ball_dy = -ball_dy else: ball_dx = -ball_dx bricks.remove(b) score += 1 break #draw ball, bricks, paddle drawing_surface.fill(BACKGROUND_COLOR) draw.rect(drawing_surface, PADDLE_COLOR, Rect((paddle_pos_x - PADDLE_LENGTH/2), (WINDOW_Y - PADDLE_WIDTH), PADDLE_LENGTH, PADDLE_WIDTH)) if launch_mode: x = ball_pos_x - math.cos(math.radians(launch_angle)) * PADDLE_AIM_LENGTH y = ball_pos_y - math.sin(math.radians(launch_angle)) * PADDLE_AIM_LENGTH draw.line(drawing_surface, Color("black"), (ball_pos_x, ball_pos_y), (x, y)) draw.circle(drawing_surface, BALL_COLOR, (ball_pos_x, ball_pos_y), BALL_R) for b in bricks: b.update(drawing_surface) #draw overlay if paused: overlay.fill(Color(0, 0, 0, 200)) text_color = Color("white") else: overlay.fill(Color(0, 0, 0, 0)) text_color = Color("black") o1 = big_overlay_font.render(overlay_text, True, text_color) o2 = small_overlay_font.render(overlay_sub, True, text_color) if lives != 1: lives_text = str(lives) + " lives" else: lives_text = "1 life" o3 = small_overlay_font.render(lives_text, True, text_color) o4 = small_overlay_font.render("score " + str(score), True, text_color) overlay.blit(o1, ((WINDOW_X - o1.get_size()[0])/2, WINDOW_Y/3)) overlay.blit(o2, ((WINDOW_X - o2.get_size()[0])/2, WINDOW_Y/3 + o1.get_size()[1] + 10)) overlay.blit(o3, (20, WINDOW_Y - o3.get_size()[1] - 10)) overlay.blit(o4, (WINDOW_X - o4.get_size()[0] - 20, WINDOW_Y - o4.get_size()[1] - 10)) screen.blit(drawing_surface, (0, 0)) screen.blit(overlay, (0, 0)) display.flip()

[Via http://structwhogrewup.wordpress.com]

Spike TV's Video Game Awards 2009 Results

The Video Game Awards just concluded on Spike TV, and I don’t think anyone (who paid attention to the ads aired) was surprised by the results. The only shocker for me personally was the game of the year, which was up in the air. Here are the winners for the 2009 Video Game Awards. Jack Black at Spike's VGA

Game of the Year:
Uncharted 2: Among Thieves

Best PS3 game:
Uncharted 2: Among Thieves

Best Graphics:
Uncharted 2: Among Thieves

Best Xbox 360 game:
Left 4 Dead 2

Best Wii game:
New Super Mario Bros. Wii

Best PC Game:
Dragon Age: Origins

Best Shooter:
Call of Duty: Modern Warfare 2

Best Multiplayer game:
Call of Duty: Modern Warfare 2

Best Action Adventure game:
Assassin’s Creed II

Best Role-Playing Game:
Dragon Age: Origins

Best Music game:
The Beatles: Rock Band

Best Driving game:
Forza 3

Best Team Sports game:
NHL 10

Best Fighting game:
Street Fighter IV

Best Independent Game Fueled By Dew:
Flower

Best Handheld game:
Grand Theft Auto: Chinatown Wars (DS)

Best Soundtrack:
DJ Hero

Best Original Score:
Halo 3 ODST

Most anticipated game:
God of War III

Best Downloadable Game:
Shadow Complex

Best game based on a movie/TV show:
South Park: Let’s Go Tower Defense Play!

Best Voice:
Jack Black as Eddie Riggs (Brutal Legend)

Studio of the Year:
Rocksteady Studios

Best Performance By a Human Male:
Hugh Jackman (X-men Origins: Wolverine Uncaged Edition)

Best Cast:
X-men Origins: Wolverine Uncaged Edition

Best Individual Sports game:
UFC 2009 Undisputed

Best Performance By a Human Female:
Megan Fox as Mikaela Banes (Transformers: Revenge of the Fallen)

Best DLC:
Grand Theft Auto IV: The Ballad of Gay Tony

[Via http://playerwon.wordpress.com]

Saturday, December 12, 2009

Money Management Game

Today I had a chance to learn a game which you could have some fun with a group of people, a pack of cards and something for keeping the score.

Here goes:
1) Write down each person’s name on the writing material with each person starting with a fictitious $10k for investment.

2) Everyone will trade for a total of 7 times (could be more,depending on the group size), by means of drawing cards from the pack, each taking turn to draw. And everyone has to decide what the value he would want to “invest” in before drawing. The result of drawng the cards would represent the results of “investment: for everyone.

3) Each black card drawn will means gain in “investment” and the gain would be multiplied by the value that had been “invested” by the amount shown on the card. For example, Charlie invested $200 dollars a 7 of spades had been drawn, he will get $1400 added to his “portfolio”. The 7 of spades will at the same time be multiplid to the vaue of the rest of the player. Red, on the other hand would be vice versa.

4) All picture cards hold a value of ten. An ace is one.

5) The drawn cards would be put back to the pack for re-shuffling before the next pick.

5) After the last investment result, whoever has the highest value in his/her portfolio would win the game..

This game is fun as a form of wager, be it money or as drinking game. It would test the money management skill of the player at the same time the soberness. Have fun!

[Via http://seejamesblogs.wordpress.com]

Thursday, December 10, 2009

Dice Wars

Dice Wars

Dice Wars is an interesting game of strategy and perseverance. It loads right on the website there is no downloading. You use your dice to defeat neighboring enemies. Your enemies are identified by different colors then your own. The more you conquer and use your dice the more dice you receive at the end of your turn. The graphics are basic and the design is simple.  Controls for Dice Wars are simple and can be played by anyone no matter their understanding of computers.

Playing this game was addicting to say the least. I enjoyed the ease of the controls and the excitement of conquering an opponent. Game play was fun and relaxing, no major pondering to conquer a few enemies. Loading time of the screens was fast and not what I expected. Dice Wars would be a good game to play on breaks at work or in your spare time out of the office. All in all I would recommend this game to anyone that likes simple strategy games.

Play Dice Wars

[Via http://casualgameplay.wordpress.com]

Strategic Primer: Players wanted for the current campaign

Strategic Primer is a game that I am designing. Each player takes the role of the commander-in-chief (and perhaps autocrat) of a small outpost in an imagined world, with the objective of conquering that world. This game first appeared as the testing apparatus in my eighth grade science fair project, but has undergone such extensive revision since that scarcely anything except the map remains recognizable. I am running a campaign now, which is in all-but-desperate need of players. I’ve posted about it extensively on my blog before, but in hopes of enticing some of you to join, will describe the game and what your participation would entail again.

The most concise and accurate one-sentence summary of the game that I can come up with is: “Strategic Primer is a turn-based strategy game of my own design.” Strategy, because the player normally has limited control over tactics. Turn-based, because each player submits a strategy for a period of time and receives results. While it was invented for my eighth grade science fair project, it has changed based on ideas I’ve borrowed from all sorts of games, my experiences running past campaigns, and players’ comments.

This campaign was intended to run quickly last January, at least one turn per day for the fifteen days of Calvin’s Interim term. That obviously didn’t happen, and the pace of the campaign has so far been quite slow. I have finally closed off the first turn for some of the players after many months, and am waiting on final data from one other, but because the various players’ starting positions are scattered randomly across the game-world I could introduce a new player even when the current players have progressed for several turns. The pace will depend on how much time the players can devote to the game, but probably will be no faster than one turn every week, and most likely much slower than that to begin with.

Each turn, each player submits (in this campaign, by email) a list of orders–a “strategy”–to the “Judge.” Until everyone gets up to speed, I (the Judge for this campaign) will help the players draft their strategies and revise them into acceptable form. After a final strategy is submitted, the Judge “runs” that strategy, determining based on the rules of the game, the nature of the world, and other players’ strategies what the results of the player’s orders were, and reports these results to the player as that player’s advisors, officers, and other subordinates in the game-world would have presented them.

At the beginning of the game, each player begins with a fortress (constructed according to a design he or she creates, with my help if desired), a certain amount of resources, knowledge of some scientific/technical advances (more on that later), and ten workers. Because the starting population is so small, each worker must be given individual orders, but once the settlement grows (nearly every player’s population is expected to grow exponentially for a few turns) a chain of command will form, allowing the player to give orders in more general terms.

One of the greatest “features” of the game, and one of the few surviving from the original design, is the method of scientific and technical advancement. Everyone in the game-world except for the players themselves (who, since they don’t consume food, hardly count) begins at a quasi-medieval level of technology and thought. If workers are assigned to scientific research, this level advances slowly, but the primary mechanism for advancement comes from the players. If a player can describe (or draw, or whatever) a technology, principle, or other idea well enough that I’m convinced that player understands it and that I can understand it, and if the player’s scientists or other workers have the mental capacity and mental machinery to understand it (and the tools necessary to build it if it’s a technology), that player’s scientists and mechanics gain the knowledge of that scientific or technical advance and can use it in the next turn. (There are a few more conditions related to whether a principle is true in the game-world or a technology could exist, but they’re actually looser than our world.)

I’m posting this now in hope that someone will decide to join the game as a new player. As it stands, there are not as many players as I would like, even counting the “players” that I’m controlling, which I call “AI” players. If this sounds interesting and you’d like more information or would like to join, please comment here or otherwise contact me. I, and the other players, will be grateful.

[Via http://shinecycle.wordpress.com]

Tuesday, December 8, 2009

'Shoot-'em-up' video game increases teenagers' science knowledge

Students navigate microscopic world of immune system proteins and cells to save patient with bacterial infection

While navigating the microscopic world of immune system proteins and cells to save a patient suffering from a raging bacterial infection, young teenage players of the “Immune Attack” video game measurably improved their understanding of cell biology and molecular science, according to a study that will be presented at the American Society for Cell Biology (ASCB) 49th Annual Meeting, Dec. 5-9, 2009 in San Diego.

Remotely controlling the Microbot Explorer,  named for its 25-micron diameter, the teenagers traveled through the bloodstream and connective tissue, interacting at the nanometer scale with receptors, hormones and lipids that have been drawn to appear like the schematics that scientists use in their own models.

Game actions, such as the capture of white blood cells by proteins on blood vessel walls, mimic activities that occur in nature.

“Immune Attack,” a “third person shooter,” three-dimensional video game, was devised by Melanie A. Stegman, Ph.D., and Michelle L. Fox of the Learning Technologies Program at the Federation of American Scientists in Washington, D.C.

Collaborating directly with teachers, Stegman and Fox evaluated “Immune Attack” with 180 seventh grade students.

The students’ knowledge, comprehension of game dynamics and confidence with the material were much higher than the 142 students who were tested after playing the Medical Mysteries Series video game, which covers non-molecular aspects of infectious disease.

“Additionally, we have used ‘Immune Attack’ to inspire high school computer programming classes to create their own new videos games based on ‘Immune Attack,’” Stegman added.

The first edition of “Immune Attack” is available for free download at www.ImmuneAttack.org. “Immune Attack 2.0″ should be released in early 2010.

Students navigate microscopic world of immune system proteins and cells to save patient with bacterial infection

[Via http://webdroidz.com]

blokus classics game

Buy Cheap Blokus Classics Game

Buy Low Price From Here Now
Blokus develops logic and spatial perception while kids learn to be tactical. Players take turns placing pieces on their board, each starting from their corner. Each new piece must touch at least one other piece of the same color, but only at the corners. The goal is to get rid of all your pieces. The game ends when all players are blocked from laying down any more of their pieces. Includes one game board with 400 squares, 84 game pieces in four bright translucent colors, and an instruction guide……..
Readmore

Technical Details

– Blokus great strategy game for the whole family!
– Promotes healthy brain activity
– Includes 400 – piece game board with raised edges
– Winner of over 20 prestigious awards
– The most awarded game of the 21st century
See more technical details
Customer Buzz

 “Easy to teach and quick to play!” 2009-12-06
By J. Green
You can teach this game to someone in five minutes and play a whole game in half an hour. It is a great party game and good for introducing people who aren’t really “into” more complicated board games to the genre of table game playing. I would recommend it as an addition for any board game collection, but it got only four stars from me because my husband (who loves the more complicated games) often tires of it and will not play. So be advised, most people will love it, some people will rapidly get bored when playing because of the simplicity.

Customer Buzz

 “Great family fun – just try to avoid being blocked” 2009-12-02
By Trent Howell
Watch Video Here: http://www.amazon.com/review/R2O2GM3G0CBB1Z We love playing board games as a family and Blokus has been a big hit.

The very simple game play mechanics make it easy for people of all ages to understand. And don’t think just because you’re older that you can beat younger players. We’ve all been trumped by our 6 year old. Playing with 3 players is possible, but it is funnest as a 2 or 4 player game.

The colorful pieces are also very durable – which is good, because we know we’ll be playing it for years to come.

See for yourself as our daughter explains why she likes to play Blokus.

Customer Buzz

 “Surprisingly addicting” 2009-12-02
By Gift Card Recipient (Minneapolis, MN)
This was recommended by a friend for my game crazy 5 year old. I was hesitant, but it turns out to have been a marvelous suggestion. The game is never the same twice and is quite a fun, yet fairly short, mental challenge. All family members enjoy this one!

Customer Buzz

 “Awesome for Family Game Night” 2009-12-02
By Christine W. (Vermilion, OH)
This game has simple rules so an average 5 year old could play, but is addicting to anyone who plays…when it comes out at holidays and get-togethers, we always have adults hovering around waiting for their turn to jump in on the next round. There aren’t too many games in which children and adults can truly enjoy together, and this one definitely fits the bill!

Customer Buzz

 “Like competitive Tetris, only better!” 2009-11-28
By T. Samuelson (Waikapu, Hawaii)
If you want a great game to play with friends and family, this is great. Very good for people who are good at spatial problems and like Tetris. Its competitive, but not overly so, and pretty addictive. We tried the 3D and it was not as fun as this – basically you take shapes and put them corner to corner on the board and try to place all your pieces while not letting the other players place theirs in your area. Try it at your own risk!

Images Product

Buy Blokus Classics Game Now

[Via http://cheapeducationaltoys.wordpress.com]