-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
107 lines (73 loc) · 2.43 KB
/
Copy pathmain.py
File metadata and controls
107 lines (73 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#hi this very cool, super epic code was made by nullcomputer/taryn
#imports
import pygame
import time
import tkinter as tk
import random
import numpy as np
#init
root = tk.Tk()
pygame.init()
#settings
vel = 0.6
x = root.winfo_screenwidth()/2
y = root.winfo_screenheight()/2
playersize_height = 100
playersize_width = 100
#resize and load images
img_test = pygame.image.load('img\\test-img.png')
img_acorn = pygame.image.load('img\\acorn.png')
img_player1 = pygame.image.load('img\\player1.png')
img_player1 = pygame.transform.scale(img_player1, (playersize_height, playersize_width))
img_tree1 = pygame.image.load('img\\tree1.png')
img_tree1 = pygame.transform.scale(img_tree1, (random.randrange(10, 200), playersize_width))
#img_tree2 = pygame.image.load('img\\tree2.png')
#colors
#color_ = (, , )
color_white = (255, 255, 255)
color_black = (0, 0, 0)
color_red = (255, 0, 0)
color_green = (0, 255, 0)
color_blue = (0, 0, 255)
color_backroundgreen = (0, 90, 0)
#get and set window size
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
window = pygame.display.set_mode((screen_width-100, screen_height-100), pygame.RESIZABLE)
#set title and icon
pygame.display.set_caption('treesgobrrr')
img_acorn = pygame.transform.scale(img_acorn, (playersize_width, playersize_height))
pygame.display.set_icon(img_acorn)
#tree placement
trees = []
def treeplace(tree_x, tree_y):
if random.randint(0, 10000) > 9981:
trees.append(random.randrange())
trees.append(random.randrange())
elif random.randint(0, 10000) > 9986:
if (i % 2) == 0:
trees.pop()
else:
trees.pop()
for i in trees:
window.blit(img_tree1, (tree_x, tree_y))
#main loop
running = True
while(running):
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and x>0:
x -= vel
if keys[pygame.K_RIGHT] and x<screen_width-75-playersize_width:
x += vel
if keys[pygame.K_UP] and y>0:
y -= vel
if keys[pygame.K_DOWN] and y<screen_height-75-playersize_height:
y += vel
screen_width, screen_height = window.get_size()
window.fill(color_backroundgreen)
treeplace(random.randrange(100, screen_width), random.randrange(100, screen_height ))
window.blit(img_player1, (x, y))
pygame.display.update()