ok I got it working, but i have a different problem now. I am trying to load the position of the image, I open the file, save the first 3-digit number in the variable positionx, the second in positiony, and use rstrip("\r\n") to strip the new lines. Then, I use posisitonx and positiony as the coordinates, and I get this error:
TypeError: Expected a 2-tuple of integers or a wxPoint object.
import wx
level=1
attack=1
defense=1
health=5
app = wx.PySimpleApp()
class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,size = (600, 400))
self.panel = wx.Panel(self,-1)
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPress)
self.Center()
self.drawmap()
try:
filehandle = open ('location.txt', 'r')
except IOError:
filehandle = open ('location.txt', 'w')
filehandle.write('270\r\n170')
filehandle.close
filehandle = open ('location.txt', 'r')
filehandle.seek(0)
positionx = filehandle.readline().rstrip("\n\r")
positiony = filehandle.readline()
self.char(positionx,positiony)
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(self.panel, -1, self.map1, (270, 170), (width,height))
def char(self,positionx,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(self.panel, -1, self.playerbmp, (positionx,positiony), (width,height))
def moveup(self):
global playerpositiony
playerpositiony+=30
print playerpositiony
self.char(playerpositiony)
def OnKeyPress(self,event):
keycode=event.GetKeyCode()
print keycode
if keycode==87:
self.moveup()
if __name__ == "__main__":
MainWindow()
MainWindow().Show()
app.MainLoop()