1 / 40

Art 315 Lecture 5

Art 315 Lecture 5. Dr. J. Parker AB 606. Last time …. We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to move left when we type aleft arrow key. That’s all. This is a program?.

alexis
Télécharger la présentation

Art 315 Lecture 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Art 315Lecture 5 Dr. J. Parker AB 606

  2. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to move left when we type aleft arrow key. That’s all.

  3. This is a program? The equivalent C code for a PC would be between 500-700 lines long. Let’s continue with the program. There are three other directions to move the ball, let’s do that first.

  4. Gamemaker Double click on the file L0401.gmk from last time and it will open in GameMaker. Now we can edit things, add new ones, and run the program.

  5. GameMaker Add event -> Key Press -> Right

  6. GameMaker Add event -> Key Press -> Up

  7. … and Down Add event -> Key Press -> Down

  8. Run the program

  9. This program is now bigger and better than a typical ‘Hello, World’, but still has very little in the way of function. Most programs in intro programming classes are, in fact, pure demonstrations, and have no other real value. They are pedagogical tools. Ours will ultimately become something else. The Program

  10. The Relative Box This determines whether the motion/direction specified is absolute or relative. If Relative is unchecked, then motion is absolute. EG Speed = 1 (unit/turn) If checked, the motion is relative to the current motion. That is, speed=1 means add 1 to the current speed.

  11. If the motions we specified are made relative, Then each time an arrow is pressed the speed will change. We can make the ball go faster and slower. Relative Well, faster, anyhow. Why can’t we make it go slower?

  12. We could make it go slower, we just asked incorrectly. What we asked for was a relative change in speed of +1 and specified a new direction. So it will go faster with each key press, but in a new direction, just as we asked. How can we get it to move slower? Slower?

  13. The combination of speed and direction change is called velocity. We can change speed by adding to the speed value. Making the speed value negative makes the ball go ‘backwards’, or in the opposite direction. (going DOWN with negative speed means going UP) Slower?

  14. So we could specify the DOWN motion as a negative change in the UP speed. We could specify RIGHT motion as a negative change in LEFT speed. Slower? Right is –ve left Down is –ve up

  15. The Result

  16. You may recall that in the Move menu there is an item for gravity. It does what you probably think – it pulls the object in a specified direction. Gravity

  17. Problem: just turning gravity on the ball will make it fall, past the bottom of the room, and forever. Let’s do it anyhow. When??? We can turn gravity on when the ball is created, in this case it will be when the program starts to run. Gravity

  18. Gravity Creation is an event. Make a new event for Create and as the action, select the gravity item. Set gravity down, and with intensity 1. When does the creation event occur? In this case, when the program starts running (green arrow pushed)

  19. Falling The ball falls. Good. It falls quickly, and passes off of the visible part of the screen. I guess this is to be expected (but did you?) Programs are often guilty of this kind of unexpected behaviour; that which could have been predicted, but which did not seem obvious. How can we keep the ball on the screen?

  20. Build a Floor We could build a floor, an object that the ball could collide with. This works as before: create a sprite (get a texture, set centre), create an object using that sprite. Then place those objects in a row along the bottom of the room. Important: make the object solid by checking the box. (ball too)

  21. The Room Looks Like This:

  22. Are we Done? Nope. If you run this program, the ball falls as before, passing right through the floor. Why? All interactions have to be specifically allowed and accounted for in a program. We did not do this.

  23. We Program A Collision With the Floor Double click on ‘obj_ball’ and select Add Event->Collision Select the obj_wall as the collision target. This will allow us to create some code to deal with a collision between the ball and the wall (floor)

  24. Collision Code What do we want to happen? The ball should stop falling, I guess. I set the vertical speed to 0. There are other ways to do this. Tell me what they are:

  25. Gravity, Balls, and such In the ‘real’ world, a ball usually bounces. Can we write a program to do that? Of course. When the ball collides with the floor, is should change Direction instead of stopping. There is a Motion item that does that. Making it seem realistic is a bit trickier.

  26. Bouncing You should play with this problem too. My solution: - Set vertical speed to -3 relative - Reverse vertical direction Why -3 relative? Because I tried -1 and -2 and it Did not seem realistic. Why reverse vertical direction? Because that’s what a bounce is. The gravity setting automatically pulls the ball down again, and so it bounces again …

  27. Bouncing

  28. What Have We Learned?(about programming, that is) We have to understand how to do it before we can write a program to do it. We can experiment with a program if we don’t know exactly what to do. Programs can do things we may not have anticipated (usually this is our fault) Programming can be fun. *(RH)

  29. Now Lets Have Some Fun It’s called ‘GameMaker’, so let’s make a game. We can make a ball move around, and ‘fall’ in simulated gravity. Sounds a bit like basketball. But perhaps we can do better. Ideas?

  30. An Opponent or Target Conflict is a key aspect of game design. I suggest a target, as an opponent is harder. Each time the ball, controlled by the player, collides with a new object, a target, then a point will be scored. Make it challenging – reverse the control directions left for right.

  31. Game Reverse control directions: Pressing left key goes right, right key goes left.

  32. Make a Target Target could be another ball-type object that moves. Or a ‘goal’-like thing. Ideas??

  33. Goal You will make your own game in the lab. Mine will have a goal, and a wall protecting it. Behind the goal is a target that moves. Quite tricky.

  34. Scores In a game, there must be some sort of goal or objective to be achieved. Often this is recognized by an increase in a value called the score. In a shooting game, for instance, the score increases whenever an opponent is shot or destroyed.

  35. Scores Because GameMaker was designed to make games, there is a built-in mechanism for keeping track of the score.

  36. Score Set Score Test score Draw score Score is a name that represents a value, the number of ‘points’ earned by the player. It can be incremented, decremented, or displayed. You get to decide how points are added/subtracted.

  37. Score

  38. Variable Score is an example of a variable. This will be the subject of the next class.

More Related