Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # draw enemey in game update, need to do jump, need to do coollisions with platforms. need to implement the colision class still but it has been made.
- import simplegui
- import codeskulptor
- import random
- from user301_734IOKEVrN_0 import Vector
- #constants
- CANVAS_WIDTH = 1000
- CANVAS_HEIGHT = 600
- CLEARANCE = 300
- PLATFORM_SPACING = 100
- NUM_PLAT = CANVAS_HEIGHT//PLATFORM_SPACING
- #global variables
- welcome_screen_timer = 0
- highscore = 0
- attempts = 0
- timer_after_hits_player = 0
- count = 0
- image = simplegui.load_image("https://raw.githubusercontent.com/0xForge/GameDevUni35/bb681c9841c3e5ee34ca63d3a5d4ba0c8cba3f72/player_character_animaitons/absorb_fall/absorb_fall_00.png?token=AeotiQthMQ7uiTyOvUX3sH3gtThVpMDrks5ckjMwwA%3D%3D")
- #game mode global variables
- background_colour = ''
- platform_colour = ''
- enemy_damage = 0
- enemy_speed = 0
- class Platform:
- def __init__(self, height):
- self.plat_per_row = random.randrange(2,5)
- #Depending on how many platformss are in a row, the platform sizes will differ
- if self.plat_per_row == 2:
- distence_between_plats = random.randrange(40, 100)
- left_offset = random.randrange(0, 100)
- if left_offset >= 25:
- plat_width = random.randrange(370, 420)
- if left_offset < 25:
- plat_width = random.randrange(420, 470)
- elif self.plat_per_row == 3:
- distence_between_plats = random.randrange(40, 50)
- left_offset = random.randrange(0, 100)
- if left_offset >= 25:
- plat_width = random.randrange(230, 270)
- if left_offset < 25:
- plat_width = random.randrange(245, 285)
- elif self.plat_per_row == 4:
- distence_between_plats = random.randrange(50, 80)
- left_offset = random.randrange(0, 100)
- if left_offset >= 25:
- plat_width = random.randrange(160, 205)
- if left_offset < 25:
- plat_width = random.randrange(180, 220)
- #creates coordinates left and right x coordinates for each platform in a row
- self.left_1 = left_offset
- self.right_1 = self.left_1 + plat_width
- self.left_2 = self.right_1 + distence_between_plats
- self.right_2 = self.left_2 + plat_width
- self.left_3 = self.right_2 + distence_between_plats
- self.right_3 = self.left_3 + plat_width
- self.left_4 = self.right_3 + distence_between_plats
- self.right_4 = self.left_4 + plat_width
- self.height = height
- def draw_platform(self, canvas, state):
- #Draws the platforms depending on how many platofrms are meant to be in a row
- if self.plat_per_row == 2:
- canvas.draw_line([self.left_1, self.height],
- [self.right_1,self.height], 10, platform_colour)
- canvas.draw_line([self.left_2, self.height],
- [self.right_2,self.height], 10, platform_colour)
- elif self.plat_per_row == 3:
- canvas.draw_line([self.left_1, self.height],
- [self.right_1,self.height], 10, platform_colour)
- canvas.draw_line([self.left_2, self.height],
- [self.right_2,self.height], 10, platform_colour)
- canvas.draw_line([self.left_3, self.height],
- [self.right_3,self.height], 10, platform_colour)
- else:
- canvas.draw_line([self.left_1, self.height],
- [self.right_1,self.height], 10, platform_colour)
- canvas.draw_line([self.left_2, self.height],
- [self.right_2,self.height], 10, platform_colour)
- canvas.draw_line([self.left_3, self.height],
- [self.right_3,self.height], 10, platform_colour)
- canvas.draw_line([self.left_4, self.height],
- [self.right_4,self.height], 10, platform_colour)
- class ColisionsPlatform:
- def __init__(self, platform, player):
- self.player = player
- self.platform = platform # so platform is goign o be cordinates of each line
- def update(self):
- if self.platform.hitUp(self.player):# hit up was going to be a function in platfrom class but that was when i thought each platfrom could be teated individually
- print("hitup")
- #player.getP
- if self.platform.hitBottom(self.player)
- print("hit bottom")
- class Character:
- def __init__(self):
- self.vel = Vector(0,0)
- self.rad = 25
- self.pos = Vector(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - self.rad)- 5))#add position
- self.image = simplegui.load_image('https://raw.githubusercontent.com/0xForge/GameDevUni35/master/player_character_animaitons/full_sprite_sheet/full_sprite_sheet.png?token=AVJ2jOa9eIVlFINQHLRtYaeV3iCp7jHqks5clnDGwA%3D%3D')
- self.width = self.image.get_width()
- self.height = self.image.get_height()
- self.columns = 11
- self.rows = 4
- self.frameSize = (self.width // self.columns, self.height // self.rows)
- self.frameCentre = (self.frameSize[0]/2, self.frameSize[1]/2)
- self.lives = 3
- self.score = 0
- def reduceLives(self):
- self.lives = self.lives-1
- self.pos = Vector(CANVAS_WIDTH / 2, ((CANVAS_HEIGHT - self.rad)- 5)) #puts player back at begining
- def draw(self,canvas):
- canvas.draw_circle((self.pos.x, self.pos.y),self.rad,1,'Blue','Blue')
- self.drawScore(canvas)
- self.drawLives(canvas)
- def update(self):
- global count
- self.pos.add(self.vel)
- self.vel.multiply(0.85)
- if (count & 60 == 0):
- self.score += 1
- def died(self):# will have to implement the
- global highscore
- if (self.lives==0):
- if (self.score<highscore):
- highscore = self.score
- frame.set_draw_handler(drawWelcome)
- def drawScore(self,canvas):
- canvas.draw_text("Time: "+str(self.score), [10, 20], 18, "White")# player or what ever you intiate player oo
- def drawLives(self,canvas):
- canvas.draw_text("lives: "+str(self.lives), [10, 40], 18, "White")
- def check(self,canvas):
- self.update()
- self.died()
- self.draw(canvas)
- def getPlayerPos(self):
- return self.pos
- class Keyboard:
- def __init__(self):
- self.right = False
- self.left = False
- self.up = False
- def keyDown(self, key):
- if key == simplegui.KEY_MAP['right']:
- self.right = True
- elif key == simplegui.KEY_MAP['left']:
- self.left = True
- def keyUp(self, key):
- if key == simplegui.KEY_MAP['right']:
- self.right = False
- elif key == simplegui.KEY_MAP['left']:
- self.left = False
- class Interaction:
- def __init__(self, character, keyboard):
- self.character = character
- self.keyboard = keyboard
- def update(self):
- if self.keyboard.right:
- self.character.vel = Vector(4,0)
- elif self.keyboard.left:
- self.character.vel = Vector(-4,0)
- #if self.keyboard.up:
- # self.character.vel = #need to do
- class Enemy:
- def __init__(self, pos):
- self.pos = pos
- self.vel = Vector(0,0)
- self.rad=40
- self.image = simplegui.load_image('https://raw.githubusercontent.com/0xForge/GameDevUni35/master/fb6e7c32-f658-4776-bc35-2a8a2f8aeb07%20(1).jpeg?token=AVJ2jGJTIWfJ37O2p2tpySSEFIQ44Oxnks5cllfzwA%3D%3D')#
- self.width = self.image.get_width()
- self.height = self.image.get_height()
- self.columns = 11
- self.rows = 4
- self.frameSize = (self.width // self.columns, self.height // self.rows)
- self.frameCentre = (self.frameSize[0]/2, self.frameSize[1]/2)
- def getPos(self):
- return self.pos
- def draw(self, canvas):
- canvas.draw_circle((self.pos.x, self.pos.y),self.rad,1,'Orange','Orange')
- def update(self, character):
- if self.pos.getP() < character.pos.getP():
- self.vel = Vector(1,0)
- elif self.pos.getP() > character.pos.getP():
- self.vel = Vector(-1,0)
- self.pos.add(self.vel)
- class CollsionsPlayerEnemey():
- def __inint__(player,enemey):
- self.player = player
- self.enemey = enemey
- def playerDistance(self):
- playerDistance = self.player.getPos - self.enemey.getPos.length()#dont know what .length
- return playerDistance
- def enemeyColission(self):
- if self.playerDistance()< 20:#20 is collision distance
- self.player.reduceLives()
- def update(self):
- self.enemeyColission()
- class mainMenu:
- def quitButton(self):
- exit()
- #Changes all the variables in relation to the classic game mode
- def playClassicMode(self):
- global attempts
- global background_colour
- global platform_colour
- global enemy_damage
- global enemy_speed
- background_colour = 'blue'
- platform_colour = 'cyan'
- enemy_damage = 1
- enemy_speed = 1
- attempts += 1
- print("playing classic gamemode...")
- Game()
- #Changes all the variables in relation to the hard game mode
- def playHardMode(self):
- global attempts
- global background_colour
- global platform_colour
- global enemy_damage
- global enemy_speed
- background_colour = 'red'
- platform_colour = 'pink'
- enemy_damage = 2
- enemy_speed = 2
- attempts += 1
- print("playing hard gamemode...")
- Game()
- def mainMenu(self):
- frame.set_draw_handler(self.drawMenu)
- frame.add_button("Classic", self.playClassicMode, 100)
- frame.add_button("Hard", self.playHardMode, 100)
- frame.add_button("Quit", self.quitButton, 100)
- #Handler to draw menu screen
- def drawMenu(self,canvas):
- canvas.draw_text("Main Menu", [380, 100], 48, "Blue")
- canvas.draw_text("Best Time: " + str(highscore), [400, 200], 32, "White")
- canvas.draw_text("Attempts: "+str(attempts) , [410, 250], 32, "White")
- canvas.draw_text("How To Play:", [400, 400], 32, "Red")
- canvas.draw_text("The goal of Oblong is to traverse the platfroms unt- ", [250, 430], 24, "Orange")
- canvas.draw_text("ill you reach the top of the screen. You will have", [250, 450], 24, "Orange")
- canvas.draw_text("to dodge many hostiles and projectiles. You control", [250, 470], 24, "Orange")
- canvas.draw_text("the blue Oblong using the arrow keys to move up,", [250, 490], 24, "Orange")
- canvas.draw_text("left and right.", [400, 520], 24, "Orange")
- # Handler to draw welcome screen
- def drawWelcome(self, canvas):
- global count
- canvas.draw_text("Welcome To...", [360,200], 48, "Blue")
- canvas.draw_text("Oblong!", [420,300], 48, "Blue")
- frame.set_canvas_background('Black')
- #canvas.draw_image(image, , , ,)#set a background image#add the sprite/ have animation of it jumping
- if(count > 300):# displays welcome for 5 seconds
- self.mainMenu()
- count += 1
- class Game:
- def __init__(self):
- #self.frame = simplegui.create_frame("Platforms", CANVAS_WIDTH, CANVAS_HEIGHT)
- self.platform_list = [Platform(idx * PLATFORM_SPACING) for idx in range(1, NUM_PLAT)]
- #self.frame.start()
- self.kbd = Keyboard()
- self.player = Character()
- self.inter = Interaction(self.player, self.kbd)
- self.enemyOne = Enemy(Vector(CANVAS_WIDTH/4,CANVAS_HEIGHT-20))#enemey doesnt spawn
- frame.set_draw_handler(self.draw)
- frame.set_keyup_handler(self.kbd.keyUp)
- frame.set_keydown_handler(self.kbd.keyDown)
- def start_game(self):
- frame.set_draw_handler(drawGame)
- self.platform_list = [Platform(idx * PLATFORM_SPACING) for idx in range(0, NUM_PLAT)]
- def draw(self, canvas):
- global count
- frame.set_canvas_background(background_colour)
- canvas.draw_line((0, CANVAS_HEIGHT), (CANVAS_WIDTH, CANVAS_HEIGHT), 10, platform_colour)
- for plat_index in range(0, NUM_PLAT):
- if plat_index < NUM_PLAT-1:
- self.platform_list[plat_index].draw_platform(canvas, self)
- self.player.check(canvas)
- self.inter.update()
- #at end
- count += 1# only need once
- # Create a frame and assign callbacks to event handlers
- mainMenu = mainMenu()
- frame = simplegui.create_frame("Oblong", CANVAS_WIDTH, CANVAS_HEIGHT)
- frame.set_draw_handler(mainMenu.drawWelcome)
- # Start the frame animation
- frame.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement