Syönti MAVittaa

Voit pyytää apua ohjelmointiongelmiin täältä.
Post Reply
mato1223
Member
Posts: 69
Joined: Sat Aug 16, 2008 12:04 pm
Location: Rääkkylä

Syönti MAVittaa

Post by mato1223 »

Nonni. Nytten kun syön pelissä ruokaa tulee MAV... Kun on "DeleteObject Food" tulee MAV kun menee syömään ruokaa.... Ja mistäköhän syystä?

Code: Select all

game:
SCREEN 800,600

y# = Rand(-400,396)
x# = Rand(-300,296)
rx# = 24
ry# = 24
mu# = -1
md# = 1
ml# = -1
mr# = 1
ct# = 0

Food = LoadObject("Food.bmp")
RNAimage = LoadImage("RNA.bmp")
ResizeImage RNAimage, rx,ry
RNAmolecyle = MakeObject()

PositionObject Food,x,y

Repeat
    
    PaintObject RNAmolecyle,-RNAimage
    
    If ObjectsOverlap(RNAmolecyle, Food, 3) Then rx = rx+5 : ry = ry+5 : ResizeImage RNAimage, rx,ry : DeleteObject Food
    If UpKey() Then MoveObject RNAmolecyle,0,mu
    If DownKey() Then MoveObject RNAmolecyle,0,md
    If LeftKey() Then MoveObject RNAmolecyle,ml
    If RightKey() Then MoveObject RNAmolecyle,mr
    
    DrawScreen
Forever

mutation:
SCREEN 800,600
w# = 0
a# = 0
s# = 10
Repeat

Color cbRed
Line 710,0,710,600
Line 790,0,790,600

Color 0,255,0
GeniticString(780,0,60,s,a)

a = a + 1
DrawScreen
Forever

Function GeniticString(px,py,w,h,a#)
r = getRGB(1) : g = getRGB(2) : b = getRGB(3)
x = px - w / 2
y = py

  For I = 1 To h
  Box x-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
  Box x+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
  Next I

  r2 = r - 60
   If r2 = < 0 Then r2 = 0
   If r2 = > 255 Then r2 = 255
  g2 = g -60
   If g2 = < 0 Then g2 = 0
   If g2 = > 255 Then g2 = 255
  b2 = b - 60
   If b2 = < 0 Then b2 = 0
   If b2 = > 255 Then b2 = 255
   Color r2,g2,b2

  For I = 1 To h
   Box x+1-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
   Box x-1-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
   Box x-1+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
   Box x+1+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
  Next I

  r5 = r - 80
   If r5 = < 0 Then r5 = 0
   If r5 = > 255 Then r5 = 255
  g5 = g - 80
   If g5 = < 0 Then g5 = 0
   If g5 = > 255 Then g5 = 255
  b5 = b - 80
   If b5 = < 0 Then b5 = 0
   If b5 = > 255 Then b5 = 255
  Color r5,g5,b5

For I = 1 To h / 40
Line  x-Cos(WrapAngle(a+(i*40)))*w/2,y+(i*40)-Sin(WrapAngle(a+(i*40)))*10,x+Cos(WrapAngle(a+(i*40)))*w/2,y+(i*40)+Sin(WrapAngle(a+(i*40)))*10
Next I
Color r,g,b

EndFunction 
Jonhu
Active Member
Posts: 186
Joined: Mon Aug 04, 2008 5:45 pm

Re: Syönti MAVittaa

Post by Jonhu »

mato1223 wrote:Nonni. Nytten kun syön pelissä ruokaa tulee MAV... Kun on "DeleteObject Food" tulee MAV kun menee syömään ruokaa.... Ja mistäköhän syystä?

Code: Select all

game:
SCREEN 800,600

y# = Rand(-400,396)
x# = Rand(-300,296)
rx# = 24
ry# = 24= Rand(-300,296)
rx# = 24
ry# = 24
mu# = -1
md# = 1
ml# = -1
mr# = 1
ct# = 0

Food = LoadObject("Food.bmp")
RNAimage = LoadImage("RNA.bmp")
ResizeImage RNAimage, rx,ry
RNAmolecyle = MakeObject()

PositionObject Food,x,y

Repeat
    
    PaintObject RNAmolecyle,-RNAimage
    
    If ObjectsOverlap(RNAmolecyle, Food, 3) Then rx = rx+5 : ry = ry+5 : ResizeImage RNAimage, rx,ry : DeleteObject Food
    If UpKey() Then MoveObject RNAmolecyle,0,mu
    If DownKey() Then MoveObject RNAmolecyle,0,md
    If LeftKey() Then MoveObject RNAmolecyle,ml
    If RightKey() Then MoveObject RNAmolecyle,mr
    
    DrawScreen
Forever

mutation:
SCREEN 800,600
w# = 0
a# = 0
s# = 10
Repeat

Color cbRed
Line 710,0,710,600
Line 790,0,790,600

Color 0,255,0
GeniticString(780,0,60,s,a)

a = a + 1
DrawScreen
Forever

Function GeniticString(px,py,w,h,a#)
r = getRGB(1) : g = getRGB(2) : b = getRGB(3)
x = px - w / 2
y = py

  For I = 1 To h
  Box x-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
  Box x+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
  Next I

  r2 = r - 60
   If r2 = < 0 Then r2 = 0
   If r2 = > 255 Then r2 = 255
  g2 = g -60
   If g2 = < 0 Then g2 = 0
   If g2 = > 255 Then g2 = 255
  b2 = b - 60
   If b2 = < 0 Then b2 = 0
   If b2 = > 255 Then b2 = 255
   Color r2,g2,b2

  For I = 1 To h
   Box x+1-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
   Box x-1-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
   Box x-1+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
   Box x+1+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
  Next I

  r5 = r - 80
   If r5 = < 0 Then r5 = 0
   If r5 = > 255 Then r5 = 255
  g5 = g - 80
   If g5 = < 0 Then g5 = 0
   If g5 = > 255 Then g5 = 255
  b5 = b - 80
   If b5 = < 0 Then b5 = 0
   If b5 = > 255 Then b5 = 255
  Color r5,g5,b5

For I = 1 To h / 40
Line  x-Cos(WrapAngle(a+(i*40)))*w/2,y+(i*40)-Sin(WrapAngle(a+(i*40)))*10,x+Cos(WrapAngle(a+(i*40)))*w/2,y+(i*40)+Sin(WrapAngle(a+(i*40)))*10
Next I
Color r,g,b
mu# = -1
md# = 1
ml# = -1
mr# = 1
ct# = 0

Food = LoadObject("Food.bmp")
RNAimage = LoadImage("RNA.bmp")
ResizeImage RNAimage, rx,ry
RNAmolecyle = MakeObject()

PositionObject Food,x,y

Repeat
    
    PaintObject RNAmolecyle,-RNAimage
    
    If ObjectsOverlap(RNAmolecyle, Food, 3) Then rx = rx+5 : ry = ry+5 : ResizeImage RNAimage, rx,ry : DeleteObject Food
    If UpKey() Then MoveObject RNAmolecyle,0,mu
    If DownKey() Then MoveObject RNAmolecyle,0,md
    If LeftKey() Then MoveObject RNAmolecyle,ml
    If RightKey() Then MoveObject RNAmolecyle,mr
    
    DrawScreen
Forever

mutation:
SCREEN 800,600
w# = 0
a# = 0
s# = 10
Repeat

Color cbRed
Line 710,0,710,600
Line 790,0,790,600

Color 0,255,0
GeniticString(780,0,60,s,a)

a = a + 1
DrawScreen
Forever

Function GeniticString(px,py,w,h,a#)
r = getRGB(1) : g = getRGB(2) : b = getRGB(3)
x = px - w / 2
y = py

  For I = 1 To h
  Box x-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
  Box x+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
  Next I

  r2 = r - 60
   If r2 = < 0 Then r2 = 0
   If r2 = > 255 Then r2 = 255
  g2 = g -60
   If g2 = < 0 Then g2 = 0
   If g2 = > 255 Then g2 = 255
  b2 = b - 60
   If b2 = < 0 Then b2 = 0
   If b2 = > 255 Then b2 = 255
   Color r2,g2,b2

  For I = 1 To h
   Box x+1-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
   Box x-1-Cos(WrapAngle(a+i))*w/2,y+i-Sin(WrapAngle(a+i))*10,1,1
   Box x-1+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
   Box x+1+Cos(WrapAngle(a+i))*w/2,y+i+Sin(WrapAngle(a+i))*10,1,1
  Next I

  r5 = r - 80
   If r5 = < 0 Then r5 = 0
   If r5 = > 255 Then r5 = 255
  g5 = g - 80
   If g5 = < 0 Then g5 = 0
   If g5 = > 255 Then g5 = 255
  b5 = b - 80
   If b5 = < 0 Then b5 = 0
   If b5 = > 255 Then b5 = 255
  Color r5,g5,b5

For I = 1 To h / 40
Line  x-Cos(WrapAngle(a+(i*40)))*w/2,y+(i*40)-Sin(WrapAngle(a+(i*40)))*10,x+Cos(WrapAngle(a+(i*40)))*w/2,y+(i*40)+Sin(WrapAngle(a+(i*40)))*10
Next I
Color r,g,b

EndFunction 

Nopeasti katsottuna vaikuttaisi, että tarkastelet food-nimistä objektia, vaikka se voidaan olla poistettu..

Code: Select all

If ObjectsOverlap(RNAmolecyle, Food, 3) Then rx = rx+5 : ry = ry+5 : ResizeImage RNAimage, rx,ry : DeleteObject Food 
Tarkista tuo vain, jos Food-objekti on olemassa..

Lisäksi, miksi maalaat joka kierros RNAmolecyle- objectin uudestaan? Tämä laskee huomattavasti FPS:ää. Paintobject komentoa ei kannata käyttää pääsilmukassa.
"PaintObject RNAmolecyle,-RNAimage"
Tekeillä pikkupelejä ja ohjelmia :)
mato1223
Member
Posts: 69
Joined: Sat Aug 16, 2008 12:04 pm
Location: Rääkkylä

Re: Syönti MAVittaa

Post by mato1223 »

Ai laskee FPS? Onko sulla huono kone vai. :) Mulla ei näy missään toi. Ja hyvinhän se näyttää mulla toimivan. ;) Ja kyllä toi Food objecti on olemassa. Ihan Food:ina.
Jonhu
Active Member
Posts: 186
Joined: Mon Aug 04, 2008 5:45 pm

Re: Syönti MAVittaa

Post by Jonhu »

mato1223 wrote:Ai laskee FPS? Onko sulla huono kone vai. :) Mulla ei näy missään toi. Ja hyvinhän se näyttää mulla toimivan. ;) Ja kyllä toi Food objecti on olemassa. Ihan Food:ina.
600Mhz läpäri itellä, mutta en minä edes voi testata tuota ohjelmaasi, kun ei ole medioita, mutta turha paintobjectin käyttö kuitenkin rasittaa turhaan konetta..

Ja if-lauseen toteutumisen jälkeen poistat food-objectin, jolloin se ei ole olemassa, mutta seuraavalla kierroksella edelleen tarkastelet sitä.. Tämä aiheuttaa mavin, jos et aijemmasta viestistä ymmärtänyt...
Tekeillä pikkupelejä ja ohjelmia :)
Post Reply