def update(self, stage=1): if stage == 0: for i in range(7, 14, 2): self.image = self.wizSheet.images[i] self.image = py.transform.scale(self.image, (self.image.get_rect().width * 2, self.image.get_rect().height * 2)) self.rect = (0, 0, 1280, 720) py.draw.rect(v.screen, (0, 0, 0), self.rect) v.screen.blit(self.image, (640 - self.image.get_rect().width / 2, 360 - self.image.get_rect().height / 2)) v.screen.blit(self.label, (640 - self.mod[0], 360 - self.mod[1] + 100)) self.fade.draw() self.fade.opacity -= 40 MenuItems.screenFlip() py.time.delay(100) self.time = clock() if stage == 1: self.image = self.wizSheet.images[14] self.image = py.transform.scale(self.image, (self.image.get_rect().width * 2, self.image.get_rect().height * 2)) self.rect = (0, 0, 1280, 720) py.draw.rect(v.screen, (0, 0, 0), self.rect) v.screen.blit(self.image, ((1280 / 2) - self.image.get_rect().width / 2, (720 / 2) - self.image.get_rect().height / 2)) v.screen.blit(self.label, ((1280 / 2) - self.mod[0], (720 / 2) - self.mod[1] + 50/640 * 1280)) if stage == 2: t = self.font.render("Load Time: " + str(clock() - self.time), 1, (255, 255, 255)) for i in range(28, 38, 2): py.time.delay(100) self.image = self.wizSheet.images[i] self.image = py.transform.scale(self.image, (self.image.get_rect().width * 2, self.image.get_rect().height * 2)) self.rect = (0, 0, 1280, 720) py.draw.rect(v.screen, (0, 0, 0), self.rect) v.screen.blit(self.image, ((1280 / 2) - self.image.get_rect().width / 2, (720 / 2) - self.image.get_rect().height / 2)) v.screen.blit(self.label, ((1280 / 2) - self.mod[0], (720 / 2) - self.mod[1] + 50/640 * 1280)) v.screen.blit(t, (200/640 * 1280, 300/640 * 1280)) self.fade.draw() self.fade.opacity += 40 MenuItems.screenFlip()
def game(): v.clock = py.time.Clock() ping = MenuItems.textLabel("Ping: 0", (320, 10), (255, 0, 0), "Resources/Fonts/RPGSystem.ttf", 20, centred=True, screen=v.screen) server() while True: py.event.pump() v.clock.tick(30) #print(clock.get_fps()) v.screen.fill((0, 0, 0)) py.draw.rect(v.screen, (0, 0, 255), (v.posx, v.posy, 50, 50)) #posx, posy = v.mouse_pos pressed = py.key.get_pressed() if pressed[py.K_a]: v.posx -= 5 if pressed[py.K_d]: v.posx += 5 if pressed[py.K_w]: v.posy -= 5 if pressed[py.K_s]: v.posy += 5 ping.text = "Ping: " + str(round(v.fetchTime * 1000, 1)) for event in py.event.get(): if event.type == py.KEYDOWN: if event.key == py.K_ESCAPE: return for name, values in v.data["players"].items(): if not "position" in values: values["position"] = (0, 0) if not name == v.username: if values["online"]: if v.fetched == False: if name in v.vectors.keys(): values["position"] = (values["position"][0] + v.vectors[name][0], values["position"][1] + v.vectors[name][1]) else: print("VALUES POS", values) if not values["position"] == None: if name in v.pastdata.keys(): v.vectors[name] = ((values["position"][0] - v.pastdata[name][0]) / (30 * v.fetchTime), (values["position"][1] - v.pastdata[name][1]) / (30 * v.fetchTime)) v.pastdata[name] = values["position"] #print(values["position"]) py.draw.rect(v.screen, (255, 0, 0), (values["position"], (50, 50))) MenuItems.textLabel(name, (values["position"][0] + 25, values["position"][1] - 40), (255, 255, 255), "Resources/Fonts/RPGSystem.ttf", 20, centred=True, screen=v.screen).update() if not name in v.pastdata.keys(): v.pastdata[name] = [] v.fetched = False ping.update() py.display.flip()
def __init__(self): self.wizSheet = entityClasses.SpriteSheet("Resources/Images/LoadingWizard.png", 6, 7) self.aniPos = 7 self.fade = MenuItems.fadeIn() self.fade.fadeIn = True self.font = py.font.Font("Resources/Fonts/RPGSystem.ttf", 40) self.label = self.font.render("Loading...", 1, (255, 255, 255)) self.mod = self.font.size("Loading...") self.mod = (self.mod[0] / 2, self.mod[1] / 2)
def __init__(self): self.pos = (640, 360) self.bigRect = py.Rect(0, 0, 1280, 720) self.text = py.sprite.Group() self.text.add(MenuItems.textLabel("Paused", (640, 100), (255, 255, 255), "Resources\Fonts\RunicClear.ttf", 120, centred=True)) self.buttons = py.sprite.Group() self.buttons.add(MenuItems.Button("Resume", (640, 200), 60, (165,42,42), (255, 255, 255), "Resources\Fonts\RunicSolid.ttf", "resume", True)) self.buttons.add(MenuItems.Button("Main Menu", (640, 300), 60, (165,42,42), (255, 255, 255), "Resources\Fonts\RunicSolid.ttf", "mainMenu", True)) self.buttons.add(MenuItems.Button("Options", (640, 400), 60, (165,42,42), (255, 255, 255), "Resources\Fonts\RunicSolid.ttf", "options", True)) self.buttons.add(MenuItems.Button("Exit Game", (640, 500), 60, (165,42,42), (255, 255, 255), "Resources\Fonts\RunicSolid.ttf", "quit", True))
def downloadSave(): #TODO: test this MenuItems.shiftingGradient((0, 0, 'x')).draw() MenuItems.textLabel("Downloading Save", (1280 * 0.5, 720 * 0.5), (255, 255, 255), "Resources/Fonts/RPGSystem.ttf", int(30/640 * 1280), variable=False, centred=True).update() MenuItems.screenFlip() page = urllib.request.urlopen(v.url + "accounts/") accounts = page.read() accounts = pickle.loads(accounts) for un, vals in accounts.items(): if un == v.username: if v.password == vals["password"]: print(vals.keys()) print(vals["xp"]) if 'save' in vals.keys(): save = vals['save'] with open("Saves/Entities.save", "wb") as s: #pickle.dump(save["Entities"], s) s.write(save["Entities"]) with open("Saves/Inventory.save", "wb") as s: #pickle.dump(save["Inventory"], s) s.write(save["Inventory"]) with open("Saves/Variables.save", "wb") as s: #pickle.dump(save["Variables"], s) s.write(save["Variables"]) else: return "PASSWORD" return "USERNAME"
def __init__(self): v.PAUSED = True v.pauseType = "Death" v.playerDead = True self.back = py.image.tostring(v.screen, "RGBA") self.back = py.image.fromstring(self.back, (1280, 720), "RGBA") self.cycle = 100 self.red = py.Surface((1280, 720)).convert_alpha() self.ghost = entityClasses.playerGhost() v.p_class.direction = "Down" v.p_class.draw() self.pimg = v.p_class.image self.buttons = py.sprite.Group() self.buttons.add(MenuItems.Button("Respawn", (400, 375), 120, (200, 200, 200), (200, 0, 0), "Resources/Fonts/Vecna.otf", "rs", True)) self.buttons.add(MenuItems.Button("Load Save", (880, 375), 120, (200, 200, 200), (200, 0, 0), "Resources/Fonts/Vecna.otf", "ls", True)) self.buttons.add(MenuItems.Button("Quit", (640, 480), 120, (200, 200, 200), (200, 0, 0), "Resources/Fonts/Vecna.otf", "qt", True)) self.text = py.sprite.Group() self.text.add(MenuItems.textLabel("You Died!", (640, 255), (240, 240, 240), "Resources/Fonts/Vecna.otf", 180, centred=True))
def uploadSave(): MenuItems.shiftingGradient((0, 0, 'x')).draw() MenuItems.textLabel("Uploading Save", (1280 * 0.5, 720 * 0.5), (255, 255, 255), "Resources/Fonts/RPGSystem.ttf", int(30/640 * 1280), variable=False, centred=True).update() MenuItems.screenFlip() url = v.url + "senddata/" save = {} with open("Saves/Entities.save", "rb") as s: d = s.read() save["Entities"] = d with open("Saves/Inventory.save", "rb") as s: d = s.read() save["Inventory"] = d with open("Saves/Variables.save", "rb") as s: d = s.read() save["Variables"] = d xp = pickle.loads(d)["experience"]["Total"] payload = {'username': v.username, 'password': v.password, 'save': save, 'xp': xp} jpayload = json.dumps(str(payload)) # GET #r = requests.get(url) # GET with params in URL #r = requests.get(url, params=payload) # POST with form-encoded data #r = requests.post(url, data=payload) # POST with JSON r = requests.post(url, data=jpayload) # Response, status etc #print(r.text) print(r.status_code)