Jump to content
  • Advertisement

RedLynx

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

122 Neutral

About RedLynx

  • Rank
    Newbie
  1. RedLynx

    PyGame Sprite Sheet Help

    Thanks for your help dmreichard. when i made those classes i knew in the back of my mind that there was probably a better way for me to do it i just didnt know how. also eventually found a good sprite sheet snippet that needed a bit of tweaking for use with python 3.3 and to fit nicely with my code.   Thanks :D
  2. Hey guys i have been making a game (trying to make a game) in PyGame how ever i'm afraid that my code is pretty messy and that the way i have coded things i might not be able to use sprite sheets to animate characters and whatnot i have tried various functions and modules on the internet to try to get my code use sprite sheets  i'm hoping you guys can help me see where i can clean up my code and hopefully help me implement a system to handle sprite sheets. here's my source   import sys import pygame import math import random from pygame.locals import * # Define colours white = (255, 255, 255) black = (0, 0, 0) red = (255, 0, 0) green = (0, 255, 0) blue = (0, 0, 255) magenta =(255, 45, 255) # Variables player_x = 0 player_y = 0 player_xspeed = 0 player_yspeed = 0 show_inventory = False # Initialize Pygame pygame.init() # Set size of screen and stuff :P size = (800, 480) screen = pygame.display.set_mode(size) pygame.display.set_caption("Engine") # Loop until user exits the application done = False # Manage the screen update speed clock = pygame.time.Clock() # Mouse visibility pygame.mouse.set_visible(0) # Declare classes class Character(): level = 0 experience = 0 attributes = {"strength":0,"dexterity":0,"intelligence":0,"wisdom":0,"constitution":0,"charisma":0,"agility":0} items = {"h_potion":0,"m_potion":0,"antidote":0} equiped = {"w_primary":"none", "w_secondary":"none", "armor_helm":"none", "armor_gauntlets":"none", "armor_torso":"none", "armor_greaves":"none", "armor_boots":"none"} inventory = [] class Fighter(Character): Character.level = 1 Character.experience = 0 Character.attributes["strength"] += 16 Character.attributes["dexterity"] = 13 Character.attributes["intelligence"] = 11 Character.attributes["wisdom"] = 11 Character.attributes["constitution"] = 12 Character.attributes["charisma"] = 15 Character.attributes["agility"] = 7 Character.items["h_potion"] = 2 Character.items["m_potion"] = 2 Character.items["antidote"] = 1 Character.equiped["w_primary"] = "s_sword" Character.equiped["w_secondary"] = "leather_shield" Character.equiped["armor_torso"] = "leather cuircass" class Rogue(Character): Character.level = 1 Character.experience = 0 Character.attributes["strength"] = 13 Character.attributes["dexterity"] = 16 Character.attributes["intelligence"] = 13 Character.attributes["wisdom"] = 11 Character.attributes["constitution"] = 10 Character.attributes["charisma"] = 16 Character.attributes["agility"] = 8 Character.items["h_potion"] = 2 Character.items["m_potion"] = 2 Character.items["antidote"] = 1 Character.equiped["w_primary"] = "knife" Character.equiped["armor_torso"] = "cloth_armor" class Mage(Character): Character.level = 1 Character.experience = 0 Character.attributes["strength"] = 12 Character.attributes["dexterity"] = 13 Character.attributes["intelligence"] = 13 Character.attributes["wisdom"] = 16 Character.attributes["constitution"] = 10 Character.attributes["charisma"] = 9 Character.attributes["agility"] = 5 Character.items["h_potion"] = 2 Character.items["m_potion"] = 2 Character.items["antidote"] = 1 Character.equiped["w_primary"] = "q_staff" Character.equiped["armor_torso"] = "mage_robes" class Sorcerer(Character): Character.level = 1 Character.experience = 0 Character.attributes["strength"] = 14 Character.attributes["dexterity"] = 15 Character.attributes["intelligence"] = 16 Character.attributes["wisdom"] = 13 Character.attributes["constitution"] = 10 Character.attributes["charisma"] = 10 Character.attributes["agility"] = 5 Character.items["h_potion"] = 2 Character.items["m_potion"] = 2 Character.items["antidote"] = 1 Character.equiped["w_primary"] = "q_staff" Character.equiped["armor_torso"] = "sorcerers_robes" class Demigod(Character): Character.level = 1 Character.experience = 0 Character.attributes["strength"] = 17 Character.attributes["dexterity"] = 16 Character.attributes["intelligence"] = 16 Character.attributes["wisdom"] = 15 Character.attributes["constitution"] = 14 Character.attributes["charisma"] = 15 Character.attributes["agility"] = 8 Character.items["h_potion"] = 2 Character.items["m_potion"] = 2 Character.items["antidote"] = 1 Character.equiped["w_primary"] = "l_sword" Character.equiped["w_secondary"] = "g_axe" Character.equiped["armor_torso"] = "iron_chainmail" Character.equiped["armor_helm"] = "iron_helm" Character.equiped["armor_gauntlets"] = "iron_gauntlets" Character.equiped["armor_greaves"] = "iron_greaves" Character.equiped["armor_boots"] = "iron_boots" def print_stats(self): print("Level: ", Character.level,"\nExperience: ", Character.experience) class Player_sprite(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("player.png") self.image.convert() self.image.set_colorkey(black) self.rect = self.image.get_rect() class Inventory_window(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("inventory_menu.png") self.image.convert() self.image.set_colorkey(black) self.rect = self.image.get_rect() class Cursor(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.image.load("cursor.png") self.image.convert() self.rect = self.image.get_rect() invent_w = Inventory_window() invent_w.rect.x = 50 invent_w.rect.y = 50 m_cursor = Cursor() non_collision_sprites = pygame.sprite.Group() non_collision_sprites.add(m_cursor) inventory_sprites = pygame.sprite.Group() inventory_sprites.add(invent_w) player = Player_sprite() all_sprites = pygame.sprite.Group() all_sprites.add(player) def inventory(): inventory_sprites.draw(screen) #---------- MAIN LOOP ---------- while done == False: # Event Processing BELOW # When the use clicks close, exit the main loop for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: player_yspeed = -8 if event.key == pygame.K_DOWN: player_yspeed = 8 if event.key == pygame.K_LEFT: player_xspeed = -8 if event.key == pygame.K_RIGHT: player_xspeed = 8 # Inventory if event.key == pygame.K_TAB: if show_inventory == True: show_inventory = False else: show_inventory = True if event.type == pygame.KEYUP: if event.key == pygame.K_UP: player_yspeed = 0 if event.key == pygame.K_DOWN: player_yspeed = 0 if event.key == pygame.K_LEFT: player_xspeed = 0 if event.key == pygame.K_RIGHT: player_xspeed = 0 """player_x = player_x + player_xspeed player_y = player_y + player_yspeed player.rect.x = player_x player.rect.y = player_y""" # Event Processing ABOVE # Game Logic BELOW #Get mouse Position mouse_pos = pygame.mouse.get_pos() mouse_x = mouse_pos[0] mouse_y = mouse_pos[1] m_cursor.rect.x = mouse_x m_cursor.rect.y = mouse_y # Game Logic ABOVE # Draw Code BELOW # Clear Screen screen.fill(black) # Draw sprites all_sprites.draw(screen) non_collision_sprites.draw(screen) if show_inventory == True: inventory() # Draw Code ABOVE # Update screen pygame.display.flip() # Limit Framerate clock.tick(20) # Exit pygame pygame.quit()    Thanks Guys
  3. RedLynx

    Splitting up Spritesheets

    Thanks this helps a lot :D
  4. RedLynx

    Splitting up Spritesheets

    I never really thought about doing it the other way around? I had an idea in my head of having the the sheet in a regular grid then splitting it up in the engine somehow then give each grid square a coordinate.   and wow i never know tools like that existed renderhjs. i guess i didn't look around enough.    this information does clarify things thanks guys
  5. Hey Everyone   This is my first thread one this wonderful forum. i have mucked around with game development for about 5 or 6 years but i have never done anything serious or fulling completed a game project. this time i have been getting serious and learning C++ i intend to use OpenGL and SDL. and i also intend to build the engine from scratch. The game is going to use sprites and tiles so my question to you guys for now is how would i go about splitting up the spritesheets into an imaginary grid within the engine.   Cheers. :P
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!