def draw(self): """Draw sphere at viewport center.""" pyxel.cls(BG_COL) # Clear screen for point in self.my_sphere.vectors: px_out = point + ORIGIN pyxel.pset(px_out.x, px_out.y, px_out.b) self.draw_hud() pyxel.flip() # Progress pyxel
def drawAll(): drawBackGround() if combo > 0 and combo % 5 == 0: drawOrange(fruitX, fruitY) else: drawRingo(fruitX, fruitY) drawHiyoko(hiyokoX, hiyokoY) drawScore(score) drawCombo(combo) drawNum(numOfFruits) pyxel.flip()
def run(self): # """ Main Program Loop """ while self.ongame: P.cls self.handle_events() for player in self.players: player.act() self.gameupdate() self.draw_game(self.GS) #P.display.flip() P.flip() InputState.clear_tick_states() self.GS.PZ_MGR.clear_tick_changes() # self.clock.tick(60)# --- Limit to 60 frames per second #P.display.quit() self.server.shutdown()
def main(): global list_render global list_laser global list_crash global list_enemy pyxel.init(SCREEN_W, SCREEN_H) pyxel.mouse(True) while True: pyxel.cls(0) if pyxel.btn(pyxel.MOUSE_LEFT_BUTTON): o = CLaser(Vector2(random.randint(0, SCREEN_W), SCREEN_W)) list_laser.append(o) o = CEnemy(Vector2(random.randint(0, SCREEN_W), -CEnemy.SIZE)) list_enemy.append(o) for o in list_enemy: o.update() for o in list_laser: o.set_target(Vector2(pyxel.mouse_x, pyxel.mouse_y)) o.update() for o in list_crash: o.update() [o.render() for o in list_render] pyxel.text(8, 8, "Render(s) {:4d}".format(len(list_render)), 7) pyxel.text(8, 16, "Enemy(s) {:4d}".format(len(list_enemy)), 7) pyxel.text(8, 24, "Laser(s) {:4d}".format(len(list_laser)), 7) pyxel.text(8, 32, "Crash(s) {:4d}".format(len(list_crash)), 7) list_enemy = [o for o in list_enemy if o.enable is True] list_laser = [o for o in list_laser if o.enable is True] list_crash = [o for o in list_crash if o.enable is True] list_render = [] pyxel.flip()
def run(self): #""" Main Program Loop """ for local_id, player in enumerate(self.players): self.server_connection.register_player( local_id, player) #""" Register client players to the server """ while not self.done: self.handle_events() if not self.server_connection.receive_game_uptate(): self.done = 1 break self.update_game_state() self.update_collision_structures() self.process_player_input() self.draw_game(self.GS) #P.display.flip() P.flip() InputState.clear_tick_states() # Client rendering timed by server update messages # self.clock.tick(60) self.server_connection.shutdown()
if n == 0: return col = n + 7 if n % 2 == 0: pyxel.tri(x1, y1, x2, y2, x3, y3, col) else: pyxel.trib(x1, y1, x2, y2, x3, y3, col) h1 = (x1 + x2) / 2 w1 = (y1 + y2) / 2 h2 = (x2 + x3) / 2 w2 = (y2 + y3) / 2 h3 = (x3 + x1) / 2 w3 = (y3 + y1) / 2 triangles.append((x1, y1, h1, w1, h3, w3, n - 1)) triangles.append((h1, w1, x2, y2, h2, w2, n - 1)) triangles.append((h3, w3, h2, w2, x3, y3, n - 1)) pyxel.init(200, 150, title="Pyxel Triangle API") pyxel.cls(13) pyxel.text(6, 6, "tri(x1,y1,x2,y2,x3,y3,col)", 7) pyxel.text(6, 14, "trib(x1,y1,x2,y2,x3,y3,col)", 7) triangles = [(100, 24, 7, 143, 193, 143, 7)] while True: if pyxel.btnp(pyxel.KEY_Q): pyxel.quit() if triangles: triangle = triangles.pop(0) draw_triangle(*triangle) pyxel.flip()
# for 5 frames the player's friction is set to 0, and a force proportional to the friction force between the player (when not 0) and surface is exerted if walking: if (c % 7 == 0): # friction = 1, 35 # friction = 2, 70 player.apply_impulse_at_local_point((walking * 35 * 2.5, 22), (0, 0)) dx = player.position[0] - prev_x print(dx) prev_x = player.position[0] walk_frame = (c // 5) % 12 px.blt(player.position[0] - 7, 256 - player.position[1] - 10, 0, 1 + (15 + 2 + 1) * (1 + (walking * walk_frame % 12)), 1, 1 * 15, 19) draw(body, poly) draw(body2, poly2) draw(player, player_poly) draw(large, large_poly) drawLine(player, feet) #player.apply_force_at_local_point((velWalkHorz, velVert), (0, 0)) res = space.shape_query(feet) if res: print(res[0].shape.friction) px.flip() #print(body2.position, body2.angle)
def drawAll(): drawBackGround() drawRingo(ringoX, ringoY) drawHiyoko(hiyokoX, hiyokoY) pyxel.flip()
def drawAll(): drawBackGround() drawHiyoko(hiyokoX, hiyokoY) pyxel.flip()
def update(self): #Player1 Keys if (pyxel.btn(pyxel.KEY_W) and self.OnePlayerY > 0): self.OnePlayerY -= self.PASOS if (pyxel.btn(pyxel.KEY_S) and self.OnePlayerY < 125): self.OnePlayerY += self.PASOS #Plater2 Keys if (pyxel.btn(pyxel.KEY_UP) and self.TwoPlayerY > 0): self.TwoPlayerY -= self.PASOS if (pyxel.btn(pyxel.KEY_DOWN) and self.TwoPlayerY < 125): self.TwoPlayerY += self.PASOS #TocaBordeDerecho if (self.BallX >= 240): Pong.ColorDefine(self) self.BallX = 120 self.BallY = 75 self.Horizontal = True self.PuntosPlayerOne += 1 #TocaBordeIzquierdo if (self.BallX <= 0): Pong.ColorDefine(self) self.BallX = 120 self.BallY = 75 self.Horizontal = False self.PuntosPlayerTwo += 1 #Concional de ganador if (self.PuntosPlayerOne == 5 or self.PuntosPlayerTwo == 5): if (self.PuntosPlayerOne == 5): self.MensajeGanador = "Player ONE win \n\n\n\n R = Reset\n ESC = Exit" if (self.PuntosPlayerTwo == 5): self.MensajeGanador = "Player TWO win \n\n\n\n R = Reset\n ESC = Exit" pyxel.flip() self.Velocity = 0 self.PASOS = 0 self.BallX = 120 self.BallY = 75 self.OnePlayerY = 63 self.TwoPlayerY = 63 if (pyxel.btn(pyxel.KEY_R)): self.Score = 0 self.PuntosPlayerOne = 0 self.PuntosPlayerTwo = 0 self.MensajeGanador = "" self.PASOS = 4 self.Velocity = 3 self.OnePlayerY = 63 self.TwoPlayerY = 63 #TocaBordes Inferior y Superior if (self.BallY >= 150): self.Vertical = True if (self.BallY <= 0): self.Vertical = False #SeleccionaDireccion en las 4 diagonales if (self.Horizontal == False and self.Vertical == False): self.OrientacionX = False self.OrientacionY = False if (self.Horizontal == False and self.Vertical == True): self.OrientacionX = False self.OrientacionY = True if (self.Horizontal == True and self.Vertical == False): self.OrientacionX = True self.OrientacionY = False if (self.Horizontal == True and self.Vertical == True): self.OrientacionX = True self.OrientacionY = True #Mueve la pelota if (self.OrientacionX == True and self.Horizontal == True): self.BallX -= self.Velocity if (self.OrientacionX == False and self.Horizontal == False): self.BallX += self.Velocity if (self.OrientacionY == True and self.Vertical == True): self.BallY -= self.Velocity if (self.OrientacionY == False and self.Vertical == False): self.BallY += self.Velocity #Update position players self.PlayerOne.y = self.OnePlayerY self.PlayerTwo.y = self.TwoPlayerY #Update position ball self.BallDetails.x = self.BallX self.BallDetails.y = self.BallY #Collsions if self.PlayerOne.is_colliding(self.BallDetails): self.Horizontal = False self.Score += 5 if self.PlayerTwo.is_colliding(self.BallDetails): self.Horizontal = True self.Score += 5
def draw_empty(self): """Draw unlit scene.""" pyxel.flip() # Progress pyxel pyxel.cls(BG_COL) # Clear screen pyxel.circ(ORIGIN.x,ORIGIN.y,self.my_sphere.r,SHADOW_COL) self.draw_hud()
import pyxel pyxel.init(160, 120) while True: pyxel.cls(pyxel.COLOR_GREEN) # 緑の画面 # 座標 (x, y) で大きさ w × h の長方形 pyxel.rectb(x=pyxel.frame_count % 160 - 40, y=20, w=40, h=40, col=pyxel.COLOR_WHITE) pyxel.flip() # 画面を更新
from pyxel import init,cls,circ,circb,flip x=y=30 # ボールの座標 u=v=5 # ボールの速度 c=1 # ball color init(159, 119,scale=1) # 160x120で画面を作成する while 1: cls(1) # fill screen by color 1 x,y=x+u,y+v if not 7<x<152:u,c=-u,c+1# x reflect if not 7<y<112:v,c=-v,c+1# y reflect circ(min(max(x,7),152),min(max(y,7),112),7,c%16) # draw ball circb(min(max(x,7),152),min(max(y,7),112),7,(c+1)%16) # draw ball outline flip() # draw screen
def main(): pyxel.init(SCREEN_W, SCREEN_H) pyxel.mouse(True) # 中心座標 vct_center = Vector2(CENTER_X, CENTER_Y) # 角度制限の初期値 limit = math.radians(45) rotation = 0 back_color = 0 text_color = 0 while True: # 計算基準となるベクトルを作成 dir_basic = Vector2(1, 0).rotated(math.radians(rotation)) dir_basic.normalize() # 中心からみてマウスの方向を向いているベクトルを作成 vct_mouse = Vector2(pyxel.mouse_x, pyxel.mouse_y) dir_mouse = vct_mouse - vct_center dir_mouse.normalize() # dir_basicとdir_mouseの角度を計算。 # angle_toの計算結果はラジアンとして戻ります。 raw = dir_basic.angle_to(dir_mouse) fix = min(max(raw, -limit), limit) # 内積の計算。 # 二つのベクトルの内積を求めると計算相手の向き(前後)を調べることが出来ます。 dot = dir_basic.dot(dir_mouse) # 外積を計算。 # 二つのベクトルの外積を求めると計算相手の向き(左右)を調べることが出来ます。 crs = dir_basic.cross(dir_mouse) if pyxel.btnp(pyxel.KEY_SPACE) == 1: rotation = 0 limit = math.radians(45) if pyxel.btnp(pyxel.MOUSE_LEFT_BUTTON) == 1: rotation += 15 if rotation == 360: rotation = 0 if pyxel.btnp(pyxel.MOUSE_RIGHT_BUTTON) == 1: limit = abs(raw) back_color = 0 if abs(raw) > limit: back_color = 1 text_color = 7 if dot < 0: text_color = 8 # 描画処理部 pyxel.cls(back_color) pyxel.line( CENTER_X, CENTER_Y, CENTER_X + dir_basic.x * 64, CENTER_Y + dir_basic.y * 64, 5, ) vct_calc = dir_basic.rotated(raw) pyxel.line( CENTER_X, CENTER_Y, CENTER_X + vct_calc.x * 64, CENTER_Y + vct_calc.y * 64, 7, ) vct_calc = dir_basic.rotated(fix) pyxel.line( CENTER_X, CENTER_Y, CENTER_X + vct_calc.x * 48, CENTER_Y + vct_calc.y * 48, 12, ) list_text = [ " mouse: {:7.2f} {:7.2f}".format(pyxel.mouse_x, pyxel.mouse_y), " dir_mouse: {:7.2f} {:7.2f}".format(dir_mouse.x, dir_mouse.y), "angle(rad): {:7.2f}".format(raw), "angle(deg): {:7.2f}".format(math.degrees(raw)), " dot: {:7.2f} [{:5s}]".format( dot, "front" if dot > 0 else "back"), " cross: {:7.2f} [{:5s}]".format( crs, "right" if crs > 0 else "left"), " frame: {:4d}".format(pyxel.frame_count), ] for n, text in enumerate(list_text): pyxel.text(8, 8 * n + 8, text, text_color) pyxel.text(8, 208, " rotation: {:4d}".format(rotation), 5) pyxel.text(8, 216, "limit(rad): {:7.2f}".format(limit), 12) pyxel.text(8, 224, "limit(deg): {:7.2f}".format(math.degrees(limit)), 12) pyxel.flip()
def drawAll(): drawBackGround() pyxel.flip()
def render(self) -> None: pyxel.cls(0) self.scene.render() pyxel.flip()
from pyxel import circ, cls, flip, init t, s = 0, 128 R = range(0, s, 4) init(s, s, scale=2) while 1: cls(0) for x in R: for y in R: d = ((x - 64)**2 + (y - 64)**2)**.5 b = __import__('math').sin((t + d) / 5) * 4 circ(x + b, y + b, 1, d / 4 % 16) t += 1 flip()