Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import *
- from math import *
- import pygame
- from OpenGL.GL import *
- from OpenGL.GLU import *
- from pygame.locals import *
- going_left = False
- going_right = False
- going_up = False
- going_down = False
- x_pos = 100
- y_pos = 100
- game_width = 800
- game_height = 600
- def init_game():
- pygame.display.init()
- pygame.display.set_mode((game_width, game_height), DOUBLEBUF | OPENGL)
- glClearColor(0.0, 1.0, 0.1, 0.0)
- def update():
- global x_pos
- global y_pos
- global going_left
- global going_right
- global going_down
- global going_up
- if going_left:
- x_pos -= 8
- if going_right:
- x_pos += 8
- if going_up:
- y_pos += 8
- if going_down:
- y_pos -= 8
- def display():
- global y_pos
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- glMatrixMode(GL_MODELVIEW)
- glLoadIdentity()
- glViewport(0, 0, game_width, game_height)
- gluOrtho2D(0, game_width, 0, game_height)
- glColor3f(0.5, 1.0, 1.0)
- glBegin(GL_TRIANGLES)
- glVertex2f(x_pos, 100)
- glVertex2f(x_pos, 200)
- glVertex2f(x_pos + 300, y_pos)
- glEnd()
- glBegin(GL_TRIANGLES)
- glVertex2f(x_pos, 100)
- glVertex2f(x_pos, 200)
- glVertex2f(x_pos + 300, y_pos + 50)
- glEnd()
- pygame.display.flip()
- def game_loop():
- global going_left
- global going_right
- global going_down
- global going_up
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- quit()
- elif event.type == pygame.KEYDOWN:
- if event.key == K_ESCAPE:
- pygame.quit()
- quit()
- elif event.key == K_q:
- glClearColor(random(), random(), random(), 1.0)
- elif event.key == K_RIGHT:
- going_right = True
- elif event.key == K_LEFT:
- going_left = True
- elif event.key == K_UP:
- going_up = True
- elif event.key == K_DOWN:
- going_down = True
- elif event.type == pygame.KEYUP:
- if event.key == K_LEFT:
- going_left = False
- if event.key == K_RIGHT:
- going_right = False
- if event.key == K_UP:
- going_up = False
- if event.key == K_DOWN:
- going_down = False
- elif event.type == pygame.MOUSEBUTTONDOWN:
- if event.button == 1:
- x_pos = pygame.mouse.get_pos()[0]
- y_pos = pygame.mouse.get_pos()[1]
- update()
- display()
- if __name__ == "__main__":
- init_game()
- while True:
- game_loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement