I have 2 images, one is supposed to be on top of the other. This works fine until one of the "movement" keys are hit (a,s,d,w)
import sqlite3 as sqlite
import wx
username=None
class MainWindow():
def drawmap(self):
self.map4_31="C:/python27/game/4_31.gif"
self.map1=wx.Image(self.map4_31,wx.BITMAP_TYPE_GIF).ConvertToBitmap()
height=self.map1.GetHeight()
width=self.map1.GetWidth()
self.map1.map4_31 = wx.StaticBitmap(frame, -1, self.map1, (270, 170), (width,height))
def char(self,username):
con=sqlite.connect('Characters.sqlite')
cur=con.cursor()
sql="""SELECT locationx,locationy FROM Characters WHERE name=%s""" % \
(username)
cur.execute(sql)
data=cur.fetchall()
positionx=str(data[0][0]).replace(" ","")
positiony=str(data[0][1]).replace(" ","")
positionx=int(positionx)
positiony=int(positiony)
self.playerFile = "C:/python27/game/player_tile.gif"
self.playerbmp = wx.Image(self.playerFile,wx.BITMAP_TYPE_GIF).ConvertToBitmap()
height=self.playerbmp.GetHeight()
width=self.playerbmp.GetWidth()
self.playerbmp.playerbitmap = wx.StaticBitmap(frame, -1, self.playerbmp, (positionx,positiony), (width,height))
def OnKeyPress(self,event):
keycode=event.GetKeyCode()
con=sqlite.connect('Characters.sqlite')
cur=con.cursor()
sql="SELECT locationx,locationy FROM Characters WHERE name=%s""" % \
(username)
cur.execute(sql)
data=cur.fetchall()
locationx=data[0][0]
locationy=data[0][1]
if keycode==87:
locationy=locationy-10
sql="UPDATE Characters SET locationy=%s WHERE name=%s""" % \
(locationy,username)
cur.execute(sql)
con.commit()
con.close()
for char in frame.GetChildren():
char.Destroy()
self.drawmap()
self.char(username)
if keycode==83:
locationy=locationy+10
sql="UPDATE Characters SET locationy=%s WHERE name=%s""" % \
(locationy,username)
cur.execute(sql)
con.commit()
con.close()
for child in frame.GetChildren():
child.Destroy()
self.drawmap()
self.char(username)
if keycode==68:
locationx=locationx+10
sql="UPDATE Characters SET locationx=%s WHERE name=%s""" % \
(locationx,username)
cur.execute(sql)
con.commit()
con.close()
for child in frame.GetChildren():
child.Destroy()
self.drawmap()
self.char(username)
if keycode==65:
locationx=locationx-10
sql="UPDATE Characters SET locationx=%s WHERE name=%s""" % \
(locationx,username)
cur.execute(sql)
con.commit()
con.close()
for child in frame.GetChildren():
child.Destroy()
self.drawmap()
self.char(username)
class loginWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,size = (600, 400))
self.Center()
def user(self):
global username
con=sqlite.connect('Characters.sqlite')
cur=con.cursor()
name=wx.TextEntryDialog(None, "Username", "Username")
if name.ShowModal()==wx.ID_OK:
username=name.GetValue()
username="'" + username + "'"
sql="""SELECT * FROM Characters WHERE name=%s""" % \
(username)
cur.execute(sql)
data=cur.fetchall()
if len(data)==0:
print "incorrect username"
else:
return username
con.close()
def password(self,username):
password=wx.TextEntryDialog(None, "Password", "Password")
if password.ShowModal()==wx.ID_OK:
password=password.GetValue()
con=sqlite.connect('Characters.sqlite')
cur=con.cursor()
sql="""SELECT * FROM Characters WHERE name=%s""" % \
(username)
cur.execute(sql)
data=cur.fetchall()
if password!=data[0][2]:
print "incorrect password"
else:
return password
while True:
app=wx.PySimpleApp()
if username==None:
username = loginWindow().user()
password=loginWindow().password(username)
frame=wx.Frame(None,-1,'game',size = (600, 600))
MainWindow().drawmap()
MainWindow().char(username)
frame.Bind(wx.EVT_KEY_DOWN, MainWindow().OnKeyPress)
frame.Show()
frame.Center()
app.MainLoop()