Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Challenge: 2D Tank

Name: Anonymous 2010-05-14 15:43

The Challenge:
|---->Program a 2d tank application in the language of your choice that adheres to the following:

#-The tank must rotate using the left and right directional keys.
#-The tank must loosely resemble a tank.
#-The tank must move forward or backward respectively from the direction it is facing using the up and down directional keys.
#-Pressing spacebar must fire a 'shot' in the direction the tank is facing.
#-The perspective of the user must be fixed and facing down at the tank.
#-The tank, shot, and ground must each have their own color. (all shots may have the same color)


<------You have 24 hours!------>
GET TO WORK!

Name: Anonymous 2010-05-21 14:49

I didn't even use any classes.

import sys, os
import pygame
import math
import random
import time
from pygame.locals import *

if not pygame.font : print "Fonts's turned off"
if not pygame.mixer : print "Sound's turned off"
if not pygame.key : print "Input's turned off"

pygame.init ()
pygame.font.init()
clock = pygame.time.Clock()
def input(events):
    for event in events:
        if event.type == QUIT:
            sys.exit (0)
        else :
            print event
           
os.environ['SDL_VIDEO_CENTERED'] = '1'
window = pygame.display.set_mode ((800, 600))
pygame.display.set_caption (' Simple Shooter' )
screen = pygame.display.get_surface ()


tangent = pygame.key.get_pressed
spelare_y = 0
spelare_x = 100
spelare_rect = pygame.Rect (spelare_x, spelare_y, 80, 60 )

pos_x = 400
pos_y = 400
target_rect = pygame.Rect (pos_x, pos_y, 80, 60)

cirkel_y = spelare_y
cirkel_x = spelare_x + 50
cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
cirkel_aktiv = 0

targetz = 0

font = pygame.font.SysFont (None, 48)
font_2 = pygame.font.SysFont (None, 22)
start_text = font.render ("A GAME!", True, (255,255,255))
score_int = 0
score_str = str(score_int)
score_text = font_2.render ("Score:" + score_str, True, (255,255,255))

screen.blit (start_text, (0,0))
pygame.display.update()
time.sleep (3.0)
screen.fill ((0,0,0))

while True:
    pygame.key.get_pressed()
    input(pygame.event.get())
    clock.tick(60)
    if tangent() [K_ESCAPE] == True:
        pygame.quit()
        sys.exit()
       
    if tangent() [K_UP]== True:
        if spelare_y >= 15 :
            spelare_y = spelare_y - 15
            if cirkel_aktiv == 0:
                cirkel_y = spelare_y
               
    if tangent () [K_DOWN] == True:
        if spelare_y <= 525:
            spelare_y = spelare_y + 15
            if cirkel_aktiv == 0:
                cirkel_y = spelare_y

    if pos_y >= 15:
           
        pos_y = pos_y + random.choice ([-4,-5,-2, -3, +2, +3])
        target_rect = pygame.Rect (pos_x, pos_y, 80, 60)

       
        if pos_y <= 525 +60:
            
            pos_y = pos_y + random.choice ([+8,+4,+3, - 3, -2, -5])
            target_rect = pygame.Rect (pos_x, pos_y, 80, 60)
           
       
    if tangent () [K_SPACE] == True:
        cirkel_aktiv = 1
       
    if cirkel_aktiv == 1:
        cirkel_x = cirkel_x + 10
        pygame.draw.circle(screen, (30,97,200), (cirkel_x, cirkel_y), 20, 0)
        cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
        pygame.display.update()
       
    if cirkel_x >= 799:
        cirkel_aktiv = 0
        cirkel_y = spelare_y + 30
        cirkel_x = spelare_x + 120
        pygame.draw.circle(screen, (30,97,200), (cirkel_x, cirkel_y), 20, 0)
        cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
       
    if cirkel_rect.colliderect (target_rect) == True:
        cirkel_aktiv = 0
        cirkel_x = spelare_x +  20
        cirkel_y = spelare_y + 30
        cirkel_rect = pygame.Rect (cirkel_x, cirkel_y, 30, 30)
        score_int = score_int + 10
        score_str = str(score_int)
        score_text = font_2.render ("Score:" + score_str, True, (255,255,255))
       
    screen.fill ((0,0,0))
    pygame.draw.rect (screen, (230,160, 125), (pos_x,pos_y,80,60)) 
    pygame.draw.rect(screen, (200,200,200),(spelare_x, spelare_y, 80, 60))
    screen.blit (score_text, (0,0))
   
    if cirkel_aktiv == 0:
        pygame.display.update()

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List