Discuss Scratch
- Discussion Forums
- » Things I'm Making and Creating
- » World of cubes
- typemaster
-
Scratcher
100+ posts
World of cubes
Right now, I am still working on the finishing touches of a python game called world of cubes. I will post in the forum in the download. Controls: arrow keys to move, 1, 2, 3 or 4 to place a block (if you have the material.) Post if you have any instructions!! 
Compiled Code:
`³ò
v;éSc @ s d d k Z d d k Z d d k Z d d k Td Z d Z d Z d Z d Z d Z d Z
d Z d Z h e i
i d
ƒ e <e i
i d ƒ e
<e i
i d ƒ e <e i
i d
ƒ e <Z h d e <d e
<d e <d e <Z d Z d Z d Z e i
i d ƒ Z d d g Z e e
e e g Z g Z e e ƒ D]. Z e g Z e e ƒ D]
Z e e qU[ q;[ Z e i ƒ e i i e e e e d f ƒ Z e i i! d ƒ e i i" e i
i d ƒ ƒ e i# i$ d d ƒ Z% x° e e ƒ D]¢ Z& x™ e e ƒ D]‹ Z' e i( d d ƒ Z) e) d j o
e Z* nO e) d j p
e) d j o
e Z* n+ e) d j o e) d j o
e
Z* n e Z* e* e e& e' <qWqîWxze+ orxSe i, i- ƒ D]BZ, e, i. e/ j o e i0 ƒ e i1 ƒ q®e, i. e2 j oe, i3 e4 j o) e d e d j o e d c d 7<n e, i3 e5 j o% e d d j o e d c d 8<n e, i3 e6 j o% e d d j o e d c d 8<n e, i3 e7 j o) e d e d j o e d c d 7<n e, i3 e8 j o@ e e d e d Z9 e e9 c d 7<e e e d e d <n e, i3 e: j oe e e d e d Z9 e e d j o: e e c d 8<e e e d e d <e e9 c d 7<qn e, i3 e; j oe e e d e d Z9 e e
d j o: e e
c d 8<e
e e d e d <e e9 c d 7<qn e, i3 e< j oe e e d e d Z9 e e d j o: e e c d 8<e e e d e d <e e9 c d 7<qwn e, i3 e= j oe e e d e d Z9 e e d j o: e e c d 8<e e e d e d <e e9 c d 7<qìqðq®q®WxU e e ƒ D]G Z> x> e e ƒ D]0 Z? e i@ e e e> e? e? e e> e f ƒ qWqWe i@ e e d e e d e f ƒ d ZA x„ e D]| ZB e i@ e eB eA e e d f ƒ eA d 7ZA e% iC eD e eB ƒ e+ e e ƒ ZE e i@ eE eA e e d f ƒ eA d 7ZA qWe i iF ƒ q—Wd S( iÿÿÿÿN( t *i i™ iL iÿ i i i s dirt.pngs grass.pngs water.pngs coal.pngi i( i i s
player.pngi2 s World Of Cubess logo.pngs verdanab.ttfi i i i
( i i i ( i™ iL i ( i iÿ i ( i i iÿ ( iÿ iÿ iÿ (G t pygamet syst randomt
pygame.localst BLACKt BROWNt GREENt BLUEt WHITEt DIRTt GRASSt WATERt COALt imaget loadt texturest inventoryt TILESIZEt MAPWIDTHt MAPHEIGHTt PLAYERt playerPost resourcest _t ranget ht _t wt tilemapt initt displayt set_modet DISPLAYSURFt set_captiont set_icont fontt Fontt INVFONTt rwt clt randintt randomNumbert tilet Truet eventt gett typet QUITt quitt exitt KEYDOWNt keyt K_RIGHTt K_LEFTt K_UPt K_DOWNt K_SPACEt currentTilet K_1t K_2t K_3t K_4t rowt columnt blitt
placePositiont itemt rendert strt textObjt update( ( ( s= C:\Users\Andrea\Desktop\Apps\World Of Cubes\World Of Cubes.pys <module> sÎ $
H
$
%!!%
2& “
”`

Compiled Code:
`³ò
v;éSc @ s d d k Z d d k Z d d k Z d d k Td Z d Z d Z d Z d Z d Z d Z
d Z d Z h e i
i d
ƒ e <e i
i d ƒ e
<e i
i d ƒ e <e i
i d
ƒ e <Z h d e <d e
<d e <d e <Z d Z d Z d Z e i
i d ƒ Z d d g Z e e
e e g Z g Z e e ƒ D]. Z e g Z e e ƒ D]
Z e e qU[ q;[ Z e i ƒ e i i e e e e d f ƒ Z e i i! d ƒ e i i" e i
i d ƒ ƒ e i# i$ d d ƒ Z% x° e e ƒ D]¢ Z& x™ e e ƒ D]‹ Z' e i( d d ƒ Z) e) d j o
e Z* nO e) d j p
e) d j o
e Z* n+ e) d j o e) d j o
e
Z* n e Z* e* e e& e' <qWqîWxze+ orxSe i, i- ƒ D]BZ, e, i. e/ j o e i0 ƒ e i1 ƒ q®e, i. e2 j oe, i3 e4 j o) e d e d j o e d c d 7<n e, i3 e5 j o% e d d j o e d c d 8<n e, i3 e6 j o% e d d j o e d c d 8<n e, i3 e7 j o) e d e d j o e d c d 7<n e, i3 e8 j o@ e e d e d Z9 e e9 c d 7<e e e d e d <n e, i3 e: j oe e e d e d Z9 e e d j o: e e c d 8<e e e d e d <e e9 c d 7<qn e, i3 e; j oe e e d e d Z9 e e
d j o: e e
c d 8<e
e e d e d <e e9 c d 7<qn e, i3 e< j oe e e d e d Z9 e e d j o: e e c d 8<e e e d e d <e e9 c d 7<qwn e, i3 e= j oe e e d e d Z9 e e d j o: e e c d 8<e e e d e d <e e9 c d 7<qìqðq®q®WxU e e ƒ D]G Z> x> e e ƒ D]0 Z? e i@ e e e> e? e? e e> e f ƒ qWqWe i@ e e d e e d e f ƒ d ZA x„ e D]| ZB e i@ e eB eA e e d f ƒ eA d 7ZA e% iC eD e eB ƒ e+ e e ƒ ZE e i@ eE eA e e d f ƒ eA d 7ZA qWe i iF ƒ q—Wd S( iÿÿÿÿN( t *i i™ iL iÿ i i i s dirt.pngs grass.pngs water.pngs coal.pngi i( i i s
player.pngi2 s World Of Cubess logo.pngs verdanab.ttfi i i i
( i i i ( i™ iL i ( i iÿ i ( i i iÿ ( iÿ iÿ iÿ (G t pygamet syst randomt
pygame.localst BLACKt BROWNt GREENt BLUEt WHITEt DIRTt GRASSt WATERt COALt imaget loadt texturest inventoryt TILESIZEt MAPWIDTHt MAPHEIGHTt PLAYERt playerPost resourcest _t ranget ht _t wt tilemapt initt displayt set_modet DISPLAYSURFt set_captiont set_icont fontt Fontt INVFONTt rwt clt randintt randomNumbert tilet Truet eventt gett typet QUITt quitt exitt KEYDOWNt keyt K_RIGHTt K_LEFTt K_UPt K_DOWNt K_SPACEt currentTilet K_1t K_2t K_3t K_4t rowt columnt blitt
placePositiont itemt rendert strt textObjt update( ( ( s= C:\Users\Andrea\Desktop\Apps\World Of Cubes\World Of Cubes.pys <module> sÎ $
H
$
%!!%
2& “
”`
- AonymousGuy
-
Scratcher
1000+ posts
World of cubes
Wait - Python code is… compiled?
I thought it was interpreted!
Oh well. Anyways, cool! I've never found Python very good for game design, however.
I thought it was interpreted!Oh well. Anyways, cool! I've never found Python very good for game design, however.
- ssss
-
Scratcher
500+ posts
World of cubes
Wait - Python code is… compiled?Python uses both a Compiler and Interpreter from my understanding.I thought it was interpreted!
Oh well. Anyways, cool! I've never found Python very good for game design, however.
- typemaster
-
Scratcher
100+ posts
World of cubes
Wait - Python code is… compiled?I used pygame, anyway,I thought it was interpreted!
Oh well. Anyways, cool! I've never found Python very good for game design, however.
Here is the non compiled code:
import pygame, sys, random
from pygame.locals import *
#constants representing colours
BLACK = (0, 0, 0 )
BROWN = (153, 76, 0 )
GREEN = (0, 255, 0 )
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
#constants representing the different resources
DIRT = 0
GRASS = 1
WATER = 2
COAL = 3
#a dictionary linking resources to textures
textures = {
DIRT : pygame.image.load('dirt.png'),
GRASS : pygame.image.load('grass.png'),
WATER : pygame.image.load('water.png'),
COAL : pygame.image.load('coal.png'),
}
inventory = {
DIRT : 10
GRASS : 7
WATER : 5
COAL : 5
}
#useful game dimensions
TILESIZE = 40
MAPWIDTH = 30
MAPHEIGHT = 20
#the player image
PLAYER = pygame.image.load('player.png')
#the position of the player
playerPos =
#a list of resources
resources =
#use list comprehension to create our tilemap
tilemap = [ for h in range(MAPHEIGHT) ]
#set up the display
pygame.init()
DISPLAYSURF = pygame.display.set_mode((MAPWIDTH*TILESIZE, MAPHEIGHT*TILESIZE + 50))
pygame.display.set_caption('World Of Cubes')
pygame.display.set_icon(pygame.image.load('logo.png'))
#add a font for our inventory
INVFONT = pygame.font.Font('verdanab.ttf', 18)
#loop through each row
for rw in range(MAPHEIGHT):
#loop through each column in that row
for cl in range(MAPWIDTH):
#pick a random number between 0 and 15
randomNumber = random.randint(0,15)
#if a zero, then the tile is coal
if randomNumber == 0:
tile = COAL
#water if the random number is a 1 or a 2
elif randomNumber == 1 or randomNumber == 2:
tile = WATER
elif randomNumber >= 3 and randomNumber <= 7:
tile = GRASS
else:
tile = DIRT
#set the position in the tilemap to the randomly chosen tile
tilemap = tile
while True:
#get all the user events
for event in pygame.event.get():
#if the user wants to quit
if event.type == QUIT:
#and the game and close the window
pygame.quit()
sys.exit()
#if a key is pressed
elif event.type == KEYDOWN:
#if the right arrow is pressed
if event.key == K_RIGHT and playerPos < MAPWIDTH - 1:
#change the player's x position
playerPos += 1
if event.key == K_LEFT and playerPos > 0:
#change the player's x position
playerPos -= 1
if event.key == K_UP and playerPos > 0:
#change the player's x position
playerPos -= 1
if event.key == K_DOWN and playerPos < MAPHEIGHT -1:
#change the player's x position
playerPos += 1
if event.key == K_SPACE:
#what resource is the player standing on?
currentTile = tilemap[playerPos][playerPos]
#player now has 1 more of this resource
inventory += 1
#the player is now standing on dirt
tilemap[playerPos][playerPos] = DIRT
#placing blocks
if (event.key == K_1):
currentTile = tilemap[playerPos][playerPos]
if inventory > 0:
inventory -= 1
tilemap[playerPos][playerPos] = DIRT
inventory += 1
if (event.key == K_2):
currentTile = tilemap[playerPos][playerPos]
if inventory > 0:
inventory -= 1
tilemap[playerPos][playerPos] = GRASS
inventory += 1
if (event.key == K_3):
currentTile = tilemap[playerPos][playerPos]
if inventory > 0:
inventory -= 1
tilemap[playerPos][playerPos] = WATER
inventory += 1
if (event.key == K_4):
currentTile = tilemap[playerPos][playerPos]
if inventory > 0:
inventory -= 1
tilemap[playerPos][playerPos] = COAL
inventory += 1
#loop through each row
for row in range(MAPHEIGHT):
#loop through each column in the row
for column in range(MAPWIDTH):
#draw the resource at that position in the tilemap, using the correct image
DISPLAYSURF.blit(textures[tilemap], (column*TILESIZE,row*TILESIZE))
#display the player at the correct position
DISPLAYSURF.blit(PLAYER,(playerPos*TILESIZE,playerPos*TILESIZE))
#display the inventory, starting 10 pixels in
placePosition = 10
for item in resources:
#add the image
DISPLAYSURF.blit(textures,(placePosition,MAPHEIGHT*TILESIZE+20))
placePosition += 30
#add the text showing the amount in the inventory
textObj = INVFONT.render(str(inventory), True, WHITE, BLACK)
DISPLAYSURF.blit(textObj,(placePosition,MAPHEIGHT*TILESIZE+20))
placePosition += 50
#update the display
pygame.display.update()
- Discussion Forums
- » Things I'm Making and Creating
-
» World of cubes
I thought it was interpreted!