Tải bản đầy đủ (.pdf) (17 trang)

đồ án đồ họa máy tính

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (556.44 KB, 17 trang )

TRƯỜNG ĐẠI HỌC XÂY DỰNG
KHOA CNTT – BỘ MÔN CÔNG NGHỆ PHẦN MỀM





ĐỒ ÁN: ĐỒ HỌA MÁY TÍNH 2


GIÁO VIÊN: PHAN THÁI TRUNG
SINH VIÊN: NGUYỄN HỒNG GIANG
MS: 4228.51
LỚP 51PM1




HÀ NỘI, 11/2009
Đồ Án Đồ Họa 2 2009

3
Nguyễn Hồng Giang – 4228.51 – Lớp 51PM1

Mục Lục

Mở Đầu 3

Quy trình thực hiện 4

Bước 1. Thay nhân vật. 4



Bước 2. Thay Map. 8

Bước 3. Thay và thêm Enemy. 11

Bước 4. Lưu điểm. 14

Bước 5. Preloader. 16

Bước 7. Pause / un-Pause. 17

Website đồ án 18



Mở Đầu
Đồ họa máy tính 2 mang đến cho sinh viên những kiến thức về lập trình 3d, làm
game trên các nền tảng.
Đồ án đồ họa 2, chúng em chọn làm một game flash nhỏ dựa trên platform game có sẵn.
Qua quá trình làm đồ án, chúng em đã học hỏi được thêm kiến thức về lập trình action
scripts trong flash.
Website:





4

Quy t

Bước 1
Nhân v
Lập trìn
onClip
j
/
s
h
/
s
s
h
s
/
s
X
Y


m
i

}
onCli
p
i











i





4
Nguyễn
trình thự
1. Thay n
vật trong pl
nh cho nhâ
pEvent (l
jumping =
// jumpin
speed = 0
healthX =
//sets he
scoreX =
scoreY =
healthY =
skyX = r
//sets sc
skyY = r

Xpos = th
Ypos = th
maxmove =
ispaused
root.ma
x
pEvent (e
if (Key.i
if(


} e


}
}
if ( root

if


}
Hồng Gian
ực hiện
hân vật.
atform có s
ân vật:
oad) {
= false;
ng is tru

0;
= root.h
ealthX to
root.sc
root.sc
= root.h
root.sky.
coreX to
root.sky.
his. x;
his. y;
= 15;
= false;
xshoottim
nterFrame
isDown(11
ispaused=
root.
ispau
s
lse {
root.
ispau
s
t. pause=
(this. y
root.

ng – 4228.5
sẵn được th

ue
health. x
o the sta
core. x;
core. y;
health. y
x;
the star
y;

me = 60;
e) {
12) || Ke
==true) {
pause =
sed = fal
pause
sed = tru
==false)
> Stage
.
health.t
51 – Lớp 5
hay bằng m
;
rting X
p
;
ting X p
o

y.isDown
{
false;
se;
= true;
e;
{
.height +
ext = 0;
Đồ
51PM1
một nhân vậ
postition
ostition
(80))
{
+ 100) {
Án Đồ H
http://
ật mới.
n of the
of the "
Họa 2
/www.eboo

"health"
score" M
2009
ok.edu.vn
MC

C
Đồ Án Đồ Họa 2 2009

5
Nguyễn Hồng Giang – 4228.51 – Lớp 51PM1

if (_root.health.text == 0)
{
_root.dead=true;
}
_x = Xpos-_root._x;
//sets the X pos to the starting X postition of this MC
_root.score._x = scoreX-_root._x;
_root.score._y = scoreY-_root._y;
_root.sky._x = skyX - _root._x;
_root.sky._y = skyY - _root._y;
//sets the scire MCs X pos to its starting point on the
screen
_root.health._x = healthX-_root._x;
_root.health._y = healthY-_root._y;
//sets the health MCs X pos to its starting point on the
screen
if (!_root.ground.hitTest(this._x, this._y, true) &&
!jumping) {
// if NOT hitting X and Y postion with the ground and
NOT jumping
this._y += 6;
// Y positon moves up 6
}
_global.tongdiem = _root.score.text;

if (!_root.shooting) {
// if _root.shooting is false
_root.timer = 0;
// _root.timer is set to 0
_root.mvsp = _xscale/20;
// _root.mvsp is set to the chars xscale divided by 20
// the answer to this is the speed of the bullets
}
//if (this._y > Stage.height + 100) {
//_root.stop();
//_root.gotoAndStop("loser");
//}
if (_root.dead) {
stopAllSounds();
var atDie = new Sound();
atDie.attachSound("charDie");
atDie.start(0, 1);
this.gotoAndStop("dead");
_root.health.text = 100;
} else {
speed *= .85;
if (dir == "right") {
_root.health._x += speed;
// moves the health, the opposite way to the
_root
_root.score._x += speed;
// moves the score, the opposite way to the _root
this._x += speed;
// moves the char, the opposite way to the _root
_root._x -= speed;

// moves the _root
_root.tree._x += 0.7*speed;
}
Đồ Án Đồ Họa 2 2009

6
Nguyễn Hồng Giang – 4228.51 – Lớp 51PM1

if (speed>0) {
//if speed is smaller than 0
dir = "right";
// the variable dir is set to right
} else if (speed<0) {
//if speed is greater than 0
dir = "left";
// the var dir is set to left
}
if (dir == "left" && !_root.cotmoc.hitTest(this._x-20,
this._y, true)) {
_root.health._x += speed;
_root.score._x += speed;
this._x += speed;
_root._x -= speed;
_root.tree._x += 0.7*speed;
}
if (Key.isDown(Key.LEFT)) {
// if left is pressed
if (speed>-maxmove) {
// if the speed is greater than neg.
maxmove

speed ;
// speed goes lower
}
this.gotoAndStop("run");
this._xscale = -100;

} else if (Key.isDown(Key.RIGHT)) {
if (speed<maxmove) {
// if the speed is smaller than maxmove
speed++;
// speed goes up
}
this._xscale = 100;
this.gotoAndStop("run");
} else if (Key.isDown(Key.CONTROL)) {
this.gotoAndStop("attack");
attacking = true;
speed = 0;
} else if (Key.isDown(Key.SPACE)) {
if (_root.gotgun == true && !_root.shooting) {
_root.attachMovie("bullet",
"bulleter", 1, {_x:_root.char._x, _y:_root.char._y-25});
var _banAT = new Sound();
_banAT.attachSound("sound8");
_banAT.start(0, true);

// attach the movie with the Linkage name
"bullet" to the _root at the character X position and the Y position
minus 25
_root.shooting = true;

// _root.shooting is set true
with (_root.bulleter) {
// all code below this code and it's
closer refer to _root.bulleter
Đồ Án Đồ Họa 2 2009

7
Nguyễn Hồng Giang – 4228.51 – Lớp 51PM1

onEnterFrame = function () {
if
(_root.timer>_root.maxshoottime) {
// if _root.timer is
smaller than _root.maxshoottime
_root.shooting = false;
// shooting is false
unloadMovie(this);
// this movie clip is
unloaded
}
_root.timer+=5;
// _root.timer goes up 1
_x += _root.mvsp*5;
// the X goes up _root.mvsp
(which is set constantly and stays the same when shooting.)
};
};
}
attacking = true;
// attacking is true

speed = 0;
// speed is set to 0
this.gotoAndStop("shoot");
// goto and stop on the shoot frame
}
} else if (speed<1 && speed>-1 && !attacking) {
// if speed is smaller than one and greater than
neg. 1
speed = 0;
// speed is set to 0
this.gotoAndStop("idle");
// gotoAndStop the idle frame
}
if (Key.isDown(Key.UP) && !jumping) {
// if up is pressed and NOT jumping
jumping = true;
// jumping is set true
}
if (jumping) {
// if jumping is true
this.gotoAndStop("jump");
this._y -= jump;
_root._y += 0.2 * jump;
// Y position is set down jump
jump -= .5;
// jump is set down .5
if (jump<0) {
// if jump is smaller than 0
falling = true;
// falling is true

}
if (jump<-15) {
// if jump is smaller than neg. 5
jump = -15;
// jump is set to neg 5
Đồ Án Đồ Họa 2 2009

8
Nguyễn Hồng Giang – 4228.51 – Lớp 51PM1

// capping fall speeds prevents falling
through grounds
}
}
if (_root.ground.hitTest(this._x, this._y, true) &&
falling) {
// if hitting X an Y postions with the ground and
falling
jump = 12;
// jump is set to 9
jumping = false;
// jumping is false
falling = false;
gotoAndStop("idle");
// falling is false
}
}
}
}
onClipEvent (keyUp) {

// on Key Up
if (Key.getCode() == Key.CONTROL) {
// if the release is control
attacking = false;
// attacking is false
}
if (Key.getCode() == Key.SPACE) {
gotoAndStop("idle");
}
if (Key.getCode() == Key.RIGHT) {
gotoAndStop("idle");
}
if (Key.getCode() == Key.LEFT) {
gotoAndStop("idle");
}
}

Bước 2. Thay Map.
Thay map có sẵn, thêm những chi tiết : cây, cảnh nền để làm cho game sinh động hơn.

9

9
Nguyễn Hồng Gianng – 4228.551 – Lớp 5
Đồ
51PM1
Án Đồ H
http://
Họa 2
/www.eboo


2009
ok.edu.vn


10

Cột m

Đặt tên
không đ
if (di
{



t


}

Thanh n
bờ bên
0
Nguyễn
ốc ngăn khô
n cho movie
đi được nữ
ir == "le
root.he

a
root.sco
this. x +
root. x
root.tr
e
ngang chuy
kia.
Hồng Gian
ông cho đi
e này là cot
ữa.
ft" && !
alth. x +
ore. x +=
+= speed;
-= spee
d
ee. x +=
yển động lê
ng – 4228.5
tiếp có tác
tmoc và kh
root.cot
+= speed;
= speed;

d;
0.7*spee
ên xuống g

51 – Lớp 5
dụng khóa
hi nhân vật
tmoc.hitT

d;
giúp nhân v
Đồ
51PM1
a lại map.
chạm vào
Test(this
vật có thể n
Án Đồ H
http://
tức là hitT
. x-20, t

nhảy từ bên
Họa 2
/www.eboo
Test thì nhân
this. y,
n bờ bên nà
2009
ok.edu.vn
n vật sẽ
true))
ày sang


11

Để nh
â
và nhân
onClip
d
u
d
}
onCli
p
i



root.


i



root.


i





i




}
Bước 3
Enemy
Loại 1
:



Loại 2
:
1
Nguyễn
ân vật khi đ
n vật. Nếu h
pEvent(lo
dir = "up
upstep =
downstep
pEvent(en
if(dir=="
ups
thi
if
char. y

}
if(dir=="
dow
thi
if
char. y
}
if(upstep
ups
dir
}
if(downst
dow
dir
}
3. Thay và
có 3 loại:
: bắn một p

: loại này k
Hồng Gian
đứng trên th
hitTest thì
oad) {
p";
0;
= 0;
nterFrame
"up") {
tep ;

s. y +=
-
(this.hit
+= -2;
"down") {
nstep++;
s. y +=
2
(this.hit
+= 2;
p == -100
tep = 0;
= "down
tep == 10
nstep = 0
= "up";
à thêm En
phát là chết
khởi tạo cho
ng – 4228.5
hanh ngang
di chuyển
) {
-2;
tTest( ro

2;
tTest( ro
0) {
";

00) {
0;
nemy.
t.
o chúng 50
51 – Lớp 5
g không bị r
tung độ củ
oot.char.
oot.char.
0 máu và m
Đồ
51PM1
rơi, ta sẽ k
ủa nhân vật
x, roo
x, roo
mỗi lần hitT
Án Đồ H
http://
iểm tra hitT
theo.
t.char. y
t.char. y
Test với viê
Họa 2
/www.eboo
Test của ch
y, true))
y, true))

n đạn mất
2009
ok.edu.vn
hính nó


2 máu.

12

onClip
e
e
e
e
d
m
}

onCli
p
i




i
i
































2

Nguyễn
pEvent (l
enemyspee
enemystep
enemystep
enemydir
dead = fa
mau = 50;
pEvent (e
if (Key.i
ro
if
}
if (Key.i
if (! roo
if



}

if


}
if






}
if









}
if


Hồng Gian

oad) {
ed = 2;
psright =
psleft =
= "left"
alse;
;
nterFram
e
isDown(11
ot. pause
(jumping)

isDown(11
ot. pause
(this.hit

mau -
=

(this.hi
t

mau -
=
(mau<=0)
enemy
s
enemys
enemys
dead =
this.g
(this.hit
// if
root.
// ch
a
// roo
while(

}
// ro
o

// ro
(!dead)
// if
if (e
n
ng – 4228.5
= 0;
0;
";
e) {
12) || Ke
e = true;
) root.c
11) || Ke
e) {
tTest( ro
= 1;
tTest( ro
= 2;
{
speed = 0
stepsrigh
stepsleft
= true;
gotoAndSto
tTest( ro
this hit
char.jum
p
aracters

ot.dead =
root.he
root.he
a
ot.health
oot.dead
{
NOT dead
nemydir =
51 – Lớp 5
y.isDown
;
char.goto
y.isDown
oot.char.
oot.bulle
;
t = 0;
= 0;
op("dead"
oot.char)
s the ch
a
ping = fa
jumping s
true;
alth.tex
t
alth.text
.text =

0
is set tr
= "right"
Đồ
51PM1
(80)) {
oAndStop(
(79)) r
o
attackpo
eter)) {
");
&& !dea
d
aracter a
alse;
state is
t!=0) {
-= 5;
0;
rue
") {
Án Đồ H
http://
"idle");
oot. paus
int)) {
d) {
and is no
set fals

Họa 2
/www.eboo
se = fals
ot dead
e
2009
ok.edu.vn
e;
Đồ Án Đồ Họa 2 2009

13
Nguyễn Hồng Giang – 4228.51 – Lớp 51PM1

enemystepsright += 1;
this._xscale = -100;
this._x += enemyspeed;
} else if (enemydir == "left") {
enemystepsleft += 1;
this._xscale = 100;
this._x -= enemyspeed;
}
if (enemystepsright == 100) {
enemystepsright = 0;
enemydir = "left";
} else if (enemystepsleft == 100) {
enemystepsleft = 0;
// enemystepsleft is set to 0
enemydir = "right";
}
}

}
}



14

Loại 3
:
onClip
e
e
e
e
d
m
}

Bước 4
Lưu điể
sử dụng
4
Nguyễn
: Loại này g
pEvent (l
enemyspee
enemystep
enemystep
enemydir
dead = fa

mau = 100
4. Lưu điể
ểm là một k
g PHP & M
Hồng Gian
giống loại
oad) {
ed = 2;
psright =
psleft =
= "left"
alse;
0;
ểm.
khâu cũng
MySQL hoặ
ng – 4228.5
2 nhưng có
= 0;
0;
";
rất cần thiế
ặc PHP lưu
51 – Lớp 5
ó 100 máu.

ết với các g
u vào file tx
Đồ
51PM1

.
game flash.
xt,….
Án Đồ H
http://
. Để lưu đi
Họa 2
/www.eboo
ểm thì bạn

2009
ok.edu.vn
n có thể

15

Tạo m

được đặ
Tại fram
scoreT
scoreT
scoreT
scoreT
uce.co

đoạn co
từ file s

Lưu đi


Khi bạn
lưu lại.
on(rel
i




5
Nguyễn
ột movie cl
ặt tên NAM
me high sc
Table.fil
Table.sco
Table.vie
Table.loa
om/scores
ode trên ch
scores.txt th
ểm khi bạn
n là người c
lease) {
if(! glob
sco
sco
sco
sco
Hồng Gian

lip scoreTa
ME0-NAM
ore, ta viết
ename="sc
oresize=1
wtype="F
L
adVariable
.php", "G
hỉ ra file tex
hông qua f
n đã vượt qu
chiến thắng
bal.luu)
reTable.
f
reTable.s
reTable.a
reTable.w
ng – 4228.5
able chứa cá
ME9 và SCO
t đoạn code
cores.txt
0;
LASH";
es("http:
GET");
xt lưu điểm
file scores.p

ua (chiến th
g, nhập tên
{
filename
scoresize
action =
winname =
51 – Lớp 5
ác dynamic
ORE0-SCO
e sau:
t";
://nguyen
m là scores.t
php
hắng) gam
n vào ô dyn
= "score
e = 10;
"INSERT"
= root.t
Đồ
51PM1
c text. Các
ORE9.
nhonggian
txt, kích thư
e.
namic text v
es.txt";

;
tenBan;
Án Đồ H
http://
dynamic te
g.it-
ước là mản
và nhấn sav
Họa 2
/www.eboo
ext tên và đ
ng và load d
ve, điểm sẽ
2009
ok.edu.vn
điểm
dữ liệu

ẽ được

16



uce.c
o


}



Lưu điể
Cũng tư
và tên s
scores.t
Bước 5
Thanh l
chờ đợi
không b
biến đi

6
Nguyễn
sco
sco
om/scores
gl
}
ểm khi bạn
ương tự nh
sẽ được gử
txt
5. Preload
loader biểu
i. Nếu gam
biết game h
sự nghi ng
Hồng Gian
reTable.w
reTable.l

.php", "G
obal.luu
n thua.
hư frame wi
ửi đến cho f
der.
u diễn tình
me hay file f
hay flash củ
gờ đó.

ng – 4228.5
winscore
loadVaria
GET");
= true;
in, khi bạn
file scores.p
trạng tải ga
flash của b
ủa bạn có t
51 – Lớp 5
= globa
ables("ht
nhập tên v
php và file
ame sẽ làm
ạn tương đ
tải được ha
Đồ

51PM1
al.tongdi
ttp://nguy
vào ô dynam
này sẽ làm
m cho ngườ
đối nặng, m
ay không. L
Án Đồ H
http://
em;
yenhonggi
mic text, nh
m nhiệm vụ
ời dùng cảm
mạng chậm
Lúc đó pre-
Họa 2
/www.eboo
iang.it-

hấn save th
ụ lưu điểm v
m thấy thoả
người dùn
g
-loader sẽ l
2009
ok.edu.vn
hì điểm

vào file
ải mái khi
g có thể
làm tan

17


onClip
t
t

}

onCli
p
v
v
v
t
t


i



}

Bước 7

Khi pau
Ta khai
if (Ke


i
7
Nguyễn
pEvent(lo
this.prel
this.text
root.sto
pEvent(en
var loade
var total
var perce
this.prel
this.text
if (loade
ro
got
}
7. Pause /
use, ta dừn
i báo một b
ey.isDown
root. pa
if (jumpi
Hồng Gian
oad) {

loaderBar
tLoader.t
op();
nterFrame
ed = roo
l = root
ent = loa
loaderBar
tLoader.t
ed >= tot
ot.play()
oAndStop
un-Pause
g tất cả hàn
biến _root.p
n(112) ||
ause = tr
ing) roo
ng – 4228.5
r. xscale
text = 0
)
{
ot.getByt
t.getByte
aded / to
r. xscale
text = Ma
tal) {
);

("game",
e.
nh động củ
pause
Key.isDo
rue;
ot.char.g
51 – Lớp 5
= 1;
+ "%";
esLoaded
sTotal()
tal;
= Math.
r
th.round
1);
ủa nhân vật
own(80))
otoAndSt
o
Đồ
51PM1
();
;
round(100
(percent
t, enemy .
{
op("idle"

Án Đồ H
http://
0 / total
* 100) +
");
Họa 2
/www.eboo

l * loaded
+ "%";
2009
ok.edu.vn
d);

18

}
if (K
e

Nếu nh
Nhấn p
Webs
Địa chỉ
8
Nguyễn
ey.isDown
hấn phím p
phím o hoặc
site đồ án

ỉ: http://ngu
Hồng Gian
n(111) ||
hoặc P : pa
c O: un pau
n
uyenhongg
ng – 4228.5
Key.isDo
ause,
use.
giang.it-uce

51 – Lớp 5
own(79))
e.com
-THE END
Đồ
51PM1
root. p
D
Án Đồ H
http://
ause = fa

Họa 2
/www.eboo
alse;
2009
ok.edu.vn


×