-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
195 lines (123 loc) · 4.33 KB
/
main.py
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Authors: TurBoss
# Models: TurBoss
# Main
#import pdb
import sys
import os
import time
import json
from pprint import pprint
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 CollisionTraverser, CollisionNode
from panda3d.core import CollisionHandlerQueue, CollisionRay
from panda3d.core import CollideMask
from panda3d.core import PandaNode,NodePath,Camera,TextNode
from panda3d.core import Vec3,Vec4,BitMask32, VBase4
from panda3d.core import Point3, TransparencyAttrib,TextNode
from panda3d.core import Filename,AmbientLight,DirectionalLight, PointLight, Spotlight
from panda3d.core import PerspectiveLens, OrthographicLens
from panda3d.core import TransformState
from panda3d.core import WindowProperties
from panda3d.core import PStatClient
from panda3d.physics import BaseParticleEmitter, BaseParticleRenderer
from panda3d.physics import PointParticleFactory, SpriteParticleRenderer
from panda3d.physics import LinearNoiseForce, DiscEmitter
from direct.particles.Particles import Particles
from direct.particles.ParticleEffect import ParticleEffect
from direct.particles.ForceGroup import ForceGroup
from panda3d.ai import *
from joypad import Joypad
from gui import StartMenu
from collision import MouseCollision, ShipCollision
from ship import Ship
from bg import Background
from rock import Rock
class World(ShowBase):
def __init__(self):
ShowBase.__init__(self)
print("- init game")
self.ship_control_type = 1 # 0 keyboard, 1 mouse, 2 joystick
self.accept('escape', self.do_exit)
self.accept('r', self.do_reset)
self.start_menu = StartMenu(self)
def do_exit(self):
self.cleanup()
print("- end game")
sys.exit(0)
def cleanup(self):
print("-- clean up")
#self.joypad.clean()
def do_reset(self):
self.cleanup()
self.setup()
def setup(self):
print("-- start level")
self.init_particles()
self.init_world()
self.init_ship()
self.init_lights()
self.init_camera()
self.mouse_collision = MouseCollision(self)
#self.joypad = Joypad()
# Tasks
self.taskMgr.add(self.update, 'update')
#self.taskMgr.add(self.joypad.update, 'updateJoypad')
def init_world(self):
print("-- init world")
self.bg = Background(self)
self.bg.draw()
self.rock1 = Rock(self, 5, 5)
self.rock2 = Rock(self, -5, 6)
self.rock3 = Rock(self, -5, 3)
self.taskMgr.add(self.bg.update, 'updateBackground')
def init_ship(self):
print("-- init ship")
self.ship = Ship(self)
self.ship_collision = ShipCollision(self.ship)
self.ship.draw()
self.taskMgr.add(self.ship.update, 'updateShip')
def init_particles(self):
base.enableParticles()
def init_lights(self):
print("-- init lights")
# Light
alight = AmbientLight('ambientLight')
alight.setColor(Vec4(0.1, 0.1, 0.1, 1))
alightNP = render.attachNewNode(alight)
dlight = DirectionalLight('directionalLight')
dlight.setDirection(Vec3(1, 1, -1))
dlight.setColor(Vec4(0.7, 0.7, 0.7, 1))
dlightNP = render.attachNewNode(dlight)
render.clearLight()
render.setLight(alightNP)
render.setLight(dlightNP)
def init_camera(self):
print("-- init camera")
self.disableMouse()
lens = OrthographicLens()
lens.setFilmSize(20, 15) # Or whatever is appropriate for your scene
self.cam.node().setLens(lens)
self.cam.setPos(0, -20, 0)
self.cam.lookAt(0, 0, 0)
def update(self, task):
dt = globalClock.getDt()
return task.cont
def main():
props = WindowProperties( )
props.setTitle('Hostil Galaxy')
props.setCursorFilename(Filename.binaryFilename('cursor.ico'))
props.setCursorHidden(False)
props.setFullscreen(False)
props.setSize(1024, 768)
game = World()
game.win.setClearColor((0, 0, 0, 1))
game.win.requestProperties(props)
game.setFrameRateMeter(True)
game.run()
if __name__ == "__main__": main()