Last active
October 7, 2022 07:55
-
-
Save fox3000foxy/fcbd41e9c3de584be1f9fd6e15134bb5 to your computer and use it in GitHub Desktop.
main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
from kandinsky import * | |
from time import * | |
from kandinsky import fill_rect as fl | |
from kandinsky import draw_line as dl | |
p=[200,200,-100,-100,30,10] | |
def cube(x,y,a,b,z,z_,d=None): | |
if d==1:_z=[x+z,y-z_] | |
elif d==2:_z=[x-z,y-z_] | |
elif d==3:_z=[x-z,y+z_] | |
else: _z=[x+z,y+z_] | |
#carré | |
dl(x,y,x+a,y,(0,0,0)) | |
dl(x,y,x,y+b,(0,0,0)) | |
dl(x+a,y,x+a,y+b,(0,0,0)) | |
dl(x,y+b,x+a,y+b,(0,0,0)) | |
#z | |
dl(x,y,_z[0],_z[1],(0,0,0)) | |
dl(x+a,y,_z[0]+a,_z[1],(0,0,0)) | |
dl(x,y+b,_z[0],_z[1]+b,(0,0,0)) | |
dl(x+a,y+b,_z[0]+a,_z[1]+b,(0,0,0)) | |
#carré derrière | |
dl(_z[0],_z[1],_z[0],_z[1]+b,(0,0,0)) | |
dl(_z[0],_z[1],_z[0]+a,_z[1],(0,0,0)) | |
dl(_z[0]+a,_z[1],_z[0]+a,_z[1]+b,(0,0,0)) | |
dl(_z[0],_z[1]+b,_z[0]+a,_z[1]+b,(0,0,0)) | |
#print("x={} y={} a={} b={} z={} _z={}".format(x,y,a,b,z,_z)) | |
cube(10,10,100,100,50,50) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
from kandinsky import * | |
from time import * | |
from kandinsky import fill_rect as fl | |
from kandinsky import draw_line as dl | |
p=[200,200,-100,-100,30,10] | |
def cube(x,y,a,b,z,z_,d=None): | |
if d==1:_z=[x+z,y-z_] | |
elif d==2:_z=[x-z,y-z_] | |
elif d==3:_z=[x-z,y+z_] | |
else: _z=[x+z,y+z_] | |
#carré | |
dl(x,y,x+a,y,(0,0,0)) | |
dl(x,y,x,y+b,(0,0,0)) | |
dl(x+a,y,x+a,y+b,(0,0,0)) | |
dl(x,y+b,x+a,y+b,(0,0,0)) | |
#z | |
dl(x,y,_z[0],_z[1],(0,0,0)) | |
dl(x+a,y,_z[0]+a,_z[1],(0,0,0)) | |
dl(x,y+b,_z[0],_z[1]+b,(0,0,0)) | |
dl(x+a,y+b,_z[0]+a,_z[1]+b,(0,0,0)) | |
#carré derrière | |
dl(_z[0],_z[1],_z[0],_z[1]+b,(0,0,0)) | |
dl(_z[0],_z[1],_z[0]+a,_z[1],(0,0,0)) | |
dl(_z[0]+a,_z[1],_z[0]+a,_z[1]+b,(0,0,0)) | |
dl(_z[0],_z[1]+b,_z[0]+a,_z[1]+b,(0,0,0)) | |
#print("x={} y={} a={} b={} z={} _z={}".format(x,y,a,b,z,_z)) | |
cube(10,10,100,100,50,50) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
from time import sleep | |
from kandinsky import * | |
from ion import * | |
def code(): | |
SKIN = { | |
'head': 'red', | |
'bottom': 'red' | |
} | |
BLOCKS = { | |
-1: { | |
'out': color(110, 191, 207), # ARRIERE PLAN EXTERIEUR | |
'in': color(10, 10, 10) # ARRIERE PLAN INTERIEUR | |
}, | |
0: color(175, 255, 50), # HERBE | |
1: color(130, 100, 50), # TERRE | |
2: color(63, 81, 181), # EAU | |
3: color(100 ,100 ,100) #STONE | |
} | |
class Player: | |
def __init__(self, pskin, px=30, py=100): | |
self.map = Map() | |
self.lastpos = (None, None) | |
self.x = px | |
self.y = py | |
self.skin = pskin | |
def place_block(self, direction): | |
if direction == 'right': | |
b = self.map.get_index(self.x+10,self.y+10) | |
b.id = 3 | |
b.render() | |
if direction == 'left': | |
b = self.map.get_index(self.x-10,self.y+10) | |
b.id = 3 | |
b.render() | |
def render(self): | |
fill_rect(self.x, self.y, 10, 20, self.skin['head']) | |
fill_rect(self.x, self.y + 10, 10, 10, self.skin['bottom']) | |
def move(self, direction): | |
self.lastpos = (self.x, self.y) | |
if direction == 'left': | |
self.x -= 10 | |
elif direction == 'right': | |
self.x += 10 | |
head = self.map.get_index(*self.lastpos) | |
bottom = self.map.get_index(self.lastpos[0], self.lastpos[1]+10) | |
bottom.render() | |
head.render() | |
class Block: | |
def __init__(self, bx, by, id: int): | |
self.id = id | |
self.x = bx | |
self.y = by | |
def render(self): | |
print('rendering ', self.x, self.y) | |
if self.id!=-1: # autre que vide | |
final_col = BLOCKS[self.id] | |
else: | |
final_col = BLOCKS[-1]['out'] if self.y<=110 else BLOCKS[-1]['in'] # DEHORS SI EN DESSOUS Y 11 | |
fill_rect(self.x, self.y, 10, 10, final_col) | |
def __repr__(self): | |
return '<{},{}: {}>'.format(self.x, self.y, self.id) | |
class Map: | |
def __init__(self): | |
self.blocks = [] | |
def render(self): | |
for b in self.blocks: | |
b.render() | |
def add_block(self, b): | |
self.blocks.append(b) | |
def get_index(self, x_px_pos, y_px_pos): | |
for b in self.blocks: | |
if int(b.x) == x_px_pos and int(b.y) == y_px_pos: | |
return b | |
P = Player(SKIN) | |
for y in range(0, 152, 10): | |
for x in range(0, 240, 10): | |
b_nb = y / 10 | |
# print(y, b_nb) | |
if b_nb < 12: | |
P.map.add_block(Block(x, y, -1)) | |
elif b_nb == 12: | |
P.map.add_block(Block(x, y, 0)) | |
elif b_nb > 12: | |
P.map.add_block(Block(x, y, 1)) | |
P.map.render() | |
P.render() | |
while True: | |
if keydown(KEY_LEFT): | |
P.move('left') | |
P.render() | |
sleep(0.1) | |
elif keydown(KEY_RIGHT): | |
P.move('right') | |
P.render() | |
sleep(0.1) | |
P.place_block(input('Enter block>')) | |
# code for calc | |
code() | |
""" | |
from eratz import * |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment