@idrawhorsechamp/

Minecraft I Guess 2

Pygame

the better sequel to minecraft i guess- using pygame!

fork
loading
Files
  • main.py
  • animations.py
  • crafting_table.png
  • glass_edge_bottom.png
  • glass.png
  • grass.png
  • hotbar.png
  • loadtextures.py
  • nohup.out
  • oak_canopy.png
  • oak_leaves.png
  • oak_log.png
  • oak_planks.png
  • pixil-frame-0 (2).png
  • player_front_step1.png
  • player_front_step2.png
  • player_front.png
  • player.py
  • stone_edge_left.png
  • stone_edge_right.png
  • stone_edge_top.png
  • stone.png
  • tiledata.py
  • visual.py
main.py
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# current total line count: 348
import tiledata
import pygame as pg
import noise
from random import randint
from animations import animation as anim
import loadtextures
import visual
from player import player
pg.init()
version = "dev.test7"
screensize = 2.5
normalfont = pg.font.Font(None, 16)
screen = pg.display.set_mode((int(256 * screensize), int(240 * screensize)), pg.FULLSCREEN)
clock = pg.time.Clock()
screenimg = pg.Surface((256, 240))
textures = loadtextures.createtextures()
def generate(tilemap, coord):
  for y in range(int(coord[0]) - 13, int(coord[0]) + 13):
    try:
      h = tilemap[y]
    except:
      tilemap[y] = {}
    for x in range(int(coord[1]) - 13, int(coord[1]) + 13):
      try:
        h = tilemap[y][x]
      except:
        h = noise.pnoise2(y / 40, x / 40, octaves=3, persistence=5, lacunarity=5, repeatx=1000, repeaty=1000, base=0)
        e = ((y * y + x * x) * y * x) % 120
        if h < 0:
          h = h * -1
        if h > 1:
          h = 1
        if e >= 118:
          layer = ["grass", "oak_log", None, None]
        elif e >= 110:
          layer = ["grass", "oak_log", "oak_log", "oak_canopy"]
        elif h <= 0.4:
          layer = ["grass", None, None, None]
        else:
          layer = ["grass", "stone", None, None]
        tilemap[y][x] = layer
  return tilemap
tilemap = {}
speed = 0.0625
facingdir = ["down", None]
up = False
down = False
left = False
right = False
running = False
coord = [0, 0, 0, 0, 0, 0]
fullscreen = True
screenchanged = False
versiontext = normalfont.render(version, False, (0, 0, 0))
while True:
  strcoord = "X: " + str(coord[1]) + " Y: " + str(coord[0])
  coordtext = normalfont.render(strcoord, False, (0, 0, 0))
  for i in textures:
    for e in textures[i]["images"]:
      if len(textures[i]["images"][e]) > 1:
        textures[i]["frame"][e] += 1
        if textures[i]["frame"][e] >= len(textures[i]["images"][e]):
          textures[i]["frame"][e] = 0
  tilemap = generate(tilemap, coord)
  screenimg.fill(0)
  screen.fill(0)
  for event in pg.event.get():
    if event.type == pg.KEYDOWN:
      if event.key == pg.K_ESCAPE:
        quit()
      elif event.key == pg.K_w:
        up = True
      elif event.key == pg.K_s:
        down = True
      elif event.key == pg.K_a:
        left = True
      elif event.key == pg.K_d:
        right = True
      elif event.key == pg.K_1:
        player.invslot = 0
      elif event.key == pg.K_2:
        player.invslot = 1
      elif event.key == pg.K_3:
        player.invslot = 2
      elif event.key == pg.K_4:
        player.invslot = 3
      elif event.key == pg.K_5:
        player.invslot = 4
      elif event.key == pg.K_6:
        player.invslot = 5
      elif event.key == pg.K_7:
        player.invslot = 6
      elif event.key == pg.K_8:
        player.invslot = 7
      elif event.key == pg.K_9:
        player.invslot = 8
      elif event.key == pg.K_f:
        if fullscreen == False:
          fullscreen = True
        elif fullscreen == True:
          fullscreen = False
        screenchanged = True
      elif event.key == pg.K_UP:
        screensize += 1
      elif event.key == pg.K_DOWN:
        screensize -= 1
      elif event.key == pg.K_l:
        running = True
      elif event.key == pg.K_j:
        if coord[0] < 0:
          y = int(coord[2] - coord[4])
        else:
          y = int(coord[0])
        if coord[1] < 0:
          x = int(coord[3] - coord[5])
        else:
          x = int(coord[1])
        tilemap = player.removetile(player, tilemap, y, x)
      elif event.key == pg.K_k:
        if coord[0] < 0:
          y = int(coord[2] - coord[4])
        else:
          y = int(coord[0])
        if coord[1] < 0:
          x = int(coord[3] - coord[5])
        else:
          x = int(coord[1])
        tilemap = player.placetile(player, tilemap, y, x)
    elif event.type == pg.KEYUP:
      if event.key == pg.K_w:
        up = False
      elif event.key == pg.K_s:
        down = False
      elif event.key == pg.K_a:
        left = False
      elif event.key == pg.K_d:
        right = False
      elif event.key == pg.K_l:
        running = False
  if up == True and down == False:
    facingdir[0] = "up"
    player.moved = True
  elif down == True and up == False:
    facingdir[0] = "down"
    player.moved = True
  else:
    if left == True and right == False or left == False and right == True:
      facingdir[0] = None
      player.moved = True
    else:
      player.moved = False
  if left == True and right == False:
    facingdir[1] = "left"
    player.moved = True
  elif left == False and right == True:
    facingdir[1] = "right"
    player.moved = True
  else:
    if up == True and down == False or up == False and down == True:
      facingdir[1] = None
      player.moved = True
    else:
      player.moved = False
  player = player.findanimation(player, facingdir)
  if running == True:
    Speed = speed * 2
  elif running == False:
    Speed = speed
  if down == True:
    coord[4] += 1 * Speed
  if up == True:
    coord[4] -= 1 * Speed
  if right == True:
    coord[5] += 1 * Speed
  if left == True:
    coord[5] -= 1 * Speed
  if coord[4] >= 1:
    coord[4] -= 1
    coord[2] += 1
  elif coord[4] < 0:
    coord[4] += 1
    coord[2] -= 1
  if coord[5] >= 1:
    coord[5] -= 1
    coord[3] += 1
  elif coord[5] < 0:
    coord[5] += 1
    coord[3] -= 1
  coord[0] = coord[2] + coord[4]
  coord[1] = coord[3] + coord[5]
  if screenchanged == True:
    if fullscreen == True:
      screen = pg.display.set_mode((int(256 * screensize), int(240 * screensize)), pg.FULLSCREEN)
    else:
      screen = pg.display.set_mode((int(256 * screensize), int(240 * screensize)))
  screenchanged = False
  screenimg = visual.render.rendermap(tilemap, screenimg, coord, textures, player)
  player = player.animate(player)
  screenimg.blit(versiontext, (0, 0))
  screenimg.blit(coordtext, (0, 10))
  screen.blit(pg.transform.scale(screenimg, (int(256 * screensize), int(240 * screensize))), (0, 0))
  pg.display.update()
  clock.tick(60)