Changed Projectstructure + Some changes on pygame-test
Added Username function Added Gameobjectposition lastframe Added prototype function stepping_movement Code cleanup
This commit is contained in:
106
modules/Game.py
Normal file
106
modules/Game.py
Normal file
@@ -0,0 +1,106 @@
|
||||
import modules.User as User
|
||||
import modules.Statics as Statics
|
||||
import Controls
|
||||
|
||||
from math import pi, sin, cos
|
||||
from direct.showbase.ShowBase import ShowBase
|
||||
from direct.task import Task
|
||||
from direct.actor.Actor import Actor
|
||||
from direct.interval.IntervalGlobal import Sequence
|
||||
from panda3d.core import Point3
|
||||
from panda3d.core import WindowProperties
|
||||
from panda3d.core import Loader
|
||||
from direct.showbase.ShowBase import ShowBase #Grundmodul zum Starten eines Fenster mit Grundszene
|
||||
from direct.gui.OnscreenText import OnscreenText #Ermöglicht die direkte Einblendung von Texten
|
||||
from direct.gui.DirectGui import * #Ermöglicht das Einblenden von Menüs und deren Manipulation
|
||||
from panda3d.core import TextNode #Texte
|
||||
from direct.task import Task
|
||||
from panda3d.core import Vec4, Vec3
|
||||
from panda3d.core import loadPrcFile #Ermöglicht das Laden eigener Konfigurationsdatein zur Panda3D API
|
||||
import random
|
||||
|
||||
class game(ShowBase):
|
||||
__debug_mode = [0,1,2,3,4]
|
||||
__debuglevel = 0
|
||||
__us = User.User
|
||||
__statics = Statics.statics
|
||||
#__ctrl = Controls.controls
|
||||
# __game_mechanics = Game_Mechanics.Game_Mechanics()
|
||||
__onscreentext1 = OnscreenText
|
||||
__actor1 = 0
|
||||
__p3d_conf = loadPrcFile("conf/conf.prc") #Pfadangabe zum .prc File
|
||||
|
||||
__keymap = {"up":False,
|
||||
"down":False,
|
||||
"left":False,
|
||||
"right":False
|
||||
}
|
||||
|
||||
|
||||
def __init__(self) -> None:
|
||||
ShowBase.__init__(self)
|
||||
self.__us = User.User()
|
||||
self.__statics = Statics.statics()
|
||||
#self.__ctrl = Controls.controls(self)
|
||||
|
||||
#font1 = self.loader.load_font("/usr/share/fonts/TTF/Inconsolata-UltraExpandedExtraBold.ttf")
|
||||
font1 = self.loader.load_font("data/fonts/Inconsolata-UltraExpandedExtraBold.ttf")
|
||||
self.__onscreentext1 = OnscreenText(self.__statics._menupoints[0], font=font1, pos= (0.1,0))
|
||||
self.__onscreentext1.setText("Ich bewege mich fortlaufen!")
|
||||
|
||||
#self.actor1 = Actor("data/models/myfile.bam")
|
||||
self.__actor1 = self.loader.load_model("data/models/myfile.bam")
|
||||
self.__actor1.getPos()
|
||||
self.__actor1.reparentTo(self.render)
|
||||
|
||||
self.accept('arrow_up', self.update_keystate, ["up", True])
|
||||
self.accept('arrow_up-up', self.update_keystate, ["up", False])
|
||||
self.accept('arrow_down', self.update_keystate, ["down", True])
|
||||
self.accept('arrow_down-up', self.update_keystate, ["down", False])
|
||||
self.accept('arrow_left', self.update_keystate, ["left", True])
|
||||
self.accept('arrow_left-up', self.update_keystate, ["left", False])
|
||||
self.accept('arrow_right', self.update_keystate, ["right", True])
|
||||
self.accept('arrow_right-up', self.update_keystate, ["right", False])
|
||||
|
||||
self.taskMgr.add(self.task1, "task1")
|
||||
self.taskMgr.add(self.keyboard_event, "keyboard_event")
|
||||
|
||||
#Zusatzfunktionen innerhalb instanzierter ShowBase-Klasse
|
||||
def update_keystate(self, controlName, controlState):
|
||||
self.__keymap[controlName] = controlState
|
||||
|
||||
def setDebugMode(self, debugmode:int):
|
||||
"""DEBUGLEVEL"""
|
||||
self.__debuglevel = debugmode
|
||||
|
||||
|
||||
#Taskfunctions and definitions
|
||||
def task1(self, task):
|
||||
_x = -2.8 + (task.time*0.3)
|
||||
#print("Task läuft seit: " + str(_x))
|
||||
#print(str(self.__actor1.getPos()))
|
||||
#self.__actor1.setPos(1*_x,1*_x,0)
|
||||
|
||||
if (_x >= 2.8000):
|
||||
print("Finished")
|
||||
return Task.again
|
||||
return Task.cont
|
||||
|
||||
def keyboard_event(self, task):
|
||||
|
||||
if(self.__debuglevel == 4): print(self.__keymap)
|
||||
|
||||
if (self.__keymap['up']):
|
||||
self.__actor1.setPos(self.__actor1.getPos() + Vec3(0,0.2,0))
|
||||
if(self.__debuglevel >= 3): print("Nach oben!")
|
||||
if (self.__keymap['down']):
|
||||
self.__actor1.setPos(self.__actor1.getPos() - Vec3(0,0.2,0))
|
||||
if(self.__debuglevel >= 3): print("Nach unten!")
|
||||
if (self.__keymap['left']):
|
||||
self.__actor1.setPos(self.__actor1.getPos() - Vec3(0.2,0,0))
|
||||
if(self.__debuglevel >= 3): print("Nach links!")
|
||||
if (self.__keymap['right']):
|
||||
self.__actor1.setPos(self.__actor1.getPos() + Vec3(0.2,0,0))
|
||||
if(self.__debuglevel >= 3): print("Nach rechts!")
|
||||
|
||||
return Task.cont
|
||||
15
modules/Statics.py
Normal file
15
modules/Statics.py
Normal file
@@ -0,0 +1,15 @@
|
||||
class statics:
|
||||
|
||||
_menutitle = "Hauptmenü"
|
||||
_menupoints = ("Einstellungen",
|
||||
"Highscore")
|
||||
_version = "1.0"
|
||||
|
||||
|
||||
|
||||
#def __init__(self) -> None:
|
||||
# for x in self._menupoints:
|
||||
# print(x)
|
||||
|
||||
# pass
|
||||
|
||||
130
modules/User.py
Normal file
130
modules/User.py
Normal file
@@ -0,0 +1,130 @@
|
||||
import sqlite3
|
||||
|
||||
#from sqlite3.dbapi2 import Cursor
|
||||
|
||||
# Start einer Userklasse
|
||||
# Lade, sofern vorhanden, Spieler aus der Datenbank
|
||||
|
||||
|
||||
class User:
|
||||
__usercount = 0
|
||||
__highscore = 0
|
||||
__uid = -1
|
||||
__username = ""
|
||||
__db_player_exist = 0
|
||||
__lastlogin = ""
|
||||
__played_time = 0
|
||||
__all_listed_users = list()
|
||||
#__sql_create_table = "CREATE TABLE IF NOT EXISTS user ( `id` INTEGER PRIMARY KEY, `username` VARCHAR(100) NOT NULL , `highscore` INT NOT NULL)"
|
||||
__sql_create_table = """CREATE TABLE IF NOT EXISTS "user" (
|
||||
"id" INTEGER UNIQUE,
|
||||
"username" VARCHAR(100) NOT NULL,
|
||||
"highscore" INT NOT NULL,
|
||||
"lastlogin" TEXT,
|
||||
"played_time" INTEGER,
|
||||
PRIMARY KEY("id")
|
||||
);"""
|
||||
|
||||
__sqlhandle = 0 #Statichandle
|
||||
|
||||
def __init__(self) -> None:
|
||||
|
||||
print("Userklasse erstellt")
|
||||
|
||||
if(len(self.__username) <= 0 or self.__user == "") and (self.__uid == -1):
|
||||
#print("Es existieren noch keine Daten!")
|
||||
|
||||
if(self.__sqlhandle == 0):
|
||||
self.__sqlhandle = sqlite3.connect("user.db")
|
||||
cursor = self.__sqlhandle.cursor()
|
||||
cursor.execute(self.__sql_create_table)
|
||||
self.__sqlhandle.commit()
|
||||
|
||||
def __del__(self):
|
||||
print("Userklasse zerstört")
|
||||
if(self.__sqlhandle != 0):
|
||||
print(self.__sqlhandle)
|
||||
print("Datenbank wird ordentlich geschlossen\n")
|
||||
self.__sqlhandle.close()
|
||||
#self.__sqlhandle = 0
|
||||
#print(self.__sqlhandle) Debug only
|
||||
|
||||
|
||||
def createuser(self, username :str):
|
||||
if(len(username) > 0):
|
||||
cursor = self.__sqlhandle.cursor()
|
||||
if(cursor != 0):
|
||||
if(self.__username == ""):
|
||||
print("SQLHANDLE:", self.__sqlhandle)
|
||||
sql = "INSERT INTO user (username, highscore, lastlogin) VALUES('"+username+"', 0, datetime())"
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
self.__sqlhandle.commit()
|
||||
print("User hinzugefügt!")
|
||||
except:
|
||||
print("Es ist beim Erstellen es Spielers ein Fehler aufgetreten!")
|
||||
else:
|
||||
print("Scheinbar besteht keine Verbindung zur Datenbank")
|
||||
else:
|
||||
print("Es wurde kein Name übergeben")
|
||||
|
||||
|
||||
def select(self, username):
|
||||
sql = "SELECT * FROM user WHERE username ='"+username+"'"
|
||||
sql_update_login_date = "UPDATE user SET lastlogin = datetime() WHERE username = '"+username+"'"
|
||||
try:
|
||||
c = self.__sqlhandle.cursor()
|
||||
row = c.execute(sql)
|
||||
res = row.fetchone()
|
||||
c.execute(sql_update_login_date)
|
||||
|
||||
self.__sqlhandle.commit()
|
||||
self.__uid = res[0]
|
||||
self.__username = res[1]
|
||||
self.__highscore = res[2]
|
||||
self.__lastlogin = res[3]
|
||||
|
||||
except:
|
||||
print("Fehler bei der Nutzerauswahl")
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def getplayed_time(self):
|
||||
return self.__played_time
|
||||
|
||||
def getlastlogin(self):
|
||||
return self.__lastlogin
|
||||
|
||||
def getusername(self):
|
||||
return self.__username
|
||||
|
||||
|
||||
def gethighscore(self):
|
||||
return self.__highscore
|
||||
|
||||
def getuid(self):
|
||||
return self.__uid
|
||||
|
||||
def listallusers(self):
|
||||
cursor = self.__sqlhandle.cursor()
|
||||
|
||||
for row in cursor.execute("SELECT * FROM user"):
|
||||
print("ID:",row[0],", Username:", row[1], ", Highscore:", row[2])
|
||||
self.__all_listed_users.append(row[1])
|
||||
print (self.__all_listed_users)
|
||||
|
||||
cursor.close()
|
||||
self.__sqlhandle.commit()
|
||||
|
||||
return self.__all_listed_users
|
||||
|
||||
def checkuserdb(self):
|
||||
cursor = self.__sqlhandle.cursor()
|
||||
rows=cursor.execute("SELECT * FROM user")
|
||||
rows_count =len(list(rows))
|
||||
if(rows_count >= 1):
|
||||
#print("Es gibt", rows_count, "Datensätze")
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
Reference in New Issue
Block a user