Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/run.py
blob: 9682b3dc4e4d2fed09f72ee76a32d368ff9c51c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# filename: run.py
#
# Ceibal Rol
# Copyright (C) 2008,2009 Gabriel Balbuena
#
# This program 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.
#
# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Ceibal Jam http://ceibaljam.org

import pygame
from pygame.locals import *

from universe import Map
from entity   import Player
from menu     import Menu

from ogre import Ogre

SCREEN_SIZE = (640, 480)


def start_game():

	fullscreen  = False

	pygame.display.init()
	screen = pygame.display.set_mode(SCREEN_SIZE) # re init screen
	clock = pygame.time.Clock()

	#--------------------------------------------------------------------
	map = Map('./data/maps/map1.level')
	player = Player(map)

	ogre = Ogre(map)
	# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	allSprites = pygame.sprite.Group(ogre)
	#--------------------------------------------------------------------

	exit = False

	#----------------------------------------------------------------------------------------------------- - - -
	while not exit:
		clock.tick(60)
		#--------------------------------------------------------------------
		for event in pygame.event.get():
			# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			if event.type == QUIT:
				exit()
			# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
			elif event.type == KEYDOWN:
				if event.key == K_f:
					fullscreen = not fullscreen
					if fullscreen:
						screen = pygame.display.set_mode(SCREEN_SIZE,0,32)
					else:
						screen = pygame.display.set_mode(SCREEN_SIZE,FULLSCREEN,32)
				if event.key == pygame.K_UP:
					ogre.moving = True
					ogre.speed += 50/3
					ogre.turnUp()
				elif event.key == pygame.K_DOWN:
					ogre.moving = True
					ogre.speed += 50/3
					ogre.turnDown()
				elif event.key == pygame.K_LEFT:
					ogre.moving = True
					ogre.speed += 50/3
					ogre.turnLeft()
				elif event.key == pygame.K_RIGHT:
					ogre.moving = True
					ogre.speed += 50/3
					ogre.turnRight()

		if ogre.speed > 0:
			if ogre.speed > 25:
				ogre.speed = 25

			ogre.speed = ogre.speed - 1

			if ogre.speed == 0:
				ogre.moving = False

		#map = map.mirar_a(ogre.rect) re implementar
		#--------------------------------------------------------------------
		map.update()
		# actualiza la posicion de la camara
		# se actualiza el personaje todo el tiempo,
		# de modo que este pueda alterar la posicionn de la camara.
		#player.update() 
		# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		map.imprimir(screen)
		#player._print(screen)
		#ogre._print(screen)
		#--------------------------------------------------------------------
		allSprites.clear(screen, map.field)
		allSprites.update()
		allSprites.draw(screen)
		# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		pygame.display.update()
		#--------------------------------------------------------------------
	#----------------------------------------------------------------------------------------------------- - - -
def show_options(): print " menu de opciones "

def creditos(): print " desplegando creditos "

def exit_game():
	import sys
	sys.exit(0)

if __name__ == '__main__':

	exit = False

	options = 	[
			("Jugar", start_game),
			("Opciones", show_options),
			("Creditos", creditos),
			("Salir", exit_game)
			]

	pygame.init()
	pygame.display.set_caption("Ceibal Rol - PreAlpha 0.0.8")

	screen = pygame.display.set_mode(SCREEN_SIZE) # init screen

	background = pygame.image.load("./data/menu/fondo.png").convert()
	background = pygame.transform.scale(background, SCREEN_SIZE)
	#background = pygame.transform.smoothscale(background, SCREEN_SIZE)

	logo  = pygame.image.load("./data/menu/logo.png").convert_alpha()


	menu = Menu(options)

	while not exit:
		for e in pygame.event.get():
			if e.type == QUIT:
				exit = True

		#-Menu - - - - - - - - - - - - - - - -
		screen.blit(background, (0, 0))
		screen.blit(logo, (30, 0))

		menu.update()
		menu._print(screen)
		#- - - - - - - - - - - - - - - - - - -

		pygame.display.flip()
		pygame.time.delay(10)