Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import random
- import simplegui
- #http://www.codeskulptor.org/#user43_rE3EqTnb00CuIk0_0.py
- WIDTH = 1920 * .8
- HEIGHT = 1080 * .8
- #0-start menu, 1- character creation, 2-spawn
- gamestate = 0
- def newgame():
- global gamestate
- gamestate = 0
- def keydown(key):
- global gamestate
- if gamestate == 1:
- strength.incremental(key)
- if key == simplegui.KEY_MAP['space']:
- gamestate = 1
- print "spacebar"
- if key == simplegui.KEY_MAP['left']:
- if gamestate == 1:
- strength.incremental('left')
- elif key == simplegui.KEY_MAP['right']:
- if gamestate == 1:
- strength.incremental('right')
- # elif key == simplegui.KEY_MAP['up']:
- # elif key == simplegui.KEY_MAP['space']:
- def keyup(key):
- # if key == simplegui.KEY_MAP['left']:
- # my_ship.increment_angle_vel()
- # elif key == simplegui.KEY_MAP['right']:
- # my_ship.decrement_angle_vel()
- # elif key == simplegui.KEY_MAP['up']:
- # my_ship.set_thrust(False)
- pass
- def click(pos):
- if gamestate == 1:
- if pos[0] > strength.position[0] and pos[0] < strength.position[0]+strength.size[0]:
- if pos[1] > strength.position[1] and pos[1] < strength.position[1]+strength.size[1]:
- strength.update(pos)
- class statbar:
- def __init__(self, name, minvalue, maxvalue, increment, size, position):
- self.name = name
- self.minvalue = minvalue
- self.maxvalue = maxvalue
- self.increment = increment
- self.size = size
- self.position = position
- self.currentval = 0.0
- self.color = "Gray"
- def __str__(self):
- print "Sliding Stat Bar: " + self.name
- print "Current Value: " + self.currentval
- def incremental(self,key):
- if key == "right" and self.currentval < self.maxvalue:
- self.currentval += self.increment
- elif key == "left" and self.currentval > self.minvalue:
- self.currentval -= self.increment
- def update(self, pos):
- self.currentval = ((pos[0]-self.position[0])/self.size[0])*100.0//self.increment * self.increment
- # percent = ((pos[0]-self.position[0])/self.size[0])*100.0
- # if percent > 100-self.increment:
- # self.currentval = self.maxvalue
- # else:
- # self.currentval = ((pos[0]-self.position[0])/self.size[0])*100.0//self.increment * self.increment
- print self.currentval
- def draw(self, canvas):
- canvas.draw_polygon((self.position, (self.position[0] + self.size[0], self.position[1]),
- (self.position[0] + self.size[0], self.position[1]+self.size[1]),
- (self.position[0], self.position[1]+self.size[1])), 1, "Red", "Red")
- canvas.draw_text(self.name + " = " + str(self.currentval),
- (self.position[0]+self.size[0]/15,self.position[1]+self.size[1]/1.45), 20, "White")
- def draw_handler(canvas):
- global gamestate
- if gamestate == 0:
- canvas.draw_text("Call of the Eternals", (WIDTH/3.5, HEIGHT/2), 80, "Red")
- canvas.draw_text("Press Spacebar to Begin", (WIDTH/2.8, HEIGHT * .7), 40, "Red")
- elif gamestate == 1:
- canvas.draw_text("Character Creation", (WIDTH/3.5, HEIGHT/8), 80, "Red")
- strength.draw(canvas)
- strength = statbar("Strength", 0, 100, 1, (400,30), (WIDTH/10, HEIGHT/6))
- frame = simplegui.create_frame("Call of the Eternals", WIDTH, HEIGHT)
- frame.set_keyup_handler(keyup)
- frame.set_keydown_handler(keydown)
- frame.set_mouseclick_handler(click)
- frame.set_canvas_background("black")
- frame.set_draw_handler(draw_handler)
- frame.start()
Advertisement
Add Comment
Please, Sign In to add comment