def __init__(self): super().__init__() font = pygame.font.Font(getResource("fonts/Lato/Lato-Black.ttf"), 32) titleFont = pygame.font.Font( getResource("fonts/Lato/Lato-Black.ttf"), 64 ) self.title = titleFont.render("Trash Hunt", True, (255, 255, 255)) self.instruction = font.render( "Press Enter to Start", True, (255, 255, 255) ) self.shouldStart = False # Audio self.gameMusic = GameAudio(0) self.gameMusic.playLooped(getResource("audio/bgmLoopIntro.wav"), 0.3) # Background self.scrollSpeed = 300 self.lastUpdated = time_ns() self.foreground = ForegroundRail((0, 410), -600, -self.scrollSpeed) self.middleground = MiddlegroundRail( (0, 200), -600, -self.scrollSpeed * PARALLAX_RATIO ) self.background = BackgroundRail( (0, 0), -1024, -self.scrollSpeed * PARALLAX_RATIO ** 2 )
def __init__(self, position: Tuple[float, float], limit: float, speed: float): source = pygame.image.load( getResource("images/underwater-fantasy/sand.png")) source = pygame.transform.scale2x(source) images = [source] * 5 super().__init__(position, limit, speed, images)
def __init__(self, score: int): super().__init__() font = pygame.font.Font(getResource("fonts/Lato/Lato-Black.ttf"), 32) self.title = font.render( "Game Over", True, (255, 0, 0) ) self.scoreMessage = font.render( f"Your score is : {score}", True, (255, 255, 255) ) self.instruction = font.render( "Press 'R' key to restart.", True, (255, 255, 255) ) self.shouldStart = False
def calcIngredientQuality(conn, spawnID, schematicID, user): # Calculate the quality of ingredient resource for schematic resQuality = None if spawnID != None: qualityData = schematics.getQualityData(conn, schematicID) qualityResSum = 0 qualityResCount = 0.0 spawn = resource.getResource(conn, 1, user, spawnID, None, None) for prop in qualityData: for item in prop: if getattr(spawn.stats, item[0]) != None: qualityResCount += item[1] qualityResSum += getattr(spawn.stats, item[0]) * item[1] if qualityResCount > 0: resQuality = qualityResSum / qualityResCount else: resQuality = None return resQuality
def calcIngredientQuality(conn, spawnID, schematicID, user): # Calculate the quality of ingredient resource for schematic resQuality = None if spawnID != None: qualityData = schematics.getQualityData(conn, schematicID) qualityResSum = 0 qualityResCount = 0.0 spawn = resource.getResource(conn, 1, user, spawnID, None, None) for prop in qualityData: for item in prop: if getattr(spawn.stats, item[0]) != None: qualityResCount += item[1] qualityResSum += getattr(spawn.stats, item[0])*item[1] if qualityResCount > 0: resQuality = qualityResSum/qualityResCount else: resQuality = None return resQuality
def addIngredient(conn, recipeID, spawnID, schematicID, user): # Try to add a spawn to an available ingredient slot returnStr = "" filledCandidates = 0 ingredientsUpdated = 0 s = resource.getResource(conn, 1, user, spawnID, None, None) ingCursor = conn.cursor() ingSql = "SELECT si.ingredientName, ingredientObject, ingredientResource FROM tSchematicIngredients si LEFT JOIN (SELECT ingredientName, ingredientResource FROM tRecipeIngredients WHERE recipeID=" + str( recipeID ) + ") ri ON si.ingredientName = ri.ingredientName WHERE schematicID='" + schematicID + "' ORDER BY ingredientQuantity DESC, si.ingredientName;" ingCursor.execute(ingSql) ingRow = ingCursor.fetchone() while ingRow != None: if s.groupList.find("," + ingRow[1] + ",") > -1: if ingRow[2] == None: cursor = conn.cursor() # create new record for ingredient slot ingredientQuality = recipe.calcIngredientQuality( conn, spawnID, schematicID, user) tempSQL = "INSERT INTO tRecipeIngredients (recipeID, ingredientName, ingredientResource, ingredientQuality) VALUES (" + str( recipeID) + ",'" + ingRow[0] + "'," + str( spawnID) + "," + n2n(ingredientQuality) + ");" cursor.execute(tempSQL) ingredientsUpdated += cursor.rowcount cursor.close() else: filledCandidates += 1 ingRow = ingCursor.fetchone() if ingredientsUpdated > 0: returnStr = "Added " + s.spawnName + " to " + str( ingredientsUpdated) + " available slot(s)." else: if filledCandidates > 0: returnStr = "Any slots that could take the resource are already filled." else: returnStr = "That resource cannot be used in any of the slots of that schematic." conn.commit() ingCursor.close() return returnStr
def addIngredient(conn, recipeID, spawnID, schematicID, user): # Try to add a spawn to an available ingredient slot returnStr = "" filledCandidates = 0 ingredientsUpdated = 0 s = resource.getResource(conn, 1, user, spawnID, None, None) ingCursor = conn.cursor() ingSql = "SELECT si.ingredientName, ingredientObject, ingredientResource FROM tSchematicIngredients si LEFT JOIN (SELECT ingredientName, ingredientResource FROM tRecipeIngredients WHERE recipeID=" + str(recipeID) + ") ri ON si.ingredientName = ri.ingredientName WHERE schematicID='" + schematicID + "' ORDER BY ingredientQuantity DESC, si.ingredientName;" ingCursor.execute(ingSql) ingRow = ingCursor.fetchone() while ingRow != None: if s.groupList.find("," + ingRow[1] + ",") > -1: if ingRow[2] == None: cursor = conn.cursor() # create new record for ingredient slot ingredientQuality = recipe.calcIngredientQuality(conn, spawnID, schematicID, user) tempSQL = "INSERT INTO tRecipeIngredients (recipeID, ingredientName, ingredientResource, ingredientQuality) VALUES (" + str(recipeID) + ",'" + ingRow[0] + "'," + str(spawnID) + "," + n2n(ingredientQuality) + ");" cursor.execute(tempSQL) ingredientsUpdated += cursor.rowcount cursor.close() else: filledCandidates += 1 ingRow = ingCursor.fetchone() if ingredientsUpdated > 0: returnStr = "Added " + s.spawnName + " to " + str(ingredientsUpdated) + " available slot(s)." else: if filledCandidates > 0: returnStr = "Any slots that could take the resource are already filled." else: returnStr = "That resource cannot be used in any of the slots of that schematic." conn.commit() ingCursor.close() return returnStr
def main(): # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' form = cgi.FieldStorage() uiTheme = '' # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid, 2592000) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' # Get recipe id from path path = [] if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] recipeHTML = '' slotHTML = '' schemImageName = '' schematicDetailsHTML = '' ingTypes = '' ingGroups = '' pageType = 'recipe' if len(path) > 0: recipeID = dbShared.dbInsertSafe(path[0]) url = url + '/' + recipeID r = ghObjectRecipe.schematicRecipe() if logged_state == 1: # Look up recipe info try: conn = dbShared.ghConn() cursor = conn.cursor() except Exception: recipeHTML = "Error: could not connect to database" if (cursor and recipeID.isdigit()): cursor.execute( 'SELECT recipeID, userID, tRecipe.schematicID, recipeName, (SELECT imageName FROM tSchematicImages si WHERE si.schematicID=tRecipe.schematicID AND si.imageType=1) AS schemImage, schematicName, complexity FROM tRecipe INNER JOIN tSchematic ON tRecipe.schematicID = tSchematic.schematicID WHERE recipeID=' + recipeID + ';') row = cursor.fetchone() if (row != None): if row[1] == currentUser: # main recipe data if (row[4] != None): schemImageName = row[4] else: schemImageName = 'none.jpg' r.recipeID = row[0] r.schematicID = row[2] r.recipeName = row[3] r.schematicImage = schemImageName # schematic quality data schematicDetailsHTML = '<div><a href="' + ghShared.BASE_SCRIPT_URL + 'schematics.py/' + row[ 2] + '" title="Go to schematic page.">' + row[ 5] + '</a></div>' schematicDetailsHTML += '<div>Complexity: ' + str( row[6]) + '</div>' expGroup = '' expProp = '' schematicDetailsHTML += '<td valign="top"><h3>Qualities</h3><ul id="qualitiesList" style="margin-top:6px;">' expCursor = conn.cursor() expCursor.execute( 'SELECT tSchematicQualities.expQualityID, expProperty, expGroup, statName, statWeight, weightTotal FROM tSchematicQualities INNER JOIN tSchematicResWeights ON tSchematicQualities.expQualityID = tSchematicResWeights.expQualityID WHERE schematicID="' + r.schematicID + '" ORDER BY expGroup, expProperty, statName;') expRow = expCursor.fetchone() while (expRow != None): if (expGroup != expRow[2]): tmpName = expRow[2].replace('_', ' ') schematicDetailsHTML = schematicDetailsHTML + '<li class="groupText">' + tmpName + '</li>' expGroup = expRow[2] if (expProp != expRow[1]): tmpName = expRow[1].replace('_', ' ') schematicDetailsHTML = schematicDetailsHTML + '<li class="schemQualityProperty altText">' + tmpName + '</li>' expProp = expRow[1] schematicDetailsHTML += '<li class="schemQualityItem" tag="' + expRow[ 3] + ':' + str( (expRow[4] * 1.0 / expRow[5]) * 100 ) + '"><span class="inlineBlock" style="width:100px;">' + ghNames.getStatName( expRow[3]) + (': </span><span>%.0f' % ( (expRow[4] * 1.0 / expRow[5]) * 100) ) + '%</span></li>' expRow = expCursor.fetchone() expCursor.close() # Look up ingredient data ri = None sqlStr = 'SELECT si.ingredientName, ingredientResource, ingredientObject, ingredientQuantity, ingredientContribution, rt.containerType tcontainer, rg.containerType gcontainer, rt.resourceTypeName, rg.groupName, ingredientQuality FROM tSchematicIngredients si LEFT JOIN (SELECT ingredientName, ingredientResource, ingredientQuality FROM tRecipeIngredients WHERE recipeID=' + str( r.recipeID ) + ') ri ON si.ingredientName = ri.ingredientName LEFT JOIN tResourceType rt ON si.ingredientObject = rt.resourceType LEFT JOIN tResourceGroup rg ON si.ingredientObject = rg.resourceGroup WHERE schematicID="' + r.schematicID + '" ORDER BY ingredientQuantity DESC, si.ingredientName' ingCursor = conn.cursor() ingCursor.execute(sqlStr) ingRow = ingCursor.fetchone() while (ingRow != None): if ingRow[5] == None: if ingRow[6] == None: container = 'default' objectName = ingRow[2].rpartition( '/')[2].replace('_', ' ') if objectName[-4:] == '.iff': objectName = objectName[:-4] else: ingGroups += '"' + ingRow[2] + '",' container = ingRow[6] objectName = ingRow[8] else: ingTypes += '"' + ingRow[2] + '",' container = ingRow[5] objectName = ingRow[7] # get details of ingredient resource for schematic resDetails = '' if ingRow[1] != None and (ingRow[5] != None or ingRow[6] != None): spawn = resource.getResource( conn, logged_state, currentUser, ingRow[1], None, None) resDetails = 'Loaded with: ' + spawn.spawnName + ', ' + spawn.resourceTypeName + '<br />' + spawn.getStatList( ) r.recipeIngredients.append( ghObjectRecipe.recipeIngredient( ingRow[2], ingRow[1], ingRow[0], ingRow[3], container, objectName, ingRow[9], resDetails)) ingRow = ingCursor.fetchone() ingCursor.close() if ingTypes != '': ingTypes = ingTypes[:-1] if ingGroups != '': ingGroups = ingGroups[:-1] slotHTML = r.getIngredientSlots() else: recipeHTML = "That is not your recipe." else: recipeHTML = "The recipe ID given could not be found." cursor.close() else: # Render recipe home if any non number in sub path pageType = 'home' conn.close() else: recipeHTML = "You must be logged in to manage recipes." else: recipeHTML = 'You have not specified a recipe to edit, would you like to create a new one?<div style="float:right;"><button type=button value="New Recipe" class="ghButton" onclick="addRecipe();">New Recipe</button></div>' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL env.globals['MOBILE_PLATFORM'] = ghShared.getMobilePlatform( os.environ['HTTP_USER_AGENT']) template = env.get_template('recipe.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(), recipeHTML=recipeHTML, slotHTML=slotHTML, schematicDetailsHTML=schematicDetailsHTML, ingTypes=ingTypes, ingGroups=ingGroups, pageType=pageType, recipeID=r.recipeID, recipeName=r.recipeName, schemImageName=schemImageName)
import pygame from typing import Tuple from config import X_LOWER_LIM from KinemeticBody import KinematicBody from resource import getResource from animation import splitImage import random FRAME_RATE = 10 # per second SHARK_SPRITE_SHEET = pygame.image.load(getResource("images/shark.png")) class Shark(KinematicBody): def __init__( self, position: Tuple[float, float], velocity: Tuple[float, float] = None, ): self.frames = splitImage(SHARK_SPRITE_SHEET, 4, 3)[3:6] self.currentFrame = 0 self.timeToNextFrame = 0 if velocity is None: velocity = (random.randint(-250, -200), 0) super().__init__(self.frames[0], position, velocity) def update(self, delta: float): # Animate. self.timeToNextFrame -= delta if self.timeToNextFrame <= 0: self.currentFrame = (self.currentFrame + 1) % len(self.frames) self.image = self.frames[self.currentFrame]
import pygame from StartScene import StartScene from config import SCREEN_HEIGHT, SCREEN_WIDTH from resource import getResource # Initialize the pygame pygame.mixer.pre_init(44100, -16, 6, 512) pygame.init() # Create the screen screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) # Title and Icon pygame.display.set_caption("Trash hunt") icon = pygame.image.load(getResource("images/icon.png")) pygame.display.set_icon(icon) # Scene scene = StartScene() # Game Loop RUNNING = True while RUNNING: screen.fill((0, 0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: RUNNING = False scene.handleEvent(event)
def buildBestRecipe(conn, schem, inventory, user): #sys.stderr.write(str(schem) + '\n') r = ghObjectRecipe.schematicRecipe() r.schematicID = schem[0] r.recipeName = schem[4] if schem[5] != None: r.schematicImage = schem[5] # Look up the schematic ingredients oingSql = 'SELECT ingredientObject, Sum(ingredientContribution) FROM tSchematicIngredients WHERE schematicID="' + schem[0] + '" AND ingredientType = 0 GROUP BY ingredientObject;' oingCursor = conn.cursor() oingCursor.execute(oingSql) # Find other potential ingredients and their quality from inventory filledIng = True oingRow = oingCursor.fetchone() ingredients = [] while oingRow != None and oingRow[0] != None: thisFilled = False # Iterate over the option for each ingredient and save top quality to new list for resType in inventory.iterkeys(): if str(resType).find('\'' + oingRow[0] + '\'') > -1: thisFilled = True spawns = inventory[resType].split() for s in spawns: spawnQuality = recipe.calcIngredientQuality(conn, s.split('|')[0].strip(','), schem[0], user) ingredients.append((oingRow[0], s, spawnQuality)) if thisFilled == False: filledIng = False break oingRow = oingCursor.fetchone() oingCursor.close() oingRow = None # If all ingredients can be found in inventory if filledIng: # Add the top quality scores found from sorted lists as new suggestion ingredients = sorted(ingredients, key=lambda ing: ing[2], reverse=True) cingSql = 'SELECT si.ingredientName, ingredientObject, ingredientQuantity, ingredientContribution, rt.containerType tcontainer, rg.containerType gcontainer, rt.resourceTypeName, rg.groupName FROM tSchematicIngredients si LEFT JOIN tResourceType rt ON si.ingredientObject = rt.resourceType LEFT JOIN tResourceGroup rg ON si.ingredientObject = rg.resourceGroup WHERE schematicID="' + r.schematicID + '" ORDER BY ingredientQuantity DESC, si.ingredientName' cingCursor = conn.cursor() cingCursor.execute(cingSql) cingRow = cingCursor.fetchone() while (cingRow != None): for ing in ingredients: if ing[0] == cingRow[1]: # get details of ingredient resource and add to recipe if cingRow[4] == None: if cingRow[5] == None: container = 'default' objectName = cingRow[1].rpartition('/')[2].replace('_',' ') if objectName[-4:] == '.iff': objectName = objectName[:-4] else: container = cingRow[5] objectName = cingRow[7] else: container = cingRow[4] objectName = cingRow[6] resDetails = '' spawn = resource.getResource(conn, 1, user, ing[1].split('|')[0].strip(','), None, None) resDetails = 'Loaded with: ' + spawn.spawnName + ', ' + spawn.resourceTypeName + '<br />' + spawn.getStatList() r.recipeIngredients.append(ghObjectRecipe.recipeIngredient(cingRow[1], ing[1].split('|')[0].strip(','), cingRow[0], cingRow[2], container, objectName, ing[2], resDetails)) break cingRow = cingCursor.fetchone() cingCursor.close() return r
import pygame from typing import Tuple from KinemeticBody import KinematicBody from config import SCREEN_HEIGHT, SCREEN_WIDTH from resource import getResource from animation import splitImage FRAME_RATE = 10 PLAYER_SPRITE_SHEET = pygame.image.load( getResource("images/underwater-diving/player/player-swimming.png")) # Player sprite. class Player(KinematicBody): def __init__( self, position: Tuple[float, float], ): self.frames = splitImage(PLAYER_SPRITE_SHEET, 1, 7) self.currentFrame = 0 self.timeToNextFrame = 0 super().__init__(self.frames[0], position) self.damping_constant = 1 self.ACCEL_CONST = 2500 def update(self, delta: float): # Animate. self.timeToNextFrame -= delta if self.timeToNextFrame <= 0: self.currentFrame = (self.currentFrame + 1) % len(self.frames) self.image = self.frames[self.currentFrame]
def main(): # Get current url try: url = os.environ['SCRIPT_NAME'] except KeyError: url = '' form = cgi.FieldStorage() uiTheme = '' # Get Cookies useCookies = 1 cookies = Cookie.SimpleCookie() try: cookies.load(os.environ['HTTP_COOKIE']) except KeyError: useCookies = 0 if useCookies: try: currentUser = cookies['userID'].value except KeyError: currentUser = '' try: loginResult = cookies['loginAttempt'].value except KeyError: loginResult = 'success' try: sid = cookies['gh_sid'].value except KeyError: sid = form.getfirst('gh_sid', '') try: uiTheme = cookies['uiTheme'].value except KeyError: uiTheme = '' try: galaxy = cookies['galaxy'].value except KeyError: galaxy = "8" else: currentUser = '' loginResult = form.getfirst('loginAttempt', '') sid = form.getfirst('gh_sid', '') # escape input to prevent sql injection sid = dbShared.dbInsertSafe(sid) # Get a session logged_state = 0 linkappend = '' disableStr = '' if loginResult == None: loginResult = 'success' sess = dbSession.getSession(sid, 2592000) if (sess != ''): logged_state = 1 currentUser = sess if (uiTheme == ''): uiTheme = dbShared.getUserAttr(currentUser, 'themeName') if (useCookies == 0): linkappend = 'gh_sid=' + sid else: disableStr = ' disabled="disabled"' if (uiTheme == ''): uiTheme = 'crafter' # Get recipe id from path path = [] if os.environ.has_key('PATH_INFO'): path = os.environ['PATH_INFO'].split('/')[1:] path = [p for p in path if p != ''] recipeHTML = '' slotHTML = '' schematicSummaryHTML = '' schematicDetailsHTML = '' ingTypes = '' ingGroups = '' pageType = 'recipe' if len(path) > 0: recipeID = dbShared.dbInsertSafe(path[0]) url = url + '/' + recipeID if logged_state == 1: # Look up recipe info try: conn = dbShared.ghConn() cursor = conn.cursor() except Exception: recipeHTML = "Error: could not connect to database" if (cursor and recipeID.isdigit()): cursor.execute('SELECT recipeID, userID, tRecipe.schematicID, recipeName, (SELECT imageName FROM tSchematicImages si WHERE si.schematicID=tRecipe.schematicID AND si.imageType=1) AS schemImage, schematicName, complexity FROM tRecipe INNER JOIN tSchematic ON tRecipe.schematicID = tSchematic.schematicID WHERE recipeID=' + recipeID + ';') row = cursor.fetchone() if (row != None): if row[1] == currentUser: # main recipe data if (row[4] != None): schemImageName = row[4] else: schemImageName = 'none.jpg' schematicSummaryHTML = '<img src="/images/schematics/' + schemImageName + '" class="schematics" />' r = ghObjectRecipe.schematicRecipe() r.recipeID = row[0] r.schematicID = row[2] r.recipeName = row[3] r.schematicImage = schemImageName recipeHTML = '<div><a href="" id="nameLink" onclick="$(this).hide();$(\'#nameEditor\').show();$(\'#recipeName\').focus();return false;" title="Click to edit name." class="nameLink">' + r.recipeName + '</a></div><div id="nameEditor" style="display:none;"><input type="text" id="recipeName" size="30" maxlength="255" value="' + r.recipeName + '" onblur="$(\'#nameLink\').html(this.value).show();$(\'#nameEditor\').hide();" onkeyup="if(event.keyCode == 13){$(\'#nameLink\').html(this.value).show();$(\'#nameEditor\').hide();}"/></div><div style="float:right;"><button type=button value="Save" class="ghButton" onclick="saveRecipe(' + recipeID + ',$(\'#recipeName\').val());">Save</button> <button type=button value="Delete" class="ghButton" onclick="deleteRecipe(\'recipe\',' + str(r.recipeID) + ');">Delete</button></div>' recipeHTML += '<div class="footer"/><div id="factoryCalc" style="text-align:left">Calculate Factory Run: <input type="text" id="factoryAmount" size="6" maxlength="4"/> units. <button type="button" value="Calculate" class="ghButton" onclick="getFactoryList(parseInt($(\'#factoryAmount\').val()))">Calculate</button><div id="factoryResults"></div></div>' # schematic quality data schematicDetailsHTML = '<div><a href="' + ghShared.BASE_SCRIPT_URL + 'schematics.py/' + row[2] + '" title="Go to schematic page.">' + row[5] + '</a></div>' schematicDetailsHTML += '<div>Complexity: ' + str(row[6]) + '</div>' expGroup = '' expProp = '' schematicDetailsHTML += '<td valign="top"><h3>Qualities</h3><ul id="qualitiesList" style="margin-top:6px;">' expCursor = conn.cursor() expCursor.execute('SELECT tSchematicQualities.expQualityID, expProperty, expGroup, statName, statWeight, weightTotal FROM tSchematicQualities INNER JOIN tSchematicResWeights ON tSchematicQualities.expQualityID = tSchematicResWeights.expQualityID WHERE schematicID="' + r.schematicID + '" ORDER BY expGroup, expProperty, statName;') expRow = expCursor.fetchone() while (expRow != None): if (expGroup != expRow[2]): tmpName = expRow[2].replace('_',' ') schematicDetailsHTML = schematicDetailsHTML + '<li class="groupText">' + tmpName + '</li>' expGroup = expRow[2] if (expProp != expRow[1]): tmpName = expRow[1].replace('_',' ') schematicDetailsHTML = schematicDetailsHTML + '<li class="schemQualityProperty altText">' + tmpName + '</li>' expProp = expRow[1] schematicDetailsHTML += '<li class="schemQualityItem" tag="' + expRow[3] + ':' + str((expRow[4]*1.0/expRow[5])*100) + '"><span class="inlineBlock" style="width:100px;">' + ghNames.getStatName(expRow[3]) + (': </span><span>%.0f' % ((expRow[4]*1.0/expRow[5])*100)) + '%</span></li>' expRow = expCursor.fetchone() expCursor.close() # Look up ingredient data ri = None sqlStr = 'SELECT si.ingredientName, ingredientResource, ingredientObject, ingredientQuantity, ingredientContribution, rt.containerType tcontainer, rg.containerType gcontainer, rt.resourceTypeName, rg.groupName, ingredientQuality FROM tSchematicIngredients si LEFT JOIN (SELECT ingredientName, ingredientResource, ingredientQuality FROM tRecipeIngredients WHERE recipeID=' + str(r.recipeID) + ') ri ON si.ingredientName = ri.ingredientName LEFT JOIN tResourceType rt ON si.ingredientObject = rt.resourceType LEFT JOIN tResourceGroup rg ON si.ingredientObject = rg.resourceGroup WHERE schematicID="' + r.schematicID + '" ORDER BY ingredientQuantity DESC, si.ingredientName' ingCursor = conn.cursor() ingCursor.execute(sqlStr) ingRow = ingCursor.fetchone() while (ingRow != None): if ingRow[5] == None: if ingRow[6] == None: container = 'default' objectName = ingRow[2].rpartition('/')[2].replace('_',' ') if objectName[-4:] == '.iff': objectName = objectName[:-4] else: ingGroups += '"' + ingRow[2] + '",' container = ingRow[6] objectName = ingRow[8] else: ingTypes += '"' + ingRow[2] + '",' container = ingRow[5] objectName = ingRow[7] # get details of ingredient resource for schematic resDetails = '' if ingRow[1] != None and (ingRow[5] != None or ingRow[6] != None): spawn = resource.getResource(conn, logged_state, currentUser, ingRow[1], None, None) resDetails = 'Loaded with: ' + spawn.spawnName + ', ' + spawn.resourceTypeName + '<br />' + spawn.getStatList() r.recipeIngredients.append(ghObjectRecipe.recipeIngredient(ingRow[2], ingRow[1], ingRow[0], ingRow[3], container, objectName, ingRow[9], resDetails)) ingRow = ingCursor.fetchone() ingCursor.close() if ingTypes != '': ingTypes = ingTypes[:-1] if ingGroups != '': ingGroups = ingGroups[:-1] slotHTML = r.getIngredientSlots() else: recipeHTML = "That is not your recipe." else: recipeHTML = "The recipe ID given could not be found." cursor.close() else: # Render recipe home if any non number in sub path pageType = 'home' recipeHTML = 'Home<div style="float:right;"><button type=button value="New Recipe" class="ghButton" onclick="addRecipe();">New Recipe</button></div>' conn.close() else: recipeHTML = "You must be logged in to manage recipes." else: recipeHTML = 'You have not specified a recipe to edit, would you like to create a new one?<div style="float:right;"><button type=button value="New Recipe" class="ghButton" onclick="addRecipe();">New Recipe</button></div>' pictureName = dbShared.getUserAttr(currentUser, 'pictureName') print 'Content-type: text/html\n' env = Environment(loader=FileSystemLoader('templates')) env.globals['BASE_SCRIPT_URL'] = ghShared.BASE_SCRIPT_URL template = env.get_template('recipe.html') print template.render(uiTheme=uiTheme, loggedin=logged_state, currentUser=currentUser, loginResult=loginResult, linkappend=linkappend, url=url, pictureName=pictureName, imgNum=ghShared.imgNum, planetList=ghLists.getPlanetList(), galaxyList=ghLists.getGalaxyList(), professionList=ghLists.getProfessionList(), recipeHTML=recipeHTML, slotHTML=slotHTML, schematicSummaryHTML=schematicSummaryHTML, schematicDetailsHTML=schematicDetailsHTML, ingTypes=ingTypes, ingGroups=ingGroups, pageType=pageType)
def __init__(self, position: Tuple[float, float], limit: float, speed: float): source = pygame.image.load( getResource("images/underwater-fantasy/foreground-merged.png")) images = [source] * 5 super().__init__(position, limit, speed, images)
import pygame import random from typing import Tuple, Set from config import X_LOWER_LIM from os import walk from os.path import join from KinemeticBody import KinematicBody from resource import getResource GARBAGE_IMAGES: Set[str] = set() for (dirpath, _, filenames) in walk(getResource("images/garbage")): for filename in filenames: GARBAGE_IMAGES.add(join(dirpath, filename)) def getRandomGarbageImagePath(): return random.sample(GARBAGE_IMAGES, 1)[0] # Player sprite. class Garbage(KinematicBody): def __init__( self, position: Tuple[float, float], velocity: Tuple[float, float] = None, ): if velocity is None: velocity = (random.randint(-150, -100), 0) super().__init__(pygame.image.load(getRandomGarbageImagePath()), position, velocity)