Download - Gamelogic
How can make this?
Programming Language!
Code
• printf(“Hello World”);
Code
• DrawImage( img, x, y );
Important Logic
• Game loop• Change screen• Collision detection• Status check
What is computer?
• Fast calculator
Game loop
Game loop
• It’s all of the game loop logic
Game loop
Game loop
Game loop
Game loop
Change screen
Change screen
• Simple code
Change screen
Change screen
Change screen
Change screen
Change screen
Change screen
• How can change screen?
Notice!
• Do not write code like this.• This code is not stable.• Just for showing example.
Collision detection
Collision detection
• Why check collision?
Collision detection
• Computer don’t know anything• Just have data
Collision detection
• Remember mathematics!
Collision detection
• Circle collision detection
Collision detection
• Rectangle collision detection
Collision detection
• Rectangle collision detection
boolean rectangle_collision(float x_1, float y_1, float width_1, float height_1, float x_2, float y_2, float width_2, float height_2)
{return !(x_1 > x_2+width_2 || x_1+width_1 < x_2 ||
y_1 > y_2+height_2 || y_1+height_1 < y_2);}
Collision detection
• How about button?
Collision detection
• But how about it?
Collision detection
• But how about it?
Status check
Status check
• Player is dead?
Status check
• I want to buy weapon!
Status check
• Do I have money?
Status check
• Drinking potion!
Status check
• Drinking potion!
What do you think about it?
Q n A