-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the imp,entation of title screen, add button implentation for…
… future use, add comments to code files
- Loading branch information
Showing
5 changed files
with
77 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pygame as pg | ||
class button: | ||
def __init__(self,posx,posy,width,height): | ||
self.x=posx | ||
self.y=posy | ||
self.width=width | ||
self.height=height | ||
def onclick(self,action,mousepos): | ||
if mousepos[0] > self.x: | ||
if mousepos[1] > self.y: | ||
if mousepos[0] < self.x+self.width: | ||
if mousepos[1] < self.y+self.height: | ||
action() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
''' | ||
Codes used to initalize pygame and config | ||
''' | ||
import pygame as pg | ||
import warnings | ||
import json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
''' | ||
Start screen codes, Nothing more | ||
''' | ||
import pygame as pg | ||
from . import textview as tv | ||
import os | ||
import json | ||
class startscr: | ||
bgexist=0 | ||
textview="" | ||
font4title="" | ||
def __init__(self): | ||
self.bgexist=0 | ||
self.textview=tv.textview() | ||
self.font4title=self.textview.new_text() | ||
if os.access("../res/bg.png",os.R_OK): | ||
self.bg=pg.image.load("../res/bg.png").convert() | ||
self.bgexist=1 | ||
print("Initilization of start screen complete successfully") | ||
#loading texts | ||
def load_title(self,main): | ||
if main.config_exist==1: | ||
config={} | ||
with open(main.config_path,'r') as config_reader:#read configs | ||
config=json.load(config_reader) | ||
#load title text properties from config.json | ||
self.textview.textlist[self.font4title].set_color(config["font_color"]) | ||
self.textview.textlist[self.font4title].set_font(config["font"]) | ||
self.textview.textlist[self.font4title].set_content(config["title"]) | ||
self.textview.textlist[self.font4title].set_size(config["font_size"]) | ||
print("Text is load successfully") | ||
def show_title(self,window,main): | ||
self.textview.textlist[self.font4title].set_text() | ||
self.textview.textlist[self.font4title].render_surface() | ||
F_width,F_height=self.textview.textlist[self.font4title].get_dimensions() | ||
window.blit(self.textview.textlist[self.font4title].get_surface(),((main.get_reso_horizontal()-F_width)/2,100)) | ||
pg.display.update() | ||
def show_background(self,window): | ||
if self.bgexist==1: | ||
window.blit(self.bg,(0,0)) | ||
pg.display.update() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,26 @@ | ||
from codes import init as base | ||
from codes import startscreen as ss | ||
from codes import button | ||
import pygame as pg | ||
import pygame.locals as pgl | ||
import os | ||
import json | ||
from codes import textview | ||
#intialize objects | ||
main=base.inital() | ||
main.init_window() | ||
mainwindow=main.get_screen_object() | ||
bgexist=0 | ||
textlist=textview.textview() | ||
font4title_index=textlist.new_text() | ||
font4title=textlist.get_object(font4title_index) | ||
|
||
if os.access("./res/bg.png",os.R_OK): | ||
bg=pg.image.load("./res/bg.png").convert() | ||
bgexist=1 | ||
|
||
if main.config_exist==1: | ||
config={} | ||
with open(main.config_path,'r') as config_reader:#read configs | ||
config=json.load(config_reader) | ||
#load title text properties from config.json | ||
font4title.set_color(config["font_color"]) | ||
font4title.set_font(config["font"]) | ||
font4title.set_content(config["title"]) | ||
font4title.set_size(config["font_size"]) | ||
|
||
font4title.set_text() | ||
|
||
start_screen=ss.startscr() | ||
start_screen.load_title(main) | ||
easter_egg_quit_button=button.button(10,10,100,100) | ||
while True: | ||
for event in pg.event.get(): | ||
if event.type == pgl.QUIT: | ||
main.onquit() | ||
if event.type==pgl.MOUSEBUTTONDOWN: | ||
mousepos=pg.mouse.get_pos() | ||
easter_egg_quit_button.onclick(main.onquit(),mousepos) | ||
|
||
#show background if it's there | ||
if bgexist==1: | ||
mainwindow.blit(bg,(0,0)) | ||
|
||
font4title.render_surface() | ||
#get title text size for show it in center | ||
F_width,F_height=font4title.get_dimensions() | ||
start_screen.show_background(mainwindow) | ||
#show title text | ||
mainwindow.blit(font4title.get_surface(),((main.get_reso_horizontal()-F_width)/2,100)) | ||
start_screen.show_title(mainwindow,main) | ||
#Update display | ||
pg.display.update() |