Added player and level and world objects.
This commit is contained in:
52
robotgame/worldobject.py
Normal file
52
robotgame/worldobject.py
Normal file
@@ -0,0 +1,52 @@
|
||||
# This file is part of ROBOTGAME
|
||||
#
|
||||
# ROBOTGAME is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation, either version 3 of the License, or (at your option) any later
|
||||
# version.
|
||||
#
|
||||
# ROBOTGAME is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# ROBOTGAME. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
||||
#
|
||||
# worldobject.py
|
||||
# --------------------
|
||||
# date created : Tue Aug 7 2012
|
||||
# copyright : (C) 2012 Sakse Dalum
|
||||
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
||||
|
||||
"""
|
||||
A generic world object.
|
||||
"""
|
||||
|
||||
class WorldObject(object):
|
||||
def __init__(self, x, y, speed=5, tile_x=64, tile_y=48):
|
||||
self.__dict__.update(locals())
|
||||
|
||||
self.move_x, self.move_y = self.x, self.y
|
||||
|
||||
def move(self, move_x, move_y):
|
||||
if self.move_x == self.x and self.move_y == self.y:
|
||||
self.move_x += move_x * self.tile_x
|
||||
self.move_y += move_y * self.tile_y
|
||||
|
||||
def update(self, e, t, dt):
|
||||
if self.x > self.move_x:
|
||||
self.x -= min(self.speed * dt * self.tile_x,
|
||||
abs(self.x - self.move_x))
|
||||
if self.x < self.move_x:
|
||||
self.x += min(self.speed * dt * self.tile_x,
|
||||
abs(self.x - self.move_x))
|
||||
if self.y > self.move_y:
|
||||
self.y -= min(self.speed * dt * self.tile_y,
|
||||
abs(self.y - self.move_y))
|
||||
if self.y < self.move_y:
|
||||
self.y += min(self.speed * dt * self.tile_y,
|
||||
abs(self.y - self.move_y))
|
||||
|
||||
self.x, self.y = int(self.x), int(self.y)
|
||||
Reference in New Issue
Block a user