I need this tooZitat:
Zitat von Grimfate126
Printable View
I need this tooZitat:
Zitat von Grimfate126
Depends, AI is just alot of booling really. If enemy 1 walks at the speed of 1, then enemy 2 walks at speed of 2. If enemy 1Xco-Ordiante >= player1, enemy1Shooting_Function() .Zitat:
Zitat von <
^Just a HORRIBLE example lo. But you get the point. Maybe ill post a quick tut for easy AI waling around.
Its proabbly the funnesyt, and hardest part of coding. :p
Thanks an AI tutorial would be nice
guys i kinda forgot this but can anyone remember me how to make the hello appear and stay only when i pres Xthis is to make it appear while holding cross, what do i change to appear the hello and make it say after i release cross button?Code:blue=Color.new(0,200,350)
while true do
screen:clear()
pad = Controls.read()
if pad:cross() then screen:print(200, 70, "Hello!", blue) end
if pad:select() then
break
end
screen.waitVblankStart()
screen.flip()
end
ok, ill probably make a basic AI tutorial in LUA, but i dunno if my syntax will be right, so I may do it in C and convert it, but i dunno stilll. What kind of AI are you looking for? Aimlessly walking around AI? If the enemy is looking toward your direction have him fire or what? ya know, just look at a pong exmaple i guess. But AI isnt really tat hard, its just alot of bools/if statements.
Now, this is a pathetic atempt to give you all a general idea of AI. Since my LUA is rusty, bare with me. This is an exmaple of using bools and if statements to make a simple player1 and enemyAI interaction.Code:AIenemy = Image.load("AIenemy.png") --Line 1
Player1 = Image.load("Player1.png") -- Line 2
AIenemyX = 1 --3
AIenemyY = 240 --4
Player1x = 440 --5
Player1y = 240 --6
AIenemyWalking = 3 --7
AIenemyCharging = 7 --8
Seen_distance = 125 --9
Seen_flag=false --10
while true do --11
screen:blit(blit Player1 to co-ordinates Player1x & y) -- 12
screen:blit(blit AIenemy to co-ordinates AienemyX & Y) --13
if AIenemyX>Player1x-Seen_distance and AIenemyX<Player1x then Seen_flag=true --14
else if AIenemyX<Player1x-Seen_distance then Seen_flag=false --15
else if AIenemyX==Player1x then Seen_flag=NULL --16
elseif Seen_flag==false then AIenemyX=AIenemyX+AIenemyWalking --17
else if Seen_flag==true then AIenemyX=AIenemyX+AIenemyCharging --18
else if Seen_flag==NULL then --19
AIenemyX=AIenemyX+0 --20
screen: print(10, 10, "The Enemy has Charged and hit you Player1!", Color.new(120, 120, 120)) --21
end --22
end --23
Now i know this is crappy, but its just to show some pople what AI really is. Plus I wrote this in about 10 minutes. There are probably some LUA syntax or mispelled errors in there.
- Load our Enemy Image to put AI on
- Load our player1 Image to get abused by AI
- Define the Enemy's X Co-Ordinate
- Define the Enemy's Y Co-ordinate
- Define the Player1;s X Co-Ordinate
- Define the Player1's Y Co-Ordinate
- Define the Enemy's Walking Speed (3)
- Define the Enemy's Charging/Running Speed (7)
- Define the Enemy's Sight Distance
- Create a 'flag' to indicate what our Enemy's AI state is at
- While 1 = true, keep looping, and 1 = true, so infinte loop
- Blit the Player1 Image to the Co-Ordinates: (Player1x, Player1y)
- Blit the Enemy Image to the Co-ordianates: (AIenemyX, AIenemyY)
- Specify that if the Enemy's X co-ordinate gets too close to player1's X co-ordinate, by the Seen_distance integer, then change the Seen_flag from false, meaning no it cant see the player, to true, it can see it. please note how i put an extra 'and' statement in there. This is to say that while the Enemy is within the pixel range of 1 - 125 of Player1, he'll charge. the Pixel range shouldnt be 0-125, or else the Seen_flag will both = NULL and true, thus causing an exception handler (in C). Thats becasue Player1x and the range 0-125 have Player1x's value in there. That is the 0 pixel distance from the Enemy.
- ^ Complete opposite, if the Enemy's X co-ordinate is farther then its sight of view, Seen_distance, then the Seen_flag is false, since it cannot see it, thus setting up for the effect, now that we have a trigger.
- This is saying that if the Enemy's X Co-ord matches Player1's, then the Seen_flag=NULL. this is just used to link towards an effect, now that its a trigger. You can rename NULL, to collision_encountered, or w/e.
- Now that we have our triggers linked to the correct 'variable', lets substitue those variables with effects/actions shall we? this line here is saying that if our 'Seen_flag' flag/variable is triggered to = true, then the Enemy can see Player1, and will now start charging by changing the X increase speed to 7 (AIenemyCharging) from 3 (AIenemyWalking).
- ^ Opposite of above. if our 'Seen_flag' flag is linked/changed to 'false' then the Enemy cannot see player1, therefore he is not running, maintaining his walking speed (3).
- This is the 'collision' effect. It is very crappy for i am too lazy to re-convert my C collision to LUA for a simple tut. This means if our 'Seen_flag' flag is triggered towards/to NULL, then we know the Enemy and Player1 have collided.
- Therefore we dont want the Enemy to keep running by, we want him to stop/halt. That is why the running speed of the Enemy = 0, so he stops. P.S. i would have included the AIenemyHalt variable for when collided, but i do not want to re-order this list to accomadate to the small change in 1 line :p
- Now we can add a little more touch to our game demo type thing. When collided, it will print to the screen "The Enemy has Charged and hit you Player1!" Since well, this is true cause the enemy did collide with Player1, so it shall print the truth :mrgreen:
- Now Simply Close your only 'if' statement that actually needs you to close it. ('elseif' has an end built in)
- now just Close our infinite loop and walaa
Hope this helps somebody! Now you cna look at Halo 2 and be like... That hunter saw me from an X co-ordinate of 'insert#here' Thats cause Bungie has somewhat of the same concept of this tut. (P.S. That is not including the Y and Z co-ordinates also when detecting presense of a player via AI)
~SG57
help me pls.
I want to make my program to change to the 2nd background when I select "Click Here to Start" with the arrow and press start. the code bellow gives error =/Code:screen:print(200, 136, "Click Here to Start", red)
if pad:start() then letterPosx >= 200 and letterPosx <= 220 and letterPosy >= 136 and letterPosy <= 150 = screen:blit(0,0, blank)
end
can somebody help?
and also, how can i make the arrow that i m controlling with nub stop moving at certain point, becuase so it will freeze when it tryies to get out of the screen
all you need to do is change if pad:starts()... to
if pad:start() and letterposx >=200 and letterPosx <= 220 and letterPosy >= 136 and letterposy <= 150 then
screen:blit(0, 0, blank)
end
can you rotate/flip images or text in lua?
oh, and good mini AI tut SG57
dint work, it gave me an error when i press start :(Zitat:
Zitat von brtn_cruzer
anyways, if "if pad:start() then screen:blit(0,0, blank)
end" make the screen blank with an image while holding start, how can i make it blank pressing start only 1 time ?
umm what does this error mean?
Code:
method must be called with a colon!